Skip to content

Commit

Permalink
Distill semantics of use-def maps to fewer and more-obvious words.
Browse files Browse the repository at this point in the history
- Remove redundant uses of 'resolve' and 'referent' in semant.
- Use defn, defn_id, lval, lval_base more consistently.
- Make associated query functions more consistent.
- Closes #127.
  • Loading branch information
graydon committed Jul 27, 2010
1 parent b7d7f70 commit 4d31cf1
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 180 deletions.
11 changes: 5 additions & 6 deletions src/boot/me/alias.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ let alias_analysis_visitor
in

let alias lval =
let lv_id = lval_base_id lval in
let referent = Hashtbl.find cx.ctxt_lval_to_referent lv_id in
if (referent_is_slot cx referent)
then alias_slot referent
let defn_id = lval_base_defn_id cx lval in
if (defn_id_is_slot cx defn_id)
then alias_slot defn_id
in

let alias_atom at =
Expand Down Expand Up @@ -85,8 +84,8 @@ let alias_analysis_visitor
in

let visit_lval_pre lv =
let slot_id = lval_to_referent cx (lval_base_id lv) in
if (not (Stack.is_empty curr_stmt)) && (referent_is_slot cx slot_id)
let slot_id = lval_base_defn_id cx lv in
if (not (Stack.is_empty curr_stmt)) && (defn_id_is_slot cx slot_id)
then
begin
let slot_depth = get_slot_depth cx slot_id in
Expand Down
4 changes: 2 additions & 2 deletions src/boot/me/effect.ml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ let function_effect_propagation_visitor
lower_to s taux.Ast.fn_effect;
| _ -> bug () "non-fn callee"
in
if lval_is_slot cx fn
if lval_base_is_slot cx fn
then
lower_to_callee_ty (lval_ty cx fn)
else
Expand Down Expand Up @@ -335,7 +335,7 @@ let process_crate
match lookup_by_name cx [] root_scope name with
None -> ()
| Some (_, id) ->
if referent_is_item cx id
if defn_id_is_item cx id
then htab_put item_auth id eff
else err (Some id) "auth clause in crate refers to non-item"
in
Expand Down
6 changes: 3 additions & 3 deletions src/boot/me/layout.ml
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,9 @@ let layout_visitor
let static = lval_is_static cx callee in
let closure = if static then None else Some Il.OpaqueTy in
let n_ty_params =
match resolve_lval cx callee with
DEFN_item i -> Array.length i.Ast.decl_params
| _ -> 0
if lval_base_is_item cx callee
then Array.length (lval_item cx callee).node.Ast.decl_params
else 0
in
let rty =
call_args_referent_type cx n_ty_params lv_ty closure
Expand Down
24 changes: 12 additions & 12 deletions src/boot/me/resolve.ml
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ let type_resolving_visitor
| Ast.MOD_ITEM_tag (header_slots, _, nid)
when Hashtbl.mem recursive_tag_groups nid ->
begin
match ty_of_mod_item true item with
match ty_of_mod_item item with
Ast.TY_fn (tsig, taux) ->
let input_slots =
Array.map
Expand All @@ -586,7 +586,7 @@ let type_resolving_visitor
end

| _ ->
let t = ty_of_mod_item true item in
let t = ty_of_mod_item item in
let ty =
resolve_type cx (!scopes) recursive_tag_groups
all_tags empty_recur_info t
Expand Down Expand Up @@ -686,7 +686,7 @@ let lval_base_resolving_visitor
(scopes:(scope list) ref)
(inner:Walk.visitor)
: Walk.visitor =
let lookup_referent_by_ident id ident =
let lookup_defn_by_ident id ident =
log cx "looking up slot or item with ident '%s'" ident;
match lookup cx (!scopes) (Ast.KEY_ident ident) with
None -> err (Some id) "unresolved identifier '%s'" ident
Expand All @@ -702,10 +702,10 @@ let lval_base_resolving_visitor
| Some (_, id) ->
(log cx "resolved to node id #%d" (int_of_node id); id)
in
let lookup_referent_by_name_base id nb =
let lookup_defn_by_name_base id nb =
match nb with
Ast.BASE_ident ident
| Ast.BASE_app (ident, _) -> lookup_referent_by_ident id ident
| Ast.BASE_app (ident, _) -> lookup_defn_by_ident id ident
| Ast.BASE_temp temp -> lookup_slot_by_temp id temp
in

Expand All @@ -723,10 +723,10 @@ let lval_base_resolving_visitor
| _ -> ()
end
| Ast.LVAL_base nb ->
let referent_id = lookup_referent_by_name_base nb.id nb.node in
iflog cx (fun _ -> log cx "resolved lval #%d to referent #%d"
(int_of_node nb.id) (int_of_node referent_id));
htab_put cx.ctxt_lval_to_referent nb.id referent_id
let defn_id = lookup_defn_by_name_base nb.id nb.node in
iflog cx (fun _ -> log cx "resolved lval #%d to defn #%d"
(int_of_node nb.id) (int_of_node defn_id));
htab_put cx.ctxt_lval_base_id_to_defn_base_id nb.id defn_id
in

(*
Expand All @@ -745,7 +745,7 @@ let lval_base_resolving_visitor
-> lval_is_name lv'
| _ -> false
in
if lval_is_name lv && lval_is_item cx lv
if lval_is_name lv && lval_base_is_item cx lv
then ignore (lookup_by_name cx [] (!scopes) (lval_to_name lv))
in

Expand Down Expand Up @@ -932,7 +932,7 @@ let pattern_resolving_visitor
let lval_nm = lval_to_name lval in
let lval_id = lval_base_id lval in
let tag_ctor_id = (lval_item cx lval).id in
if referent_is_item cx tag_ctor_id
if defn_id_is_item cx tag_ctor_id

(* FIXME (issue #76): we should actually check here that the
* function is a tag value-ctor. For now this actually allows
Expand Down Expand Up @@ -1050,7 +1050,7 @@ let process_crate
Hashtbl.iter
begin
fun n _ ->
if referent_is_item cx n
if defn_id_is_item cx n
then
log cx "referenced: %a"
Ast.sprintf_name
Expand Down
Loading

0 comments on commit 4d31cf1

Please sign in to comment.