Skip to content

Commit

Permalink
add load_instance_mode (#11557)
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn authored Feb 7, 2024
1 parent 454d3da commit 2fb7155
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 85 deletions.
6 changes: 3 additions & 3 deletions src/context/display/displayTexpr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ let check_display_class ctx decls c =
ignore(Typeload.type_type_params ctx TPHType c.cl_path null_pos sc.d_params);
List.iter (function
| (HExtends ptp | HImplements ptp) when display_position#enclosed_in ptp.pos_full ->
ignore(Typeload.load_instance ~allow_display:true ctx ptp ParamNormal)
ignore(Typeload.load_instance ~allow_display:true ctx ptp ParamNormal LoadNormal)
| _ ->
()
) sc.d_flags;
Expand All @@ -112,14 +112,14 @@ let check_display_enum ctx decls en =
let check_display_typedef ctx decls td =
let st = find_typedef_by_position decls td.t_name_pos in
ignore(Typeload.type_type_params ctx TPHType td.t_path null_pos st.d_params);
ignore(Typeload.load_complex_type ctx true st.d_data)
ignore(Typeload.load_complex_type ctx true LoadNormal st.d_data)

let check_display_abstract ctx decls a =
let sa = find_abstract_by_position decls a.a_name_pos in
ignore(Typeload.type_type_params ctx TPHType a.a_path null_pos sa.d_params);
List.iter (function
| (AbOver(ct,p) | AbFrom(ct,p) | AbTo(ct,p)) when display_position#enclosed_in p ->
ignore(Typeload.load_complex_type ctx true (ct,p))
ignore(Typeload.load_complex_type ctx true LoadNormal (ct,p))
| _ ->
()
) sa.d_flags
Expand Down
10 changes: 5 additions & 5 deletions src/core/inheritDoc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ let rec get_class_field c field_name =
| None -> raise Not_found
| Some (csup, _) -> get_class_field csup field_name

let find_type ctx (tp,p) =
try Typeload.load_instance' ctx (make_ptp tp p) ParamSpawnMonos
let find_type ctx mode (tp,p) =
try Typeload.load_instance' ctx (make_ptp tp p) ParamSpawnMonos mode
with _ -> raise Not_found

(**
Expand Down Expand Up @@ -160,7 +160,7 @@ and get_target_doc ctx e_target =
| _ ->
mk_type_path path
in
let t = (find_type ctx (tp,snd e_target)) in
let t = (find_type ctx LoadNormal (tp,snd e_target)) in
try
match follow t with
| TInst (c, _) ->
Expand Down Expand Up @@ -207,11 +207,11 @@ and get_target_doc ctx e_target =
in
let resolve_type () =
let tp = mk_type_path path, snd e_target in
resolve_type_t (find_type ctx tp)
resolve_type_t (find_type ctx LoadNormal tp)
in
let resolve_sub_type sub =
let tp = mk_type_path ~sub path, snd e_target in
resolve_type_t (find_type ctx tp)
resolve_type_t (find_type ctx LoadNormal tp)
in
try
match sub with
Expand Down
12 changes: 6 additions & 6 deletions src/filters/exceptions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -511,23 +511,23 @@ let filter tctx =
make_ptp tp null_pos
in
let wildcard_catch_type =
let t = Typeload.load_instance tctx (tp config.ec_wildcard_catch) ParamSpawnMonos in
let t = Typeload.load_instance tctx (tp config.ec_wildcard_catch) ParamSpawnMonos LoadNormal in
if is_dynamic t then t_dynamic
else t
and base_throw_type =
let t = Typeload.load_instance tctx (tp config.ec_base_throw) ParamSpawnMonos in
let t = Typeload.load_instance tctx (tp config.ec_base_throw) ParamSpawnMonos LoadNormal in
if is_dynamic t then t_dynamic
else t
and haxe_exception_type, haxe_exception_class =
match Typeload.load_instance tctx (tp haxe_exception_type_path) ParamSpawnMonos with
match Typeload.load_instance tctx (tp haxe_exception_type_path) ParamSpawnMonos LoadNormal with
| TInst(cls,_) as t -> t,cls
| _ -> raise_typing_error "haxe.Exception is expected to be a class" null_pos
and value_exception_type, value_exception_class =
match Typeload.load_instance tctx (tp value_exception_type_path) ParamSpawnMonos with
match Typeload.load_instance tctx (tp value_exception_type_path) ParamSpawnMonos LoadNormal with
| TInst(cls,_) as t -> t,cls
| _ -> raise_typing_error "haxe.ValueException is expected to be a class" null_pos
and haxe_native_stack_trace =
match Typeload.load_instance tctx (tp (["haxe"],"NativeStackTrace")) ParamSpawnMonos with
match Typeload.load_instance tctx (tp (["haxe"],"NativeStackTrace")) ParamSpawnMonos LoadNormal with
| TInst(cls,_) -> cls
| TAbstract({ a_impl = Some cls },_) -> cls
| _ -> raise_typing_error "haxe.NativeStackTrace is expected to be a class or an abstract" null_pos
Expand Down Expand Up @@ -644,7 +644,7 @@ let insert_save_stacks tctx =
*)
let patch_constructors tctx =
let tp = make_ptp (mk_type_path haxe_exception_type_path) null_pos in
match Typeload.load_instance tctx tp ParamSpawnMonos with
match Typeload.load_instance tctx tp ParamSpawnMonos LoadNormal with
(* Add only if `__shiftStack` method exists *)
| TInst(cls,_) when PMap.mem "__shiftStack" cls.cl_fields ->
(fun mt ->
Expand Down
4 changes: 2 additions & 2 deletions src/typing/generic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ let static_method_container gctx c cf p =
let pack = fst c.cl_path in
let name = (snd c.cl_path) ^ "_" ^ cf.cf_name ^ "_" ^ gctx.name in
try
let t = Typeload.load_instance ctx (make_ptp (mk_type_path (pack,name)) p) ParamSpawnMonos in
let t = Typeload.load_instance ctx (make_ptp (mk_type_path (pack,name)) p) ParamSpawnMonos LoadNormal in
match t with
| TInst(cg,_) -> cg
| _ -> raise_typing_error ("Cannot specialize @:generic static method because the generated type name is already used: " ^ name) p
Expand Down Expand Up @@ -271,7 +271,7 @@ let build_generic_class ctx c p tl =
let gctx = make_generic ctx c.cl_params tl (Meta.has (Meta.Custom ":debug.generic") c.cl_meta) p in
let name = (snd c.cl_path) ^ "_" ^ gctx.name in
try
let t = Typeload.load_instance ctx (make_ptp (mk_type_path (pack,name)) p) ParamNormal in
let t = Typeload.load_instance ctx (make_ptp (mk_type_path (pack,name)) p) ParamNormal LoadNormal in
match t with
| TInst({ cl_kind = KGenericInstance (csup,_) },_) when c == csup -> t
| _ -> raise_typing_error ("Cannot specialize @:generic because the generated type name is already used: " ^ name) p
Expand Down
16 changes: 8 additions & 8 deletions src/typing/macroContext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,14 @@ let make_macro_api ctx mctx p =
mk_type_path path
in
try
let m = Some (Typeload.load_instance ctx (make_ptp tp p) ParamSpawnMonos) in
let m = Some (Typeload.load_instance ctx (make_ptp tp p) ParamSpawnMonos LoadAny) in
m
with Error { err_message = Module_not_found _; err_pos = p2 } when p == p2 ->
None
)
);
MacroApi.resolve_type = (fun t p ->
typing_timer ctx false (fun ctx -> Typeload.load_complex_type ctx false (t,p))
typing_timer ctx false (fun ctx -> Typeload.load_complex_type ctx false LoadAny (t,p))
);
MacroApi.resolve_complex_type = (fun t ->
typing_timer ctx false (fun ctx ->
Expand Down Expand Up @@ -450,7 +450,7 @@ let make_macro_api ctx mctx p =
MacroApi.define_type = (fun v mdep ->
let cttype = mk_type_path ~sub:"TypeDefinition" (["haxe";"macro"],"Expr") in
let mctx = (match ctx.g.macros with None -> die "" __LOC__ | Some (_,mctx) -> mctx) in
let ttype = Typeload.load_instance mctx (make_ptp cttype p) ParamNormal in
let ttype = Typeload.load_instance mctx (make_ptp cttype p) ParamNormal LoadNormal in
let f () = Interp.decode_type_def v in
let m, tdef, pos = safe_decode ctx.com v "TypeDefinition" ttype p f in
let has_native_meta = match tdef with
Expand Down Expand Up @@ -825,7 +825,7 @@ let type_macro ctx mode cpath f (el:Ast.expr list) p =
in
let mpos = mfield.cf_pos in
let ctexpr = mk_type_path (["haxe";"macro"],"Expr") in
let expr = Typeload.load_instance mctx (make_ptp ctexpr p) ParamNormal in
let expr = Typeload.load_instance mctx (make_ptp ctexpr p) ParamNormal LoadNormal in
(match mode with
| MDisplay ->
raise Exit (* We don't have to actually call the macro. *)
Expand All @@ -834,18 +834,18 @@ let type_macro ctx mode cpath f (el:Ast.expr list) p =
| MBuild ->
let params = [TPType (make_ptp_th (mk_type_path ~sub:"Field" (["haxe";"macro"],"Expr")) null_pos)] in
let ctfields = mk_type_path ~params ([],"Array") in
let tfields = Typeload.load_instance mctx (make_ptp ctfields p) ParamNormal in
let tfields = Typeload.load_instance mctx (make_ptp ctfields p) ParamNormal LoadNormal in
unify mctx mret tfields mpos
| MMacroType ->
let cttype = mk_type_path (["haxe";"macro"],"Type") in
let ttype = Typeload.load_instance mctx (make_ptp cttype p) ParamNormal in
let ttype = Typeload.load_instance mctx (make_ptp cttype p) ParamNormal LoadNormal in
try
unify_raise mret ttype mpos;
(* TODO: enable this again in the future *)
(* warning ctx WDeprecated "Returning Type from @:genericBuild macros is deprecated, consider returning ComplexType instead" p; *)
with Error { err_message = Unify _ } ->
let cttype = mk_type_path ~sub:"ComplexType" (["haxe";"macro"],"Expr") in
let ttype = Typeload.load_instance mctx (make_ptp cttype p) ParamNormal in
let ttype = Typeload.load_instance mctx (make_ptp cttype p) ParamNormal LoadNormal in
unify_raise mret ttype mpos;
);
(*
Expand Down Expand Up @@ -971,7 +971,7 @@ let type_macro ctx mode cpath f (el:Ast.expr list) p =
spawn_monomorph ctx.e p
else try
let ct = Interp.decode_ctype v in
Typeload.load_complex_type ctx false ct;
Typeload.load_complex_type ctx false LoadNormal ct;
with MacroApi.Invalid_expr | EvalContext.RunTimeException _ ->
Interp.decode_type v
in
Expand Down
2 changes: 1 addition & 1 deletion src/typing/matcher/exprToPattern.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ let get_general_module_type ctx mt p =
end
| _ -> raise_typing_error "Cannot use this type as a value" p
in
Typeload.load_instance ctx (make_ptp {tname=loop mt;tpackage=[];tsub=None;tparams=[]} p) ParamSpawnMonos
Typeload.load_instance ctx (make_ptp {tname=loop mt;tpackage=[];tsub=None;tparams=[]} p) ParamSpawnMonos LoadNormal

let unify_type_pattern ctx mt t p =
let tcl = get_general_module_type ctx mt p in
Expand Down
2 changes: 1 addition & 1 deletion src/typing/operators.ml
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ let make_binop ctx op e1 e2 is_assign_op p =
unify ctx e2.etype b p;
mk_op e1 e2 b
| OpInterval ->
let t = Typeload.load_instance ctx (make_ptp (mk_type_path (["std"],"IntIterator")) null_pos) ParamNormal in
let t = Typeload.load_instance ctx (make_ptp (mk_type_path (["std"],"IntIterator")) null_pos) ParamNormal LoadNormal in
let e1 = AbstractCast.cast_or_unify_raise ctx tint e1 e1.epos in
let e2 = AbstractCast.cast_or_unify_raise ctx tint e2 e2.epos in
BinopSpecial (mk (TNew ((match t with TInst (c,[]) -> c | _ -> die "" __LOC__),[],[e1;e2])) t p,false)
Expand Down
2 changes: 1 addition & 1 deletion src/typing/strictMeta.ml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ let get_strict_meta ctx meta params pos =
display_error ctx.com "A @:strict metadata must contain exactly one parameter. Please check the documentation for more information" pos;
raise Exit
in
let t = Typeload.load_complex_type ctx false (ctype,pos) in
let t = Typeload.load_complex_type ctx false LoadNormal (ctype,pos) in
flush_pass ctx.g PBuildClass "get_strict_meta";
let texpr = type_expr ctx changed_expr NoValue in
let with_type_expr = (ECheckType( (EConst (Ident "null"), pos), (ctype,null_pos) ), pos) in
Expand Down
Loading

0 comments on commit 2fb7155

Please sign in to comment.