Skip to content

Commit ede42cf

Browse files
committed
A certain incomplete quantity of wrestling with "INIT" statements that don't actually initialize. Should probably rename them to MAKE. Anyway, WIP, but two steps forward (and one back). More later.
1 parent c6af9dd commit ede42cf

File tree

3 files changed

+82
-31
lines changed

3 files changed

+82
-31
lines changed

src/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ TEST_XFAILS_X86 := test/run-pass/bind-obj-ctor.rs \
357357
test/run-pass/vec-slice.rs \
358358
test/run-pass/fn-lval.rs \
359359
test/run-pass/generic-fn-infer.rs \
360+
test/run-pass/generic-tag-alt.rs \
360361
test/run-pass/generic-recursive-tag.rs \
361362
test/run-pass/iter-ret.rs \
362363
test/run-pass/mlist-cycle.rs \
@@ -387,6 +388,7 @@ TEST_XFAILS_LLVM := $(addprefix test/run-pass/, \
387388
bind-thunk.rs \
388389
bind-trivial.rs \
389390
bitwise.rs \
391+
box-in-tup.rs \
390392
box-unbox.rs \
391393
cast.rs \
392394
clone-with-exterior.rs \
@@ -476,6 +478,7 @@ TEST_XFAILS_LLVM := $(addprefix test/run-pass/, \
476478
vec-append.rs \
477479
vec-concat.rs \
478480
vec-drop.rs \
481+
vec-in-tup.rs \
479482
vec-late-init.rs \
480483
vec-lib.rs \
481484
vec-slice.rs \

src/boot/me/trans.ml

Lines changed: 76 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,12 +1248,16 @@ let trans_visitor
12481248
(sorted_htab_keys fns))
12491249
end
12501250

1251-
and trans_init_str (dst:Ast.lval) (s:string) : unit =
1251+
and trans_init_str (initializing:bool) (dst:Ast.lval) (s:string) : unit =
12521252
(* Include null byte. *)
12531253
let init_sz = Int64.of_int ((String.length s) + 1) in
12541254
let static = trans_static_string s in
1255-
let (dst, _) = trans_lval_init dst in
1256-
trans_upcall "upcall_new_str" dst [| static; imm init_sz |]
1255+
let (dst_cell, dst_ty) = trans_lval_maybe_init initializing dst in
1256+
let _ =
1257+
if not initializing
1258+
then drop_ty_in_current_frame dst_cell dst_ty
1259+
in
1260+
trans_upcall "upcall_new_str" dst_cell [| static; imm init_sz |]
12571261

12581262
and trans_lit (lit:Ast.lit) : Il.operand =
12591263
match lit with
@@ -2220,22 +2224,33 @@ let trans_visitor
22202224
trans_atom (Ast.ATOM_lval chan) |];
22212225
end
22222226

2223-
and trans_init_port (dst:Ast.lval) : unit =
2224-
let (dstcell, dst_ty) = trans_lval_init dst in
2227+
and trans_init_port (initializing:bool) (dst:Ast.lval) : unit =
2228+
let (dst_cell, dst_ty) = trans_lval_maybe_init initializing dst in
2229+
let _ =
2230+
if not initializing
2231+
then drop_ty_in_current_frame dst_cell dst_ty
2232+
in
22252233
let unit_ty = match dst_ty with
22262234
Ast.TY_port t -> t
22272235
| _ -> bug () "init dst of port-init has non-port type"
22282236
in
22292237
let unit_sz = ty_sz abi unit_ty in
2230-
trans_upcall "upcall_new_port" dstcell [| imm unit_sz |]
2238+
trans_upcall "upcall_new_port" dst_cell [| imm unit_sz |]
22312239

22322240
and trans_del_port (port:Il.cell) : unit =
22332241
trans_void_upcall "upcall_del_port" [| Il.Cell port |]
22342242

2235-
and trans_init_chan (dst:Ast.lval) (port:Ast.lval) : unit =
2236-
let (dstcell, _) = trans_lval_init dst
2243+
and trans_init_chan
2244+
(initializing:bool)
2245+
(dst:Ast.lval)
2246+
(port:Ast.lval)
2247+
: unit =
2248+
let (dst_cell, dst_ty) = trans_lval_maybe_init initializing dst in
2249+
let _ =
2250+
if not initializing
2251+
then drop_ty_in_current_frame dst_cell dst_ty
22372252
in
2238-
trans_upcall "upcall_new_chan" dstcell
2253+
trans_upcall "upcall_new_chan" dst_cell
22392254
[| trans_atom (Ast.ATOM_lval port) |]
22402255

22412256
and trans_del_chan (chan:Il.cell) : unit =
@@ -2258,8 +2273,16 @@ let trans_visitor
22582273
* part out for reuse in string code.
22592274
*)
22602275

2261-
and trans_init_vec (dst:Ast.lval) (atoms:Ast.atom array) : unit =
2262-
let (dst_cell, dst_ty) = trans_lval_init dst in
2276+
and trans_init_vec
2277+
(initializing:bool)
2278+
(dst:Ast.lval)
2279+
(atoms:Ast.atom array)
2280+
: unit =
2281+
let (dst_cell, dst_ty) = trans_lval_maybe_init initializing dst in
2282+
let _ =
2283+
if not initializing
2284+
then drop_ty_in_current_frame dst_cell dst_ty
2285+
in
22632286
let gc_ctrl =
22642287
if (ty_mem_ctrl dst_ty) = MEM_gc
22652288
then Il.Cell (get_tydesc None dst_ty)
@@ -2292,17 +2315,26 @@ let trans_visitor
22922315
mov (get_element_ptr vec Abi.vec_elt_fill) (Il.Cell fill);
22932316

22942317

2295-
and trans_init_box (dst:Ast.lval) (src:Ast.atom) : unit =
2318+
and trans_init_box
2319+
(initializing:bool)
2320+
(dst:Ast.lval)
2321+
(src:Ast.atom)
2322+
: unit =
22962323
let src_op = trans_atom src in
22972324
let src_cell = Il.Mem (force_to_mem src_op) in
22982325
let src_ty = simplified_ty (atom_type cx src) in
2299-
let dst_sloti = lval_base_to_slot cx dst in
2300-
let dst_cell = cell_of_block_slot dst_sloti.id in
2301-
let dst_cell = deref_slot true dst_cell dst_sloti.node in
2302-
let dst_ty = slot_ty dst_sloti.node in
2326+
let (dst_cell, dst_ty) = trans_lval_maybe_init initializing dst in
2327+
let _ =
2328+
if not initializing
2329+
then drop_ty_in_current_frame dst_cell dst_ty
2330+
in
2331+
let dst_ty = strip_mutable_or_constrained_ty dst_ty in
23032332
let (dst_cell, dst_ty) =
23042333
deref_ty DEREF_one_box true dst_cell dst_ty
23052334
in
2335+
let _ = log cx "init_box: dst ty %a, src ty %a"
2336+
Ast.sprintf_ty dst_ty Ast.sprintf_ty src_ty
2337+
in
23062338
let _ = assert (dst_ty = src_ty) in
23072339
trans_copy_ty (get_ty_params_of_current_frame()) true
23082340
dst_cell dst_ty src_cell src_ty None
@@ -2868,6 +2900,12 @@ let trans_visitor
28682900
: unit =
28692901
drop_slot (get_ty_params_of_current_frame()) cell slot curr_iso
28702902

2903+
and drop_ty_in_current_frame
2904+
(cell:Il.cell)
2905+
(ty:Ast.ty)
2906+
: unit =
2907+
drop_ty (get_ty_params_of_current_frame()) cell ty None
2908+
28712909
and null_check (cell:Il.cell) : quad_idx =
28722910
emit (Il.cmp (Il.Cell cell) zero);
28732911
let j = mark() in
@@ -4338,7 +4376,7 @@ let trans_visitor
43384376

43394377

43404378
and trans_copy_binop dst binop a_src =
4341-
let (dst_cell, dst_ty) = trans_lval_maybe_init false dst in
4379+
let (dst_cell, dst_ty) = trans_lval dst in
43424380
let src_oper = trans_atom a_src in
43434381
match dst_ty with
43444382
Ast.TY_str
@@ -4440,15 +4478,15 @@ let trans_visitor
44404478
end
44414479

44424480
| Ast.STMT_init_rec (dst, atab, base) ->
4443-
let (slot_cell, ty) = trans_lval_init dst in
4481+
let init = maybe_init stmt.id "rec-init" dst in
4482+
let (dst_cell, ty) = trans_lval_maybe_init init dst in
44444483
let (trec, dst_tys) =
44454484
match ty with
44464485
Ast.TY_rec trec -> (trec, Array.map snd trec)
44474486
| _ ->
44484487
bugi cx stmt.id
44494488
"non-rec destination type in stmt_init_rec"
44504489
in
4451-
let (dst_cell, _) = deref_ty DEREF_none true slot_cell ty in
44524490
begin
44534491
match base with
44544492
None ->
@@ -4461,42 +4499,52 @@ let trans_visitor
44614499
end
44624500

44634501
| Ast.STMT_init_tup (dst, elems) ->
4464-
let (slot_cell, ty) = trans_lval_init dst in
4502+
let init = maybe_init stmt.id "tup-init" dst in
4503+
let (dst_cell, dst_ty) = trans_lval_maybe_init init dst in
4504+
let _ =
4505+
if not init
4506+
then drop_ty_in_current_frame dst_cell dst_ty
4507+
in
44654508
let dst_tys =
4466-
match ty with
4509+
match dst_ty with
44674510
Ast.TY_tup ttup -> ttup
44684511
| _ ->
44694512
bugi cx stmt.id
44704513
"non-tup destination type in stmt_init_tup"
44714514
in
44724515
let atoms = Array.map snd elems in
4473-
let (dst_cell, _) = deref_ty DEREF_none true slot_cell ty in
4516+
let (dst_cell, _) = deref_ty DEREF_none init dst_cell dst_ty in
44744517
trans_init_structural_from_atoms dst_cell dst_tys atoms
44754518

44764519

44774520
| Ast.STMT_init_str (dst, s) ->
4478-
trans_init_str dst s
4521+
let init = maybe_init stmt.id "str-init" dst in
4522+
trans_init_str init dst s
44794523

44804524
| Ast.STMT_init_vec (dst, _, atoms) ->
4481-
trans_init_vec dst atoms
4525+
let init = maybe_init stmt.id "vec-init" dst in
4526+
trans_init_vec init dst atoms
44824527

44834528
| Ast.STMT_init_port dst ->
4484-
trans_init_port dst
4529+
let init = maybe_init stmt.id "port-init" dst in
4530+
trans_init_port init dst
44854531

44864532
| Ast.STMT_init_chan (dst, port) ->
4533+
let init = maybe_init stmt.id "chan-init" dst in
44874534
begin
44884535
match port with
44894536
None ->
44904537
let (dst_cell, _) =
4491-
trans_lval_init dst
4538+
trans_lval_maybe_init init dst
44924539
in
44934540
mov dst_cell imm_false
44944541
| Some p ->
4495-
trans_init_chan dst p
4542+
trans_init_chan init dst p
44964543
end
44974544

44984545
| Ast.STMT_init_box (dst, _, src) ->
4499-
trans_init_box dst src
4546+
let init = maybe_init stmt.id "box-init" dst in
4547+
trans_init_box init dst src
45004548

45014549
| Ast.STMT_block block ->
45024550
trans_block block

src/test/run-pass/mlist-cycle.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ type cell = tup(mutable @list);
66
type list = tag(link(@cell), nil());
77

88
fn main() {
9-
let @cell first = tup(@nil());
10-
let @cell second = tup(@link(first));
9+
let @cell first = @tup(mutable @nil());
10+
let @cell second = @tup(mutable @link(first));
1111
first._0 = @link(second);
1212
std.sys.rustrt.gc();
13-
let @cell third = tup(@nil());
13+
let @cell third = @tup(mutable @nil());
1414
}

0 commit comments

Comments
 (0)