Skip to content

Commit 4634f23

Browse files
committed
rustc: Add some missing cases to ty.rs for interior vectors, and modify the pattern match so this is less likely to happen again. Add the LLVM type mapping as well.
1 parent d8b271e commit 4634f23

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/comp/middle/trans.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,25 @@ fn T_opaque_vec_ptr() -> TypeRef {
560560
ret T_ptr(T_vec(T_int()));
561561
}
562562

563+
// Interior vector.
564+
//
565+
// TODO: Support user-defined vector sizes.
566+
fn T_ivec(TypeRef t) -> TypeRef {
567+
ret T_struct([T_int(), // Length ("fill")
568+
T_int(), // Alloc (if zero, it's heapified)
569+
T_array(t, 16u) // Body elements
570+
]);
571+
}
572+
573+
// Interior vector on the heap. Cast to this when the allocated length (second
574+
// element of T_ivec above) is zero.
575+
fn T_ivec_heap(TypeRef t) -> TypeRef {
576+
ret T_struct([T_int(), // Length ("fill")
577+
T_int(), // Alloc (zero in this case)
578+
T_ptr(T_struct([T_int(), // Real alloc
579+
T_array(t, 0u)]))]); // Body elements
580+
}
581+
563582
fn T_str() -> TypeRef {
564583
ret T_vec(T_i8());
565584
}
@@ -834,6 +853,7 @@ fn type_of_inner(&@crate_ctxt cx, &span sp, &ty::t t) -> TypeRef {
834853
}
835854
case (ty::ty_char) { llty = T_char(); }
836855
case (ty::ty_str) { llty = T_ptr(T_str()); }
856+
case (ty::ty_istr) { llty = T_ivec(T_i8()); }
837857
case (ty::ty_tag(_, _)) {
838858
if (ty::type_has_dynamic_size(cx.tcx, t)) {
839859
llty = T_opaque_tag(cx.tn);
@@ -848,6 +868,9 @@ fn type_of_inner(&@crate_ctxt cx, &span sp, &ty::t t) -> TypeRef {
848868
case (ty::ty_vec(?mt)) {
849869
llty = T_ptr(T_vec(type_of_inner(cx, sp, mt.ty)));
850870
}
871+
case (ty::ty_ivec(?mt)) {
872+
llty = T_ivec(type_of_inner(cx, sp, mt.ty));
873+
}
851874
case (ty::ty_ptr(?mt)) {
852875
llty = T_ptr(type_of_inner(cx, sp, mt.ty));
853876
}

src/comp/middle/ty.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,20 @@ fn mk_raw_ty(&ctxt cx, &sty st, &option::t[str] cname) -> raw_t {
295295
}
296296

297297
alt (st) {
298+
case (ty_nil) { /* no-op */ }
299+
case (ty_bot) { /* no-op */ }
300+
case (ty_bool) { /* no-op */ }
301+
case (ty_int) { /* no-op */ }
302+
case (ty_float) { /* no-op */ }
303+
case (ty_uint) { /* no-op */ }
304+
case (ty_machine(_)) { /* no-op */ }
305+
case (ty_char) { /* no-op */ }
306+
case (ty_str) { /* no-op */ }
307+
case (ty_istr) { /* no-op */ }
308+
case (ty_task) { /* no-op */ }
309+
case (ty_type) { /* no-op */ }
310+
case (ty_native) { /* no-op */ }
311+
298312
case (ty_param(_)) {
299313
has_params = true;
300314
}
@@ -312,6 +326,10 @@ fn mk_raw_ty(&ctxt cx, &sty st, &option::t[str] cname) -> raw_t {
312326
derive_flags_mt(cx, has_params, has_vars, m);
313327
}
314328

329+
case (ty_ivec(?m)) {
330+
derive_flags_mt(cx, has_params, has_vars, m);
331+
}
332+
315333
case (ty_port(?tt)) {
316334
derive_flags_t(cx, has_params, has_vars, tt);
317335
}
@@ -346,7 +364,6 @@ fn mk_raw_ty(&ctxt cx, &sty st, &option::t[str] cname) -> raw_t {
346364
m.output);
347365
}
348366
}
349-
case (_) { }
350367
}
351368

352369
ret rec(struct=st, cname=cname, hash=h,
@@ -581,6 +598,7 @@ fn fold_ty(&ctxt cx, fold_mode fld, t ty_0) -> t {
581598
case (ty_machine(_)) { /* no-op */ }
582599
case (ty_char) { /* no-op */ }
583600
case (ty_str) { /* no-op */ }
601+
case (ty_istr) { /* no-op */ }
584602
case (ty_type) { /* no-op */ }
585603
case (ty_native) { /* no-op */ }
586604
case (ty_task) { /* no-op */ }
@@ -596,6 +614,10 @@ fn fold_ty(&ctxt cx, fold_mode fld, t ty_0) -> t {
596614
ty = copy_cname(cx, mk_vec(cx, rec(ty=fold_ty(cx, fld, tm.ty),
597615
mut=tm.mut)), ty);
598616
}
617+
case (ty_ivec(?tm)) {
618+
ty = copy_cname(cx, mk_ivec(cx, rec(ty=fold_ty(cx, fld, tm.ty),
619+
mut=tm.mut)), ty);
620+
}
599621
case (ty_port(?subty)) {
600622
ty = copy_cname(cx, mk_port(cx, fold_ty(cx, fld, subty)), ty);
601623
}

0 commit comments

Comments
 (0)