Skip to content

Commit e0442f7

Browse files
committed
---
yaml --- r: 1275 b: refs/heads/master c: 8bc57fa h: refs/heads/master i: 1273: d7be25e 1271: b822dc2 v: v3
1 parent 1f2f8b1 commit e0442f7

File tree

4 files changed

+222
-184
lines changed

4 files changed

+222
-184
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: 2c27feb76a4754faee6e997339826c6f2afc1432
2+
refs/heads/master: 8bc57fa85e6191117c8c27bf53f8e051e13783c3

trunk/src/boot/me/effect.ml

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ let effect_checking_visitor
179179
then Ast.EFF_pure
180180
else Stack.top auth_stack
181181
in
182-
let next = lower_effect_of e curr in
183-
Stack.push next auth_stack;
182+
Stack.push e auth_stack;
184183
iflog cx
185184
begin
186185
fun _ ->
@@ -189,40 +188,62 @@ let effect_checking_visitor
189188
"entering '%a', adjusting auth effect: '%a' -> '%a'"
190189
Ast.sprintf_name name
191190
Ast.sprintf_effect curr
192-
Ast.sprintf_effect next
191+
Ast.sprintf_effect e
193192
end
194193
end;
194+
let report_mismatch declared_effect calculated_effect =
195+
let name = Hashtbl.find cx.ctxt_all_item_names i.id in
196+
err (Some i.id)
197+
"%a claims effect '%a' but calculated effect is '%a'%s"
198+
Ast.sprintf_name name
199+
Ast.sprintf_effect declared_effect
200+
Ast.sprintf_effect calculated_effect
201+
begin
202+
if Stack.is_empty auth_stack
203+
then ""
204+
else
205+
Printf.sprintf " (auth effects are '%s')"
206+
(stk_fold
207+
auth_stack
208+
(fun e s ->
209+
if s = ""
210+
then
211+
Printf.sprintf "%a"
212+
Ast.sprintf_effect e
213+
else
214+
Printf.sprintf "%s, %a" s
215+
Ast.sprintf_effect e) "")
216+
end
217+
in
195218
begin
196219
match i.node.Ast.decl_item with
197220
Ast.MOD_ITEM_fn f
198221
when htab_search cx.ctxt_required_items i.id = None ->
199-
let e =
222+
let calculated_effect =
200223
match htab_search item_effect i.id with
201224
None -> Ast.EFF_pure
202225
| Some e -> e
203226
in
204-
let fe = f.Ast.fn_aux.Ast.fn_effect in
205-
let ae =
206-
if Stack.is_empty auth_stack
207-
then None
208-
else Some (Stack.top auth_stack)
209-
in
210-
if e <> fe && (ae <> (Some e))
227+
let declared_effect = f.Ast.fn_aux.Ast.fn_effect in
228+
if calculated_effect <> declared_effect
211229
then
230+
(* Something's fishy in this case. If the calculated effect
231+
* is equal to one auth'ed by an enclosing scope -- not just
232+
* a lower one -- we accept this mismatch; otherwise we
233+
* complain.
234+
*
235+
* FIXME: this choice of "what constitutes an error" in
236+
* auth/effect mismatches is subjective and could do
237+
* with some discussion. *)
212238
begin
213-
let name = Hashtbl.find cx.ctxt_all_item_names i.id in
214-
err (Some i.id)
215-
"%a claims effect '%a' but calculated effect is '%a'%s"
216-
Ast.sprintf_name name
217-
Ast.sprintf_effect fe
218-
Ast.sprintf_effect e
219-
begin
220-
match ae with
221-
Some ae when ae <> fe ->
222-
Printf.sprintf " (auth effect is '%a')"
223-
Ast.sprintf_effect ae
224-
| _ -> ""
225-
end
239+
match
240+
stk_search auth_stack
241+
(fun e ->
242+
if e = calculated_effect then Some e else None)
243+
with
244+
Some _ -> ()
245+
| None ->
246+
report_mismatch declared_effect calculated_effect
226247
end
227248
| _ -> ()
228249
end;
@@ -239,16 +260,16 @@ let effect_checking_visitor
239260
then Ast.EFF_pure
240261
else Stack.top auth_stack
241262
in
242-
iflog cx
243-
begin
244-
fun _ ->
245-
let name = Hashtbl.find cx.ctxt_all_item_names i.id in
246-
log cx
247-
"leaving '%a', restoring auth effect: '%a' -> '%a'"
248-
Ast.sprintf_name name
249-
Ast.sprintf_effect curr
250-
Ast.sprintf_effect next
251-
end
263+
iflog cx
264+
begin
265+
fun _ ->
266+
let name = Hashtbl.find cx.ctxt_all_item_names i.id in
267+
log cx
268+
"leaving '%a', restoring auth effect: '%a' -> '%a'"
269+
Ast.sprintf_name name
270+
Ast.sprintf_effect curr
271+
Ast.sprintf_effect next
272+
end
252273
in
253274
{ inner with
254275
Walk.visit_mod_item_pre = visit_mod_item_pre;

0 commit comments

Comments
 (0)