浏览代码

Merge branch 'development' into out_of_curiosity_(don't_freak_out)

# Conflicts:
#	src/codegen/gencommon/closuresToClass.ml
Simon Krajewski 1 年之前
父节点
当前提交
c1eee86a88

+ 1 - 1
.github/workflows/main.yml

@@ -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

+ 1 - 1
extra/github-actions/build-mac.yml

@@ -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

+ 14 - 0
src-json/define.json

@@ -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",

+ 1 - 1
src/context/abstractCast.ml

@@ -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 =

+ 14 - 18
src/context/typecore.ml

@@ -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
@@ -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))
 

+ 19 - 11
src/core/tPrinting.ml

@@ -28,6 +28,8 @@ 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 ->
@@ -35,21 +37,27 @@ let rec s_type ctx t =
 		| 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) ->

+ 3 - 3
src/core/texpr.ml

@@ -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

+ 18 - 3
src/filters/exceptions.ml

@@ -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)`
@@ -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`
@@ -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

+ 1 - 1
src/filters/filters.ml

@@ -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

+ 11 - 9
src/generators/genjvm.ml

@@ -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
@@ -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

+ 3 - 2
src/generators/jvm/jvmMethod.ml

@@ -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 = []
@@ -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) =
@@ -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;

+ 3 - 3
src/optimization/inline.ml

@@ -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
@@ -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
@@ -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__

+ 1 - 1
src/typing/fieldAccess.ml

@@ -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. *)

+ 2 - 2
src/typing/forLoop.ml

@@ -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) ->
@@ -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 ->

+ 1 - 1
src/typing/matcher/texprConverter.ml

@@ -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 =

+ 3 - 3
src/typing/operators.ml

@@ -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;
@@ -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. *)
@@ -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

+ 2 - 2
src/typing/typeloadCheck.ml

@@ -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 () ->

+ 1 - 1
src/typing/typer.ml

@@ -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

+ 2 - 0
std/Date.hx

@@ -178,6 +178,8 @@ extern class Date {
 
 		The first two formats expressed a date in local time. The third is a time
 		relative to the UTC epoch.
+
+		If `s` does not match these formats, the result is unspecified.
 	**/
 	static function fromString(s:String):Date;
 }

+ 1 - 1
std/sys/thread/Mutex.hx

@@ -28,7 +28,7 @@ package sys.thread;
 
 /**
 	Creates a mutex, which can be used to acquire a temporary lock
-	to access some ressource. The main difference with a lock is
+	to access some resource. The main difference with a lock is
 	that a mutex must always be released by the owner thread.
 **/
 extern class Mutex {

+ 10 - 0
tests/misc/cs/projects/Issue11350/Main.hx

@@ -0,0 +1,10 @@
+class Main {
+	public static function main() {}
+
+	public static function forComparable<T : Comparable<T>>(): T->T->Void
+		return (a: T, b: T) -> {}
+}
+
+typedef Comparable<T> = {
+	public function compareTo(that : T) : Int;
+}

+ 3 - 0
tests/misc/cs/projects/Issue11350/compile.hxml

@@ -0,0 +1,3 @@
+--main Main
+-cs bin
+-D net-ver=45