@@ -220,37 +220,12 @@ end
220220module VarMap = Collections. MakeMap (VarOrderedType )
221221
222222(* * Context to lookup definitions *)
223- type ctx = {
224- type_decls : T .type_decl T.TypeDeclId.Map .t ;
225- global_decls : LlbcAst .global_decl T.GlobalDeclId.Map .t ;
226- fun_decls : A .fun_decl A.FunDeclId.Map .t ;
227- trait_decls : A .trait_decl T.TraitDeclId.Map .t ;
228- trait_impls : A .trait_impl T.TraitImplId.Map .t ;
229- }
223+ type ctx = { crate : A .crate }
230224
231225let ctx_to_fmt_env (ctx : ctx ) : PrintLlbcAst.fmt_env =
232- {
233- type_decls = ctx.type_decls;
234- fun_decls = ctx.fun_decls;
235- global_decls = ctx.global_decls;
236- trait_decls = ctx.trait_decls;
237- trait_impls = ctx.trait_impls;
238- generics = [] ;
239- locals = [] ;
240- }
226+ { crate = ctx.crate; generics = [] ; locals = [] }
241227
242- let ctx_from_crate (crate : LlbcAst.crate ) : ctx =
243- let {
244- LlbcAst. type_decls;
245- fun_decls;
246- global_decls;
247- trait_decls;
248- trait_impls;
249- _;
250- } =
251- crate
252- in
253- { type_decls; global_decls; trait_decls; fun_decls; trait_impls }
228+ let ctx_from_crate (crate : LlbcAst.crate ) : ctx = { crate }
254229
255230(* * Match configuration *)
256231type match_config = {
@@ -512,7 +487,7 @@ and match_pattern_with_type_id (ctx : ctx) (c : match_config) (m : maps)
512487 match id with
513488 | TAdtId id ->
514489 (* Lookup the type decl and match the name *)
515- let d = T.TypeDeclId.Map. find id ctx.type_decls in
490+ let d = T.TypeDeclId.Map. find id ctx.crate. type_decls in
516491 match_name_with_generics ctx c ~m pid d.item_meta.name generics
517492 | TTuple -> false
518493 | TBuiltin id -> (
@@ -574,10 +549,10 @@ and match_expr_with_ty (ctx : ctx) (c : match_config) (m : maps) (pty : expr)
574549and match_expr_with_trait_impl_id (ctx : ctx ) (c : match_config ) (ptr : expr )
575550 (impl_id : T.TraitImplId.id ) : bool =
576551 (* Lookup the trait implementation *)
577- let impl = T.TraitImplId.Map. find impl_id ctx.trait_impls in
552+ let impl = T.TraitImplId.Map. find impl_id ctx.crate. trait_impls in
578553 (* Lookup the trait declaration *)
579554 let d =
580- T.TraitDeclId.Map. find impl.impl_trait.trait_decl_id ctx.trait_decls
555+ T.TraitDeclId.Map. find impl.impl_trait.trait_decl_id ctx.crate. trait_decls
581556 in
582557 (* Match *)
583558 match ptr with
@@ -590,7 +565,7 @@ and match_trait_decl_ref (ctx : ctx) (c : match_config) (m : maps)
590565 (pid : pattern ) (tr : T.trait_decl_ref T.region_binder ) : bool =
591566 (* Lookup the trait declaration *)
592567 let d =
593- T.TraitDeclId.Map. find tr.binder_value.trait_decl_id ctx.trait_decls
568+ T.TraitDeclId.Map. find tr.binder_value.trait_decl_id ctx.crate. trait_decls
594569 in
595570 (* Push a region group in the map, if necessary - TODO: make this more precise *)
596571 let m = maps_push_bound_regions_group_if_nonempty m tr.binder_regions in
@@ -680,7 +655,7 @@ and match_expr_with_const_generic (ctx : ctx) (c : match_config) (m : maps)
680655 | EVar pv , _ -> opt_update_cmap c m pv cg
681656 | EComp pat , CgGlobal gid ->
682657 (* Lookup the decl and match the name *)
683- let d = T.GlobalDeclId.Map. find gid ctx.global_decls in
658+ let d = T.GlobalDeclId.Map. find gid ctx.crate. global_decls in
684659 match_name ctx c pat d.item_meta.name
685660 | _ -> false
686661
@@ -733,7 +708,7 @@ let match_fn_ptr (ctx : ctx) (c : match_config) (p : pattern) (func : E.fn_ptr)
733708 let name = builtin_fun_id_to_string fid in
734709 match_name_with_generics ctx c p (to_name [ name ]) func.generics)
735710 | FunId (FRegular fid ) ->
736- let d = A.FunDeclId.Map. find fid ctx.fun_decls in
711+ let d = A.FunDeclId.Map. find fid ctx.crate. fun_decls in
737712 (* Match the pattern on the name of the function. *)
738713 let match_function_name =
739714 match_name_with_generics ctx c p d.item_meta.name func.generics
@@ -948,7 +923,7 @@ and impl_elem_to_pattern (ctx : ctx) (c : to_pat_config) (impl : T.impl_elem) :
948923 | ImplElemTy bound_ty ->
949924 PImpl (ty_to_pattern ctx c bound_ty.binder_params bound_ty.binder_value)
950925 | ImplElemTrait impl_id ->
951- let impl = T.TraitImplId.Map. find impl_id ctx.trait_impls in
926+ let impl = T.TraitImplId.Map. find impl_id ctx.crate. trait_impls in
952927 PImpl (trait_decl_ref_to_pattern ctx c impl.generics impl.impl_trait)
953928
954929and trait_decl_ref_to_pattern (ctx : ctx ) (c : to_pat_config )
@@ -958,7 +933,7 @@ and trait_decl_ref_to_pattern (ctx : ctx) (c : to_pat_config)
958933 let { T. trait_decl_id; decl_generics } = tr in
959934 let generics = generic_args_to_pattern ctx c m decl_generics in
960935 (* Lookup the declaration *)
961- let d = T.TraitDeclId.Map. find trait_decl_id ctx.trait_decls in
936+ let d = T.TraitDeclId.Map. find trait_decl_id ctx.crate. trait_decls in
962937 EComp
963938 (name_with_generic_args_to_pattern_aux ctx c d.item_meta.name
964939 (Some generics))
@@ -971,7 +946,7 @@ and ty_to_pattern_aux (ctx : ctx) (c : to_pat_config) (m : constraints)
971946 match id with
972947 | TAdtId id ->
973948 (* Lookup the declaration *)
974- let d = T.TypeDeclId.Map. find id ctx.type_decls in
949+ let d = T.TypeDeclId.Map. find id ctx.crate. type_decls in
975950 EComp
976951 (name_with_generic_args_to_pattern_aux ctx c d.item_meta.name
977952 (Some generics))
@@ -1017,7 +992,7 @@ and trait_ref_item_with_generics_to_pattern (ctx : ctx) (c : to_pat_config)
1017992 let trait_decl_ref = trait_ref.trait_decl_ref in
1018993 let d =
1019994 T.TraitDeclId.Map. find trait_decl_ref.binder_value.trait_decl_id
1020- ctx.trait_decls
995+ ctx.crate. trait_decls
1021996 in
1022997 (* Push a regions map if necessary - TODO: make this more precise *)
1023998 let m =
@@ -1048,7 +1023,7 @@ and const_generic_to_pattern (ctx : ctx) (c : to_pat_config) (m : constraints)
10481023 | CgVar v -> GExpr (EVar (const_generic_var_to_pattern m v))
10491024 | CgValue v -> GValue (literal_to_pattern c v)
10501025 | CgGlobal gid ->
1051- let d = T.GlobalDeclId.Map. find gid ctx.global_decls in
1026+ let d = T.GlobalDeclId.Map. find gid ctx.crate. global_decls in
10521027 let n = name_to_pattern_aux ctx c d.item_meta.name in
10531028 GExpr (EComp n)
10541029
@@ -1138,7 +1113,7 @@ let fn_ptr_to_pattern (ctx : ctx) (c : to_pat_config)
11381113 let fid = builtin_fun_id_to_string fid in
11391114 [ PIdent (fid, args) ])
11401115 | FunId (FRegular fid ) ->
1141- let d = A.FunDeclId.Map. find fid ctx.fun_decls in
1116+ let d = A.FunDeclId.Map. find fid ctx.crate. fun_decls in
11421117 name_with_generic_args_to_pattern_aux ctx c d.item_meta.name (Some args)
11431118 | TraitMethod (tr , method_name , _ ) ->
11441119 trait_ref_item_with_generics_to_pattern ctx c m tr method_name
0 commit comments