Skip to content

Commit

Permalink
Instance builder cleanup (HaxeFoundation#11376)
Browse files Browse the repository at this point in the history
* change return of build_instance to record

* also rename

* also seperate

* also bring back typedef deprecation check

* alsp keep special cases in the right place

* mess around

* avoid some work if we need no params anyway

* make @:generic inference work again

* remove Generic_Exception

* push expected type before loading instance

closes HaxeFoundation#3864

* expand generic types on field call candidate when expanding generic function

closes HaxeFoundation#5482

* build generic parents as well

closes HaxeFoundation#6761

* inherit `@:autoBuild` to generic instance

closes HaxeFoundation#5536

* also inherit @:keepSub while we're at it

closes HaxeFoundation#6500

* deal with KExpr in generic classes properly

closes HaxeFoundation#7574

* don't inherit cf_expr_unoptimized to generic instances

closes HaxeFoundation#9358

* reroute FClosure in map_expr_type

closes HaxeFoundation#9395

* inherit cl_using to generic instances

closes HaxeFoundation#10528

* set inherited flags on generic instance fields at the right time

closes HaxeFoundation#11010

* I really don't care

* wild guess

* avoid the follow change
  • Loading branch information
Simn authored and 0b1kn00b committed Jan 25, 2024
1 parent 5a09a4e commit 88b5af6
Show file tree
Hide file tree
Showing 40 changed files with 867 additions and 404 deletions.
2 changes: 0 additions & 2 deletions src/compiler/compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,6 @@ with
end
| Error.Error err ->
error_ext ctx err
| Generic.Generic_Exception(m,p) ->
error ctx m p
| Arg.Bad msg ->
error ctx ("Error: " ^ msg) null_pos
| Failure msg when not Helper.is_debug_run ->
Expand Down
2 changes: 1 addition & 1 deletion 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 (fun() -> c.cl_params) null_pos sc.d_params);
List.iter (function
| (HExtends(ct,p) | HImplements(ct,p)) when display_position#enclosed_in p ->
ignore(Typeload.load_instance ~allow_display:true ctx (ct,p) false)
ignore(Typeload.load_instance ~allow_display:true ctx (ct,p) ParamNormal)
| _ ->
()
) sc.d_flags;
Expand Down
24 changes: 23 additions & 1 deletion src/context/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ type delay = {
delay_functions : (unit -> unit) list;
}

type build_kind =
| BuildNormal
| BuildGeneric of tclass
| BuildGenericBuild
| BuildMacroType

type build_info = {
build_kind : build_kind;
build_path : path;
build_params : type_params;
build_extern : bool;
build_apply : Type.t list -> Type.t;
}

type typer_globals = {
mutable delayed : delay list;
mutable debug_delayed : (typer_pass * ((unit -> unit) * (string * string list) * typer) list) list;
Expand All @@ -94,7 +108,7 @@ type typer_globals = {
do_load_macro : typer -> bool -> path -> string -> pos -> ((string * bool * t) list * t * tclass * Type.tclass_field);
do_load_module : typer -> path -> pos -> module_def;
do_load_type_def : typer -> pos -> type_path -> module_type;
do_build_instance : typer -> module_type -> pos -> (typed_type_param list * path * (t list -> t));
get_build_info : typer -> module_type -> pos -> build_info;
do_format_string : typer -> string -> pos -> Ast.expr;
do_load_core_class : typer -> tclass -> tclass;
}
Expand Down Expand Up @@ -200,6 +214,14 @@ type dot_path_part = {
pos : pos
}

let make_build_info kind path params extern apply = {
build_kind = kind;
build_path = path;
build_params = params;
build_extern = extern;
build_apply = apply;
}

exception Forbid_package of (string * path * pos) * pos list * string

exception WithTypeError of error
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 allow_no_params =
try Typeload.load_instance' ctx tp allow_no_params
let find_type ctx tp =
try Typeload.load_instance' ctx tp ParamSpawnMonos
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) true) in
let t = (find_type ctx (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 true)
resolve_type_t (find_type ctx 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 true)
resolve_type_t (find_type ctx tp)
in
try
match sub with
Expand Down
5 changes: 4 additions & 1 deletion src/core/tFunctions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,10 @@ let rec follow t =
| Some t -> follow t
| _ -> t)
| TLazy f ->
follow (lazy_type f)
(match !f with
| LAvailable t -> follow t
| _ -> follow (lazy_type f)
)
| TType (t,tl) ->
follow (apply_typedef t tl)
| TAbstract({a_path = [],"Null"},[t]) ->
Expand Down
2 changes: 1 addition & 1 deletion src/core/tType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ type flag_tclass_field =

(* Order has to match declaration for printing*)
let flag_tclass_field_names = [
"CfPublic";"CfStatic";"CfExtern";"CfFinal";"CfModifiesThis";"CfOverride";"CfAbstract";"CfOverload";"CfImpl";"CfEnum";"CfGeneric";"CfDefault"
"CfPublic";"CfStatic";"CfExtern";"CfFinal";"CfModifiesThis";"CfOverride";"CfAbstract";"CfOverload";"CfImpl";"CfEnum";"CfGeneric";"CfDefault";"CfPostProcessed"
]

type flag_tvar =
Expand Down
13 changes: 13 additions & 0 deletions src/core/texpr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,19 @@ let map_expr_type f ft fv e =
{ e with eexpr = TEnumParameter (f e1,ef,i); etype = ft e.etype }
| TEnumIndex e1 ->
{ e with eexpr = TEnumIndex (f e1); etype = ft e.etype }
| TField (e1,(FClosure(None,cf) as fa)) ->
let e1 = f e1 in
let fa = try
begin match quick_field e1.etype cf.cf_name with
| FInstance(c,tl,cf) ->
FClosure(Some(c,tl),cf)
| _ ->
raise Not_found
end
with Not_found ->
fa
in
{ e with eexpr = TField (e1,fa); etype = ft e.etype }
| TField (e1,v) ->
let e1 = f e1 in
let v = try
Expand Down
12 changes: 6 additions & 6 deletions src/filters/exceptions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -532,23 +532,23 @@ let filter tctx =
(mk_type_path (pack,name), null_pos)
in
let wildcard_catch_type =
let t = Typeload.load_instance tctx (tp config.ec_wildcard_catch) true in
let t = Typeload.load_instance tctx (tp config.ec_wildcard_catch) ParamSpawnMonos 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) true in
let t = Typeload.load_instance tctx (tp config.ec_base_throw) ParamSpawnMonos 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) true with
match Typeload.load_instance tctx (tp haxe_exception_type_path) ParamSpawnMonos 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) true with
match Typeload.load_instance tctx (tp value_exception_type_path) ParamSpawnMonos 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")) true with
match Typeload.load_instance tctx (tp (["haxe"],"NativeStackTrace")) ParamSpawnMonos 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 @@ -665,7 +665,7 @@ let insert_save_stacks tctx =
*)
let patch_constructors tctx =
let tp = (mk_type_path haxe_exception_type_path, null_pos) in
match Typeload.load_instance tctx tp true with
match Typeload.load_instance tctx tp ParamSpawnMonos with
(* Add only if `__shiftStack` method exists *)
| TInst(cls,_) when PMap.mem "__shiftStack" cls.cl_fields ->
(fun mt ->
Expand Down
2 changes: 1 addition & 1 deletion src/optimization/inline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ let rec type_inline ctx cf f ethis params tret config p ?(self_calling_closure=f
let tl = arg_types params f.tf_args in
let e = state#finalize e tl tret has_params map_type p in
if Meta.has (Meta.Custom ":inlineDebug") ctx.meta then begin
let se t = s_expr_pretty true t true (s_type (print_context())) in
let se t = s_expr_ast true t (s_type (print_context())) in
print_endline (Printf.sprintf "Inline %s:\n\tArgs: %s\n\tExpr: %s\n\tResult: %s"
cf.cf_name
(String.concat "" (List.map (fun (i,e) -> Printf.sprintf "\n\t\t%s<%i> = %s" (i.i_subst.v_name) (i.i_subst.v_id) (se "\t\t" e)) state#inlined_vars))
Expand Down

0 comments on commit 88b5af6

Please sign in to comment.