Rename STMT_init_* to STMT_new_*; former name was confusing.

This commit is contained in:
Graydon Hoare 2010-07-23 11:37:38 -07:00
parent 1730d2e037
commit 4d4fa99b31
8 changed files with 108 additions and 120 deletions

View File

@ -200,13 +200,13 @@ and stmt' =
(* lval-assigning stmts. *)
STMT_spawn of (lval * domain * lval * (atom array))
| STMT_init_rec of (lval * (rec_input array) * lval option)
| STMT_init_tup of (lval * (tup_input array))
| STMT_init_vec of (lval * mutability * atom array)
| STMT_init_str of (lval * string)
| STMT_init_port of lval
| STMT_init_chan of (lval * (lval option))
| STMT_init_box of (lval * mutability * atom)
| STMT_new_rec of (lval * (rec_input array) * lval option)
| STMT_new_tup of (lval * (tup_input array))
| STMT_new_vec of (lval * mutability * atom array)
| STMT_new_str of (lval * string)
| STMT_new_port of lval
| STMT_new_chan of (lval * (lval option))
| STMT_new_box of (lval * mutability * atom)
| STMT_copy of (lval * expr)
| STMT_copy_binop of (lval * binop * atom)
| STMT_call of (lval * lval * (atom array))
@ -1028,7 +1028,7 @@ and fmt_stmt_body (ff:Format.formatter) (s:stmt) : unit =
| STMT_decl (DECL_mod_item (ident, item)) ->
fmt_mod_item ff ident item
| STMT_init_rec (dst, entries, base) ->
| STMT_new_rec (dst, entries, base) ->
fmt_lval ff dst;
fmt ff " = rec(";
for i = 0 to (Array.length entries) - 1
@ -1050,7 +1050,7 @@ and fmt_stmt_body (ff:Format.formatter) (s:stmt) : unit =
end;
fmt ff ");"
| STMT_init_vec (dst, mutability, atoms) ->
| STMT_new_vec (dst, mutability, atoms) ->
fmt_lval ff dst;
fmt ff " = vec";
if mutability = MUT_mutable then fmt ff "[mutable]";
@ -1063,7 +1063,7 @@ and fmt_stmt_body (ff:Format.formatter) (s:stmt) : unit =
done;
fmt ff ");"
| STMT_init_tup (dst, entries) ->
| STMT_new_tup (dst, entries) ->
fmt_lval ff dst;
fmt ff " = tup(";
for i = 0 to (Array.length entries) - 1
@ -1076,15 +1076,15 @@ and fmt_stmt_body (ff:Format.formatter) (s:stmt) : unit =
done;
fmt ff ");";
| STMT_init_str (dst, s) ->
| STMT_new_str (dst, s) ->
fmt_lval ff dst;
fmt ff " = \"%s\"" (String.escaped s)
| STMT_init_port dst ->
| STMT_new_port dst ->
fmt_lval ff dst;
fmt ff " = port();"
| STMT_init_chan (dst, port_opt) ->
| STMT_new_chan (dst, port_opt) ->
fmt_lval ff dst;
fmt ff " = chan(";
begin
@ -1188,7 +1188,7 @@ and fmt_stmt_body (ff:Format.formatter) (s:stmt) : unit =
fmt_lval ff t;
fmt ff ";"
| STMT_init_box (lv, mutability, at) ->
| STMT_new_box (lv, mutability, at) ->
fmt_lval ff lv;
fmt ff " = @@";
if mutability = MUT_mutable then fmt ff " mutable ";

View File

@ -1008,7 +1008,7 @@ let expand_pexp_custom
ignore (Unix.close_process_in c);
Buffer.contents b
in
[| spanner (Ast.STMT_init_str (dst_lval, r())) |]
[| spanner (Ast.STMT_new_str (dst_lval, r())) |]
| _ ->
raise (err ("unknown syntax extension: " ^ nstr) ps)
@ -1018,7 +1018,7 @@ let expand_pexp_custom
* Desugarings depend on context:
*
* - If a pexp is used on the RHS of an assignment, it's turned into
* an initialization statement such as STMT_init_rec or such. This
* an initialization statement such as STMT_new_rec or such. This
* removes the possibility of initializing into a temp only to
* copy out. If the topmost pexp in such a desugaring is an atom,
* unop or binop, of course, it will still just emit a STMT_copy
@ -1265,13 +1265,13 @@ and desugar_expr_init
Some base ->
let (base_stmts, base_lval) = desugar_lval ps base in
let rec_stmt =
ss (Ast.STMT_init_rec
ss (Ast.STMT_new_rec
(dst_lval, entries, Some base_lval))
in
ac [ arg_stmts; base_stmts; [| rec_stmt |] ]
| None ->
let rec_stmt =
ss (Ast.STMT_init_rec (dst_lval, entries, None))
ss (Ast.STMT_new_rec (dst_lval, entries, None))
in
aa arg_stmts [| rec_stmt |]
end
@ -1283,22 +1283,22 @@ and desugar_expr_init
in
let arg_atoms = Array.to_list arg_atoms in
let tup_args = Array.of_list (List.combine muts arg_atoms) in
let stmt = ss (Ast.STMT_init_tup (dst_lval, tup_args)) in
let stmt = ss (Ast.STMT_new_tup (dst_lval, tup_args)) in
aa arg_stmts [| stmt |]
| PEXP_str s ->
let stmt = ss (Ast.STMT_init_str (dst_lval, s)) in
let stmt = ss (Ast.STMT_new_str (dst_lval, s)) in
[| stmt |]
| PEXP_vec (mutability, args) ->
let (arg_stmts, arg_atoms) = desugar_expr_atoms ps args in
let stmt =
ss (Ast.STMT_init_vec (dst_lval, mutability, arg_atoms))
ss (Ast.STMT_new_vec (dst_lval, mutability, arg_atoms))
in
aa arg_stmts [| stmt |]
| PEXP_port ->
[| ss (Ast.STMT_init_port dst_lval) |]
[| ss (Ast.STMT_new_port dst_lval) |]
| PEXP_chan pexp_opt ->
let (port_stmts, port_opt) =
@ -1315,7 +1315,7 @@ and desugar_expr_init
in
let chan_stmt =
ss
(Ast.STMT_init_chan (dst_lval, port_opt))
(Ast.STMT_new_chan (dst_lval, port_opt))
in
aa port_stmts [| chan_stmt |]
@ -1324,7 +1324,7 @@ and desugar_expr_init
desugar_expr_atom ps arg
in
let stmt =
ss (Ast.STMT_init_box (dst_lval, mutability, arg_mode_atom))
ss (Ast.STMT_new_box (dst_lval, mutability, arg_mode_atom))
in
aa arg_stmts [| stmt |]

View File

@ -925,7 +925,7 @@ let trans_crate
set_debug_loc head.id;
match head.node with
Ast.STMT_init_tup (dest, elems) ->
Ast.STMT_new_tup (dest, elems) ->
let zero = const_i32 0 in
let (lldest, _) = trans_lval dest in
let trans_tup_elem idx (_, atom) =
@ -1025,7 +1025,7 @@ let trans_crate
ignore (Llvm.build_cond_br llexpr llok llfail llbuilder);
trans_tail_with_builder llokbuilder
| Ast.STMT_init_str (dst, str) ->
| Ast.STMT_new_str (dst, str) ->
let (d, _) = trans_lval dst in
let s = static_str str in
let len =

View File

@ -65,10 +65,10 @@ let alias_analysis_visitor
| Ast.STMT_send (_, src) -> alias src
| Ast.STMT_recv (dst, _) -> alias dst
| Ast.STMT_init_port (dst) -> alias dst
| Ast.STMT_init_chan (dst, _) -> alias dst
| Ast.STMT_init_vec (dst, _, _) -> alias dst
| Ast.STMT_init_str (dst, _) -> alias dst
| Ast.STMT_new_port (dst) -> alias dst
| Ast.STMT_new_chan (dst, _) -> alias dst
| Ast.STMT_new_vec (dst, _, _) -> alias dst
| Ast.STMT_new_str (dst, _) -> alias dst
| Ast.STMT_for_each sfe ->
let (slot, _) = sfe.Ast.for_each_slot in
alias_slot slot.id

View File

@ -1250,15 +1250,16 @@ let trans_visitor
(sorted_htab_keys fns))
end
and trans_init_str (initializing:bool) (dst:Ast.lval) (s:string) : unit =
and drop_existing_if_not_init init cell ty =
if not init
then drop_ty_in_current_frame cell ty
and trans_new_str (initializing:bool) (dst:Ast.lval) (s:string) : unit =
(* Include null byte. *)
let init_sz = Int64.of_int ((String.length s) + 1) in
let static = trans_static_string s in
let (dst_cell, dst_ty) = trans_lval_maybe_init initializing dst in
let _ =
if not initializing
then drop_ty_in_current_frame dst_cell dst_ty
in
drop_existing_if_not_init initializing dst_cell dst_ty;
trans_upcall "upcall_new_str" dst_cell [| static; imm init_sz |]
and trans_lit (lit:Ast.lit) : Il.operand =
@ -2236,32 +2237,26 @@ let trans_visitor
trans_atom (Ast.ATOM_lval chan) |];
end
and trans_init_port (initializing:bool) (dst:Ast.lval) : unit =
and trans_new_port (initializing:bool) (dst:Ast.lval) : unit =
let (dst_cell, dst_ty) = trans_lval_maybe_init initializing dst in
let _ =
if not initializing
then drop_ty_in_current_frame dst_cell dst_ty
in
let unit_ty = match dst_ty with
Ast.TY_port t -> t
| _ -> bug () "init dst of port-init has non-port type"
in
let unit_sz = ty_sz abi unit_ty in
drop_existing_if_not_init initializing dst_cell dst_ty;
trans_upcall "upcall_new_port" dst_cell [| imm unit_sz |]
and trans_del_port (port:Il.cell) : unit =
trans_void_upcall "upcall_del_port" [| Il.Cell port |]
and trans_init_chan
and trans_new_chan
(initializing:bool)
(dst:Ast.lval)
(port:Ast.lval)
: unit =
let (dst_cell, dst_ty) = trans_lval_maybe_init initializing dst in
let _ =
if not initializing
then drop_ty_in_current_frame dst_cell dst_ty
in
drop_existing_if_not_init initializing dst_cell dst_ty;
trans_upcall "upcall_new_chan" dst_cell
[| trans_atom (Ast.ATOM_lval port) |]
@ -2285,16 +2280,12 @@ let trans_visitor
* part out for reuse in string code.
*)
and trans_init_vec
and trans_new_vec
(initializing:bool)
(dst:Ast.lval)
(atoms:Ast.atom array)
: unit =
let (dst_cell, dst_ty) = trans_lval_maybe_init initializing dst in
let _ =
if not initializing
then drop_ty_in_current_frame dst_cell dst_ty
in
let gc_ctrl =
if (ty_mem_ctrl dst_ty) = MEM_gc
then Il.Cell (get_tydesc None dst_ty)
@ -2306,6 +2297,7 @@ let trans_visitor
in
let fill = next_vreg_cell word_sty in
let unit_sz = ty_sz_in_current_frame unit_ty in
drop_existing_if_not_init initializing dst_cell dst_ty;
umul fill unit_sz (imm (Int64.of_int (Array.length atoms)));
trans_upcall "upcall_new_vec" dst_cell [| Il.Cell fill; gc_ctrl |];
let vec = deref dst_cell in
@ -2327,7 +2319,7 @@ let trans_visitor
mov (get_element_ptr vec Abi.vec_elt_fill) (Il.Cell fill);
and trans_init_box
and trans_new_box
(initializing:bool)
(dst:Ast.lval)
(src:Ast.atom)
@ -2337,8 +2329,7 @@ let trans_visitor
let src_ty = simplified_ty (atom_type cx src) in
let (dst_cell, dst_ty) = trans_lval_maybe_init initializing dst in
let _ =
if not initializing
then drop_ty_in_current_frame dst_cell dst_ty
drop_existing_if_not_init initializing dst_cell dst_ty
in
let dst_ty = strip_mutable_or_constrained_ty dst_ty in
let (dst_cell, dst_ty) =
@ -3395,7 +3386,7 @@ let trans_visitor
end
atoms
and trans_init_rec_update
and trans_new_rec_update
(dst:Il.cell)
(dst_tys:Ast.ty array)
(trec:Ast.ty_rec)
@ -4496,60 +4487,57 @@ let trans_visitor
| _ -> bug () "Binding unexpected lval."
end
| Ast.STMT_init_rec (dst, atab, base) ->
let init = maybe_init stmt.id "rec-init" dst in
let (dst_cell, ty) = trans_lval_maybe_init init dst in
| Ast.STMT_new_rec (dst, atab, base) ->
let init = maybe_init stmt.id "new rec" dst in
let (dst_cell, dst_ty) = trans_lval_maybe_init init dst in
let (trec, dst_tys) =
match ty with
match dst_ty with
Ast.TY_rec trec -> (trec, Array.map snd trec)
| _ ->
bugi cx stmt.id
"non-rec destination type in stmt_init_rec"
"non-rec destination type in stmt_new_rec"
in
begin
drop_existing_if_not_init init dst_cell dst_ty;
match base with
None ->
let atoms = Array.map (fun (_, _, atom) -> atom) atab in
trans_init_structural_from_atoms
dst_cell dst_tys atoms
| Some base_lval ->
trans_init_rec_update
trans_new_rec_update
dst_cell dst_tys trec atab base_lval
end
| Ast.STMT_init_tup (dst, elems) ->
let init = maybe_init stmt.id "tup-init" dst in
| Ast.STMT_new_tup (dst, elems) ->
let init = maybe_init stmt.id "new tup" dst in
let (dst_cell, dst_ty) = trans_lval_maybe_init init dst in
let _ =
if not init
then drop_ty_in_current_frame dst_cell dst_ty
in
let dst_tys =
match dst_ty with
Ast.TY_tup ttup -> ttup
| _ ->
bugi cx stmt.id
"non-tup destination type in stmt_init_tup"
"non-tup destination type in stmt_new_tup"
in
let atoms = Array.map snd elems in
let (dst_cell, _) = deref_ty DEREF_none init dst_cell dst_ty in
drop_existing_if_not_init init dst_cell dst_ty;
trans_init_structural_from_atoms dst_cell dst_tys atoms
| Ast.STMT_init_str (dst, s) ->
let init = maybe_init stmt.id "str-init" dst in
trans_init_str init dst s
| Ast.STMT_new_str (dst, s) ->
let init = maybe_init stmt.id "new str" dst in
trans_new_str init dst s
| Ast.STMT_init_vec (dst, _, atoms) ->
let init = maybe_init stmt.id "vec-init" dst in
trans_init_vec init dst atoms
| Ast.STMT_new_vec (dst, _, atoms) ->
let init = maybe_init stmt.id "new vec" dst in
trans_new_vec init dst atoms
| Ast.STMT_init_port dst ->
let init = maybe_init stmt.id "port-init" dst in
trans_init_port init dst
| Ast.STMT_new_port dst ->
let init = maybe_init stmt.id "new port" dst in
trans_new_port init dst
| Ast.STMT_init_chan (dst, port) ->
let init = maybe_init stmt.id "chan-init" dst in
| Ast.STMT_new_chan (dst, port) ->
let init = maybe_init stmt.id "new chan" dst in
begin
match port with
None ->
@ -4558,12 +4546,12 @@ let trans_visitor
in
mov dst_cell imm_false
| Some p ->
trans_init_chan init dst p
trans_new_chan init dst p
end
| Ast.STMT_init_box (dst, _, src) ->
let init = maybe_init stmt.id "box-init" dst in
trans_init_box init dst src
| Ast.STMT_new_box (dst, _, src) ->
let init = maybe_init stmt.id "new box" dst in
trans_new_box init dst src
| Ast.STMT_block block ->
trans_block block

View File

@ -646,7 +646,7 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
infer_lval Ast.TY_task dst;
demand Ast.TY_nil (check_fn callee args)
| Ast.STMT_init_rec (dst, fields, Some base) ->
| Ast.STMT_new_rec (dst, fields, Some base) ->
let ty = check_lval base in
let ty_rec = demand_rec ty in
let field_tys = Hashtbl.create (Array.length ty_rec) in
@ -664,41 +664,41 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) =
Array.iter check_field fields;
infer_lval ty dst
| Ast.STMT_init_rec (dst, fields, None) ->
| Ast.STMT_new_rec (dst, fields, None) ->
let check_field (name, mut, atom) =
(name, maybe_mutable mut (check_atom atom))
in
let ty = Ast.TY_rec (Array.map check_field fields) in
infer_lval ty dst
| Ast.STMT_init_tup (dst, members) ->
| Ast.STMT_new_tup (dst, members) ->
let check_member (mut, atom) =
maybe_mutable mut (check_atom atom)
in
let ty = Ast.TY_tup (Array.map check_member members) in
infer_lval ty dst
| Ast.STMT_init_vec (dst, mut, [| |]) ->
| Ast.STMT_new_vec (dst, mut, [| |]) ->
(* no inference allowed here *)
let lval_ty = check_lval ~mut:Ast.MUT_mutable dst in
ignore (demand_vec_with_mutability mut lval_ty)
| Ast.STMT_init_vec (dst, mut, elems) ->
| Ast.STMT_new_vec (dst, mut, elems) ->
let atom_ty = demand_all (Array.map check_atom elems) in
let ty = Ast.TY_vec (maybe_mutable mut atom_ty) in
infer_lval ty dst
| Ast.STMT_init_str (dst, _) -> infer_lval Ast.TY_str dst
| Ast.STMT_new_str (dst, _) -> infer_lval Ast.TY_str dst
| Ast.STMT_init_port _ -> () (* we can't actually typecheck this *)
| Ast.STMT_new_port _ -> () (* we can't actually typecheck this *)
| Ast.STMT_init_chan (dst, Some port) ->
| Ast.STMT_new_chan (dst, Some port) ->
let ty = Ast.TY_chan (demand_port (check_lval port)) in
infer_lval ty dst
| Ast.STMT_init_chan (_, None) -> () (* can't check this either *)
| Ast.STMT_new_chan (_, None) -> () (* can't check this either *)
| Ast.STMT_init_box (dst, mut, src) ->
| Ast.STMT_new_box (dst, mut, src) ->
let ty = Ast.TY_box (maybe_mutable mut (check_atom src)) in
infer_lval ty dst

View File

@ -411,7 +411,7 @@ let condition_assigning_visitor
in
raise_pre_post_cond s.id precond;
| Ast.STMT_init_rec (dst, entries, base) ->
| Ast.STMT_new_rec (dst, entries, base) ->
let base_slots =
begin
match base with
@ -426,7 +426,7 @@ let condition_assigning_visitor
raise_pre_post_cond s.id precond;
raise_postcondition s.id postcond
| Ast.STMT_init_tup (dst, modes_atoms) ->
| Ast.STMT_new_tup (dst, modes_atoms) ->
let precond = slot_inits
(tup_inputs_slots cx modes_atoms)
in
@ -434,27 +434,27 @@ let condition_assigning_visitor
raise_pre_post_cond s.id precond;
raise_postcondition s.id postcond
| Ast.STMT_init_vec (dst, _, atoms) ->
| Ast.STMT_new_vec (dst, _, atoms) ->
let precond = slot_inits (atoms_slots cx atoms) in
let postcond = slot_inits (lval_slots cx dst) in
raise_pre_post_cond s.id precond;
raise_postcondition s.id postcond
| Ast.STMT_init_str (dst, _) ->
| Ast.STMT_new_str (dst, _) ->
let postcond = slot_inits (lval_slots cx dst) in
raise_postcondition s.id postcond
| Ast.STMT_init_port dst ->
| Ast.STMT_new_port dst ->
let postcond = slot_inits (lval_slots cx dst) in
raise_postcondition s.id postcond
| Ast.STMT_init_chan (dst, port) ->
| Ast.STMT_new_chan (dst, port) ->
let precond = slot_inits (lval_option_slots cx port) in
let postcond = slot_inits (lval_slots cx dst) in
raise_pre_post_cond s.id precond;
raise_postcondition s.id postcond
| Ast.STMT_init_box (dst, _, src) ->
| Ast.STMT_new_box (dst, _, src) ->
let precond = slot_inits (atom_slots cx src) in
let postcond = slot_inits (lval_slots cx dst) in
raise_pre_post_cond s.id precond;
@ -999,7 +999,7 @@ let lifecycle_visitor
Stack.push sl (Stack.top block_slots)
in
let mark_slot_init sl =
let mark_slot_live sl =
Hashtbl.replace live_block_slots sl ()
in
@ -1011,7 +1011,7 @@ let lifecycle_visitor
None -> ()
| Some slot ->
push_slot slot;
mark_slot_init slot
mark_slot_live slot
end;
inner.Walk.visit_block_pre b
in
@ -1065,9 +1065,9 @@ let lifecycle_visitor
let visit_stmt_pre s =
begin
let init_lval lv_dst =
let mark_lval_live lv_dst =
let dst_slots = lval_slots cx lv_dst in
Array.iter mark_slot_init dst_slots;
Array.iter mark_slot_live dst_slots;
in
match s.node with
Ast.STMT_copy (lv_dst, _)
@ -1098,20 +1098,20 @@ let lifecycle_visitor
Ast.sprintf_lval lv_dst Ast.sprintf_stmt s
end;
Hashtbl.replace cx.ctxt_copy_stmt_is_init s.id ();
init_lval lv_dst
mark_lval_live lv_dst
end;
| Ast.STMT_decl (Ast.DECL_slot (_, sloti)) ->
push_slot sloti.id
| Ast.STMT_init_rec (lv_dst, _, _)
| Ast.STMT_init_tup (lv_dst, _)
| Ast.STMT_init_vec (lv_dst, _, _)
| Ast.STMT_init_str (lv_dst, _)
| Ast.STMT_init_port lv_dst
| Ast.STMT_init_chan (lv_dst, _)
| Ast.STMT_init_box (lv_dst, _, _) ->
init_lval lv_dst
| Ast.STMT_new_rec (lv_dst, _, _)
| Ast.STMT_new_tup (lv_dst, _)
| Ast.STMT_new_vec (lv_dst, _, _)
| Ast.STMT_new_str (lv_dst, _)
| Ast.STMT_new_port lv_dst
| Ast.STMT_new_chan (lv_dst, _)
| Ast.STMT_new_box (lv_dst, _, _) ->
mark_lval_live lv_dst
| Ast.STMT_for f ->
log cx "noting implicit init for slot %d in for-block %d"

View File

@ -384,30 +384,30 @@ and walk_stmt
Ast.STMT_log a ->
walk_atom v a
| Ast.STMT_init_rec (lv, atab, base) ->
| Ast.STMT_new_rec (lv, atab, base) ->
walk_lval v lv;
Array.iter (fun (_, _, a) -> walk_atom v a) atab;
walk_option (walk_lval v) base;
| Ast.STMT_init_vec (lv, _, atoms) ->
| Ast.STMT_new_vec (lv, _, atoms) ->
walk_lval v lv;
Array.iter (walk_atom v) atoms
| Ast.STMT_init_tup (lv, mut_atoms) ->
| Ast.STMT_new_tup (lv, mut_atoms) ->
walk_lval v lv;
Array.iter (fun (_, atom) -> walk_atom v atom) mut_atoms
| Ast.STMT_init_str (lv, _) ->
| Ast.STMT_new_str (lv, _) ->
walk_lval v lv
| Ast.STMT_init_port lv ->
| Ast.STMT_new_port lv ->
walk_lval v lv
| Ast.STMT_init_chan (chan,port) ->
| Ast.STMT_new_chan (chan,port) ->
walk_option (walk_lval v) port;
walk_lval v chan;
| Ast.STMT_init_box (dst, _, src) ->
| Ast.STMT_new_box (dst, _, src) ->
walk_lval v dst;
walk_atom v src