Skip to content

Commit

Permalink
Merge branch 'development' into out_of_curiosity_(don't_freak_out)
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/codegen/gencommon/closuresToClass.ml
  • Loading branch information
Simn committed Nov 7, 2023
2 parents f1acd1a + f5fcc45 commit c1eee86
Show file tree
Hide file tree
Showing 22 changed files with 115 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ jobs:
env:
# For compatibility with macOS 10.13
ZLIB_VERSION: 1.3
MBEDTLS_VERSION: 2.25.0
MBEDTLS_VERSION: 2.28.5
PCRE2_VERSION: 10.42
run: |
set -ex
Expand Down
2 changes: 1 addition & 1 deletion extra/github-actions/build-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
env:
# For compatibility with macOS 10.13
ZLIB_VERSION: 1.3
MBEDTLS_VERSION: 2.25.0
MBEDTLS_VERSION: 2.28.5
PCRE2_VERSION: 10.42
run: |
set -ex
Expand Down
14 changes: 14 additions & 0 deletions src-json/define.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,20 @@
"define": "haxe-next",
"doc": "Enable experimental features that are meant to be released on next Haxe version."
},
{
"name": "HaxeOutputFile",
"define": "HAXE_OUTPUT_FILE",
"doc": "Force the full output name of the executable/library without library prefix and debug suffix.",
"platforms": ["cpp"],
"params": ["name"]
},
{
"name": "HaxeOutputPart",
"define": "HAXE_OUTPUT_PART",
"doc": "Output name of the executable/library. (default: main class name)",
"platforms": ["cpp"],
"params": ["name"]
},
{
"name": "HlVer",
"define": "hl-ver",
Expand Down
2 changes: 1 addition & 1 deletion src/context/abstractCast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let rec make_static_call ctx c cf a pl args t p =
e
| _ -> die "" __LOC__
end else
make_static_abstract_call ctx a pl c cf args p
Typecore.make_static_call ctx c cf (apply_params a.a_params pl) args t p

and do_check_cast ctx uctx tleft eright p =
let recurse cf f =
Expand Down
32 changes: 14 additions & 18 deletions src/context/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -234,24 +234,6 @@ let warning ?(depth=0) ctx w msg p =

let make_call ctx e el t p = (!make_call_ref) ctx e el t p

let make_static_call_gen ctx c cf el map p =
let monos = Monomorph.spawn_constrained_monos map cf.cf_params in
let t = map (apply_params cf.cf_params monos cf.cf_type) in
match follow t with
| TFun(args,ret) ->
let ethis = Texpr.Builder.make_static_this c p in
let ef = mk (TField(ethis,FStatic(c,cf))) t p in
make_call ctx ef el ret p
| t ->
raise_typing_error (s_type (print_context()) t ^ " cannot be called") p

let make_static_class_call ctx c cf el p =
make_static_call_gen ctx c cf el (fun t -> t) p

let make_static_abstract_call ctx a tl c cf el p =
let map = apply_params a.a_params tl in
make_static_call_gen ctx c cf el map p

let type_expr ?(mode=MGet) ctx e with_type = (!type_expr_ref) ~mode ctx e with_type

let unify_min ctx el = (!unify_min_ref) ctx el
Expand All @@ -265,6 +247,20 @@ let spawn_monomorph' ctx p =
let spawn_monomorph ctx p =
TMono (spawn_monomorph' ctx p)

let make_static_this c p =
let ta = mk_anon ~fields:c.cl_statics (ref (ClassStatics c)) in
mk (TTypeExpr (TClassDecl c)) ta p

let make_static_field_access c cf t p =
let ethis = make_static_this c p in
mk (TField (ethis,(FStatic (c,cf)))) t p

let make_static_call ctx c cf map args t p =
let monos = List.map (fun _ -> spawn_monomorph ctx p) cf.cf_params in
let map t = map (apply_params cf.cf_params monos t) in
let ef = make_static_field_access c cf (map cf.cf_type) p in
make_call ctx ef args (map t) p

let raise_with_type_error ?(depth = 0) msg p =
raise (WithTypeError (make_error ~depth (Custom msg) p))

Expand Down
30 changes: 19 additions & 11 deletions src/core/tPrinting.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,36 @@ let s_module_type_kind = function
| TAbstractDecl a -> "TAbstractDecl(" ^ (s_type_path a.a_path) ^ ")"
| TTypeDecl t -> "TTypeDecl(" ^ (s_type_path t.t_path) ^ ")"

let show_mono_ids = true

let rec s_type ctx t =
match t with
| TMono r ->
(match r.tm_type with
| None ->
begin try
let id = List.assq t (!ctx) in
Printf.sprintf "Unknown<%d>" id
if show_mono_ids then
Printf.sprintf "Unknown<%d>" id
else
"Unknown"
with Not_found ->
let id = List.length !ctx in
ctx := (t,id) :: !ctx;
let s_const =
let rec loop = function
| CUnknown -> ""
| CTypes tl -> String.concat " & " (List.map (fun (t,_) -> s_type ctx t) tl)
| CStructural(fields,_) -> s_type ctx (mk_anon ~fields (ref Closed))
| CMixed l -> String.concat " & " (List.map loop l)
let s_const =
let rec loop = function
| CUnknown -> ""
| CTypes tl -> String.concat " & " (List.map (fun (t,_) -> s_type ctx t) tl)
| CStructural(fields,_) -> s_type ctx (mk_anon ~fields (ref Closed))
| CMixed l -> String.concat " & " (List.map loop l)
in
let s = loop (!monomorph_classify_constraints_ref r) in
if s = "" then s else " : " ^ s
in
let s = loop (!monomorph_classify_constraints_ref r) in
if s = "" then s else " : " ^ s
in
Printf.sprintf "Unknown<%d>%s" id s_const
if show_mono_ids then
Printf.sprintf "Unknown<%d>%s" id s_const
else
Printf.sprintf "Unknown%s" s_const
end
| Some t -> s_type ctx t)
| TEnum (e,tl) ->
Expand Down
6 changes: 3 additions & 3 deletions src/core/texpr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,9 @@ module Builder = struct
in
mk (TTypeExpr mt) t pos

let make_static_field_access c cf t p =
let ethis = make_static_this c p in
mk (TField (ethis,(FStatic (c,cf)))) t p
let make_static_field c cf p =
let e_this = make_static_this c p in
mk (TField(e_this,FStatic(c,cf))) cf.cf_type p

let make_throw e p =
mk (TThrow e) t_dynamic p
Expand Down
21 changes: 18 additions & 3 deletions src/filters/exceptions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ let haxe_exception_static_call ctx method_name args p =
try PMap.find method_name ctx.haxe_exception_class.cl_statics
with Not_found -> raise_typing_error ("haxe.Exception has no field " ^ method_name) p
in
let return_type =
match follow method_field.cf_type with
| TFun(_,t) -> t
| _ -> raise_typing_error ("haxe.Exception." ^ method_name ^ " is not a function and cannot be called") p
in
add_dependency ctx.typer.curclass.cl_module ctx.haxe_exception_class.cl_module;
make_static_class_call ctx.typer ctx.haxe_exception_class method_field args p
make_static_call ctx.typer ctx.haxe_exception_class method_field (fun t -> t) args return_type p

(**
Generate `haxe_exception.method_name(args)`
Expand Down Expand Up @@ -69,8 +74,13 @@ let std_is ctx e t p =
try PMap.find "isOfType" std_cls.cl_statics
with Not_found -> raise_typing_error ("Std has no field isOfType") p
in
let return_type =
match follow isOfType_field.cf_type with
| TFun(_,t) -> t
| _ -> raise_typing_error ("Std.isOfType is not a function and cannot be called") p
in
let type_expr = { eexpr = TTypeExpr(module_type_of_type t); etype = t; epos = p } in
make_static_class_call ctx.typer std_cls isOfType_field [e; type_expr] p
make_static_call ctx.typer std_cls isOfType_field (fun t -> t) [e; type_expr] return_type p

(**
Check if type path of `t` exists in `lst`
Expand Down Expand Up @@ -609,10 +619,15 @@ let insert_save_stacks tctx =
try PMap.find "saveStack" native_stack_trace_cls.cl_statics
with Not_found -> raise_typing_error ("haxe.NativeStackTrace has no field saveStack") null_pos
in
let return_type =
match follow method_field.cf_type with
| TFun(_,t) -> t
| _ -> raise_typing_error ("haxe.NativeStackTrace." ^ method_field.cf_name ^ " is not a function and cannot be called") null_pos
in
let catch_local = mk (TLocal catch_var) catch_var.v_type catch_var.v_pos in
begin
add_dependency tctx.curclass.cl_module native_stack_trace_cls.cl_module;
make_static_class_call tctx native_stack_trace_cls method_field [catch_local] catch_var.v_pos
make_static_call tctx native_stack_trace_cls method_field (fun t -> t) [catch_local] return_type catch_var.v_pos
end
else
mk (TBlock[]) tctx.t.tvoid catch_var.v_pos
Expand Down
2 changes: 1 addition & 1 deletion src/filters/filters.ml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ module LocalStatic = struct
| TLocal v when has_var_flag v VStatic ->
begin try
let cf = find_local_static local_static_lut v in
Texpr.Builder.make_static_field_access c cf cf.cf_type e.epos
Texpr.Builder.make_static_field c cf e.epos
with Not_found ->
raise_typing_error (Printf.sprintf "Could not find local static %s (id %i)" v.v_name v.v_id) e.epos
end
Expand Down
20 changes: 11 additions & 9 deletions src/generators/genjvm.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2494,19 +2494,21 @@ class tclass_to_jvm gctx c = object(self)
let field_info = gctx.preprocessor#get_field_info cf.cf_meta in
self#generate_expr gctx field_info jc jm e scmode mtype;
end;
begin match cf.cf_params with
| [] when c.cl_params = [] ->
()
let ssig = generate_method_signature true jsig in
let ssig = match cf.cf_params with
| [] ->
ssig
| _ ->
let stl = String.concat "" (List.map (fun tp ->
Printf.sprintf "%s:Ljava/lang/Object;" tp.ttp_name
) cf.cf_params) in
let ssig = generate_method_signature true (jsignature_of_type gctx cf.cf_type) in
let s = if cf.cf_params = [] then ssig else Printf.sprintf "<%s>%s" stl ssig in
let offset = jc#get_pool#add_string s in
jm#add_attribute (AttributeSignature offset);
Printf.sprintf "<%s>%s" stl ssig
in
if ssig <> jm#get_descriptor then begin
let offset = jc#get_pool#add_string ssig in
jm#add_attribute (AttributeSignature offset);
end;
AnnotationHandler.generate_annotations (jm :> JvmBuilder.base_builder) cf.cf_meta;
AnnotationHandler.generate_annotations (jm :> JvmBuilder.base_builder) cf.cf_meta

method generate_field gctx (jc : JvmClass.builder) c mtype cf =
let jsig = jsignature_of_type gctx cf.cf_type in
Expand All @@ -2517,7 +2519,7 @@ class tclass_to_jvm gctx c = object(self)
let jm = jc#spawn_field cf.cf_name jsig flags in
let default e =
let p = null_pos in
let efield = Texpr.Builder.make_static_field_access c cf cf.cf_type p in
let efield = Texpr.Builder.make_static_field c cf p in
let eop = mk (TBinop(OpAssign,efield,e)) cf.cf_type p in
begin match c.cl_init with
| None -> c.cl_init <- Some eop
Expand Down
5 changes: 3 additions & 2 deletions src/generators/jvm/jvmMethod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class builder jc name jsig = object(self)
inherit base_builder
val code = new JvmCode.builder jc#get_pool

val descriptor = generate_method_signature false jsig
val mutable max_num_locals = 0
val mutable debug_locals = []
val mutable stack_frames = []
Expand Down Expand Up @@ -1081,6 +1082,7 @@ class builder jc name jsig = object(self)
method is_terminated = code#is_terminated
method get_name = name
method get_jsig = jsig
method get_descriptor = descriptor
method set_terminated b = code#set_terminated b

method private get_jcode (config : export_config) =
Expand Down Expand Up @@ -1149,8 +1151,7 @@ class builder jc name jsig = object(self)
end;
let attributes = self#export_attributes jc#get_pool in
let offset_name = jc#get_pool#add_string name in
let jsig = generate_method_signature false jsig in
let offset_desc = jc#get_pool#add_string jsig in
let offset_desc = jc#get_pool#add_string descriptor in
{
field_access_flags = access_flags;
field_name_index = offset_name;
Expand Down
6 changes: 3 additions & 3 deletions src/optimization/inline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ let api_inline ctx c field params p =
let m = (try ctx.com.module_lut#find path with Not_found -> die "" __LOC__) in
add_dependency ctx.m.curmod m;
Option.get (ExtList.List.find_map (function
| TClassDecl cl when cl.cl_path = path -> Some (Texpr.Builder.make_static_this cl p)
| TClassDecl cl when cl.cl_path = path -> Some (make_static_this cl p)
| _ -> None
) m.m_types)
in
Expand Down Expand Up @@ -160,7 +160,7 @@ let api_inline ctx c field params p =
None)
| (["js"],"Boot"),"__downcastCheck",[o; {eexpr = TTypeExpr (TClassDecl cls) } as t] when ctx.com.platform = Js ->
if (has_class_flag cls CInterface) then
Some (Texpr.Builder.fcall (Texpr.Builder.make_static_this c p) "__implements" [o;t] tbool p)
Some (Texpr.Builder.fcall (make_static_this c p) "__implements" [o;t] tbool p)
else
Some (Texpr.Builder.fcall (eJsSyntax()) "instanceof" [o;t] tbool p)
| (["haxe";"ds";"_Vector"],"Vector_Impl_"),("fromArrayCopy"),[{ eexpr = TArrayDecl args } as edecl] -> (try
Expand Down Expand Up @@ -914,7 +914,7 @@ and inline_rest_params ctx f params map_type p =
in
let array = mk (TArrayDecl params) (ctx.t.tarray t_params) p in
(* haxe.Rest.of(array) *)
let e = make_static_abstract_call ctx a [t] c cf [array] p in
let e = make_static_call ctx c cf (apply_params a.a_params [t]) [array] (TAbstract(a,[t_params])) p in
[e]
| _ ->
die ~p:v.v_pos "Unexpected rest arguments type" __LOC__
Expand Down
2 changes: 1 addition & 1 deletion src/typing/fieldAccess.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ open Typecore
open Type
open Error

type field_access_mode =
type field_host =
(* Get the plain expression with applied field type parameters. *)
| FGet
(* Does not apply field type parameters. *)
Expand Down
4 changes: 2 additions & 2 deletions src/typing/forLoop.ml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ module IterationKind = struct
| TAbstract({a_impl = Some c} as a,tl) ->
let cf_length = PMap.find "get_length" c.cl_statics in
let get_length e p =
make_static_abstract_call ctx a tl c cf_length [e] p
make_static_call ctx c cf_length (apply_params a.a_params tl) [e] ctx.com.basic.tint p
in
(match follow cf_length.cf_type with
| TFun(_,tr) ->
Expand All @@ -155,7 +155,7 @@ module IterationKind = struct
let todo = mk (TConst TNull) ctx.t.tint p in
let cf,_,r,_ = AbstractCast.find_array_read_access_raise ctx a tl todo p in
let get_next e_base e_index t p =
make_static_abstract_call ctx a tl c cf [e_base;e_index] p
make_static_call ctx c cf (apply_params a.a_params tl) [e_base;e_index] r p
in
IteratorCustom(get_next,get_length),e,r
with Not_found ->
Expand Down
2 changes: 1 addition & 1 deletion src/typing/matcher/texprConverter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let constructor_to_texpr ctx con =
| ConConst ct -> make_const_texpr ctx.com.basic ct p
| ConArray i -> make_int ctx.com.basic i p
| ConTypeExpr mt -> TyperBase.type_module_type ctx mt p
| ConStatic(c,cf) -> make_static_field_access c cf cf.cf_type p
| ConStatic(c,cf) -> make_static_field c cf p
| ConFields _ -> raise_typing_error "Something went wrong" p

let s_subject v_lookup s e =
Expand Down
6 changes: 3 additions & 3 deletions src/typing/operators.ml
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ let make_binop ctx op e1 e2 is_assign_op with_type p =
die "" __LOC__

let find_abstract_binop_overload ctx op e1 e2 a c tl left is_assign_op with_type p =
let map = apply_params a.a_params tl in
let make op_cf cf e1 e2 tret needs_assign swapped =
if cf.cf_expr = None && not (has_class_field_flag cf CfExtern) then begin
if not (Meta.has Meta.NoExpr cf.cf_meta) then Common.display_error ctx.com "Recursive operator method" p;
Expand Down Expand Up @@ -436,11 +437,11 @@ let find_abstract_binop_overload ctx op e1 e2 a c tl left is_assign_op with_type
let vr = new value_reference ctx in
let e2' = vr#as_var "lhs" e2 in
let e1' = vr#as_var "rhs" e1 in
let e = make_static_abstract_call ctx a tl c cf [e1';e2'] p in
let e = make_static_call ctx c cf map [e1';e2'] tret p in
let e = vr#to_texpr e in
BinopResult.create_special e needs_assign
end else
BinopResult.create_special (make_static_abstract_call ctx a tl c cf [e1;e2] p) needs_assign
BinopResult.create_special (make_static_call ctx c cf map [e1;e2] tret p) needs_assign
in
(* special case for == and !=: if the second type is a monomorph, assume that we want to unify
it with the first type to preserve comparison semantics. *)
Expand All @@ -466,7 +467,6 @@ let find_abstract_binop_overload ctx op e1 e2 a c tl left is_assign_op with_type
let check e1 e2 swapped =
let map_arguments () =
let monos = Monomorph.spawn_constrained_monos (fun t -> t) cf.cf_params in
let map = apply_params a.a_params tl in
let map t = map (apply_params cf.cf_params monos t) in
let t1 = map t1 in
let t2 = map t2 in
Expand Down
4 changes: 2 additions & 2 deletions src/typing/typeloadCheck.ml
Original file line number Diff line number Diff line change
Expand Up @@ -550,14 +550,14 @@ module Inheritance = struct
if c.cl_super <> None then raise_typing_error "Cannot extend several classes" p;
let csup,params = check_extends ctx c t p in
if (has_class_flag c CInterface) then begin
if not (has_class_flag csup CInterface) then raise_typing_error "Cannot extend by using a class" p;
if not (has_class_flag csup CInterface) then raise_typing_error (Printf.sprintf "Cannot extend by using a class (%s extends %s)" (s_type_path c.cl_path) (s_type_path csup.cl_path)) p;
c.cl_implements <- (csup,params) :: c.cl_implements;
if not !has_interf then begin
if not is_lib then delay ctx PConnectField check_interfaces_or_delay;
has_interf := true;
end
end else begin
if (has_class_flag csup CInterface) then raise_typing_error "Cannot extend by using an interface" p;
if (has_class_flag csup CInterface) then raise_typing_error (Printf.sprintf "Cannot extend by using an interface (%s extends %s)" (s_type_path c.cl_path) (s_type_path csup.cl_path)) p;
c.cl_super <- Some (csup,params)
end;
(fun () ->
Expand Down
2 changes: 1 addition & 1 deletion src/typing/typer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2010,7 +2010,7 @@ and type_expr ?(mode=MGet) ctx (e,p) (with_type:WithType.t) =
try PMap.find "isOfType" c.cl_statics
with Not_found -> die "" __LOC__
in
Texpr.Builder.make_static_field_access c cf cf.cf_type (mk_zero_range_pos p)
Texpr.Builder.make_static_field c cf (mk_zero_range_pos p)
| _ -> die "" __LOC__
in
mk (TCall (e_Std_isOfType, [e; e_t])) ctx.com.basic.tbool p
Expand Down
Loading

0 comments on commit c1eee86

Please sign in to comment.