Skip to content

Commit 97e6e3b

Browse files
committed
---
yaml --- r: 876 b: refs/heads/master c: db955d3 h: refs/heads/master v: v3
1 parent 0ae3013 commit 97e6e3b

File tree

5 files changed

+74
-53
lines changed

5 files changed

+74
-53
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: a3d666bfdf3ef87a91eace7b533e433945b06d76
2+
refs/heads/master: db955d33b7a54df6ba90bef713110bc2f85b2830

trunk/src/boot/me/effect.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ let process_crate
273273
let root_scope = [ SCOPE_crate crate ] in
274274
let auth_effect name eff =
275275
match lookup_by_name cx [] root_scope name with
276-
None -> ()
277-
| Some (_, id) ->
276+
RES_failed _ -> ()
277+
| RES_ok (_, id) ->
278278
if defn_id_is_item cx id
279279
then htab_put item_auth id eff
280280
else err (Some id) "auth clause in crate refers to non-item"

trunk/src/boot/me/resolve.ml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ let all_item_collecting_visitor
228228
Walk.visit_stmt_pre = visit_stmt_pre; }
229229
;;
230230

231+
let report_error (full_name:Ast.name) (unbound_name:Ast.name) =
232+
if full_name = unbound_name then
233+
err None "unbound name '%a'" Ast.sprintf_name full_name
234+
else
235+
err None "unbound name '%a' in name '%a'" Ast.sprintf_name unbound_name
236+
Ast.sprintf_name full_name
237+
;;
231238

232239
let lookup_type_node_by_name
233240
(cx:ctxt)
@@ -238,8 +245,8 @@ let lookup_type_node_by_name
238245
log cx "lookup_simple_type_by_name %a"
239246
Ast.sprintf_name name);
240247
match lookup_by_name cx [] scopes name with
241-
None -> err None "unknown name: %a" Ast.sprintf_name name
242-
| Some (_, id) ->
248+
RES_failed name' -> report_error name name'
249+
| RES_ok (_, id) ->
243250
match htab_search cx.ctxt_all_defns id with
244251
Some (DEFN_item { Ast.decl_item = Ast.MOD_ITEM_type _;
245252
Ast.decl_params = _ })
@@ -274,8 +281,8 @@ let rec lookup_type_by_name
274281
log cx "+++ lookup_type_by_name %a"
275282
Ast.sprintf_name name);
276283
match lookup_by_name cx [] scopes name with
277-
None -> err None "unknown name: %a" Ast.sprintf_name name
278-
| Some (scopes', id) ->
284+
RES_failed name' -> report_error name name'
285+
| RES_ok (scopes', id) ->
279286
let ty, params =
280287
match htab_search cx.ctxt_all_defns id with
281288
Some (DEFN_item { Ast.decl_item = Ast.MOD_ITEM_type (_, t);
@@ -614,17 +621,17 @@ let lval_base_resolving_visitor
614621
let lookup_defn_by_ident id ident =
615622
log cx "looking up slot or item with ident '%s'" ident;
616623
match lookup cx (!scopes) (Ast.KEY_ident ident) with
617-
None -> err (Some id) "unresolved identifier '%s'" ident
618-
| Some (_, id) -> (log cx "resolved to node id #%d"
624+
RES_failed _ -> err (Some id) "unresolved identifier '%s'" ident
625+
| RES_ok (_, id) -> (log cx "resolved to node id #%d"
619626
(int_of_node id); id)
620627
in
621628
let lookup_slot_by_temp id temp =
622629
log cx "looking up temp slot #%d" (int_of_temp temp);
623630
let res = lookup cx (!scopes) (Ast.KEY_temp temp) in
624631
match res with
625-
None -> err
632+
RES_failed _ -> err
626633
(Some id) "unresolved temp node #%d" (int_of_temp temp)
627-
| Some (_, id) ->
634+
| RES_ok (_, id) ->
628635
(log cx "resolved to node id #%d" (int_of_node id); id)
629636
in
630637
let lookup_defn_by_name_base id nb =

trunk/src/boot/me/semant.ml

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,7 +1950,13 @@ visitor =
19501950

19511951
(* Generic lookup, used for slots, items, types, etc. *)
19521952

1953-
type resolved = ((scope list * node_id) option) ;;
1953+
type resolved =
1954+
RES_ok of scope list * node_id
1955+
| RES_failed of Ast.name
1956+
;;
1957+
1958+
let no_such_ident ident = RES_failed (Ast.NAME_base (Ast.BASE_ident ident))
1959+
let no_such_temp temp = RES_failed (Ast.NAME_base (Ast.BASE_temp temp))
19541960

19551961
let get_mod_item
19561962
(cx:ctxt)
@@ -2000,20 +2006,20 @@ let rec project_ident_from_items
20002006
in
20012007

20022008
if not (inside || (exports_permit view ident))
2003-
then None
2009+
then no_such_ident ident
20042010
else
20052011
match htab_search items ident with
20062012
Some i ->
20072013
found cx scopes i.id
20082014
| None ->
20092015
match htab_search view.Ast.view_imports ident with
2010-
None -> None
2016+
None -> no_such_ident ident
20112017
| Some name ->
20122018
lookup_by_name cx lchk scopes name
20132019

20142020
and found cx scopes id =
20152021
Hashtbl.replace cx.ctxt_node_referenced id ();
2016-
Some (scopes, id)
2022+
RES_ok (scopes, id)
20172023

20182024
and project_name_comp_from_resolved
20192025
(cx:ctxt)
@@ -2022,8 +2028,8 @@ and project_name_comp_from_resolved
20222028
(ext:Ast.name_component)
20232029
: resolved =
20242030
match mod_res with
2025-
None -> None
2026-
| Some (scopes, id) ->
2031+
RES_failed _ -> mod_res
2032+
| RES_ok (scopes, id) ->
20272033
let scope = (SCOPE_mod_item {id=id; node=get_item cx id}) in
20282034
let scopes = scope :: scopes in
20292035
let ident = get_name_comp_ident ext in
@@ -2054,27 +2060,37 @@ and lookup_by_ident
20542060
: resolved =
20552061

20562062
let check_slots scopes islots =
2057-
arr_search islots
2058-
(fun _ (sloti,ident') ->
2059-
if ident = ident'
2060-
then found cx scopes sloti.id
2061-
else None)
2063+
let rec search i =
2064+
if i == (Array.length islots) then
2065+
no_such_ident ident
2066+
else
2067+
let (sloti, ident') = islots.(i) in
2068+
if ident = ident'
2069+
then found cx scopes sloti.id
2070+
else search (i + 1)
2071+
in
2072+
search 0
20622073
in
20632074

20642075
let check_params scopes params =
2065-
arr_search params
2066-
(fun _ {node=(i,_); id=id} ->
2067-
if i = ident
2068-
then found cx scopes id
2069-
else None)
2076+
let rec search i =
2077+
if i == (Array.length params) then
2078+
no_such_ident ident
2079+
else
2080+
let { node = (ident', _); id = id } = params.(i) in
2081+
if ident = ident'
2082+
then found cx scopes id
2083+
else search (i + 1)
2084+
in
2085+
search 0
20702086
in
20712087

20722088
let passed_capture_scope = ref false in
20732089

20742090
let would_capture r =
20752091
match r with
2076-
None -> None
2077-
| Some _ ->
2092+
RES_failed _ -> r
2093+
| RES_ok _ ->
20782094
if !passed_capture_scope
20792095
then err None "attempted dynamic environment-capture"
20802096
else r
@@ -2091,7 +2107,7 @@ and lookup_by_ident
20912107
| None ->
20922108
match htab_search block_items ident with
20932109
Some id -> found cx scopes id
2094-
| None -> None
2110+
| None -> no_such_ident ident
20952111
end
20962112

20972113
| SCOPE_crate crate ->
@@ -2115,21 +2131,21 @@ and lookup_by_ident
21152131
project_ident_from_items cx lchk
21162132
scopes item.id md ident true
21172133

2118-
| _ -> None
2134+
| _ -> no_such_ident ident
21192135
in
21202136
match item_match with
2121-
Some _ -> item_match
2122-
| None ->
2137+
RES_ok _ -> item_match
2138+
| RES_failed _ ->
21232139
would_capture
21242140
(check_params scopes item.node.Ast.decl_params)
21252141
end
21262142
in
21272143
let rec search scopes =
21282144
match scopes with
2129-
[] -> None
2145+
[] -> no_such_ident ident
21302146
| scope::rest ->
21312147
match check_scope scopes scope with
2132-
None ->
2148+
RES_failed _ ->
21332149
begin
21342150
let is_ty_item i =
21352151
match i.node.Ast.decl_item with
@@ -2157,28 +2173,26 @@ let lookup_by_temp
21572173
(cx:ctxt)
21582174
(scopes:scope list)
21592175
(temp:temp_id)
2160-
: ((scope list * node_id) option) =
2161-
let passed_item_scope = ref false in
2162-
let check_scope scope =
2163-
if !passed_item_scope
2164-
then None
2165-
else
2166-
match scope with
2167-
SCOPE_block block_id ->
2176+
: resolved =
2177+
let rec search scopes' =
2178+
match scopes' with
2179+
(SCOPE_block block_id)::scopes'' ->
21682180
let block_slots = Hashtbl.find cx.ctxt_block_slots block_id in
2169-
htab_search block_slots (Ast.KEY_temp temp)
2170-
| _ ->
2171-
passed_item_scope := true;
2172-
None
2181+
begin
2182+
match htab_search block_slots (Ast.KEY_temp temp) with
2183+
Some slot -> RES_ok (scopes', slot)
2184+
| None -> search scopes''
2185+
end
2186+
| _ -> no_such_temp temp
21732187
in
2174-
list_search_ctxt scopes check_scope
2188+
search scopes
21752189
;;
21762190

21772191
let lookup
21782192
(cx:ctxt)
21792193
(scopes:scope list)
21802194
(key:Ast.slot_key)
2181-
: ((scope list * node_id) option) =
2195+
: resolved =
21822196
match key with
21832197
Ast.KEY_temp temp -> lookup_by_temp cx scopes temp
21842198
| Ast.KEY_ident ident -> lookup_by_ident cx [] scopes ident

trunk/src/boot/me/typestate.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ let determine_constr_key
119119

120120
let cid =
121121
match lookup_by_name cx [] scopes c.Ast.constr_name with
122-
Some (_, cid) ->
122+
RES_ok (_, cid) ->
123123
if defn_id_is_item cx cid
124124
then
125125
begin
@@ -134,7 +134,7 @@ let determine_constr_key
134134
end
135135
else
136136
bug () "slot used as predicate"
137-
| None -> bug () "predicate not found"
137+
| RES_failed _ -> bug () "predicate not found"
138138
in
139139

140140
let constr_arg_of_carg carg =
@@ -153,8 +153,8 @@ let determine_constr_key
153153
| Ast.CARG_base (Ast.BASE_named nb) ->
154154
begin
155155
match lookup_by_name cx [] scopes (Ast.NAME_base nb) with
156-
None -> bug () "constraint-arg not found"
157-
| Some (_, aid) ->
156+
RES_failed _ -> bug () "constraint-arg not found"
157+
| RES_ok (_, aid) ->
158158
if defn_id_is_slot cx aid
159159
then
160160
if type_has_state cx

0 commit comments

Comments
 (0)