Skip to content

Commit 641f178

Browse files
committed
Fix dependency analysis
Check modules in types + properly classify declared modules as declared
1 parent 8e0c142 commit 641f178

3 files changed

Lines changed: 25 additions & 14 deletions

File tree

src/ecCoreModules.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,9 @@ type top_module_expr = {
494494
tme_loca : locality;
495495
}
496496

497+
let is_me_body_alias (body : module_body) =
498+
match body with ME_Alias _ -> true | _ -> false
499+
497500
(* -------------------------------------------------------------------- *)
498501
let ur_hash = EcAst.ur_hash
499502

src/ecCoreModules.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ type top_module_expr = {
247247
tme_loca : locality;
248248
}
249249

250+
val is_me_body_alias : module_body -> bool
251+
250252
(* -------------------------------------------------------------------- *)
251253
val mty_equal :
252254
module_type ->

src/ecSection.ml

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ let pp_cbarg env fmt (who : cbarg) =
4242
| `Module mp ->
4343
let ppe =
4444
match mp.m_top with
45-
| `Local id -> EcPrinting.PPEnv.add_locals ppe [id]
45+
| `Local id ->
46+
if EcEnv.Mod.is_declared id env then
47+
ppe
48+
else EcPrinting.PPEnv.add_locals ppe [id]
4649
| _ -> ppe in
4750
Format.fprintf fmt "module %a" (EcPrinting.pp_topmod ppe) mp
4851
| `ModuleType p ->
@@ -153,7 +156,7 @@ and on_ty (aenv : aenv) (ty : ty) =
153156
match ty.ty_node with
154157
| Tunivar _ -> ()
155158
| Tvar _ -> ()
156-
| Tglob _ -> ()
159+
| Tglob m -> aenv.cb (`Module (mident m))
157160
| Ttuple tys -> List.iter (on_ty aenv) tys
158161
| Tconstr (p, tys) -> on_tyname aenv p; List.iter (on_ty aenv) tys
159162
| Tfun (ty1, ty2) -> List.iter (on_ty aenv) [ty1; ty2]
@@ -380,10 +383,10 @@ and on_module (aenv : aenv) (me : module_expr) =
380383

381384
(* -------------------------------------------------------------------- *)
382385
and on_mstruct (aenv : aenv) (st : module_structure) =
383-
List.iter (on_mpath_mstruct1 aenv) st.ms_body
386+
List.iter (on_mstruct1 aenv) st.ms_body
384387

385388
(* -------------------------------------------------------------------- *)
386-
and on_mpath_mstruct1 (aenv : aenv) (item : module_item) =
389+
and on_mstruct1 (aenv : aenv) (item : module_item) =
387390
match item with
388391
| MI_Module me -> on_module aenv me
389392
| MI_Variable x -> on_ty aenv x.v_type
@@ -578,15 +581,16 @@ let pp_thname scenv =
578581
(* -------------------------------------------------------------------- *)
579582
let locality (env : EcEnv.env) (who : cbarg) =
580583
match who with
581-
| `Type p -> (EcEnv. Ty.by_path p env).tyd_loca
582-
| `Op p -> (EcEnv. Op.by_path p env).op_loca
583-
| `Ax p -> (EcEnv. Ax.by_path p env).ax_loca
584-
| `Typeclass p -> ((EcEnv.TypeClass.by_path p env).tc_loca :> locality)
585-
| `Module mp ->
586-
begin match EcEnv.Mod.by_mpath_opt mp env with
584+
| `Type p -> (EcEnv.Ty.by_path p env).tyd_loca
585+
| `Op p -> (EcEnv.Op.by_path p env).op_loca
586+
| `Ax p -> (EcEnv.Ax.by_path p env).ax_loca
587+
| `Typeclass p -> ((EcEnv.TypeClass.by_path p env).tc_loca :> locality)
588+
| `Module mp -> begin
589+
match EcEnv.Mod.by_mpath_opt mp env with
587590
| Some (_, Some lc) -> lc
588-
(* in this case it should be a quantified module *)
589-
| _ -> `Global
591+
| _ ->
592+
let id = EcPath.mget_ident mp in
593+
if EcEnv.Mod.is_declared id env then `Declare else `Global
590594
end
591595
| `ModuleType p -> ((EcEnv.ModTy.by_path p env).tms_loca :> locality)
592596
| `Instance _ -> assert false
@@ -1332,17 +1336,19 @@ let check_module scenv prefix tme =
13321336
match tme.tme_loca with
13331337
| `Local -> check_section scenv from
13341338
| `Global ->
1335-
if scenv.sc_insec then
1339+
if scenv.sc_insec then begin
1340+
let isalias = EcModules.is_me_body_alias tme.tme_expr.me_body in
13361341
let cd =
13371342
{ d_ty = [`Global];
13381343
d_op = [`Global];
13391344
d_ax = [];
13401345
d_sc = [];
1341-
d_mod = [`Global]; (* FIXME section: add local *)
1346+
d_mod = [`Global] @ (if isalias then [`Declare] else []);
13421347
d_modty = [`Global];
13431348
d_tc = [`Global];
13441349
} in
13451350
on_module (mkaenv scenv.sc_env (cb scenv from cd)) me
1351+
end
13461352
| `Declare -> (* Should be SC_decl_mod ... *)
13471353
assert false
13481354

0 commit comments

Comments
 (0)