From fbec81a917224893f6f58e16205d7f790344ef4c Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Wed, 12 Jun 2024 12:06:42 +0200 Subject: [PATCH 01/35] add missing recursion when checking abstract casts closes #11676 --- src/context/abstractCast.ml | 11 ++-- tests/misc/projects/Issue11676/Main.hx | 55 +++++++++++++++++++ tests/misc/projects/Issue11676/compile.hxml | 2 + .../projects/Issue11676/compile.hxml.stdout | 1 + 4 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 tests/misc/projects/Issue11676/Main.hx create mode 100644 tests/misc/projects/Issue11676/compile.hxml create mode 100644 tests/misc/projects/Issue11676/compile.hxml.stdout diff --git a/src/context/abstractCast.ml b/src/context/abstractCast.ml index 820a6c7d420..6e01cf2898a 100644 --- a/src/context/abstractCast.ml +++ b/src/context/abstractCast.ml @@ -233,7 +233,7 @@ let find_multitype_specialization com a pl p = cf, follow m let handle_abstract_casts ctx e = - let rec loop ctx e = match e.eexpr with + let rec loop e = match e.eexpr with | TNew({cl_kind = KAbstractImpl a} as c,pl,el) -> if not (Meta.has Meta.MultiType a.a_meta) then begin (* This must have been a @:generic expansion with a { new } constraint (issue #4364). In this case @@ -285,10 +285,11 @@ let handle_abstract_casts ctx e = | TCast(e2,None) -> {e1 with eexpr = TCast(find_field e2,None)} | TField(e2,fa) -> + let e2 = loop e2 in let a,pl,e2 = find_abstract e2 e2.etype in let m = Abstract.get_underlying_type a pl in let fname = field_name fa in - let el = List.map (loop ctx) el in + let el = List.map loop el in begin try let fa = quick_field m fname in let get_fun_type t = match follow t with @@ -342,11 +343,11 @@ let handle_abstract_casts ctx e = in find_field e1 with Not_found -> - Type.map_expr (loop ctx) e + Type.map_expr loop e end | _ -> - Type.map_expr (loop ctx) e + Type.map_expr loop e in - loop ctx e + loop e ;; Typecore.cast_or_unify_raise_ref := cast_or_unify_raise diff --git a/tests/misc/projects/Issue11676/Main.hx b/tests/misc/projects/Issue11676/Main.hx new file mode 100644 index 00000000000..d4563220bb2 --- /dev/null +++ b/tests/misc/projects/Issue11676/Main.hx @@ -0,0 +1,55 @@ +class Main { + static function main() { + var comp = new AComponent([1, 2, 3]); + trace(comp.doSomething()); + } +} + +interface Component { + function doSomething():T; +} + +@:forward +@:multiType +abstract AComponent(Component) { + public function new(value:T); + + @:to public static inline function toInt(t:Component, value:Int):IntComponent { + return new IntComponent(value); + } + + @:to public static inline function toIntArray(t:Component>, value:Array):ArrayComponent { + return new ArrayComponent(value); + } +} + +@:generic +@:remove +class ArrayComponent implements Component> { + final value:Array; + + public function new(value:Array) { + this.value = value; + var x = []; + for (i in 0...value.length) { + var y = new AComponent(this.value[i]).doSomething(); + x.push(y); + } + } + + public function doSomething():Array { + return this.value; + } +} + +class IntComponent implements Component { + final value:Int; + + public function new(value:Int) { + this.value = value; + } + + public function doSomething():Int { + return value; + } +} diff --git a/tests/misc/projects/Issue11676/compile.hxml b/tests/misc/projects/Issue11676/compile.hxml new file mode 100644 index 00000000000..5f82c470c12 --- /dev/null +++ b/tests/misc/projects/Issue11676/compile.hxml @@ -0,0 +1,2 @@ +-m Main +--interp \ No newline at end of file diff --git a/tests/misc/projects/Issue11676/compile.hxml.stdout b/tests/misc/projects/Issue11676/compile.hxml.stdout new file mode 100644 index 00000000000..6f559e06558 --- /dev/null +++ b/tests/misc/projects/Issue11676/compile.hxml.stdout @@ -0,0 +1 @@ +Main.hx:4: [1,2,3] \ No newline at end of file From 85160f788c94e71f2559a33c7916d86a16994814 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Wed, 15 May 2024 14:29:20 +0200 Subject: [PATCH 02/35] [macro] Don't choke on namePos for reification pattern matching (#11671) * [macro] Don't choke on namePos for reification pattern matching * [tests] Add test for 11670 * Do it like in #11433 --- src/typing/matcher.ml | 7 ++++++- tests/misc/projects/Issue11670/Main.hx | 16 ++++++++++++++++ tests/misc/projects/Issue11670/compile.hxml | 1 + .../misc/projects/Issue11670/compile.hxml.stdout | 0 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/misc/projects/Issue11670/Main.hx create mode 100644 tests/misc/projects/Issue11670/compile.hxml create mode 100644 tests/misc/projects/Issue11670/compile.hxml.stdout diff --git a/src/typing/matcher.ml b/src/typing/matcher.ml index 450b619e1ba..f0d7cbe6f8b 100644 --- a/src/typing/matcher.ml +++ b/src/typing/matcher.ml @@ -480,9 +480,14 @@ module Pattern = struct let is_matchable cf = match cf.cf_kind with Method _ -> false | _ -> true in + (* TODO: This needs a better check, but it's not obvious how to approach this. See #11433 *) + let is_probably_pos cf = match cf.cf_name with + | "pos" | "posPath" | "namePos" -> true + | _ -> false + in let patterns,fields = List.fold_left (fun (patterns,fields) (cf,t) -> try - if pctx.in_reification && cf.cf_name = "pos" then raise Not_found; + if pctx.in_reification && is_probably_pos cf then raise Not_found; let e1 = Expr.field_assoc cf.cf_name fl in make pctx false t e1 :: patterns,cf.cf_name :: fields with Not_found -> diff --git a/tests/misc/projects/Issue11670/Main.hx b/tests/misc/projects/Issue11670/Main.hx new file mode 100644 index 00000000000..429ed1ca762 --- /dev/null +++ b/tests/misc/projects/Issue11670/Main.hx @@ -0,0 +1,16 @@ +class Main { + static function main() { + test(var foo:String); + } + + static macro function test(e) { + switch e { + // Unrecognized pattern: untyped $__mk_pos__("Test.hx", 145, 150) + case macro var $name:$ct: + case _: + } + + return macro {}; + } +} + diff --git a/tests/misc/projects/Issue11670/compile.hxml b/tests/misc/projects/Issue11670/compile.hxml new file mode 100644 index 00000000000..42409e72918 --- /dev/null +++ b/tests/misc/projects/Issue11670/compile.hxml @@ -0,0 +1 @@ +-main Main diff --git a/tests/misc/projects/Issue11670/compile.hxml.stdout b/tests/misc/projects/Issue11670/compile.hxml.stdout new file mode 100644 index 00000000000..e69de29bb2d From f54e91a95b8cf59dcf0c5f20552821e4bf69cb1d Mon Sep 17 00:00:00 2001 From: Zeta <53486764+Apprentice-Alchemist@users.noreply.github.com> Date: Thu, 9 May 2024 13:59:17 +0200 Subject: [PATCH 03/35] [struct-init] Ignore non-physical fields. (#11662) --- src/typing/typeloadFields.ml | 6 ++--- tests/misc/projects/Issue11661/Main.hx | 27 +++++++++++++++++++++ tests/misc/projects/Issue11661/compile.hxml | 2 ++ 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 tests/misc/projects/Issue11661/Main.hx create mode 100644 tests/misc/projects/Issue11661/compile.hxml diff --git a/src/typing/typeloadFields.ml b/src/typing/typeloadFields.ml index 175608066b3..11533c92015 100644 --- a/src/typing/typeloadFields.ml +++ b/src/typing/typeloadFields.ml @@ -209,9 +209,7 @@ let ensure_struct_init_constructor ctx c ast_fields p = let params = extract_param_types c.cl_params in let ethis = mk (TConst TThis) (TInst(c,params)) p in let doc_buf = Buffer.create 0 in - let args,el,tl = List.fold_left (fun (args,el,tl) cf -> match cf.cf_kind with - | Var { v_write = AccNever } -> args,el,tl - | Var _ -> + let args,el,tl = List.fold_left (fun (args,el,tl) cf -> if is_physical_var_field cf then let has_default_expr = field_has_default_expr cf.cf_name in let opt = has_default_expr || (Meta.has Meta.Optional cf.cf_meta) in let t = if opt then ctx.t.tnull cf.cf_type else cf.cf_type in @@ -245,7 +243,7 @@ let ensure_struct_init_constructor ctx c ast_fields p = Buffer.add_string doc_buf "\n"; end; (v,None) :: args,e :: el,(cf.cf_name,opt,t) :: tl - | Method _ -> + else args,el,tl ) ([],[],[]) (List.rev c.cl_ordered_fields) in let el = match super_expr with Some e -> e :: el | None -> el in diff --git a/tests/misc/projects/Issue11661/Main.hx b/tests/misc/projects/Issue11661/Main.hx new file mode 100644 index 00000000000..3d5d2043240 --- /dev/null +++ b/tests/misc/projects/Issue11661/Main.hx @@ -0,0 +1,27 @@ +@:structInit +class Foo { + @:isVar public var real(get, set):String; + public var foo(get, never):String; + public var bar(get, set):String; + + function get_real() + return real; + + function set_real(v) + return real = v; + + function get_foo() + return "foo"; + + function get_bar() + return "bar"; + + function set_bar(v) + return v; +} + +function main() { + var foo:Foo = { + real: "real" + }; +} diff --git a/tests/misc/projects/Issue11661/compile.hxml b/tests/misc/projects/Issue11661/compile.hxml new file mode 100644 index 00000000000..5f82c470c12 --- /dev/null +++ b/tests/misc/projects/Issue11661/compile.hxml @@ -0,0 +1,2 @@ +-m Main +--interp \ No newline at end of file From 76aee53f0c7fdbca44283e71857e37075787c47e Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Tue, 23 Apr 2024 11:10:16 +0200 Subject: [PATCH 04/35] inherit `@:unreflective` on generic classes see https://github.com/HaxeFoundation/hxcpp/issues/1102 --- src/typing/generic.ml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/typing/generic.ml b/src/typing/generic.ml index ba94b7bb2a6..c1645486098 100644 --- a/src/typing/generic.ml +++ b/src/typing/generic.ml @@ -254,7 +254,8 @@ let rec build_generic_class ctx c p tl = | NoClosure | NullSafety | Pure | Struct | StructInit - | Using -> + | Using + | Unreflective -> true | _ -> false From e9d811912bc7e986d782d43f8b16d68460f6f275 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Fri, 28 Jun 2024 09:50:50 +0200 Subject: [PATCH 05/35] also inherit @:keepSub while we're at it closes #6500 --- src/typing/generic.ml | 2 +- tests/unit/src/unit/TestDCE.hx | 161 +++++++++++++++++++++------------ 2 files changed, 103 insertions(+), 60 deletions(-) diff --git a/src/typing/generic.ml b/src/typing/generic.ml index c1645486098..c23636eef92 100644 --- a/src/typing/generic.ml +++ b/src/typing/generic.ml @@ -250,7 +250,7 @@ let rec build_generic_class ctx c p tl = | Final | Hack | Internal - | Keep + | Keep | KeepSub | NoClosure | NullSafety | Pure | Struct | StructInit diff --git a/tests/unit/src/unit/TestDCE.hx b/tests/unit/src/unit/TestDCE.hx index 5d670629198..7ae3e2595f0 100644 --- a/tests/unit/src/unit/TestDCE.hx +++ b/tests/unit/src/unit/TestDCE.hx @@ -1,57 +1,85 @@ package unit; private typedef Foo = { - var bar(get, null): Bar; + var bar(get, null):Bar; } private typedef Bar = { - var data: Int; + var data:Int; } private class AdrianV { - public var bar(get, null): Bar = {data: 100}; + public var bar(get, null):Bar = {data: 100}; + function get_bar() { return bar; } public function new() {} - static public function testFoo(foo: Foo) { + static public function testFoo(foo:Foo) { return foo.bar.data; } } +@:generic @:keepSub @:keep +class GenericKeepSub {} + +class ChildOfGenericKeepSub extends GenericKeepSub {} + @:analyzer(no_local_dce) class DCEClass { // used statics - static function staticUsed() { } - @:keep static function staticKeep() { } + static function staticUsed() {} + + @:keep static function staticKeep() {} + static var staticVarUsed = "foo"; @:isVar static var staticPropUsed(get, set):Int = 1; - static function get_staticPropUsed() return staticPropUsed; - static function set_staticPropUsed(i:Int) return 0; + + static function get_staticPropUsed() + return staticPropUsed; + + static function set_staticPropUsed(i:Int) + return 0; // used members - function memberUsed() { } - @:keep function memberKeep() { } + function memberUsed() {} + + @:keep function memberKeep() {} + var memberVarUsed = 0; @:isVar var memberPropUsed(get, set):Int = 1; - function get_memberPropUsed() return memberPropUsed; - function set_memberPropUsed(i:Int) return 0; + + function get_memberPropUsed() + return memberPropUsed; + + function set_memberPropUsed(i:Int) + return 0; // unused statics - static function staticUnused() { } + static function staticUnused() {} + static var staticVarUnused = "bar"; static var staticPropUnused(get, set):Int; - static function get_staticPropUnused() return 0; - static function set_staticPropUnused(i:Int) return 0; + + static function get_staticPropUnused() + return 0; + + static function set_staticPropUnused(i:Int) + return 0; // unused members - function memberUnused() { } + function memberUnused() {} + var memberVarUnused = 1; var memberPropUnused(get, set):Int; - function get_memberPropUnused() return 0; - function set_memberPropUnused(i:Int) return 0; + + function get_memberPropUnused() + return 0; + + function set_memberPropUnused(i:Int) + return 0; static var c:Array = [null, unit.UsedReferenced2]; @@ -68,7 +96,9 @@ class DCEClass { new UsedConstructed(); - try cast (null, UsedReferenced) catch(e:Dynamic) { } + try + cast(null, UsedReferenced) + catch (e:Dynamic) {} new UsedAsBaseChild(); c.push(null); @@ -77,7 +107,6 @@ class DCEClass { @:analyzer(no_local_dce) class TestDCE extends Test { - public function testFields() { var dce = new DCEClass(); var c = Type.getClass(dce); @@ -177,13 +206,17 @@ class TestDCE extends Test { var c = new ThrownWithToString(); try { throw c; - } catch (_:Dynamic) { } + } catch (_:Dynamic) {} #if js if (!js.Browser.supported || js.Browser.navigator.userAgent.indexOf('MSIE 8') == -1) #end hf(ThrownWithToString, "toString"); } + function testIssue6500() { + t(Type.resolveClass("unit.ChildOfGenericKeepSub") != null); + } + public function testIssue7259() { var me = new AdrianV(); AdrianV.testFoo(me); @@ -194,28 +227,24 @@ class TestDCE extends Test { public function testIssue10162() { eq('bar', foo(ClassWithBar)); } - static function foo & { function bar():String; }>(cls:T) + + static function foo & {function bar():String;}>(cls:T) return cls.bar(); } class ClassWithBar { - static public function bar() return 'bar'; + static public function bar() + return 'bar'; } class UsedConstructed { - public function new() { } -} - -class UsedReferenced { } -class UsedReferenced2 { } - -class UsedConstructedChild extends UsedConstructed { - + public function new() {} } -class UsedReferencedChild extends UsedReferenced { - -} +class UsedReferenced {} +class UsedReferenced2 {} +class UsedConstructedChild extends UsedConstructed {} +class UsedReferencedChild extends UsedReferenced {} interface UsedInterface { public function usedInterfaceFunc():Void; @@ -223,26 +252,28 @@ interface UsedInterface { } class UsedThroughInterface implements UsedInterface { - public function new() { } - public function usedInterfaceFunc():Void { } - public function unusedInterfaceFunc():Void { } - public function otherFunc() { } -} + public function new() {} -class UsedAsBase { } -class UsedAsBaseChild extends UsedAsBase { - public function new() { } + public function usedInterfaceFunc():Void {} + + public function unusedInterfaceFunc():Void {} + + public function otherFunc() {} } -class Unused { +class UsedAsBase {} +class UsedAsBaseChild extends UsedAsBase { + public function new() {} } -class UnusedChild extends Unused { } +class Unused {} +class UnusedChild extends Unused {} class UnusedImplements implements UsedInterface { - public function usedInterfaceFunc():Void { } - public function unusedInterfaceFunc():Void { } + public function usedInterfaceFunc():Void {} + + public function unusedInterfaceFunc():Void {} } interface PropertyInterface { @@ -250,37 +281,49 @@ interface PropertyInterface { } class PropertyAccessorsFromBaseClass { - public function get_x() return throw "must not set"; - public function set_x(x:String) return "ok"; + public function get_x() + return throw "must not set"; + + public function set_x(x:String) + return "ok"; } class PropertyAccessorsFromBaseClassChild extends PropertyAccessorsFromBaseClass implements PropertyInterface { public var x(get, set):String; - public function new() { } + + public function new() {} } class InterfaceMethodFromBaseClass { - public function usedInterfaceFunc():Void { } - public function unusedInterfaceFunc():Void { } + public function usedInterfaceFunc():Void {} + + public function unusedInterfaceFunc():Void {} } class InterfaceMethodFromBaseClassChild extends InterfaceMethodFromBaseClass implements UsedInterface { - public function new() { } + public function new() {} } class ThrownWithToString { - public function new() { } - public function toString() { return "I was thrown today"; } -} + public function new() {} + public function toString() { + return "I was thrown today"; + } +} -class RemovePropertyKeepAccessors -{ +class RemovePropertyKeepAccessors { public function new() {} var _test:Float; + public var test(get, set):Float; - public function get_test():Float return _test; - public function set_test(a:Float):Float { _test = a; return _test; } + public function get_test():Float + return _test; + + public function set_test(a:Float):Float { + _test = a; + return _test; + } } From 0fd492315b61e0c1a47d7eb4e530bf09697f456c Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Thu, 20 Jun 2024 11:11:37 +0200 Subject: [PATCH 06/35] [Pretty errors] Position file is already resolved, don't resolve again (#11700) * Pretty errors: pfile is already resolved * [tests] add test * Simplify test hxml --- src/compiler/server.ml | 13 +------------ .../projects/Issue11700/.haxelib/mylib/.current | 1 + .../Issue11700/.haxelib/mylib/git/src/Main.hx | 1 + tests/misc/projects/Issue11700/compile-fail.hxml | 5 +++++ .../projects/Issue11700/compile-fail.hxml.stderr | 6 ++++++ tests/misc/projects/Issue11700/src/Main.hx | 1 + 6 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 tests/misc/projects/Issue11700/.haxelib/mylib/.current create mode 100644 tests/misc/projects/Issue11700/.haxelib/mylib/git/src/Main.hx create mode 100644 tests/misc/projects/Issue11700/compile-fail.hxml create mode 100644 tests/misc/projects/Issue11700/compile-fail.hxml.stderr create mode 100644 tests/misc/projects/Issue11700/src/Main.hx diff --git a/src/compiler/server.ml b/src/compiler/server.ml index c29a8433833..54863874524 100644 --- a/src/compiler/server.ml +++ b/src/compiler/server.ml @@ -153,15 +153,6 @@ module Communication = struct try loop 0 ""; with End_of_file -> close_in ch; List.rev !lines - let resolve_file ctx f = - let ext = Common.extension f in - let second_ext = Common.extension (Common.remove_extension f) in - let platform_ext = "." ^ (platform_name_macro ctx) in - if platform_ext = second_ext then - (Common.remove_extension (Common.remove_extension f)) ^ ext - else - f - let compiler_pretty_message_string ctx ectx cm = match cm.cm_message with (* Filter some messages that don't add much when using this message renderer *) @@ -177,10 +168,8 @@ module Communication = struct let epos = if is_unknown_file cm.cm_pos.pfile then "(unknown position)" else cm.cm_pos.pfile in (-1, -1, -1, -1, epos, []) end else try begin - let f = resolve_file ctx.com cm.cm_pos.pfile in - let f = Common.find_file ctx.com f in let l1, p1, l2, p2 = Lexer.get_pos_coords cm.cm_pos in - let lines = resolve_source f l1 p1 l2 p2 in + let lines = resolve_source cm.cm_pos.pfile l1 p1 l2 p2 in let epos = Lexer.get_error_pos error_printer cm.cm_pos in (l1, p1, l2, p2, epos, lines) end with Not_found | Sys_error _ -> diff --git a/tests/misc/projects/Issue11700/.haxelib/mylib/.current b/tests/misc/projects/Issue11700/.haxelib/mylib/.current new file mode 100644 index 00000000000..5664e303b5d --- /dev/null +++ b/tests/misc/projects/Issue11700/.haxelib/mylib/.current @@ -0,0 +1 @@ +git diff --git a/tests/misc/projects/Issue11700/.haxelib/mylib/git/src/Main.hx b/tests/misc/projects/Issue11700/.haxelib/mylib/git/src/Main.hx new file mode 100644 index 00000000000..c9e302a78b5 --- /dev/null +++ b/tests/misc/projects/Issue11700/.haxelib/mylib/git/src/Main.hx @@ -0,0 +1 @@ +Nope diff --git a/tests/misc/projects/Issue11700/compile-fail.hxml b/tests/misc/projects/Issue11700/compile-fail.hxml new file mode 100644 index 00000000000..bf0292fa2c6 --- /dev/null +++ b/tests/misc/projects/Issue11700/compile-fail.hxml @@ -0,0 +1,5 @@ +-lib mylib +-cp src +-main Main +-D message.reporting=pretty +-D message.no-color diff --git a/tests/misc/projects/Issue11700/compile-fail.hxml.stderr b/tests/misc/projects/Issue11700/compile-fail.hxml.stderr new file mode 100644 index 00000000000..31672752986 --- /dev/null +++ b/tests/misc/projects/Issue11700/compile-fail.hxml.stderr @@ -0,0 +1,6 @@ +[ERROR] src/Main.hx:1: characters 1-6 + + 1 | trace(""); + | ^^^^^ + | Unexpected trace + diff --git a/tests/misc/projects/Issue11700/src/Main.hx b/tests/misc/projects/Issue11700/src/Main.hx new file mode 100644 index 00000000000..247d4efa543 --- /dev/null +++ b/tests/misc/projects/Issue11700/src/Main.hx @@ -0,0 +1 @@ +trace(""); From 9a7b7e6d45cb7eba78956ca97c8c37321f386446 Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Tue, 4 Jun 2024 13:15:28 +0200 Subject: [PATCH 07/35] fail nicer if unify_min can't find a common type closes #11684 --- src/core/tUnification.ml | 2 +- tests/misc/projects/Issue11684/Main.hx | 5 +++++ tests/misc/projects/Issue11684/compile-fail.hxml | 2 ++ tests/misc/projects/Issue11684/compile-fail.hxml.stderr | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 tests/misc/projects/Issue11684/Main.hx create mode 100644 tests/misc/projects/Issue11684/compile-fail.hxml create mode 100644 tests/misc/projects/Issue11684/compile-fail.hxml.stderr diff --git a/src/core/tUnification.ml b/src/core/tUnification.ml index c947fe36ec9..e7ca575d800 100644 --- a/src/core/tUnification.ml +++ b/src/core/tUnification.ml @@ -1164,7 +1164,7 @@ module UnifyMinT = struct begin match common_types with | [] -> begin match !first_error with - | None -> die "" __LOC__ + | None -> UnifyMinError([Unify_custom "Could not determine common type, please add a type-hint"],0) | Some(l,p) -> UnifyMinError(l,p) end | hd :: _ -> diff --git a/tests/misc/projects/Issue11684/Main.hx b/tests/misc/projects/Issue11684/Main.hx new file mode 100644 index 00000000000..25ba4751605 --- /dev/null +++ b/tests/misc/projects/Issue11684/Main.hx @@ -0,0 +1,5 @@ +function test(input) { + return (input is Array) ? input[0] : input; +} + +function main() {} diff --git a/tests/misc/projects/Issue11684/compile-fail.hxml b/tests/misc/projects/Issue11684/compile-fail.hxml new file mode 100644 index 00000000000..b30a755894b --- /dev/null +++ b/tests/misc/projects/Issue11684/compile-fail.hxml @@ -0,0 +1,2 @@ +--main Main +--interp \ No newline at end of file diff --git a/tests/misc/projects/Issue11684/compile-fail.hxml.stderr b/tests/misc/projects/Issue11684/compile-fail.hxml.stderr new file mode 100644 index 00000000000..f8faedf6a69 --- /dev/null +++ b/tests/misc/projects/Issue11684/compile-fail.hxml.stderr @@ -0,0 +1 @@ +Main.hx:2: characters 42-47 : Could not determine common type, please add a type-hint \ No newline at end of file From bf8028fce7b3cce047d86a124a5dc12d8844d6d3 Mon Sep 17 00:00:00 2001 From: Zeta <53486764+Apprentice-Alchemist@users.noreply.github.com> Date: Tue, 4 Jun 2024 11:59:09 +0200 Subject: [PATCH 08/35] Expose TVar VStatic flag in macros. (#11683) --- src/macro/macroApi.ml | 1 + std/haxe/macro/Type.hx | 5 +++++ tests/misc/projects/Issue11682/Main.hx | 6 ++++++ tests/misc/projects/Issue11682/Main.macro.hx | 10 ++++++++++ tests/misc/projects/Issue11682/compile.hxml | 2 ++ 5 files changed, 24 insertions(+) create mode 100644 tests/misc/projects/Issue11682/Main.hx create mode 100644 tests/misc/projects/Issue11682/Main.macro.hx create mode 100644 tests/misc/projects/Issue11682/compile.hxml diff --git a/src/macro/macroApi.ml b/src/macro/macroApi.ml index 6011ae7be39..f534c0db2c9 100644 --- a/src/macro/macroApi.ml +++ b/src/macro/macroApi.ml @@ -1296,6 +1296,7 @@ and encode_tvar v = "capture", vbool (has_var_flag v VCaptured); "extra", vopt f_extra v.v_extra; "meta", encode_meta v.v_meta (fun m -> v.v_meta <- m); + "isStatic", vbool (has_var_flag v VStatic); "$", encode_unsafe (Obj.repr v); ] diff --git a/std/haxe/macro/Type.hx b/std/haxe/macro/Type.hx index 4e2a20deb8b..7f782bc3f18 100644 --- a/std/haxe/macro/Type.hx +++ b/std/haxe/macro/Type.hx @@ -770,6 +770,11 @@ typedef TVar = { The metadata of the variable. **/ public var meta(default, never):Null; + + /** + Whether the variable is a local static variable + **/ + public var isStatic(default, never):Bool; } /** diff --git a/tests/misc/projects/Issue11682/Main.hx b/tests/misc/projects/Issue11682/Main.hx new file mode 100644 index 00000000000..12495477db9 --- /dev/null +++ b/tests/misc/projects/Issue11682/Main.hx @@ -0,0 +1,6 @@ +function main() { + static var foo = 0; + myMacro(foo); +} + +macro function myMacro(expr:haxe.macro.Expr):haxe.macro.Expr; \ No newline at end of file diff --git a/tests/misc/projects/Issue11682/Main.macro.hx b/tests/misc/projects/Issue11682/Main.macro.hx new file mode 100644 index 00000000000..56a891406db --- /dev/null +++ b/tests/misc/projects/Issue11682/Main.macro.hx @@ -0,0 +1,10 @@ +macro function myMacro(expr:haxe.macro.Expr):haxe.macro.Expr { + var texpr = haxe.macro.Context.typeExpr(expr); + switch texpr.expr { + case TLocal(tvar) if (tvar.isStatic): + case _: + haxe.macro.Context.error("Expected local static", expr.pos); + } + + return macro null; +} diff --git a/tests/misc/projects/Issue11682/compile.hxml b/tests/misc/projects/Issue11682/compile.hxml new file mode 100644 index 00000000000..5f82c470c12 --- /dev/null +++ b/tests/misc/projects/Issue11682/compile.hxml @@ -0,0 +1,2 @@ +-m Main +--interp \ No newline at end of file From 034695552ca0a4fe196326ab6683eda8da1e850e Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Thu, 18 Jul 2024 07:52:38 +0200 Subject: [PATCH 09/35] [4.3.5] Backport Json RPC diagnostics (#11707) * [display] diagnostics as json rpc (Backport #11412) * [tests] use json rpc diagnostics * [tests] Add test for 11695 * [tests] Update diagnostics tests * Run some filters in diagnostics (#11220) * let's see how much breaks * [tests] enable diagnostics tests for 11177 and 11184 * [tests] Update test for 5306 * Don't cache/run filters for find reference/implementation requests (#11226) * Only run filters and save cache on diagnostics, not usage requests * [tests] Update test for 11184 * disable test * add VUsedByTyper to avoid bad unused local errors * revert @:compilerGenerated change --------- Co-authored-by: Rudy Ges * [display] get rid of TypeloadParse.current_stdin * [display] fix -D display-stdin handling * [display] generalize fileContents behavior to other json rpc display calls * [display] fix range of pattern variables Note: not including texprConverter changes see https://github.com/HaxeFoundation/haxe/commit/160a49095d5e54fe65345c896c7d02d18369b9ce see #7282 * [tests] add test for #7282 * [tests] add test for #7931 * Remove populateCacheFromDisplay config Legacy diagnostics = false, json rpc diagnostics = true * [std] Diagnostics request doc * [tests] Test Json RPC diagnostics with several open files * [diagnostics] fix multi display files (#11722) * [diagnostics] fix json rpc diagnostics display config * [tests] Server tests: do not fail silently when runHaxeJsonCb errors * [tests] add more diagnostics tests * [display] rework multiple display files handling * clean up a bit... * [diagnostics] handle a.b.c.hx case, even if pointless * [diagnostics] do not skip errors during DisplayProcessing.process_display_file * Enable display tests again... * [tests] fix display tests --------- Co-authored-by: Simon Krajewski --- src/compiler/compiler.ml | 29 ++- src/compiler/displayOutput.ml | 12 +- src/compiler/displayProcessing.ml | 79 ++++---- src/compiler/server.ml | 23 ++- src/compiler/serverConfig.ml | 1 - src/context/common.ml | 7 +- src/context/display/diagnostics.ml | 18 +- src/context/display/diagnosticsPrinter.ml | 4 +- src/context/display/displayJson.ml | 61 ++++-- src/core/display/displayPosition.ml | 25 ++- src/core/displayTypes.ml | 1 - src/core/tType.ml | 7 +- src/filters/filters.ml | 6 +- src/optimization/analyzer.ml | 6 +- src/optimization/inline.ml | 1 - src/typing/callUnification.ml | 1 - src/typing/typeloadParse.ml | 32 ++-- src/typing/typer.ml | 4 +- src/typing/typerBase.ml | 10 +- std/haxe/display/Display.hx | 19 +- std/haxe/display/Server.hx | 1 - tests/display/build.hxml | 2 +- tests/display/src/cases/Issue5306.hx | 13 +- tests/server/src/TestCase.hx | 41 ++-- tests/server/src/cases/ServerTests.hx | 177 +++++++++++++++++- .../src/cases/display/issues/Issue10635.hx | 22 ++- tests/server/src/cases/issues/Issue10653.hx | 9 +- tests/server/src/cases/issues/Issue11177.hx | 31 +-- tests/server/src/cases/issues/Issue11184.hx | 30 +-- tests/server/src/cases/issues/Issue11203.hx | 23 +++ tests/server/src/cases/issues/Issue11695.hx | 39 ++++ tests/server/src/cases/issues/Issue7282.hx | 22 +++ tests/server/src/cases/issues/Issue7931.hx | 13 ++ tests/server/src/cases/issues/Issue8687.hx | 9 +- .../diagnostics/multi-files/File1.hx | 5 + .../diagnostics/multi-files/File2.hx | 5 + .../diagnostics/multi-files/File3.hx | 5 + .../templates/diagnostics/multi-files/Main.hx | 4 + .../issues/Issue11203/MainAbstract.hx | 16 ++ .../templates/issues/Issue11203/MainClass.hx | 15 ++ .../templates/issues/Issue11695/Macro1.hx | 1 + .../templates/issues/Issue11695/Macro2.hx | 1 + .../test/templates/issues/Issue11695/Main.hx | 3 + .../test/templates/issues/Issue7282/Main.hx | 10 + .../test/templates/issues/Issue7931/Main.hx | 6 + .../test/templates/issues/Issue9134/Main.hx | 5 + .../test/templates/issues/Issue9134/Main2.hx | 6 + .../test/templates/issues/Issue9134/Other.hx | 2 + .../test/templates/issues/Issue9134/Other2.hx | 6 + 49 files changed, 677 insertions(+), 191 deletions(-) create mode 100644 tests/server/src/cases/issues/Issue11203.hx create mode 100644 tests/server/src/cases/issues/Issue11695.hx create mode 100644 tests/server/src/cases/issues/Issue7282.hx create mode 100644 tests/server/src/cases/issues/Issue7931.hx create mode 100644 tests/server/test/templates/diagnostics/multi-files/File1.hx create mode 100644 tests/server/test/templates/diagnostics/multi-files/File2.hx create mode 100644 tests/server/test/templates/diagnostics/multi-files/File3.hx create mode 100644 tests/server/test/templates/diagnostics/multi-files/Main.hx create mode 100644 tests/server/test/templates/issues/Issue11203/MainAbstract.hx create mode 100644 tests/server/test/templates/issues/Issue11203/MainClass.hx create mode 100644 tests/server/test/templates/issues/Issue11695/Macro1.hx create mode 100644 tests/server/test/templates/issues/Issue11695/Macro2.hx create mode 100644 tests/server/test/templates/issues/Issue11695/Main.hx create mode 100644 tests/server/test/templates/issues/Issue7282/Main.hx create mode 100644 tests/server/test/templates/issues/Issue7931/Main.hx create mode 100644 tests/server/test/templates/issues/Issue9134/Main.hx create mode 100644 tests/server/test/templates/issues/Issue9134/Main2.hx create mode 100644 tests/server/test/templates/issues/Issue9134/Other.hx create mode 100644 tests/server/test/templates/issues/Issue9134/Other2.hx diff --git a/src/compiler/compiler.ml b/src/compiler/compiler.ml index 02977cd3f5f..2dcd61acfca 100644 --- a/src/compiler/compiler.ml +++ b/src/compiler/compiler.ml @@ -2,15 +2,18 @@ open Globals open Common open CompilationContext -let run_or_diagnose ctx f arg = +let run_or_diagnose ctx f = let com = ctx.com in let handle_diagnostics ?(depth = 0) msg kind = ctx.has_error <- true; add_diagnostics_message ~depth com msg kind Error; - DisplayOutput.emit_diagnostics ctx.com + match com.report_mode with + | RMLegacyDiagnostics _ -> DisplayOutput.emit_legacy_diagnostics ctx.com + | RMDiagnostics _ -> DisplayOutput.emit_diagnostics ctx.com + | _ -> die "" __LOC__ in if is_diagnostics com then begin try - f arg + f () with | Error.Error(msg,p,depth) -> handle_diagnostics ~depth (Error.error_msg p msg) DKCompilerMessage @@ -20,7 +23,7 @@ let run_or_diagnose ctx f arg = handle_diagnostics (located (Lexer.error_msg msg) p) DKParserError end else - f arg + f () let run_command ctx cmd = let t = Timer.timer ["command";cmd] in @@ -279,7 +282,7 @@ let do_type ctx tctx actx = if com.display.dms_kind <> DMNone then DisplayTexpr.check_display_file tctx cs; List.iter (fun cpath -> ignore(tctx.Typecore.g.Typecore.do_load_module tctx cpath null_pos)) (List.rev actx.classes); Finalization.finalize tctx; - ) (); + ); com.stage <- CTypingDone; (* If we are trying to find references, let's syntax-explore everything we know to check for the identifier we are interested in. We then type only those modules that contain the identifier. *) @@ -293,23 +296,25 @@ let finalize_typing ctx tctx = let t = Timer.timer ["finalize"] in let com = ctx.com in com.stage <- CFilteringStart; - let main, types, modules = run_or_diagnose ctx Finalization.generate tctx in + let main, types, modules = run_or_diagnose ctx (fun () -> Finalization.generate tctx) in com.main <- main; com.types <- types; com.modules <- modules; t() -let filter ctx tctx = +let filter ctx tctx before_destruction = let t = Timer.timer ["filters"] in DeprecationCheck.run ctx.com; - Filters.run ctx.com tctx ctx.com.main; + run_or_diagnose ctx (fun () -> Filters.run tctx ctx.com.main before_destruction); t() let compile ctx actx = let com = ctx.com in (* Set up display configuration *) DisplayProcessing.process_display_configuration ctx; + let restore = disable_report_mode com in let display_file_dot_path = DisplayProcessing.process_display_file com actx in + restore (); (* Initialize target: This allows access to the appropriate std packages and sets the -D defines. *) let ext = Setup.initialize_target ctx com actx in com.config <- get_config com; (* make sure to adapt all flags changes defined after platform *) @@ -331,8 +336,12 @@ let compile ctx actx = end; DisplayProcessing.handle_display_after_typing ctx tctx display_file_dot_path; finalize_typing ctx tctx; - DisplayProcessing.handle_display_after_finalization ctx tctx display_file_dot_path; - filter ctx tctx; + if is_diagnostics com then + filter ctx tctx (fun () -> DisplayProcessing.handle_display_after_finalization ctx tctx display_file_dot_path) + else begin + DisplayProcessing.handle_display_after_finalization ctx tctx display_file_dot_path; + filter ctx tctx (fun () -> ()); + end; if ctx.has_error then raise Abort; Generate.check_auxiliary_output com actx; com.stage <- CGenerationStart; diff --git a/src/compiler/displayOutput.ml b/src/compiler/displayOutput.ml index 46045ce6aad..725662f400e 100644 --- a/src/compiler/displayOutput.ml +++ b/src/compiler/displayOutput.ml @@ -372,12 +372,22 @@ let handle_type_path_exception ctx p c is_import pos = api.send_result (DisplayException.fields_to_json ctx fields kind (DisplayTypes.make_subject None pos)); end -let emit_diagnostics com = +let emit_legacy_diagnostics com = let dctx = Diagnostics.run com in let s = Json.string_of_json (DiagnosticsPrinter.json_of_diagnostics com dctx) in DisplayPosition.display_position#reset; raise (Completion s) +let emit_diagnostics com = + (match com.Common.json_out with + | None -> die "" __LOC__ + | Some api -> + let dctx = Diagnostics.run com in + let diagnostics = DiagnosticsPrinter.json_of_diagnostics com dctx in + DisplayPosition.display_position#reset; + api.send_result diagnostics; + raise Abort (* not reached because send_result always raises *)) + let emit_statistics tctx = let stats = Statistics.collect_statistics tctx [SFFile (DisplayPosition.display_position#get).pfile] true in let s = Statistics.Printer.print_statistics stats in diff --git a/src/compiler/displayProcessing.ml b/src/compiler/displayProcessing.ml index d228c4ad6d0..f08b091239c 100644 --- a/src/compiler/displayProcessing.ml +++ b/src/compiler/displayProcessing.ml @@ -22,7 +22,7 @@ let handle_display_argument_old com file_pos actx = actx.did_something <- true; (try Memory.display_memory com with e -> prerr_endline (Printexc.get_backtrace ())); | "diagnostics" -> - com.report_mode <- RMDiagnostics [] + com.report_mode <- RMLegacyDiagnostics [] | _ -> let file, pos = try ExtString.String.split file_pos "@" with _ -> failwith ("Invalid format: " ^ file_pos) in let file = Helper.unquote file in @@ -46,9 +46,9 @@ let handle_display_argument_old com file_pos actx = | "module-symbols" -> create (DMModuleSymbols None) | "diagnostics" -> - com.report_mode <- RMDiagnostics [file_unique]; + com.report_mode <- RMLegacyDiagnostics [file_unique]; let dm = create DMNone in - {dm with dms_display_file_policy = DFPAlso; dms_per_file = true; dms_populate_cache = !ServerConfig.populate_cache_from_display} + {dm with dms_display_file_policy = DFPAlso; dms_per_file = true} | "statistics" -> com.report_mode <- RMStatistics; let dm = create DMNone in @@ -142,11 +142,11 @@ let process_display_file com actx = | DFPOnly when (DisplayPosition.display_position#get).pfile = file_input_marker -> actx.classes <- []; com.main_class <- None; - begin match !TypeloadParse.current_stdin with - | Some input -> - TypeloadParse.current_stdin := None; + begin match com.file_contents with + | [_, Some input] -> + com.file_contents <- []; DPKInput input - | None -> + | _ -> DPKNone end | dfp -> @@ -154,36 +154,41 @@ let process_display_file com actx = actx.classes <- []; com.main_class <- None; end; - let real = Path.get_real_path (DisplayPosition.display_position#get).pfile in - let path = match get_module_path_from_file_path com real with - | Some path -> - if com.display.dms_kind = DMPackage then DisplayException.raise_package (fst path); - let path = match ExtString.String.nsplit (snd path) "." with - | [name;"macro"] -> - (* If we have a .macro.hx path, don't add the file to classes because the compiler won't find it. - This can happen if we're completing in such a file. *) - DPKMacro (fst path,name) - | [name] -> - actx.classes <- path :: actx.classes; - DPKNormal path - | [name;target] -> - let path = fst path, name in - actx.classes <- path :: actx.classes; - DPKNormal path - | e -> - die "" __LOC__ + let dpk = List.map (fun file_key -> + let real = Path.get_real_path (Path.UniqueKey.to_string file_key) in + let dpk = match get_module_path_from_file_path com real with + | Some path -> + if com.display.dms_kind = DMPackage then DisplayException.raise_package (fst path); + let dpk = match ExtString.String.nsplit (snd path) "." with + | [name;"macro"] -> + (* If we have a .macro.hx path, don't add the file to classes because the compiler won't find it. + This can happen if we're completing in such a file. *) + DPKMacro (fst path,name) + | [name] -> + actx.classes <- path :: actx.classes; + DPKNormal path + | [name;target] -> + let path = fst path, name in + actx.classes <- path :: actx.classes; + DPKNormal path + | _ -> + failwith ("Invalid display file '" ^ real ^ "'") + in + dpk + | None -> + if not (Sys.file_exists real) then failwith "Display file does not exist"; + (match List.rev (ExtString.String.nsplit real Path.path_sep) with + | file :: _ when file.[0] >= 'a' && file.[0] <= 'z' -> failwith ("Display file '" ^ file ^ "' should not start with a lowercase letter") + | _ -> ()); + DPKDirect real in - path - | None -> - if not (Sys.file_exists real) then failwith "Display file does not exist"; - (match List.rev (ExtString.String.nsplit real Path.path_sep) with - | file :: _ when file.[0] >= 'a' && file.[0] <= 'z' -> failwith ("Display file '" ^ file ^ "' should not start with a lowercase letter") - | _ -> ()); - DPKDirect real - in - Common.log com ("Display file : " ^ real); + Common.log com ("Display file : " ^ real); + dpk + ) DisplayPosition.display_position#get_files in Common.log com ("Classes found : [" ^ (String.concat "," (List.map s_type_path actx.classes)) ^ "]"); - path + match dpk with + | [dfile] -> dfile + | _ -> DPKNone (* 3. Loaders for display file that might be called *) @@ -348,10 +353,12 @@ let handle_display_after_finalization ctx tctx display_file_dot_path = end; process_global_display_mode com tctx; begin match com.report_mode with + | RMLegacyDiagnostics _ -> + DisplayOutput.emit_legacy_diagnostics com | RMDiagnostics _ -> DisplayOutput.emit_diagnostics com | RMStatistics -> DisplayOutput.emit_statistics tctx | RMNone -> () - end \ No newline at end of file + end diff --git a/src/compiler/server.ml b/src/compiler/server.ml index 54863874524..d9433fa4ede 100644 --- a/src/compiler/server.ml +++ b/src/compiler/server.ml @@ -18,15 +18,7 @@ let has_error ctx = ctx.has_error || ctx.com.Common.has_error let check_display_flush ctx f_otherwise = match ctx.com.json_out with - | None -> - if is_diagnostics ctx.com then begin - List.iter (fun cm -> - add_diagnostics_message ~depth:cm.cm_depth ctx.com (located cm.cm_message cm.cm_pos) cm.cm_kind cm.cm_severity - ) (List.rev ctx.messages); - raise (Completion (Diagnostics.print ctx.com)) - end else - f_otherwise () - | Some api -> + | Some api when not (is_diagnostics ctx.com) -> if has_error ctx then begin let errors = List.map (fun cm -> JObject [ @@ -37,6 +29,17 @@ let check_display_flush ctx f_otherwise = match ctx.com.json_out with ) (List.rev ctx.messages) in api.send_error errors end + | _ -> + if is_diagnostics ctx.com then begin + List.iter (fun cm -> + add_diagnostics_message ~depth:cm.cm_depth ctx.com (located cm.cm_message cm.cm_pos) cm.cm_kind cm.cm_severity + ) (List.rev ctx.messages); + (match ctx.com.report_mode with + | RMDiagnostics _ -> () + | RMLegacyDiagnostics _ -> raise (Completion (Diagnostics.print ctx.com)) + | _ -> die "" __LOC__) + end else + f_otherwise () let current_stdin = ref None @@ -46,7 +49,7 @@ let parse_file cs com file p = and fkey = com.file_keys#get file in let is_display_file = DisplayPosition.display_position#is_in_file (com.file_keys#get ffile) in match is_display_file, !current_stdin with - | true, Some stdin when Common.defined com Define.DisplayStdin -> + | true, Some stdin when (com.file_contents <> [] || Common.defined com Define.DisplayStdin) -> TypeloadParse.parse_file_from_string com file p stdin | _ -> let ftime = file_time ffile in diff --git a/src/compiler/serverConfig.ml b/src/compiler/serverConfig.ml index 173637cb401..4df99ef1afc 100644 --- a/src/compiler/serverConfig.ml +++ b/src/compiler/serverConfig.ml @@ -1,3 +1,2 @@ let do_not_check_modules = ref false -let populate_cache_from_display = ref true let legacy_completion = ref false diff --git a/src/context/common.ml b/src/context/common.ml index 75394ee8e80..5db64e530c3 100644 --- a/src/context/common.ml +++ b/src/context/common.ml @@ -272,7 +272,8 @@ type compiler_stage = type report_mode = | RMNone - | RMDiagnostics of Path.UniqueKey.t list + | RMLegacyDiagnostics of (Path.UniqueKey.t list) + | RMDiagnostics of (Path.UniqueKey.t list) | RMStatistics class virtual ['key,'value] lookup = object(self) @@ -382,6 +383,7 @@ type context = { display_information : display_information; file_lookup_cache : (string,string option) lookup; file_keys : file_keys; + mutable file_contents : (Path.UniqueKey.t * string option) list; readdir_cache : (string * string,(string array) option) lookup; parser_cache : (string,(type_def * pos) list) lookup; module_to_file : (path,string) lookup; @@ -852,6 +854,7 @@ let create compilation_step cs version args = }; file_lookup_cache = new hashtbl_lookup; file_keys = new file_keys; + file_contents = []; readdir_cache = new hashtbl_lookup; module_to_file = new hashtbl_lookup; stored_typed_exprs = new hashtbl_lookup; @@ -867,7 +870,7 @@ let create compilation_step cs version args = com let is_diagnostics com = match com.report_mode with - | RMDiagnostics _ -> true + | RMLegacyDiagnostics _ | RMDiagnostics _ -> true | _ -> false let disable_report_mode com = diff --git a/src/context/display/diagnostics.ml b/src/context/display/diagnostics.ml index 29b7153375e..be45370dfb7 100644 --- a/src/context/display/diagnostics.ml +++ b/src/context/display/diagnostics.ml @@ -20,13 +20,14 @@ let find_unused_variables com e = let vars = Hashtbl.create 0 in let pmin_map = Hashtbl.create 0 in let rec loop e = match e.eexpr with - | TVar({v_kind = VUser _} as v,eo) when v.v_name <> "_" -> + | TVar({v_kind = VUser origin} as v,eo) when v.v_name <> "_" && not (has_var_flag v VUsedByTyper) -> Hashtbl.add pmin_map e.epos.pmin v; let p = match eo with - | None -> e.epos - | Some e1 -> - loop e1; - { e.epos with pmax = e1.epos.pmin } + | Some e1 when origin <> TVOPatternVariable -> + loop e1; + { e.epos with pmax = e1.epos.pmin } + | _ -> + e.epos in Hashtbl.replace vars v.v_id (v,p); | TLocal ({v_kind = VUser _} as v) -> @@ -179,15 +180,10 @@ let prepare com = dctx.unresolved_identifiers <- com.display_information.unresolved_identifiers; dctx -let secure_generated_code ctx e = - (* This causes problems and sucks in general... need a different solution. But I forgot which problem this solved anyway. *) - (* mk (TMeta((Meta.Extern,[],e.epos),e)) e.etype e.epos *) - e - let print com = let dctx = prepare com in Json.string_of_json (DiagnosticsPrinter.json_of_diagnostics com dctx) let run com = let dctx = prepare com in - dctx \ No newline at end of file + dctx diff --git a/src/context/display/diagnosticsPrinter.ml b/src/context/display/diagnosticsPrinter.ml index 1e953ac7d0f..4eca774207c 100644 --- a/src/context/display/diagnosticsPrinter.ml +++ b/src/context/display/diagnosticsPrinter.ml @@ -25,8 +25,8 @@ let make_diagnostic kd p sev args = { let is_diagnostics_file com file_key = match com.report_mode with - | RMDiagnostics [] -> true - | RMDiagnostics file_keys -> List.exists (fun key' -> file_key = key') file_keys + | RMLegacyDiagnostics [] | RMDiagnostics [] -> true + | RMLegacyDiagnostics file_keys | RMDiagnostics file_keys -> List.mem file_key file_keys | _ -> false module UnresolvedIdentifierSuggestion = struct diff --git a/src/context/display/displayJson.ml b/src/context/display/displayJson.ml index 8baf530a0b1..917d5cd4e15 100644 --- a/src/context/display/displayJson.ml +++ b/src/context/display/displayJson.ml @@ -60,18 +60,49 @@ class display_handler (jsonrpc : jsonrpc_handler) com (cs : CompilationCache.t) let file = jsonrpc#get_string_param "file" in Path.get_full_path file ) file_input_marker in - let pos = if requires_offset then jsonrpc#get_int_param "offset" else (-1) in - TypeloadParse.current_stdin := jsonrpc#get_opt_param (fun () -> + let contents = jsonrpc#get_opt_param (fun () -> let s = jsonrpc#get_string_param "contents" in - Common.define com Define.DisplayStdin; (* TODO: awkward *) Some s - ) None; + ) None in + + let pos = if requires_offset then jsonrpc#get_int_param "offset" else (-1) in Parser.was_auto_triggered := was_auto_triggered; - DisplayPosition.display_position#set { - pfile = file; - pmin = pos; - pmax = pos; - } + + if file <> file_input_marker then begin + let file_unique = com.file_keys#get file in + + DisplayPosition.display_position#set { + pfile = file; + pmin = pos; + pmax = pos; + }; + + com.file_contents <- [file_unique, contents]; + end else begin + let file_contents = jsonrpc#get_opt_param (fun () -> + jsonrpc#get_opt_param (fun () -> jsonrpc#get_array_param "fileContents") [] + ) [] in + + let file_contents = List.map (fun fc -> match fc with + | JObject fl -> + let file = jsonrpc#get_string_field "fileContents" "file" fl in + let file = Path.get_full_path file in + let file_unique = com.file_keys#get file in + let contents = jsonrpc#get_opt_param (fun () -> + let s = jsonrpc#get_string_field "fileContents" "contents" fl in + Some s + ) None in + (file_unique, contents) + | _ -> invalid_arg "fileContents" + ) file_contents in + + let files = (List.map (fun (k, _) -> k) file_contents) in + com.file_contents <- file_contents; + + match files with + | [] -> DisplayPosition.display_position#set { pfile = file; pmin = pos; pmax = pos; }; + | _ -> DisplayPosition.display_position#set_files files; + end end type handler_context = { @@ -126,6 +157,12 @@ let handler = hctx.display#set_display_file false true; hctx.display#enable_display DMDefinition; ); + "display/diagnostics", (fun hctx -> + hctx.display#set_display_file false false; + hctx.display#enable_display DMNone; + hctx.com.display <- { hctx.com.display with dms_display_file_policy = DFPAlso; dms_per_file = true; dms_populate_cache = true }; + hctx.com.report_mode <- RMDiagnostics (List.map (fun (f,_) -> f) hctx.com.file_contents); + ); "display/implementation", (fun hctx -> hctx.display#set_display_file false true; hctx.display#enable_display (DMImplementation); @@ -362,12 +399,6 @@ let handler = l := jstring ("Legacy completion " ^ (if b then "enabled" else "disabled")) :: !l; () ) (); - hctx.jsonrpc#get_opt_param (fun () -> - let b = hctx.jsonrpc#get_bool_param "populateCacheFromDisplay" in - ServerConfig.populate_cache_from_display := b; - l := jstring ("Compilation cache refill from display " ^ (if b then "enabled" else "disabled")) :: !l; - () - ) (); hctx.send_result (jarray !l) ); "server/memory",(fun hctx -> diff --git a/src/core/display/displayPosition.ml b/src/core/display/displayPosition.ml index a831d727036..1a820b1bcd9 100644 --- a/src/core/display/displayPosition.ml +++ b/src/core/display/displayPosition.ml @@ -11,6 +11,7 @@ class display_position_container = (** Current display position *) val mutable pos = null_pos val mutable file_key = None + val mutable file_keys = [] (** Display position value which was set with the latest `display_position#set p` call. Kept even after `display_position#reset` call. @@ -22,7 +23,15 @@ class display_position_container = method set p = pos <- p; last_pos <- p; - file_key <- None + file_key <- None; + file_keys <- if p.pfile = DisplayProcessingGlobals.file_input_marker then [] else [Path.UniqueKey.create p.pfile] + + method set_files files = + file_keys <- files + + method get_files = + file_keys + (** Get current display position *) @@ -43,7 +52,8 @@ class display_position_container = *) method reset = pos <- null_pos; - file_key <- None + file_key <- None; + file_keys <- [] (** Check if `p` contains current display position *) @@ -53,8 +63,13 @@ class display_position_container = Check if a file with `file_key` contains current display position *) method is_in_file file_key = - pos.pfile <> "?" - && self#get_file_key = file_key + (pos.pfile <> "?" && self#get_file_key = file_key) || self#has_file file_key + (** + This is a hack; currently used by Diagnostics.collect_diagnostics when sending multiple files + to run diagnostics on via json rpc + *) + method has_file file_key = + List.mem file_key file_keys (** Cut `p` at the position of the latest `display_position#set pos` call. *) @@ -75,4 +90,4 @@ class display_position_container = {p with pmin = last_pos.pmin; pmax = last_pos.pmax} end -let display_position = new display_position_container \ No newline at end of file +let display_position = new display_position_container diff --git a/src/core/displayTypes.ml b/src/core/displayTypes.ml index 9e04cbc0195..93fe76263fd 100644 --- a/src/core/displayTypes.ml +++ b/src/core/displayTypes.ml @@ -235,7 +235,6 @@ module DisplayMode = struct | DMDefault | DMDefinition | DMTypeDefinition | DMPackage | DMHover | DMSignature -> settings | DMUsage _ | DMImplementation -> { settings with dms_full_typing = true; - dms_populate_cache = !ServerConfig.populate_cache_from_display; dms_force_macro_typing = true; dms_display_file_policy = DFPAlso; dms_exit_during_typing = false diff --git a/src/core/tType.ml b/src/core/tType.ml index 5fdb0509be7..1c140ef314a 100644 --- a/src/core/tType.ml +++ b/src/core/tType.ml @@ -442,7 +442,12 @@ let flag_tclass_field_names = [ type flag_tvar = | VCaptured | VFinal - | VUsed (* used by the analyzer *) + | VAnalyzed | VAssigned | VCaught | VStatic + | VUsedByTyper (* Set if the typer looked up this variable *) + +let flag_tvar_names = [ + "VCaptured";"VFinal";"VAnalyzed";"VAssigned";"VCaught";"VStatic";"VUsedByTyper" +] diff --git a/src/filters/filters.ml b/src/filters/filters.ml index d0af8ec9475..0cd27b07b6d 100644 --- a/src/filters/filters.ml +++ b/src/filters/filters.ml @@ -916,7 +916,8 @@ let save_class_state ctx t = a.a_meta <- List.filter (fun (m,_,_) -> m <> Meta.ValueUsed) a.a_meta ) -let run com tctx main = +let run tctx main before_destruction = + let com = tctx.com in let detail_times = Common.defined com DefineList.FilterTimes in let new_types = List.filter (fun t -> let cached = is_cached com t in @@ -1025,4 +1026,5 @@ let run com tctx main = let t = filter_timer detail_times ["callbacks"] in com.callbacks#run com.callbacks#get_after_save; (* macros onGenerate etc. *) t(); - destruction tctx detail_times main locals \ No newline at end of file + before_destruction(); + destruction tctx detail_times main locals diff --git a/src/optimization/analyzer.ml b/src/optimization/analyzer.ml index 82ab684ed66..f6c9825bb66 100644 --- a/src/optimization/analyzer.ml +++ b/src/optimization/analyzer.ml @@ -661,14 +661,14 @@ module LocalDce = struct let rec apply ctx = let is_used v = - has_var_flag v VUsed + has_var_flag v VAnalyzed in let keep v = is_used v || ((match v.v_kind with VUser _ | VInlined -> true | _ -> false) && not ctx.config.local_dce) || ExtType.has_reference_semantics v.v_type || has_var_flag v VCaptured || Meta.has Meta.This v.v_meta in let rec use v = if not (is_used v) then begin - add_var_flag v VUsed; + add_var_flag v VAnalyzed; (try expr (get_var_value ctx.graph v) with Not_found -> ()); begin match Ssa.get_reaching_def ctx.graph v with | None -> @@ -676,7 +676,7 @@ module LocalDce = struct reaching definition (issue #10972). Simply marking it as being used should be sufficient. *) let v' = get_var_origin ctx.graph v in if not (is_used v') then - add_var_flag v' VUsed + add_var_flag v' VAnalyzed | Some v -> use v; end diff --git a/src/optimization/inline.ml b/src/optimization/inline.ml index 098a1ff7af0..727c0648a66 100644 --- a/src/optimization/inline.ml +++ b/src/optimization/inline.ml @@ -589,7 +589,6 @@ class inline_state ctx ethis params cf f p = object(self) mk (TBlock (DynArray.to_list el)) tret e.epos in let e = inline_metadata e cf.cf_meta in - let e = Diagnostics.secure_generated_code ctx e in if has_params then begin let mt = map_type cf.cf_type in let unify_func () = unify_raise mt (TFun (tl,tret)) p in diff --git a/src/typing/callUnification.ml b/src/typing/callUnification.ml index 5accc16d384..13cb72f7c2b 100644 --- a/src/typing/callUnification.ml +++ b/src/typing/callUnification.ml @@ -488,7 +488,6 @@ object(self) !ethis_f(); raise exc in - let e = Diagnostics.secure_generated_code ctx e in ctx.com.located_error <- old; !ethis_f(); e diff --git a/src/typing/typeloadParse.ml b/src/typing/typeloadParse.ml index 17379ef0b77..a592cf57c44 100644 --- a/src/typing/typeloadParse.ml +++ b/src/typing/typeloadParse.ml @@ -59,23 +59,23 @@ let parse_file_from_lexbuf com file p lexbuf = let parse_file_from_string com file p string = parse_file_from_lexbuf com file p (Sedlexing.Utf8.from_string string) -let current_stdin = ref None (* TODO: we're supposed to clear this at some point *) - let parse_file com file p = - let use_stdin = (Common.defined com Define.DisplayStdin) && DisplayPosition.display_position#is_in_file (com.file_keys#get file) in - if use_stdin then - let s = - match !current_stdin with - | Some s -> - s - | None -> - let s = Std.input_all stdin in - close_in stdin; - current_stdin := Some s; - s - in + let file_key = com.file_keys#get file in + let contents = match com.file_contents with + | [] when (Common.defined com Define.DisplayStdin) && DisplayPosition.display_position#is_in_file file_key -> + let s = Std.input_all stdin in + close_in stdin; + com.file_contents <- [file_key, Some s]; + Some s + | [] -> None + | files -> + (try List.assoc file_key files with Not_found -> None) + in + + match contents with + | Some s -> parse_file_from_string com file p s - else + | _ -> let ch = try open_in_bin file with _ -> typing_error ("Could not open " ^ file) p in Std.finally (fun() -> close_in ch) (parse_file_from_lexbuf com file p) (Sedlexing.Utf8.from_channel ch) @@ -342,4 +342,4 @@ let parse_module ctx m p = (* let parse_module ctx m p = let timer = Timer.timer ["typing";"parse_module"] in - Std.finally timer (parse_module ctx m) p *) \ No newline at end of file + Std.finally timer (parse_module ctx m) p *) diff --git a/src/typing/typer.ml b/src/typing/typer.ml index 5047c26bc31..e62aca173da 100644 --- a/src/typing/typer.ml +++ b/src/typing/typer.ml @@ -350,6 +350,7 @@ let rec type_ident_raise ctx i p mode with_type = | _ -> try let v = PMap.find i ctx.locals in + add_var_flag v VUsedByTyper; (match v.v_extra with | Some ve -> let (params,e) = (ve.v_params,ve.v_expr) in @@ -1130,7 +1131,7 @@ and type_new ctx path el with_type force_inline p = typing_error (s_type (print_context()) t ^ " cannot be constructed") p end with Error(No_constructor _ as err,p,depth) when ctx.com.display.dms_kind <> DMNone -> located_display_error ~depth ctx.com (error_msg p err); - Diagnostics.secure_generated_code ctx (mk (TConst TNull) t p) + mk (TConst TNull) t p and type_try ctx e1 catches with_type p = let e1 = type_expr ctx (Expr.ensure_block e1) with_type in @@ -1796,7 +1797,6 @@ and type_call_builtin ctx e el mode with_type p = | _ -> let e = type_expr ctx e WithType.value in warning ctx WInfo (s_type (print_context()) e.etype) e.epos; - let e = Diagnostics.secure_generated_code ctx e in e end | (EField(e,"match",efk_todo),p), [epat] -> diff --git a/src/typing/typerBase.ml b/src/typing/typerBase.ml index ca6192d7ac8..3370bd3447a 100644 --- a/src/typing/typerBase.ml +++ b/src/typing/typerBase.ml @@ -155,9 +155,11 @@ let get_this ctx p = | FunMemberClassLocal | FunMemberAbstractLocal -> let v = match ctx.vthis with | None -> - let v = if ctx.curfun = FunMemberAbstractLocal then - PMap.find "this" ctx.locals - else + let v = if ctx.curfun = FunMemberAbstractLocal then begin + let v = PMap.find "this" ctx.locals in + add_var_flag v VUsedByTyper; + v + end else add_local ctx VGenerated "`this" ctx.tthis p in ctx.vthis <- Some v; @@ -347,4 +349,4 @@ let get_abstract_froms ctx a pl = acc) | _ -> acc - ) l a.a_from_field \ No newline at end of file + ) l a.a_from_field diff --git a/std/haxe/display/Display.hx b/std/haxe/display/Display.hx index aac5724c846..020ba7d73c2 100644 --- a/std/haxe/display/Display.hx +++ b/std/haxe/display/Display.hx @@ -25,6 +25,7 @@ package haxe.display; import haxe.display.JsonModuleTypes; import haxe.display.Position; import haxe.display.Protocol; +import haxe.ds.ReadOnlyArray; /** Methods of the JSON-RPC-based `--display` protocol in Haxe 4. @@ -32,6 +33,12 @@ import haxe.display.Protocol; **/ @:publicFields class DisplayMethods { + + /** + The request is sent from the client to Haxe to get diagnostics for a specific file, a list of files or the whole project. + **/ + static inline var Diagnostics = new HaxeRequestMethod("display/diagnostics"); + /** The completion request is sent from the client to Haxe to request code completion. Haxe automatically determines the type of completion to use based on the passed position, see `CompletionResultKind`. @@ -92,7 +99,6 @@ class DisplayMethods { TODO: - finish completion - - diagnostics - codeLens - workspaceSymbols ("project/symbol"?) */ @@ -438,6 +444,17 @@ typedef PatternCompletion = ToplevelCompletion & { var isOutermostPattern:Bool; } +typedef DiagnosticsParams = { + var ?file:FsPath; + var ?contents:String; + var ?fileContents:Array<{file:FsPath, ?contents:String}>; +} + +typedef DiagnosticsResult = Response>; +}>> + enum abstract CompletionModeKind(Int) { var Field:CompletionModeKind>; var StructureField; diff --git a/std/haxe/display/Server.hx b/std/haxe/display/Server.hx index 44ce700587e..63895758cec 100644 --- a/std/haxe/display/Server.hx +++ b/std/haxe/display/Server.hx @@ -73,7 +73,6 @@ typedef ConfigurePrintParams = { typedef ConfigureParams = { final ?noModuleChecks:Bool; - final ?populateCacheFromDisplay:Bool; final ?legacyCompletion:Bool; final ?print:ConfigurePrintParams; } diff --git a/tests/display/build.hxml b/tests/display/build.hxml index 97dea9fdd1a..497f2b13d6e 100644 --- a/tests/display/build.hxml +++ b/tests/display/build.hxml @@ -5,4 +5,4 @@ -lib haxeserver --interp -D use-rtti-doc --D test=11285 \ No newline at end of file +# -D test=11285 diff --git a/tests/display/src/cases/Issue5306.hx b/tests/display/src/cases/Issue5306.hx index 941379acd46..aec333a39ad 100644 --- a/tests/display/src/cases/Issue5306.hx +++ b/tests/display/src/cases/Issue5306.hx @@ -7,8 +7,8 @@ class Issue5306 extends DisplayTestCase { class Main { static function main() { var ib:Array; - ib[0] = 0; ib[1] = 1; ib[2] - {-5-}trace{-6-}("test"); + {-5-}ib{-6-}[0] = 0; ib[1] = 1; ib[2] + {-7-}trace{-8-}("test"); } } **/ @@ -22,7 +22,7 @@ class Issue5306 extends DisplayTestCase { // }, { kind: DKParserError, - range: diagnosticsRange(pos(5), pos(6)), + range: diagnosticsRange(pos(7), pos(8)), severity: Error, relatedInformation: [], args: "Missing ;" @@ -33,6 +33,13 @@ class Issue5306 extends DisplayTestCase { severity: Error, relatedInformation: [], args: "Type not found : InvalidType" + }, + { + kind: DKCompilerError, + range: diagnosticsRange(pos(5), pos(6)), + severity: Error, + relatedInformation: [], + args: "Local variable ib used without being initialized" } ]; arrayEq(expected, diagnostics()); diff --git a/tests/server/src/TestCase.hx b/tests/server/src/TestCase.hx index f3b051b1f9e..ea973aab81a 100644 --- a/tests/server/src/TestCase.hx +++ b/tests/server/src/TestCase.hx @@ -62,22 +62,26 @@ class TestCase implements ITest { server.stop(); } + function handleResult(result) { + lastResult = result; + debugLastResult = { + hasError: lastResult.hasError, + prints: lastResult.prints, + stderr: lastResult.stderr, + stdout: lastResult.stdout + } + sendLogMessage(result.stdout); + for (print in result.prints) { + var line = print.trim(); + messages.push('Haxe print: $line'); + } + } + function runHaxe(args:Array, done:() -> Void) { messages = []; errorMessages = []; server.rawRequest(args, null, function(result) { - lastResult = result; - debugLastResult = { - hasError: lastResult.hasError, - prints: lastResult.prints, - stderr: lastResult.stderr, - stdout: lastResult.stdout - } - sendLogMessage(result.stdout); - for (print in result.prints) { - var line = print.trim(); - messages.push('Haxe print: $line'); - } + handleResult(result); if (result.hasError) { sendErrorMessage(result.stderr); } @@ -92,11 +96,20 @@ class TestCase implements ITest { } function runHaxeJsonCb(args:Array, method:HaxeRequestMethod>, methodArgs:TParams, - callback:TResponse->Void, done:() -> Void) { + callback:TResponse->Void, done:() -> Void, ?pos:PosInfos) { var methodArgs = {method: method, id: 1, params: methodArgs}; args = args.concat(['--display', Json.stringify(methodArgs)]); + messages = []; + errorMessages = []; server.rawRequest(args, null, function(result) { - callback(Json.parse(result.stderr).result.result); + handleResult(result); + var json = try Json.parse(result.stderr) catch(e) {result: null, error: e.message}; + + if (json.result != null) { + callback(json.result?.result); + } else { + Assert.fail('Error: ' + json.error, pos); + } done(); }, function(msg) { sendErrorMessage(msg); diff --git a/tests/server/src/cases/ServerTests.hx b/tests/server/src/cases/ServerTests.hx index 64b4eb375c4..40738abcc01 100644 --- a/tests/server/src/cases/ServerTests.hx +++ b/tests/server/src/cases/ServerTests.hx @@ -1,7 +1,9 @@ package cases; +import haxe.display.Diagnostic; import haxe.display.Display; import haxe.display.FsPath; +import haxe.display.Position.Range; import haxe.display.Server; import haxe.io.Path; import utest.Assert; @@ -97,7 +99,9 @@ class ServerTests extends TestCase { var args = ["-main", "BrokenSyntax.hx", "--interp", "--no-output"]; runHaxe(args); assertErrorMessage("Expected }"); - runHaxe(args.concat(["--display", "Empty.hx@0@diagnostics"])); + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {file: new FsPath("Empty.hx")}, res -> { + Assert.equals(0, res.length); + }); runHaxe(args); assertErrorMessage("Expected }"); } @@ -143,6 +147,80 @@ class ServerTests extends TestCase { assertSuccess(); } + function testDiagnosticsFileContents() { + vfs.putContent("Main.hx", getTemplate("issues/Issue9134/Main.hx")); + vfs.putContent("Other.hx", getTemplate("issues/Issue9134/Other.hx")); + var args = ["-main", "Main", "Other"]; + + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {fileContents: [ + {file: new FsPath("Other.hx")}, + {file: new FsPath("Main.hx")}, + ]}, res -> { + Assert.equals(1, res.length); + Assert.equals(1, res[0].diagnostics.length); + var arg = res[0].diagnostics[0].args; + Assert.equals("Unused variable", (cast arg).description); + Assert.stringContains("Main.hx", res[0].file.toString()); + }); + + runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("Main.hx")}); + runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("Other.hx")}); + + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {fileContents: [ + {file: new FsPath("Main.hx"), contents: getTemplate("issues/Issue9134/Main2.hx")}, + {file: new FsPath("Other.hx"), contents: getTemplate("issues/Issue9134/Other2.hx")} + ]}, res -> { + Assert.equals(1, res.length); + Assert.equals(1, res[0].diagnostics.length); + var arg = res[0].diagnostics[0].args; + Assert.equals("Unused variable", (cast arg).description); + Assert.stringContains("Other.hx", res[0].file.toString()); + }); + + runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("Main.hx")}); + runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("Other.hx")}); + + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {fileContents: [ + {file: new FsPath("Main.hx"), contents: getTemplate("issues/Issue9134/Main.hx")}, + {file: new FsPath("Other.hx"), contents: getTemplate("issues/Issue9134/Other2.hx")} + ]}, res -> { + Assert.equals(2, res.length); + + for (i in 0...2) { + Assert.equals(1, res[i].diagnostics.length); + var arg = res[i].diagnostics[0].args; + Assert.equals("Unused variable", (cast arg).description); + } + }); + + // Currently, haxe compilation server will have this content anyway + // because of diagnostics with file contents, but that behavior may not + // be obvious in tests + vfs.putContent("Other.hx", getTemplate("issues/Issue9134/Other2.hx")); + runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("Other.hx")}); + + // Running project wide diagnostics; checks here aren't great since + // results will depend on haxe std which may change without updating + // this test everytime.. + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {}, res -> { + var hasMain = false; + var hasOther = false; + + for (result in res) { + var file = result.file.toString(); + if (StringTools.endsWith(file, "Main.hx")) hasMain = true; + else if (StringTools.endsWith(file, "Other.hx")) hasOther = true; + else continue; + + var arg = result.diagnostics[0].args; + Assert.equals("Unused variable", (cast arg).description); + } + + Assert.isTrue(hasMain); + Assert.isTrue(hasOther); + }); + } + function testDiagnosticsRecache() { vfs.putContent("HelloWorld.hx", getTemplate("HelloWorld.hx")); var args = ["--main", "HelloWorld", "--interp"]; @@ -152,7 +230,25 @@ class ServerTests extends TestCase { runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("HelloWorld.hx")}); runHaxe(args); assertSkipping("HelloWorld", Tainted("server/invalidate")); - runHaxe(args.concat(["--display", "HelloWorld.hx@0@diagnostics"])); + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {file: new FsPath("HelloWorld.hx")}, res -> { + Assert.equals(0, res.length); + }); + runHaxe(args); + assertReuse("HelloWorld"); + } + + function testDiagnosticsRecache1() { + vfs.putContent("HelloWorld.hx", getTemplate("HelloWorld.hx")); + var args = ["--main", "HelloWorld", "--interp"]; + runHaxe(args); + runHaxe(args); + assertReuse("HelloWorld"); + runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("HelloWorld.hx")}); + runHaxe(args); + assertSkipping("HelloWorld", Tainted("server/invalidate")); + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {fileContents: [{file: new FsPath("HelloWorld.hx")}]}, res -> { + Assert.equals(0, res.length); + }); runHaxe(args); assertReuse("HelloWorld"); } @@ -160,7 +256,9 @@ class ServerTests extends TestCase { function testDiagnosticsRecache2() { vfs.putContent("HelloWorld.hx", getTemplate("HelloWorld.hx")); var args = ["--main", "HelloWorld", "--interp"]; - runHaxe(args.concat(["--display", "HelloWorld.hx@0@diagnostics"])); + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {file: new FsPath("HelloWorld.hx")}, res -> { + Assert.equals(0, res.length); + }); runHaxe(args); assertReuse("HelloWorld"); } @@ -172,11 +270,80 @@ class ServerTests extends TestCase { runHaxe(args); assertReuse("HelloWorld"); runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("HelloWorld.hx")}); - runHaxe(args.concat(["--display", "HelloWorld.hx@0@diagnostics"])); + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {file: new FsPath("HelloWorld.hx")}, res -> { + Assert.equals(0, res.length); + }); runHaxe(args.concat(["--display", "HelloWorld.hx@0@hover"])); assertReuse("HelloWorld"); } + function testDiagnosticsMultipleOpenFiles() { + vfs.putContent("Main.hx", getTemplate("diagnostics/multi-files/Main.hx")); + vfs.putContent("File1.hx", getTemplate("diagnostics/multi-files/File1.hx")); + vfs.putContent("File2.hx", getTemplate("diagnostics/multi-files/File2.hx")); + vfs.putContent("File3.hx", getTemplate("diagnostics/multi-files/File3.hx")); + + var args = ["--main", "Main", "--interp"]; + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {fileContents: [ + {file: new FsPath("Main.hx")}, + {file: new FsPath("File1.hx")} + ]}, res -> { + Assert.equals(2, res.length); // Asked diagnostics for 2 files + + for (fileDiagnostics in res) { + final path = ~/[\/|\\]/g.split(fileDiagnostics.file.toString()).pop(); + + switch (path) { + case "Main.hx": + Assert.equals(2, fileDiagnostics.diagnostics.length); + for (diag in fileDiagnostics.diagnostics) { + Assert.equals(diag.kind, DKUnusedImport); + } + + case "File1.hx": + Assert.equals(1, fileDiagnostics.diagnostics.length); + var diag:Diagnostic<{description:String, range:Range}> = fileDiagnostics.diagnostics[0]; + Assert.equals(diag.kind, DKRemovableCode); + Assert.equals(diag.args.description, "Unused variable"); + + case _: throw 'Did not expect diagnostics for $path'; + } + } + }); + + // Check that File2 was reached + var context = null; + runHaxeJsonCb(args, ServerMethods.Contexts, null, res -> context = res.find(ctx -> ctx.desc == "after_init_macros")); + runHaxeJsonCb(args, ServerMethods.Type, {signature: context.signature, modulePath: "File2", typeName: "File2"}, res -> Assert.equals(res.pos.file, "File2.hx")); + + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {fileContents: [ + {file: new FsPath("Main.hx")}, + {file: new FsPath("File3.hx")}, // Not reached by normal compilation + ]}, res -> { + Assert.equals(2, res.length); // Asked diagnostics for 2 files + + for (fileDiagnostics in res) { + final path = ~/[\/|\\]/g.split(fileDiagnostics.file.toString()).pop(); + + switch (path) { + case "Main.hx": + Assert.equals(2, fileDiagnostics.diagnostics.length); + for (diag in fileDiagnostics.diagnostics) { + Assert.equals(diag.kind, DKUnusedImport); + } + + case "File3.hx": + Assert.equals(1, fileDiagnostics.diagnostics.length); + var diag:Diagnostic<{description:String, range:Range}> = fileDiagnostics.diagnostics[0]; + Assert.equals(diag.kind, DKRemovableCode); + Assert.equals(diag.args.description, "Unused variable"); + + case _: throw 'Did not expect diagnostics for $path'; + } + } + }); + } + function testSyntaxCache() { vfs.putContent("HelloWorld.hx", getTemplate("HelloWorld.hx")); runHaxeJson(["-cp", "."], ServerMethods.ReadClassPaths, null); @@ -397,7 +564,7 @@ class ServerTests extends TestCase { var runs = 0; function runLoop() { - runHaxe(args.concat(["--display", "Empty.hx@0@diagnostics"]), () -> { + runHaxeJson(args, DisplayMethods.Diagnostics, {file: new FsPath("Empty.hx")}, () -> { runHaxe(args.concat(["-D", "compile-only-define"]), () -> { if (assertSuccess() && ++runs < 20) runLoop(); else async.done(); diff --git a/tests/server/src/cases/display/issues/Issue10635.hx b/tests/server/src/cases/display/issues/Issue10635.hx index 1cd612e897f..e3098be5ad7 100644 --- a/tests/server/src/cases/display/issues/Issue10635.hx +++ b/tests/server/src/cases/display/issues/Issue10635.hx @@ -14,12 +14,15 @@ class Issue10635 extends DisplayTestCase { } **/ function test(_) { - var args = ["-main", "Main", "--display", "Main.hx@0@diagnostics"]; + var args = ["-main", "Main"]; vfs.putContent("Something.hx", getTemplate("issues/Issue10635/Something.hx")); - runHaxe(args); + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {file: new FsPath("Main.hx")}, res -> { + Assert.equals(0, res.length); + }); runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("Main.hx")}); - runHaxe(args); - Assert.isTrue(lastResult.stderr.length == 2); // dumb, but we don't have a proper diagnostics structure in these tests + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {file: new FsPath("Main.hx")}, res -> { + Assert.equals(0, res.length); + }); } /** @@ -32,12 +35,15 @@ class Issue10635 extends DisplayTestCase { } **/ function testGenericClassPerMethod(_) { - var args = ["-main", "Main", "--display", "Main.hx@0@diagnostics"]; + var args = ["-main", "Main"]; vfs.putContent("Something.hx", "@:genericClassPerMethod " + getTemplate("issues/Issue10635/Something.hx")); - runHaxe(args); + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {file: new FsPath("Main.hx")}, res -> { + Assert.equals(0, res.length); + }); runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("Main.hx")}); - runHaxe(args); - Assert.isTrue(lastResult.stderr.length == 2); // dumb, but we don't have a proper diagnostics structure in these tests + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {file: new FsPath("Main.hx")}, res -> { + Assert.equals(0, res.length); + }); } function testGenericAddition(_) { diff --git a/tests/server/src/cases/issues/Issue10653.hx b/tests/server/src/cases/issues/Issue10653.hx index e855ac0e61e..2ebfa0b4fd1 100644 --- a/tests/server/src/cases/issues/Issue10653.hx +++ b/tests/server/src/cases/issues/Issue10653.hx @@ -8,9 +8,12 @@ class Issue10653 extends TestCase { runHaxe(args); vfs.putContent("Main.hx", getTemplate("issues/Issue10653/MainAfter.hx")); runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("Main.hx")}); - runHaxe(args.concat(["--display", "Main.hx@0@diagnostics"])); + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {file: new FsPath("Main.hx")}, res -> { + Assert.equals(0, res.length); + }); runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("Main.hx")}); - runHaxe(args.concat(["--display", "Main.hx@0@diagnostics"])); - Assert.isTrue(lastResult.stderr.length == 2); + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {file: new FsPath("Main.hx")}, res -> { + Assert.equals(0, res.length); + }); } } diff --git a/tests/server/src/cases/issues/Issue11177.hx b/tests/server/src/cases/issues/Issue11177.hx index 42aa7423082..f967005da3d 100644 --- a/tests/server/src/cases/issues/Issue11177.hx +++ b/tests/server/src/cases/issues/Issue11177.hx @@ -1,26 +1,27 @@ package cases.issues; class Issue11177 extends TestCase { - // Disabled for now until #11177 is actually fixed, likely by #11220 - // function test(_) { - // vfs.putContent("Main.hx", getTemplate("issues/Issue11177/Main.hx")); - // vfs.putContent("Buttons.hx", getTemplate("issues/Issue11177/Buttons.hx")); - // vfs.putContent("KeyCode.hx", getTemplate("issues/Issue11177/KeyCode.hx")); - // var args = ["-main", "Main", "--interp"]; - // runHaxe(args.concat(["--display", "Buttons.hx@0@diagnostics"])); - // vfs.putContent("Main.hx", getTemplate("issues/Issue11177/Main2.hx")); - // runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("Main.hx")}); - // runHaxe(args); - // runHaxe(args.concat(["--display", "Buttons.hx@0@diagnostics"])); - // Assert.isTrue(lastResult.stderr.length == 2); - // } + function test(_) { + vfs.putContent("Main.hx", getTemplate("issues/Issue11177/Main.hx")); + vfs.putContent("Buttons.hx", getTemplate("issues/Issue11177/Buttons.hx")); + vfs.putContent("KeyCode.hx", getTemplate("issues/Issue11177/KeyCode.hx")); + var args = ["-main", "Main", "--interp"]; + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {file: new FsPath("Buttons.hx")}, res -> { + Assert.equals(0, res.length); + }); + vfs.putContent("Main.hx", getTemplate("issues/Issue11177/Main2.hx")); + runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("Main.hx")}); + runHaxe(args); + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {file: new FsPath("Buttons.hx")}, res -> { + Assert.equals(0, res.length); + }); + } - function testWithoutCacheFromDisplay(_) { + function testLegacyDiagnostics(_) { vfs.putContent("Main.hx", getTemplate("issues/Issue11177/Main.hx")); vfs.putContent("Buttons.hx", getTemplate("issues/Issue11177/Buttons.hx")); vfs.putContent("KeyCode.hx", getTemplate("issues/Issue11177/KeyCode.hx")); var args = ["-main", "Main", "--interp"]; - runHaxeJson([], ServerMethods.Configure, {populateCacheFromDisplay: false}); runHaxe(args.concat(["--display", "Buttons.hx@0@diagnostics"])); vfs.putContent("Main.hx", getTemplate("issues/Issue11177/Main2.hx")); runHaxeJson([], ServerMethods.Invalidate, {file: new FsPath("Main.hx")}); diff --git a/tests/server/src/cases/issues/Issue11184.hx b/tests/server/src/cases/issues/Issue11184.hx index 7f2d326d726..966e595e818 100644 --- a/tests/server/src/cases/issues/Issue11184.hx +++ b/tests/server/src/cases/issues/Issue11184.hx @@ -1,22 +1,28 @@ package cases.issues; class Issue11184 extends TestCase { - // Disabled for now until #11184 is actually fixed, likely by #11220 - // function test(_) { - // vfs.putContent("Main.hx", getTemplate("issues/Issue11184/Main.hx")); - // var args = ["-main", "Main", "-js", "bin/test.js"]; - // runHaxe(args.concat(["--display", "Main.hx@0@diagnostics"])); - // runHaxe(args); - // Assert.isTrue(hasErrorMessage("Cannot use Void as value")); - // runHaxe(args); - // Assert.isTrue(hasErrorMessage("Cannot use Void as value")); - // } + function testDiagnostics(_) { + vfs.putContent("Main.hx", getTemplate("issues/Issue11184/Main.hx")); + var args = ["-main", "Main", "-js", "bin/test.js"]; + + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {file: new FsPath("Main.hx")}, res -> { + Assert.equals(1, res.length); + Assert.equals(1, res[0].diagnostics.length); + Assert.equals(res[0].diagnostics[0].args, "Cannot use Void as value"); + }); + + runHaxe(args); + Assert.isTrue(hasErrorMessage("Cannot use Void as value")); + runHaxe(args); + Assert.isTrue(hasErrorMessage("Cannot use Void as value")); + } - function testWithoutCacheFromDisplay(_) { + function testLegacyDiagnostics(_) { vfs.putContent("Main.hx", getTemplate("issues/Issue11184/Main.hx")); var args = ["-main", "Main", "-js", "bin/test.js"]; - runHaxeJson([], ServerMethods.Configure, {populateCacheFromDisplay: false}); runHaxe(args.concat(["--display", "Main.hx@0@diagnostics"])); + final diagnostics = haxe.Json.parse(lastResult.stderr)[0].diagnostics; + Assert.equals(diagnostics[0].args, "Cannot use Void as value"); runHaxe(args); Assert.isTrue(hasErrorMessage("Cannot use Void as value")); runHaxe(args); diff --git a/tests/server/src/cases/issues/Issue11203.hx b/tests/server/src/cases/issues/Issue11203.hx new file mode 100644 index 00000000000..f28726dcd13 --- /dev/null +++ b/tests/server/src/cases/issues/Issue11203.hx @@ -0,0 +1,23 @@ +package cases.issues; + +class Issue11203 extends TestCase { + function testClass(_) { + vfs.putContent("Main.hx", getTemplate("issues/Issue11203/MainClass.hx")); + var args = ["Main", "--interp"]; + runHaxe(args); + runHaxe(args.concat(["--display", "Main.hx@0@diagnostics"])); + + var diag = parseDiagnostics(); + Assert.isTrue(diag.length == 0); + } + + function testAbstract(_) { + vfs.putContent("Main.hx", getTemplate("issues/Issue11203/MainAbstract.hx")); + var args = ["Main", "--interp"]; + runHaxe(args); + runHaxe(args.concat(["--display", "Main.hx@0@diagnostics"])); + + var diag = parseDiagnostics(); + Assert.isTrue(diag.length == 0); + } +} diff --git a/tests/server/src/cases/issues/Issue11695.hx b/tests/server/src/cases/issues/Issue11695.hx new file mode 100644 index 00000000000..54eb3fb0622 --- /dev/null +++ b/tests/server/src/cases/issues/Issue11695.hx @@ -0,0 +1,39 @@ +package cases.issues; + +class Issue11695 extends TestCase { + function test(_) { + vfs.putContent("Main.hx", getTemplate("issues/Issue11695/Main.hx")); + vfs.putContent("Macro.hx", getTemplate("issues/Issue11695/Macro1.hx")); + var args = ["-main", "Main", "--interp"]; + runHaxe(args); + assertHasPrint("Macro.hx:1: before"); + + // Note: this is needed because modification time is currently checked with second precision + Sys.sleep(1); + + vfs.putContent("Macro.hx", getTemplate("issues/Issue11695/Macro2.hx")); + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {file: new FsPath("Macro.hx")}, res -> { + Assert.equals(0, res.length); + }); + + runHaxe(args); + assertHasPrint("Macro.hx:1: after"); + } + + function testLegacyDiagnostics(_) { + vfs.putContent("Main.hx", getTemplate("issues/Issue11695/Main.hx")); + vfs.putContent("Macro.hx", getTemplate("issues/Issue11695/Macro1.hx")); + var args = ["-main", "Main", "--interp"]; + runHaxe(args); + assertHasPrint("Macro.hx:1: before"); + + // Note: this is needed because modification time is currently checked with second precision + Sys.sleep(1); + + vfs.putContent("Macro.hx", getTemplate("issues/Issue11695/Macro2.hx")); + runHaxe(args.concat(["--display", "Macro.hx@0@diagnostics"])); + + runHaxe(args); + assertHasPrint("Macro.hx:1: after"); + } +} diff --git a/tests/server/src/cases/issues/Issue7282.hx b/tests/server/src/cases/issues/Issue7282.hx new file mode 100644 index 00000000000..1ecb238eacd --- /dev/null +++ b/tests/server/src/cases/issues/Issue7282.hx @@ -0,0 +1,22 @@ +package cases.issues; + +import haxe.display.Diagnostic; +import haxe.display.Position.Range; + +class Issue7282 extends TestCase { + function test(_) { + var content = getTemplate("issues/Issue7282/Main.hx"); + var transform = Markers.parse(content); + + vfs.putContent("Main.hx", transform.source); + var args = ["-main", "Main"]; + runHaxe(args); + assertSuccess(); + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {file: new FsPath("Main.hx")}, res -> { + var arg:{description:String, range:Range} = res[0].diagnostics[0].args; + Assert.equals("Unused variable", arg.description); + Assert.same(transform.range(1,2), res[0].diagnostics[0].range); + Assert.same(transform.range(1,2), arg.range); + }); + } +} diff --git a/tests/server/src/cases/issues/Issue7931.hx b/tests/server/src/cases/issues/Issue7931.hx new file mode 100644 index 00000000000..2a640eedabb --- /dev/null +++ b/tests/server/src/cases/issues/Issue7931.hx @@ -0,0 +1,13 @@ +package cases.issues; + +class Issue7931 extends TestCase { + function test(_) { + vfs.putContent("Main.hx", getTemplate("issues/Issue7931/Main.hx")); + var args = ["-main", "Main"]; + runHaxe(args); + assertErrorMessage("Local variable s used without being initialized"); + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {file: new FsPath("Main.hx")}, res -> { + Assert.equals("Local variable s used without being initialized", res[0].diagnostics[0].args); + }); + } +} diff --git a/tests/server/src/cases/issues/Issue8687.hx b/tests/server/src/cases/issues/Issue8687.hx index ea7934a56f9..2f10ba7e479 100644 --- a/tests/server/src/cases/issues/Issue8687.hx +++ b/tests/server/src/cases/issues/Issue8687.hx @@ -4,9 +4,10 @@ class Issue8687 extends TestCase { function test(_) { vfs.putContent("Main.hx", getTemplate("issues/Issue8687/Main.hx")); var args = ["-main", "Main", "--interp"]; - runHaxe(args.concat(["--display", "Main.hx@0@diagnostics"])); - - var diag = parseDiagnostics(); - Assert.equals("Invalid version string \"foo\". Should follow SemVer.", diag[0].args); + runHaxeJsonCb(args, DisplayMethods.Diagnostics, {file: new FsPath("Main.hx")}, res -> { + Assert.equals(1, res.length); + Assert.equals(1, res[0].diagnostics.length); + Assert.equals(res[0].diagnostics[0].args, "Invalid version string \"foo\". Should follow SemVer."); + }); } } diff --git a/tests/server/test/templates/diagnostics/multi-files/File1.hx b/tests/server/test/templates/diagnostics/multi-files/File1.hx new file mode 100644 index 00000000000..40f142a8995 --- /dev/null +++ b/tests/server/test/templates/diagnostics/multi-files/File1.hx @@ -0,0 +1,5 @@ +class File1 { + static function test() { + var foo = 42; + } +} diff --git a/tests/server/test/templates/diagnostics/multi-files/File2.hx b/tests/server/test/templates/diagnostics/multi-files/File2.hx new file mode 100644 index 00000000000..dce8f331241 --- /dev/null +++ b/tests/server/test/templates/diagnostics/multi-files/File2.hx @@ -0,0 +1,5 @@ +class File2 { + static function test() { + var foo = 42; + } +} diff --git a/tests/server/test/templates/diagnostics/multi-files/File3.hx b/tests/server/test/templates/diagnostics/multi-files/File3.hx new file mode 100644 index 00000000000..d6836003719 --- /dev/null +++ b/tests/server/test/templates/diagnostics/multi-files/File3.hx @@ -0,0 +1,5 @@ +class File3 { + static function test() { + var foo = 42; + } +} diff --git a/tests/server/test/templates/diagnostics/multi-files/Main.hx b/tests/server/test/templates/diagnostics/multi-files/Main.hx new file mode 100644 index 00000000000..a8e2c6c106c --- /dev/null +++ b/tests/server/test/templates/diagnostics/multi-files/Main.hx @@ -0,0 +1,4 @@ +import File1; +import File2; + +function main() {} diff --git a/tests/server/test/templates/issues/Issue11203/MainAbstract.hx b/tests/server/test/templates/issues/Issue11203/MainAbstract.hx new file mode 100644 index 00000000000..8e532f5eca9 --- /dev/null +++ b/tests/server/test/templates/issues/Issue11203/MainAbstract.hx @@ -0,0 +1,16 @@ +class Main { + static function main() { + var future = new Future(); + future.eager(); + } +} + +abstract Future({}) from {} { + public function new() + this = {}; + + public inline function eager():Future { + trace("much side effect!"); + return this; + } +} diff --git a/tests/server/test/templates/issues/Issue11203/MainClass.hx b/tests/server/test/templates/issues/Issue11203/MainClass.hx new file mode 100644 index 00000000000..b965a67c71e --- /dev/null +++ b/tests/server/test/templates/issues/Issue11203/MainClass.hx @@ -0,0 +1,15 @@ +class Main { + static function main() { + var future = new Future(); + future.eager(); + } +} + +class Future { + public function new() {} + + public inline function eager():Future { + trace("much side effect!"); + return this; + } +} diff --git a/tests/server/test/templates/issues/Issue11695/Macro1.hx b/tests/server/test/templates/issues/Issue11695/Macro1.hx new file mode 100644 index 00000000000..5adc7114e93 --- /dev/null +++ b/tests/server/test/templates/issues/Issue11695/Macro1.hx @@ -0,0 +1 @@ +macro function test() return macro trace("before"); diff --git a/tests/server/test/templates/issues/Issue11695/Macro2.hx b/tests/server/test/templates/issues/Issue11695/Macro2.hx new file mode 100644 index 00000000000..fc6a9dbb6a8 --- /dev/null +++ b/tests/server/test/templates/issues/Issue11695/Macro2.hx @@ -0,0 +1 @@ +macro function test() return macro trace("after"); diff --git a/tests/server/test/templates/issues/Issue11695/Main.hx b/tests/server/test/templates/issues/Issue11695/Main.hx new file mode 100644 index 00000000000..8460064b0d2 --- /dev/null +++ b/tests/server/test/templates/issues/Issue11695/Main.hx @@ -0,0 +1,3 @@ +function main() { + Macro.test(); +} diff --git a/tests/server/test/templates/issues/Issue7282/Main.hx b/tests/server/test/templates/issues/Issue7282/Main.hx new file mode 100644 index 00000000000..a36d330addf --- /dev/null +++ b/tests/server/test/templates/issues/Issue7282/Main.hx @@ -0,0 +1,10 @@ +import haxe.ds.Option; + +class Main { + public static function main() { + switch ((null:Option)) { + case Some({-1-}value{-2-}): + case None: + } + } +} diff --git a/tests/server/test/templates/issues/Issue7931/Main.hx b/tests/server/test/templates/issues/Issue7931/Main.hx new file mode 100644 index 00000000000..057ed3a1226 --- /dev/null +++ b/tests/server/test/templates/issues/Issue7931/Main.hx @@ -0,0 +1,6 @@ +class Main { + static function main() { + var s:String; + s += "test"; + } +} diff --git a/tests/server/test/templates/issues/Issue9134/Main.hx b/tests/server/test/templates/issues/Issue9134/Main.hx new file mode 100644 index 00000000000..7d765b265c8 --- /dev/null +++ b/tests/server/test/templates/issues/Issue9134/Main.hx @@ -0,0 +1,5 @@ +class Main { + static function main() { + var unused = null; + } +} diff --git a/tests/server/test/templates/issues/Issue9134/Main2.hx b/tests/server/test/templates/issues/Issue9134/Main2.hx new file mode 100644 index 00000000000..89552046053 --- /dev/null +++ b/tests/server/test/templates/issues/Issue9134/Main2.hx @@ -0,0 +1,6 @@ +class Main { + static function main() { + var unused = null; + if (unused != null) trace("wat"); + } +} diff --git a/tests/server/test/templates/issues/Issue9134/Other.hx b/tests/server/test/templates/issues/Issue9134/Other.hx new file mode 100644 index 00000000000..1b94418eb0a --- /dev/null +++ b/tests/server/test/templates/issues/Issue9134/Other.hx @@ -0,0 +1,2 @@ +class Other { +} diff --git a/tests/server/test/templates/issues/Issue9134/Other2.hx b/tests/server/test/templates/issues/Issue9134/Other2.hx new file mode 100644 index 00000000000..b74611cfa00 --- /dev/null +++ b/tests/server/test/templates/issues/Issue9134/Other2.hx @@ -0,0 +1,6 @@ +class Other { + static function foo() { + // var foo = trace("wat"); + var unused = null; + } +} From bf6662b81b6ebeeaa2bd733b9440fe626cff135d Mon Sep 17 00:00:00 2001 From: RblSb Date: Sun, 11 Feb 2024 11:41:45 +0300 Subject: [PATCH 10/35] [ci] Build macOS universal binaries (#11572) * start messing * upd * Build universal binary before testing * separate job * Update macos ocaml version, fix warnings --- .github/workflows/main.yml | 120 +++++++++++++++++------- extra/github-actions/build-mac.yml | 24 +++-- extra/github-actions/build-windows.yml | 2 +- extra/github-actions/install-nsis.yml | 2 +- extra/github-actions/test-windows.yml | 4 + extra/github-actions/workflows/main.yml | 77 +++++++++++---- 6 files changed, 169 insertions(+), 60 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a55d3932cb6..402098f50ab 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,7 +24,7 @@ jobs: rm C:\msys64\usr\bin\bash.exe - name: choco install nsis - uses: nick-invision/retry@v2 + uses: nick-invision/retry@v3 with: timeout_minutes: 10 max_attempts: 10 @@ -114,7 +114,7 @@ jobs: [ $(ls -1 out | wc -l) -eq "3" ] - name: Upload artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: win${{env.ARCH}}Binaries path: out @@ -139,7 +139,7 @@ jobs: rm C:\msys64\usr\bin\bash.exe - name: choco install nsis - uses: nick-invision/retry@v2 + uses: nick-invision/retry@v3 with: timeout_minutes: 10 max_attempts: 10 @@ -248,7 +248,7 @@ jobs: [ $(ls -1 out | wc -l) -eq "3" ] - name: Upload artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: win${{env.ARCH}}Binaries path: out @@ -270,7 +270,7 @@ jobs: - name: Cache opam id: cache-opam - uses: actions/cache@v3.0.11 + uses: actions/cache@v4 with: path: ~/.opam/ key: ${{ runner.os }}-${{ matrix.ocaml }}-${{ hashFiles('./haxe.opam', './libs/') }} @@ -347,13 +347,13 @@ jobs: EOL - name: Upload artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: linuxBinaries${{ (matrix.ocaml == '5.0.0' && '_ocaml5') || '' }} path: out - name: Upload xmldoc artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: matrix.ocaml == '4.08.1' with: name: xmldoc @@ -385,7 +385,7 @@ jobs: - uses: actions/checkout@main with: submodules: recursive - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: linuxBinaries${{ (matrix.ocaml == '5.0.0' && '_ocaml5') || '' }} path: linuxBinaries @@ -455,13 +455,13 @@ jobs: with: submodules: recursive - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: linuxBinaries path: linuxBinaries - name: Download xmldoc artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: xmldoc path: xmldoc @@ -530,7 +530,7 @@ jobs: FORCE_COLOR: 1 steps: - name: Login to GitHub Container Registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} @@ -541,7 +541,7 @@ jobs: - name: Set up QEMU id: qemu - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 with: image: tonistiigi/binfmt:latest platforms: all @@ -573,17 +573,23 @@ jobs: EARTHLY_REMOTE_CACHE: "ghcr.io/${{env.CONTAINER_REG}}_cache:build-${{env.CONTAINER_TAG}}-arm64" - name: Upload artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: linuxArm64Binaries path: out/linux/arm64 mac-build: - runs-on: macos-latest + strategy: + fail-fast: false + matrix: + os: [macos-latest, macos-14] + runs-on: ${{ matrix.os }} env: PLATFORM: mac OPAMYES: 1 MACOSX_DEPLOYMENT_TARGET: 10.13 + OCAML_VERSION: 5.1.1 + CTYPES: 0.21.1 steps: - uses: actions/checkout@main with: @@ -591,10 +597,10 @@ jobs: - name: Cache opam id: cache-opam - uses: actions/cache@v3.0.11 + uses: actions/cache@v4 with: path: ~/.opam/ - key: ${{ runner.os }}-${{ hashFiles('./haxe.opam', './libs/') }} + key: ${{ matrix.os }}-${{ hashFiles('./haxe.opam', './libs/') }} - name: Install Neko from S3 run: | @@ -616,7 +622,7 @@ jobs: - name: Install dependencies env: # For compatibility with macOS 10.13 - ZLIB_VERSION: 1.3.1 + ZLIB_VERSION: 1.3 MBEDTLS_VERSION: 2.28.5 PCRE2_VERSION: 10.42 run: | @@ -632,19 +638,19 @@ jobs: brew install cpanminus cpanm IPC::System::Simple cpanm String::ShellQuote - curl -L https://github.com/madler/zlib/releases/download/v$ZLIB_VERSION/zlib-$ZLIB_VERSION.tar.gz | tar xz + curl -L https://www.zlib.net/zlib-$ZLIB_VERSION.tar.gz | tar xz cd zlib-$ZLIB_VERSION ./configure - make && make install + sudo make && sudo make install cd .. curl -L https://github.com/ARMmbed/mbedtls/archive/v$MBEDTLS_VERSION.tar.gz | tar xz cd mbedtls-$MBEDTLS_VERSION - make && make install + sudo make && sudo make install cd .. curl -L https://github.com/PCRE2Project/pcre2/releases/download/pcre2-$PCRE2_VERSION/pcre2-$PCRE2_VERSION.tar.gz | tar xz cd pcre2-$PCRE2_VERSION ./configure --enable-unicode --enable-pcre2-8 --enable-pcre2-16 --enable-pcre2-32 --enable-unicode-properties --enable-pcre2grep-libz --enable-pcre2grep-libbz2 --enable-jit - make && make install + sudo make && sudo make install cd .. - name: Install OCaml libraries @@ -653,10 +659,10 @@ jobs: set -ex opam init # --disable-sandboxing opam update - opam switch create 4.08.1 + opam switch create ${{env.OCAML_VERSION}} eval $(opam env) opam env - opam pin add ctypes 0.17.1 --yes + opam pin add ctypes ${{env.CTYPES}} --yes opam pin add haxe . --no-action opam install haxe --deps-only --assume-depexts opam list @@ -677,10 +683,18 @@ jobs: otool -L ./haxe otool -L ./haxelib - - name: Upload artifact - uses: actions/upload-artifact@v3 + - name: Upload artifact (x64) + if: matrix.os == 'macos-latest' + uses: actions/upload-artifact@v4 with: - name: macBinaries + name: macX64Binaries + path: out + + - name: Upload artifact (arm) + if: matrix.os == 'macos-14' + uses: actions/upload-artifact@v4 + with: + name: macArmBinaries path: out @@ -719,6 +733,10 @@ jobs: - name: Print Neko version run: neko -version 2>&1 + - uses: actions/setup-node@v4 + with: + node-version: 18.17.1 + # - name: Quick test # shell: pwsh # run: | @@ -795,7 +813,7 @@ jobs: - uses: actions/checkout@main with: submodules: recursive - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: win${{env.ARCH}}Binaries path: win${{env.ARCH}}Binaries @@ -812,6 +830,10 @@ jobs: - name: Print Neko version run: neko -version 2>&1 + - uses: actions/setup-node@v4 + with: + node-version: 18.17.1 + # - name: Quick test # shell: pwsh # run: | @@ -869,9 +891,43 @@ jobs: working-directory: ${{github.workspace}}/tests - mac-test: + mac-build-universal: needs: mac-build runs-on: macos-latest + steps: + - name: Checkout the repository + uses: actions/checkout@main + - uses: actions/download-artifact@v4 + with: + name: macX64Binaries + path: macX64Binaries + - uses: actions/download-artifact@v4 + with: + name: macArmBinaries + path: macArmBinaries + + - name: Make universal binary + run: | + set -ex + tar -xf macX64Binaries/*_bin.tar.gz -C macX64Binaries --strip-components=1 + tar -xf macArmBinaries/*_bin.tar.gz -C macArmBinaries --strip-components=1 + lipo -create -output haxe macX64Binaries/haxe macArmBinaries/haxe + # there is only x64 haxelib + mv macX64Binaries/haxelib . + make -s package_unix package_installer_mac + ls -l out + otool -L ./haxe + otool -L ./haxelib + + - name: Upload artifact (universal) + uses: actions/upload-artifact@v4 + with: + name: macBinaries + path: out + + mac-test: + needs: mac-build-universal + runs-on: macos-latest env: PLATFORM: mac TEST: ${{matrix.target}} @@ -888,7 +944,7 @@ jobs: - uses: actions/checkout@main with: submodules: recursive - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: macBinaries path: macBinaries @@ -956,7 +1012,7 @@ jobs: uses: actions/checkout@main - name: Download build artifacts - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 - name: Install awscli run: | @@ -1031,7 +1087,7 @@ jobs: sudo apt-get install -qqy libc6 - name: Download Haxe - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: linuxBinaries path: linuxBinaries @@ -1047,7 +1103,7 @@ jobs: sudo ln -s `pwd`/linuxBinaries/std /usr/local/share/haxe/std - name: Download xmldoc artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: xmldoc path: xmldoc diff --git a/extra/github-actions/build-mac.yml b/extra/github-actions/build-mac.yml index d68882a90de..31b8a62f145 100644 --- a/extra/github-actions/build-mac.yml +++ b/extra/github-actions/build-mac.yml @@ -20,16 +20,16 @@ curl -L https://www.zlib.net/zlib-$ZLIB_VERSION.tar.gz | tar xz cd zlib-$ZLIB_VERSION ./configure - make && make install + sudo make && sudo make install cd .. curl -L https://github.com/ARMmbed/mbedtls/archive/v$MBEDTLS_VERSION.tar.gz | tar xz cd mbedtls-$MBEDTLS_VERSION - make && make install + sudo make && sudo make install cd .. curl -L https://github.com/PCRE2Project/pcre2/releases/download/pcre2-$PCRE2_VERSION/pcre2-$PCRE2_VERSION.tar.gz | tar xz cd pcre2-$PCRE2_VERSION ./configure --enable-unicode --enable-pcre2-8 --enable-pcre2-16 --enable-pcre2-32 --enable-unicode-properties --enable-pcre2grep-libz --enable-pcre2grep-libbz2 --enable-jit - make && make install + sudo make && sudo make install cd .. - name: Install OCaml libraries @@ -38,10 +38,10 @@ set -ex opam init # --disable-sandboxing opam update - opam switch create 4.08.1 + opam switch create ${{env.OCAML_VERSION}} eval $(opam env) opam env - opam pin add ctypes 0.17.1 --yes + opam pin add ctypes ${{env.CTYPES}} --yes opam pin add haxe . --no-action opam install haxe --deps-only --assume-depexts opam list @@ -62,8 +62,16 @@ otool -L ./haxe otool -L ./haxelib -- name: Upload artifact - uses: actions/upload-artifact@v3 +- name: Upload artifact (x64) + if: matrix.os == 'macos-latest' + uses: actions/upload-artifact@v4 with: - name: macBinaries + name: macX64Binaries + path: out + +- name: Upload artifact (arm) + if: matrix.os == 'macos-14' + uses: actions/upload-artifact@v4 + with: + name: macArmBinaries path: out diff --git a/extra/github-actions/build-windows.yml b/extra/github-actions/build-windows.yml index f429e129ee8..2bfa654aa13 100644 --- a/extra/github-actions/build-windows.yml +++ b/extra/github-actions/build-windows.yml @@ -34,7 +34,7 @@ [ $(ls -1 out | wc -l) -eq "3" ] - name: Upload artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: win${{env.ARCH}}Binaries path: out diff --git a/extra/github-actions/install-nsis.yml b/extra/github-actions/install-nsis.yml index 752016d080e..d69fd7f4947 100644 --- a/extra/github-actions/install-nsis.yml +++ b/extra/github-actions/install-nsis.yml @@ -1,5 +1,5 @@ - name: choco install nsis - uses: nick-invision/retry@v2 + uses: nick-invision/retry@v3 with: timeout_minutes: 10 max_attempts: 10 diff --git a/extra/github-actions/test-windows.yml b/extra/github-actions/test-windows.yml index 8eaf81b613c..96c02751847 100644 --- a/extra/github-actions/test-windows.yml +++ b/extra/github-actions/test-windows.yml @@ -1,3 +1,7 @@ +- uses: actions/setup-node@v4 + with: + node-version: 18.17.1 + # - name: Quick test # shell: pwsh # run: | diff --git a/extra/github-actions/workflows/main.yml b/extra/github-actions/workflows/main.yml index 5dbff676142..ede4a966ac7 100644 --- a/extra/github-actions/workflows/main.yml +++ b/extra/github-actions/workflows/main.yml @@ -68,7 +68,7 @@ jobs: - name: Cache opam id: cache-opam - uses: actions/cache@v3.0.11 + uses: actions/cache@v4 with: path: ~/.opam/ key: ${{ runner.os }}-${{ matrix.ocaml }}-${{ hashFiles('./haxe.opam', './libs/') }} @@ -117,6 +117,7 @@ jobs: run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT - name: Build xmldoc + if: matrix.ocaml == '4.08.1' run: | set -ex make -s xmldoc @@ -128,13 +129,13 @@ jobs: EOL - name: Upload artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: linuxBinaries${{ (matrix.ocaml == '5.0.0' && '_ocaml5') || '' }} path: out - name: Upload xmldoc artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: matrix.ocaml == '4.08.1' with: name: xmldoc @@ -166,7 +167,7 @@ jobs: - uses: actions/checkout@main with: submodules: recursive - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: linuxBinaries${{ (matrix.ocaml == '5.0.0' && '_ocaml5') || '' }} path: linuxBinaries @@ -220,13 +221,13 @@ jobs: with: submodules: recursive - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: linuxBinaries path: linuxBinaries - name: Download xmldoc artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: xmldoc path: xmldoc @@ -279,7 +280,7 @@ jobs: FORCE_COLOR: 1 steps: - name: Login to GitHub Container Registry - uses: docker/login-action@v2 + uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.actor }} @@ -290,7 +291,7 @@ jobs: - name: Set up QEMU id: qemu - uses: docker/setup-qemu-action@v2 + uses: docker/setup-qemu-action@v3 with: image: tonistiigi/binfmt:latest platforms: all @@ -322,17 +323,23 @@ jobs: EARTHLY_REMOTE_CACHE: "ghcr.io/${{env.CONTAINER_REG}}_cache:build-${{env.CONTAINER_TAG}}-arm64" - name: Upload artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: linuxArm64Binaries path: out/linux/arm64 mac-build: - runs-on: macos-latest + strategy: + fail-fast: false + matrix: + os: [macos-latest, macos-14] + runs-on: ${{ matrix.os }} env: PLATFORM: mac OPAMYES: 1 MACOSX_DEPLOYMENT_TARGET: 10.13 + OCAML_VERSION: 5.1.1 + CTYPES: 0.21.1 steps: - uses: actions/checkout@main with: @@ -340,10 +347,10 @@ jobs: - name: Cache opam id: cache-opam - uses: actions/cache@v3.0.11 + uses: actions/cache@v4 with: path: ~/.opam/ - key: ${{ runner.os }}-${{ hashFiles('./haxe.opam', './libs/') }} + key: ${{ matrix.os }}-${{ hashFiles('./haxe.opam', './libs/') }} @import install-neko-unix.yml @import build-mac.yml @@ -393,7 +400,7 @@ jobs: - uses: actions/checkout@main with: submodules: recursive - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: win${{env.ARCH}}Binaries path: win${{env.ARCH}}Binaries @@ -401,9 +408,43 @@ jobs: @import install-neko-windows.yml @import test-windows.yml - mac-test: + mac-build-universal: needs: mac-build runs-on: macos-latest + steps: + - name: Checkout the repository + uses: actions/checkout@main + - uses: actions/download-artifact@v4 + with: + name: macX64Binaries + path: macX64Binaries + - uses: actions/download-artifact@v4 + with: + name: macArmBinaries + path: macArmBinaries + + - name: Make universal binary + run: | + set -ex + tar -xf macX64Binaries/*_bin.tar.gz -C macX64Binaries --strip-components=1 + tar -xf macArmBinaries/*_bin.tar.gz -C macArmBinaries --strip-components=1 + lipo -create -output haxe macX64Binaries/haxe macArmBinaries/haxe + # there is only x64 haxelib + mv macX64Binaries/haxelib . + make -s package_unix package_installer_mac + ls -l out + otool -L ./haxe + otool -L ./haxelib + + - name: Upload artifact (universal) + uses: actions/upload-artifact@v4 + with: + name: macBinaries + path: out + + mac-test: + needs: mac-build-universal + runs-on: macos-latest env: PLATFORM: mac TEST: ${{matrix.target}} @@ -420,7 +461,7 @@ jobs: - uses: actions/checkout@main with: submodules: recursive - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: macBinaries path: macBinaries @@ -440,7 +481,7 @@ jobs: uses: actions/checkout@main - name: Download build artifacts - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 - name: Install awscli run: | @@ -515,7 +556,7 @@ jobs: sudo apt-get install -qqy libc6 - name: Download Haxe - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: linuxBinaries path: linuxBinaries @@ -531,7 +572,7 @@ jobs: sudo ln -s `pwd`/linuxBinaries/std /usr/local/share/haxe/std - name: Download xmldoc artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: xmldoc path: xmldoc From d374c283443e43a30e7c6f10c87064d27b9837b6 Mon Sep 17 00:00:00 2001 From: tobil4sk Date: Tue, 2 Jul 2024 15:34:53 +0100 Subject: [PATCH 11/35] [ci] Make mac universal builds more universal (#11663) * [ci] Install arm64 neko for arm64 mac builds * [ci] Create universal binary for haxelib * [ci] Build native haxelib binary on arm64 mac * [make] Use universal neko binaries for mac package It can still be configured to specific architectures if needed, using `PACKAGE_INSTALLER_MAC_ARCH`. * [make] Default to host arch for mac installer * [make] Use neko version 2.4.0-rc * [make] Use neko version 2.4.0-rc.1 This version fixes a permission issue with universal mac binaries --- .github/workflows/main.yml | 7 +++---- Makefile | 20 +++++++++++++++----- extra/github-actions/workflows/main.yml | 7 +++---- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 402098f50ab..4ee2f9c6107 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -585,7 +585,7 @@ jobs: os: [macos-latest, macos-14] runs-on: ${{ matrix.os }} env: - PLATFORM: mac + PLATFORM: mac${{ matrix.os == 'macos-14' && '-arm64' || '' }} OPAMYES: 1 MACOSX_DEPLOYMENT_TARGET: 10.13 OCAML_VERSION: 5.1.1 @@ -912,9 +912,8 @@ jobs: tar -xf macX64Binaries/*_bin.tar.gz -C macX64Binaries --strip-components=1 tar -xf macArmBinaries/*_bin.tar.gz -C macArmBinaries --strip-components=1 lipo -create -output haxe macX64Binaries/haxe macArmBinaries/haxe - # there is only x64 haxelib - mv macX64Binaries/haxelib . - make -s package_unix package_installer_mac + lipo -create -output haxelib macX64Binaries/haxelib macArmBinaries/haxelib + make -s package_unix package_installer_mac PACKAGE_INSTALLER_MAC_ARCH=universal ls -l out otool -L ./haxe otool -L ./haxelib diff --git a/Makefile b/Makefile index a369415b02b..a3b86a753a9 100644 --- a/Makefile +++ b/Makefile @@ -59,7 +59,7 @@ PACKAGE_FILE_NAME=haxe_$(COMMIT_DATE)_$(COMMIT_SHA) HAXE_VERSION=$(shell $(CURDIR)/$(HAXE_OUTPUT) -version 2>&1 | awk '{print $$1;}') HAXE_VERSION_SHORT=$(shell echo "$(HAXE_VERSION)" | grep -oE "^[0-9]+\.[0-9]+\.[0-9]+") -NEKO_VERSION=2.3.0 +NEKO_VERSION=2.4.0-rc.1 NEKO_MAJOR_VERSION=$(shell echo "$(NEKO_VERSION)" | grep -oE "^[0-9]+") NEKO_VERSION_TAG=v$(shell echo "$(NEKO_VERSION)" | sed "s/\./-/g") @@ -168,19 +168,29 @@ xmldoc: $(INSTALLER_TMP_DIR): mkdir -p $(INSTALLER_TMP_DIR) -$(INSTALLER_TMP_DIR)/neko-osx64.tar.gz: $(INSTALLER_TMP_DIR) - wget -nv https://github.com/HaxeFoundation/neko/releases/download/$(NEKO_VERSION_TAG)/neko-$(NEKO_VERSION)-osx64.tar.gz -O installer/neko-osx64.tar.gz +# Can be 'universal', 'arm64', or 'x86_64' +ifndef PACKAGE_INSTALLER_MAC_ARCH +PACKAGE_INSTALLER_MAC_ARCH:=$(shell uname -m) +endif + +$(INSTALLER_TMP_DIR)/neko-osx.tar.gz: $(INSTALLER_TMP_DIR) + NEKO_ARCH_SUFFIX=$$(if [ "$(PACKAGE_INSTALLER_MAC_ARCH)" = "x86_64" ]; then \ + echo 64; \ + else \ + echo "-$(PACKAGE_INSTALLER_MAC_ARCH)"; \ + fi); \ + wget -nv https://github.com/HaxeFoundation/neko/releases/download/$(NEKO_VERSION_TAG)/neko-$(NEKO_VERSION)-osx$$NEKO_ARCH_SUFFIX.tar.gz -O installer/neko-osx.tar.gz # Installer -package_installer_mac: $(INSTALLER_TMP_DIR)/neko-osx64.tar.gz package_unix +package_installer_mac: $(INSTALLER_TMP_DIR)/neko-osx.tar.gz package_unix $(eval OUTFILE := $(shell pwd)/$(PACKAGE_OUT_DIR)/$(PACKAGE_FILE_NAME)_installer.tar.gz) $(eval PACKFILE := $(shell pwd)/$(PACKAGE_OUT_DIR)/$(PACKAGE_FILE_NAME)_bin.tar.gz) $(eval VERSION := $(shell $(CURDIR)/$(HAXE_OUTPUT) -version 2>&1)) bash -c "rm -rf $(INSTALLER_TMP_DIR)/{resources,pkg,tgz,haxe.tar.gz}" mkdir $(INSTALLER_TMP_DIR)/resources # neko - unpack to change the dir name - cd $(INSTALLER_TMP_DIR)/resources && tar -zxvf ../neko-osx64.tar.gz + cd $(INSTALLER_TMP_DIR)/resources && tar -zxvf ../neko-osx.tar.gz mv $(INSTALLER_TMP_DIR)/resources/neko* $(INSTALLER_TMP_DIR)/resources/neko cd $(INSTALLER_TMP_DIR)/resources && tar -zcvf neko.tar.gz neko # haxe - unpack to change the dir name diff --git a/extra/github-actions/workflows/main.yml b/extra/github-actions/workflows/main.yml index ede4a966ac7..93313a9b7ce 100644 --- a/extra/github-actions/workflows/main.yml +++ b/extra/github-actions/workflows/main.yml @@ -335,7 +335,7 @@ jobs: os: [macos-latest, macos-14] runs-on: ${{ matrix.os }} env: - PLATFORM: mac + PLATFORM: mac${{ matrix.os == 'macos-14' && '-arm64' || '' }} OPAMYES: 1 MACOSX_DEPLOYMENT_TARGET: 10.13 OCAML_VERSION: 5.1.1 @@ -429,9 +429,8 @@ jobs: tar -xf macX64Binaries/*_bin.tar.gz -C macX64Binaries --strip-components=1 tar -xf macArmBinaries/*_bin.tar.gz -C macArmBinaries --strip-components=1 lipo -create -output haxe macX64Binaries/haxe macArmBinaries/haxe - # there is only x64 haxelib - mv macX64Binaries/haxelib . - make -s package_unix package_installer_mac + lipo -create -output haxelib macX64Binaries/haxelib macArmBinaries/haxelib + make -s package_unix package_installer_mac PACKAGE_INSTALLER_MAC_ARCH=universal ls -l out otool -L ./haxe otool -L ./haxelib From 11d2ef5e83d3866f9e023d3bf620ecc041dea4ae Mon Sep 17 00:00:00 2001 From: Zeta <53486764+Apprentice-Alchemist@users.noreply.github.com> Date: Sun, 30 Jun 2024 10:32:27 +0200 Subject: [PATCH 12/35] Fix version check in genneko.ml. (#11705) --- src/generators/genneko.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generators/genneko.ml b/src/generators/genneko.ml index e8a07a980e8..4500ec0b45b 100644 --- a/src/generators/genneko.ml +++ b/src/generators/genneko.ml @@ -685,7 +685,7 @@ let generate_libs_init = function (EVars [ "@s",Some (call p (loadp "sys_string" 0) []); ],p); - (EIf (op ">=" (builtin p "version") (int p 240), + (EIf (op ">=" (call p (builtin p "version") []) (int p 240), (op "=" es (op "+" es (ESwitch (call p (loadp "sys_cpu_arch" 0) [],[ (str p "arm64", str p "Arm64"); (str p "arm", str p "Arm"); From 3491304f34840586f62f99534f4fd2171d2a59eb Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Tue, 16 Jul 2024 11:05:23 +0200 Subject: [PATCH 13/35] [macro] Compiler.include should not be called outside init macros --- std/haxe/macro/Compiler.hx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/std/haxe/macro/Compiler.hx b/std/haxe/macro/Compiler.hx index e825937054a..117f7d81f76 100644 --- a/std/haxe/macro/Compiler.hx +++ b/std/haxe/macro/Compiler.hx @@ -226,6 +226,8 @@ class Compiler { If you want to specify a different set of paths to search for modules, you can use the optional argument `classPath`. + Usage of this function outside of initialization macros is deprecated and may cause compilation server issues. + @param pack The package dot-path as String. Use `''` to include the root package. @param rec If true, recursively adds all sub-packages. @param ignore Array of module names to ignore for inclusion. @@ -301,6 +303,7 @@ class Compiler { Context.error('Package "$pack" was not found in any of class paths', Context.currentPos()); } + Context.assertInitMacro(); Context.onAfterInitMacros(() -> include(pack, rec, ignore, classPaths, strict)); } From 76c969f43aed373852c61cf6966d7038e276a3d2 Mon Sep 17 00:00:00 2001 From: Zeta <53486764+Apprentice-Alchemist@users.noreply.github.com> Date: Tue, 23 Jan 2024 11:58:29 +0100 Subject: [PATCH 14/35] Fix macOS CI. (#11503) Download zlib from the github release. Hopefully this URL will be stable. Remove those failing brew invocations. Remove unneeded dependencies in the Brewfile. --- .github/workflows/main.yml | 13 +++---------- extra/github-actions/build-mac.yml | 13 +++---------- tests/Brewfile | 7 +++---- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4ee2f9c6107..7c8660210d9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -622,23 +622,16 @@ jobs: - name: Install dependencies env: # For compatibility with macOS 10.13 - ZLIB_VERSION: 1.3 + ZLIB_VERSION: 1.3.1 MBEDTLS_VERSION: 2.28.5 PCRE2_VERSION: 10.42 run: | set -ex - brew uninstall openssl@1.0.2t || echo - brew uninstall python@2.7.17 || echo - brew untap local/openssl || echo - brew untap local/python2 || echo brew update - # brew unlink python@2 - brew bundle --file=tests/Brewfile --no-upgrade || brew link --overwrite awscli - brew install libunistring - brew install cpanminus + brew bundle --file=tests/Brewfile --no-upgrade cpanm IPC::System::Simple cpanm String::ShellQuote - curl -L https://www.zlib.net/zlib-$ZLIB_VERSION.tar.gz | tar xz + curl -L https://github.com/madler/zlib/releases/download/v$ZLIB_VERSION/zlib-$ZLIB_VERSION.tar.gz | tar xz cd zlib-$ZLIB_VERSION ./configure sudo make && sudo make install diff --git a/extra/github-actions/build-mac.yml b/extra/github-actions/build-mac.yml index 31b8a62f145..543d9ba1105 100644 --- a/extra/github-actions/build-mac.yml +++ b/extra/github-actions/build-mac.yml @@ -1,23 +1,16 @@ - name: Install dependencies env: # For compatibility with macOS 10.13 - ZLIB_VERSION: 1.3 + ZLIB_VERSION: 1.3.1 MBEDTLS_VERSION: 2.28.5 PCRE2_VERSION: 10.42 run: | set -ex - brew uninstall openssl@1.0.2t || echo - brew uninstall python@2.7.17 || echo - brew untap local/openssl || echo - brew untap local/python2 || echo brew update - # brew unlink python@2 - brew bundle --file=tests/Brewfile --no-upgrade || brew link --overwrite awscli - brew install libunistring - brew install cpanminus + brew bundle --file=tests/Brewfile --no-upgrade cpanm IPC::System::Simple cpanm String::ShellQuote - curl -L https://www.zlib.net/zlib-$ZLIB_VERSION.tar.gz | tar xz + curl -L https://github.com/madler/zlib/releases/download/v$ZLIB_VERSION/zlib-$ZLIB_VERSION.tar.gz | tar xz cd zlib-$ZLIB_VERSION ./configure sudo make && sudo make install diff --git a/tests/Brewfile b/tests/Brewfile index 2e592102571..ac7f3f61b01 100644 --- a/tests/Brewfile +++ b/tests/Brewfile @@ -1,7 +1,6 @@ -brew "ocaml" -brew "camlp5" brew "opam" brew "ninja" -brew "awscli" brew "cmake" -brew "pkg-config" \ No newline at end of file +brew "pkg-config" +brew "libunistring" +brew "cpanminus" \ No newline at end of file From d4dd1d09198b3e0dc6447b4a155948811443be6e Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Thu, 7 Sep 2023 10:08:00 +0200 Subject: [PATCH 15/35] [ci] update nsis --- .github/workflows/main.yml | 4 ++-- extra/EnvVarUpdate.nsh | 2 +- extra/github-actions/install-nsis.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7c8660210d9..b587ebd1c06 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,7 +28,7 @@ jobs: with: timeout_minutes: 10 max_attempts: 10 - command: choco install --no-progress nsis.portable --version 3.02 -y + command: choco install --no-progress nsis.portable --version 3.09 -y - name: choco install things shell: pwsh @@ -143,7 +143,7 @@ jobs: with: timeout_minutes: 10 max_attempts: 10 - command: choco install --no-progress nsis.portable --version 3.02 -y + command: choco install --no-progress nsis.portable --version 3.09 -y - name: choco install things shell: pwsh diff --git a/extra/EnvVarUpdate.nsh b/extra/EnvVarUpdate.nsh index 39682000c35..5794a0d270c 100644 --- a/extra/EnvVarUpdate.nsh +++ b/extra/EnvVarUpdate.nsh @@ -43,7 +43,7 @@ !ifndef Un${StrFuncName}_INCLUDED ${Un${StrFuncName}} !endif - !define un.${StrFuncName} "${Un${StrFuncName}}" + !define un.${StrFuncName} '${Un${StrFuncName}}' !macroend !insertmacro _IncludeStrFunction StrTok diff --git a/extra/github-actions/install-nsis.yml b/extra/github-actions/install-nsis.yml index d69fd7f4947..5f84db3d130 100644 --- a/extra/github-actions/install-nsis.yml +++ b/extra/github-actions/install-nsis.yml @@ -3,7 +3,7 @@ with: timeout_minutes: 10 max_attempts: 10 - command: choco install --no-progress nsis.portable --version 3.02 -y + command: choco install --no-progress nsis.portable --version 3.09 -y - name: choco install things shell: pwsh From d4fe4e69daa6b18f0162b67fc7358ae7e610aa73 Mon Sep 17 00:00:00 2001 From: Zeta <53486764+Apprentice-Alchemist@users.noreply.github.com> Date: Fri, 26 Apr 2024 12:15:41 +0200 Subject: [PATCH 16/35] [ci] Specify macOS runner versions instead of using macos-latest. (#11645) * [ci] Specify macOS runner versions instead of using macos-latest. Use `runner.arch` to decide where to upload the macOS artifacts. * [ci] Use macos-13 for tests. --- .github/workflows/main.yml | 8 ++++---- extra/github-actions/build-mac.yml | 4 ++-- extra/github-actions/workflows/main.yml | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b587ebd1c06..1659fc33b7a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -582,7 +582,7 @@ jobs: strategy: fail-fast: false matrix: - os: [macos-latest, macos-14] + os: [macos-14, macos-13] runs-on: ${{ matrix.os }} env: PLATFORM: mac${{ matrix.os == 'macos-14' && '-arm64' || '' }} @@ -677,14 +677,14 @@ jobs: otool -L ./haxelib - name: Upload artifact (x64) - if: matrix.os == 'macos-latest' + if: runner.arch == 'X64' uses: actions/upload-artifact@v4 with: name: macX64Binaries path: out - name: Upload artifact (arm) - if: matrix.os == 'macos-14' + if: runner.arch == 'ARM64' uses: actions/upload-artifact@v4 with: name: macArmBinaries @@ -919,7 +919,7 @@ jobs: mac-test: needs: mac-build-universal - runs-on: macos-latest + runs-on: macos-13 env: PLATFORM: mac TEST: ${{matrix.target}} diff --git a/extra/github-actions/build-mac.yml b/extra/github-actions/build-mac.yml index 543d9ba1105..65dcc41b4d8 100644 --- a/extra/github-actions/build-mac.yml +++ b/extra/github-actions/build-mac.yml @@ -56,14 +56,14 @@ otool -L ./haxelib - name: Upload artifact (x64) - if: matrix.os == 'macos-latest' + if: runner.arch == 'X64' uses: actions/upload-artifact@v4 with: name: macX64Binaries path: out - name: Upload artifact (arm) - if: matrix.os == 'macos-14' + if: runner.arch == 'ARM64' uses: actions/upload-artifact@v4 with: name: macArmBinaries diff --git a/extra/github-actions/workflows/main.yml b/extra/github-actions/workflows/main.yml index 93313a9b7ce..c2e8dd95d4b 100644 --- a/extra/github-actions/workflows/main.yml +++ b/extra/github-actions/workflows/main.yml @@ -332,7 +332,7 @@ jobs: strategy: fail-fast: false matrix: - os: [macos-latest, macos-14] + os: [macos-14, macos-13] runs-on: ${{ matrix.os }} env: PLATFORM: mac${{ matrix.os == 'macos-14' && '-arm64' || '' }} @@ -443,7 +443,7 @@ jobs: mac-test: needs: mac-build-universal - runs-on: macos-latest + runs-on: macos-13 env: PLATFORM: mac TEST: ${{matrix.target}} From c3f3be1ae4887ed2a38af00da78a80ce81403c94 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Tue, 18 Jun 2024 18:07:30 +0200 Subject: [PATCH 17/35] Windows CI doesn't like dune 3.16.0 (yet?) (#11697) --- haxe.opam | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/haxe.opam b/haxe.opam index b1b90ac2987..a5fd6d1ca6f 100644 --- a/haxe.opam +++ b/haxe.opam @@ -22,7 +22,7 @@ depends: [ ("ocaml" {>= "5.0"} & ("camlp5" {build})) | ("ocaml" {>= "4.08" & < "5.0"} & ("camlp5" {build & = "8.00.03"})) "ocamlfind" {build} - "dune" {>= "1.11"} + "dune" {>= "1.11" & < "3.16"} "sedlex" {>= "2.0"} "xml-light" "extlib" {>= "1.7.8"} From a9d49f7787ba56be388143ec890ed4117665c20a Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Thu, 18 Jul 2024 09:25:18 +0200 Subject: [PATCH 18/35] [CI] fix windows64 tests --- .github/workflows/main.yml | 2 +- extra/github-actions/workflows/main.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1659fc33b7a..79b8b50ab79 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -709,7 +709,7 @@ jobs: - uses: actions/checkout@main with: submodules: recursive - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: win${{env.ARCH}}Binaries path: win${{env.ARCH}}Binaries diff --git a/extra/github-actions/workflows/main.yml b/extra/github-actions/workflows/main.yml index c2e8dd95d4b..6e9247cebf7 100644 --- a/extra/github-actions/workflows/main.yml +++ b/extra/github-actions/workflows/main.yml @@ -373,7 +373,7 @@ jobs: - uses: actions/checkout@main with: submodules: recursive - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: win${{env.ARCH}}Binaries path: win${{env.ARCH}}Binaries From 406647ff2cfdb8a6efb778a47689afccf62478c2 Mon Sep 17 00:00:00 2001 From: tobil4sk Date: Thu, 16 May 2024 13:42:47 +0100 Subject: [PATCH 19/35] [make] Generate haxelib binary with `nekotools boot -c` on Mac/Linux (#11653) * [make] Generate haxelib binary with `nekotools boot -c` on Mac/Linux `nekotools boot` is a bit of a hack and some tools that deal with executables on linux can strip away the haxelib bytecode if it is done this way. `nekotools boot -c` will generate a .c file which can then be compiled manually. * [make] Fix for unix platforms if PLATFORM is defined * [make] Set the HAXE_STD_PATH while building haxelib Otherwise it doesn't work if haxe isn't already installed, or it might use the wrong version of the standard library * [ci] Install missing neko headers during setup They are now needed for compiling haxelib * [ci] Ensure /usr/local/include exists before installing neko * [ci] Install neko headers for earthly builds as well * [make] Omit HAXE_STD_PATH when building haxelib on windows For some reason this environment variable isn't working here on Windows * [ci] Continue building x64 haxelib on mac arm64 for now We don't have neko binaries for mac arm64 yet `nekotools boot run.n` was previously also producing an x64 binary * [make] Set rpath on mac when building haxelib It looks like /usr/local/lib is no longer used as a default path in some cases. * [make] Set std path for haxelib build on windows --- .github/workflows/main.yml | 12 +++++++++++- Earthfile | 1 + Makefile | 20 +++++++++++++++++--- Makefile.win | 7 +++++++ extra/github-actions/build-mac.yml | 2 +- extra/github-actions/install-neko-unix.yml | 2 ++ 6 files changed, 39 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 79b8b50ab79..f5b78342357 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -283,9 +283,11 @@ jobs: tar -xf $RUNNER_TEMP/neko_latest.tar.gz -C $RUNNER_TEMP NEKOPATH=`echo $RUNNER_TEMP/neko-*-*` sudo mkdir -p /usr/local/bin + sudo mkdir -p /usr/local/include sudo mkdir -p /usr/local/lib/neko sudo ln -s $NEKOPATH/{neko,nekoc,nekoml,nekotools} /usr/local/bin/ sudo ln -s $NEKOPATH/libneko.* /usr/local/lib/ + sudo ln -s $NEKOPATH/include/* /usr/local/include/ sudo ln -s $NEKOPATH/*.ndll /usr/local/lib/neko/ echo "NEKOPATH=$NEKOPATH" >> $GITHUB_ENV @@ -398,9 +400,11 @@ jobs: tar -xf $RUNNER_TEMP/neko_latest.tar.gz -C $RUNNER_TEMP NEKOPATH=`echo $RUNNER_TEMP/neko-*-*` sudo mkdir -p /usr/local/bin + sudo mkdir -p /usr/local/include sudo mkdir -p /usr/local/lib/neko sudo ln -s $NEKOPATH/{neko,nekoc,nekoml,nekotools} /usr/local/bin/ sudo ln -s $NEKOPATH/libneko.* /usr/local/lib/ + sudo ln -s $NEKOPATH/include/* /usr/local/include/ sudo ln -s $NEKOPATH/*.ndll /usr/local/lib/neko/ echo "NEKOPATH=$NEKOPATH" >> $GITHUB_ENV @@ -474,9 +478,11 @@ jobs: tar -xf $RUNNER_TEMP/neko_latest.tar.gz -C $RUNNER_TEMP NEKOPATH=`echo $RUNNER_TEMP/neko-*-*` sudo mkdir -p /usr/local/bin + sudo mkdir -p /usr/local/include sudo mkdir -p /usr/local/lib/neko sudo ln -s $NEKOPATH/{neko,nekoc,nekoml,nekotools} /usr/local/bin/ sudo ln -s $NEKOPATH/libneko.* /usr/local/lib/ + sudo ln -s $NEKOPATH/include/* /usr/local/include/ sudo ln -s $NEKOPATH/*.ndll /usr/local/lib/neko/ echo "NEKOPATH=$NEKOPATH" >> $GITHUB_ENV @@ -610,9 +616,11 @@ jobs: tar -xf $RUNNER_TEMP/neko_latest.tar.gz -C $RUNNER_TEMP NEKOPATH=`echo $RUNNER_TEMP/neko-*-*` sudo mkdir -p /usr/local/bin + sudo mkdir -p /usr/local/include sudo mkdir -p /usr/local/lib/neko sudo ln -s $NEKOPATH/{neko,nekoc,nekoml,nekotools} /usr/local/bin/ sudo ln -s $NEKOPATH/libneko.* /usr/local/lib/ + sudo ln -s $NEKOPATH/include/* /usr/local/include/ sudo ln -s $NEKOPATH/*.ndll /usr/local/lib/neko/ echo "NEKOPATH=$NEKOPATH" >> $GITHUB_ENV @@ -670,7 +678,7 @@ jobs: set -ex eval $(opam env) opam config exec -- make -s -j`sysctl -n hw.ncpu` STATICLINK=1 "LIB_PARAMS=/usr/local/lib/libz.a /usr/local/lib/libpcre2-8.a /usr/local/lib/libmbedtls.a /usr/local/lib/libmbedcrypto.a /usr/local/lib/libmbedx509.a -cclib '-framework Security -framework CoreFoundation'" haxe - opam config exec -- make -s haxelib + opam config exec -- arch -x86_64 make -s haxelib make -s package_unix package_installer_mac ls -l out otool -L ./haxe @@ -949,9 +957,11 @@ jobs: tar -xf $RUNNER_TEMP/neko_latest.tar.gz -C $RUNNER_TEMP NEKOPATH=`echo $RUNNER_TEMP/neko-*-*` sudo mkdir -p /usr/local/bin + sudo mkdir -p /usr/local/include sudo mkdir -p /usr/local/lib/neko sudo ln -s $NEKOPATH/{neko,nekoc,nekoml,nekotools} /usr/local/bin/ sudo ln -s $NEKOPATH/libneko.* /usr/local/lib/ + sudo ln -s $NEKOPATH/include/* /usr/local/include/ sudo ln -s $NEKOPATH/*.ndll /usr/local/lib/neko/ echo "NEKOPATH=$NEKOPATH" >> $GITHUB_ENV diff --git a/Earthfile b/Earthfile index dda473f6c60..af649bf118c 100644 --- a/Earthfile +++ b/Earthfile @@ -146,6 +146,7 @@ INSTALL_NEKO: ARG PREFIX=/usr/local RUN bash -c "ln -s \"$NEKOPATH\"/{neko,nekoc,nekoml,nekotools} \"$PREFIX/bin/\"" RUN bash -c "ln -s \"$NEKOPATH\"/libneko.* \"$PREFIX/lib/\"" + RUN bash -c "ln -s \"$NEKOPATH\"/*.h \"$PREFIX/include/\"" RUN mkdir -p "$PREFIX/lib/neko/" RUN bash -c "ln -s \"$NEKOPATH\"/*.ndll \"$PREFIX/lib/neko/\"" RUN ldconfig diff --git a/Makefile b/Makefile index a3b86a753a9..0588e7c5eb1 100644 --- a/Makefile +++ b/Makefile @@ -104,10 +104,24 @@ copy_haxetoolkit: /cygdrive/c/HaxeToolkit/haxe/haxe.exe cp $< $@ endif +ifeq ($(SYSTEM_NAME),Mac) +# This assumes that haxelib and neko will both be installed into INSTALL_DIR, +# which is the case when installing using the mac installer package +HAXELIB_LFLAGS= -Wl,-rpath,$(INSTALL_DIR)/lib +endif + +haxelib_unix: + cd $(CURDIR)/extra/haxelib_src && \ + HAXE_STD_PATH=$(CURDIR)/std $(CURDIR)/$(HAXE_OUTPUT) client.hxml && \ + nekotools boot -c run.n + $(CC) $(CURDIR)/extra/haxelib_src/run.c -o $(HAXELIB_OUTPUT) -lneko $(HAXELIB_LFLAGS) + # haxelib should depends on haxe, but we don't want to do that... -haxelib: - (cd $(CURDIR)/extra/haxelib_src && $(CURDIR)/$(HAXE_OUTPUT) client.hxml && nekotools boot run.n) - mv extra/haxelib_src/run$(EXTENSION) $(HAXELIB_OUTPUT) +ifeq ($(SYSTEM_NAME),Windows) +haxelib: haxelib_$(PLATFORM) +else +haxelib: haxelib_unix +endif tools: haxelib diff --git a/Makefile.win b/Makefile.win index 95500b63536..fdb34b4342b 100644 --- a/Makefile.win +++ b/Makefile.win @@ -53,6 +53,13 @@ PACKAGE_FILES=$(HAXE_OUTPUT) $(HAXELIB_OUTPUT) std \ "$$(cygcheck $(CURDIR)/$(HAXE_OUTPUT) | grep libmbedtls.dll | sed -e 's/^\s*//')" \ "$$(cygcheck $(CURDIR)/$(HAXE_OUTPUT) | grep libmbedx509.dll | sed -e 's/^\s*//')" +# haxelib should depends on haxe, but we don't want to do that... +haxelib_win: + cd $(CURDIR)/extra/haxelib_src && \ + HAXE_STD_PATH=$$(cygpath -m $(CURDIR)/std) $(CURDIR)/$(HAXE_OUTPUT) client.hxml && \ + nekotools boot run.n + mv extra/haxelib_src/run$(EXTENSION) $(HAXELIB_OUTPUT) + echo_package_files: echo $(PACKAGE_FILES) diff --git a/extra/github-actions/build-mac.yml b/extra/github-actions/build-mac.yml index 65dcc41b4d8..01de55b7171 100644 --- a/extra/github-actions/build-mac.yml +++ b/extra/github-actions/build-mac.yml @@ -49,7 +49,7 @@ set -ex eval $(opam env) opam config exec -- make -s -j`sysctl -n hw.ncpu` STATICLINK=1 "LIB_PARAMS=/usr/local/lib/libz.a /usr/local/lib/libpcre2-8.a /usr/local/lib/libmbedtls.a /usr/local/lib/libmbedcrypto.a /usr/local/lib/libmbedx509.a -cclib '-framework Security -framework CoreFoundation'" haxe - opam config exec -- make -s haxelib + opam config exec -- arch -x86_64 make -s haxelib make -s package_unix package_installer_mac ls -l out otool -L ./haxe diff --git a/extra/github-actions/install-neko-unix.yml b/extra/github-actions/install-neko-unix.yml index ab8eb43b2d9..5946d3c7fc0 100644 --- a/extra/github-actions/install-neko-unix.yml +++ b/extra/github-actions/install-neko-unix.yml @@ -6,9 +6,11 @@ tar -xf $RUNNER_TEMP/neko_latest.tar.gz -C $RUNNER_TEMP NEKOPATH=`echo $RUNNER_TEMP/neko-*-*` sudo mkdir -p /usr/local/bin + sudo mkdir -p /usr/local/include sudo mkdir -p /usr/local/lib/neko sudo ln -s $NEKOPATH/{neko,nekoc,nekoml,nekotools} /usr/local/bin/ sudo ln -s $NEKOPATH/libneko.* /usr/local/lib/ + sudo ln -s $NEKOPATH/include/* /usr/local/include/ sudo ln -s $NEKOPATH/*.ndll /usr/local/lib/neko/ echo "NEKOPATH=$NEKOPATH" >> $GITHUB_ENV From 12b134a1ef63bfc15da865ed6615f23c1da4d2cb Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Thu, 18 Jul 2024 09:42:20 +0200 Subject: [PATCH 20/35] [ci] fix cherry picking in wrong order --- .github/workflows/main.yml | 2 +- extra/github-actions/build-mac.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f5b78342357..7cb300690a1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -678,7 +678,7 @@ jobs: set -ex eval $(opam env) opam config exec -- make -s -j`sysctl -n hw.ncpu` STATICLINK=1 "LIB_PARAMS=/usr/local/lib/libz.a /usr/local/lib/libpcre2-8.a /usr/local/lib/libmbedtls.a /usr/local/lib/libmbedcrypto.a /usr/local/lib/libmbedx509.a -cclib '-framework Security -framework CoreFoundation'" haxe - opam config exec -- arch -x86_64 make -s haxelib + opam config exec -- make -s haxelib make -s package_unix package_installer_mac ls -l out otool -L ./haxe diff --git a/extra/github-actions/build-mac.yml b/extra/github-actions/build-mac.yml index 01de55b7171..65dcc41b4d8 100644 --- a/extra/github-actions/build-mac.yml +++ b/extra/github-actions/build-mac.yml @@ -49,7 +49,7 @@ set -ex eval $(opam env) opam config exec -- make -s -j`sysctl -n hw.ncpu` STATICLINK=1 "LIB_PARAMS=/usr/local/lib/libz.a /usr/local/lib/libpcre2-8.a /usr/local/lib/libmbedtls.a /usr/local/lib/libmbedcrypto.a /usr/local/lib/libmbedx509.a -cclib '-framework Security -framework CoreFoundation'" haxe - opam config exec -- arch -x86_64 make -s haxelib + opam config exec -- make -s haxelib make -s package_unix package_installer_mac ls -l out otool -L ./haxe From 23cd1bea6197ceaddf208d20be35a5fc466d4572 Mon Sep 17 00:00:00 2001 From: Yuxiao Mao Date: Thu, 4 Jan 2024 12:52:28 +0100 Subject: [PATCH 21/35] [hl] Fix do-while loop in genhl+hlopt (#11461) * [hl] Fix do-while loop in genhl+hlopt * remove can_do Closes #10783 --- src/generators/genhl.ml | 5 +---- src/generators/hlopt.ml | 13 ++++++++----- src/optimization/analyzerTexpr.ml | 5 ++--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/generators/genhl.ml b/src/generators/genhl.ml index 3754ab1d7bb..994d0f17a59 100644 --- a/src/generators/genhl.ml +++ b/src/generators/genhl.ml @@ -2636,13 +2636,10 @@ and eval_expr ctx e = ctx.m.mbreaks <- []; ctx.m.mcontinues <- []; ctx.m.mloop_trys <- ctx.m.mtrys; - let start = jump ctx (fun p -> OJAlways p) in let continue_pos = current_pos ctx in let ret = jump_back ctx in - let j = jump_expr ctx cond false in - start(); ignore(eval_expr ctx eloop); - set_curpos ctx (max_pos e); + let j = jump_expr ctx cond false in ret(); j(); List.iter (fun f -> f (current_pos ctx)) ctx.m.mbreaks; diff --git a/src/generators/hlopt.ml b/src/generators/hlopt.ml index d60e88b47c0..57a814787e3 100644 --- a/src/generators/hlopt.ml +++ b/src/generators/hlopt.ml @@ -950,8 +950,8 @@ let _optimize (f:fundecl) = (* loop : first pass does not recurse, second pass uses cache *) if b2.bloop && b2.bstart < b.bstart then (match b2.bneed_all with None -> acc | Some s -> ISet.union acc s) else ISet.union acc (live b2) - ) ISet.empty b.bnext in - let need_sub = ISet.filter (fun r -> + ) ISet.empty in + let need_sub bl = ISet.filter (fun r -> try let w = PMap.find r b.bwrite in set_live r (w + 1) b.bend; @@ -959,8 +959,8 @@ let _optimize (f:fundecl) = with Not_found -> set_live r b.bstart b.bend; true - ) need_sub in - let need = ISet.union b.bneed need_sub in + ) (need_sub bl) in + let need = ISet.union b.bneed (need_sub b.bnext) in b.bneed_all <- Some need; if b.bloop then begin (* @@ -977,8 +977,11 @@ let _optimize (f:fundecl) = in List.iter (fun b2 -> if b2.bstart > b.bstart then clear b2) b.bprev; List.iter (fun b -> ignore(live b)) b.bnext; + (* do-while loop : recompute self after recompute all next *) + let need = ISet.union b.bneed (need_sub b.bnext) in + b.bneed_all <- Some need; end; - need + Option.get b.bneed_all in ignore(live root); diff --git a/src/optimization/analyzerTexpr.ml b/src/optimization/analyzerTexpr.ml index 39dcac8b4ae..21cd2004529 100644 --- a/src/optimization/analyzerTexpr.ml +++ b/src/optimization/analyzerTexpr.ml @@ -1058,12 +1058,11 @@ module Cleanup = struct | TLocal v when IntMap.mem v.v_id !locals -> true | _ -> check_expr references_local e in - let can_do = match com.platform with Hl -> false | _ -> true in let rec loop2 el = match el with - | [{eexpr = TBreak}] when is_true_expr e1 && can_do && not has_continue -> + | [{eexpr = TBreak}] when is_true_expr e1 && not has_continue -> do_while := Some (Texpr.Builder.make_bool com.basic true e1.epos); [] - | [{eexpr = TIf(econd,{eexpr = TBlock[{eexpr = TBreak}]},None)}] when is_true_expr e1 && not (references_local econd) && can_do && not has_continue -> + | [{eexpr = TIf(econd,{eexpr = TBlock[{eexpr = TBreak}]},None)}] when is_true_expr e1 && not (references_local econd) && not has_continue -> do_while := Some econd; [] | {eexpr = TBreak | TContinue | TReturn _ | TThrow _} as e :: el -> From 0d313b0b2737e02e451550dcaa64c39a77b2ae81 Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Tue, 30 Jan 2024 08:25:04 +0100 Subject: [PATCH 22/35] [tests] add test for 10783 --- tests/unit/src/unit/issues/Issue10783.hx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/unit/src/unit/issues/Issue10783.hx diff --git a/tests/unit/src/unit/issues/Issue10783.hx b/tests/unit/src/unit/issues/Issue10783.hx new file mode 100644 index 00000000000..c7ce2c8d41e --- /dev/null +++ b/tests/unit/src/unit/issues/Issue10783.hx @@ -0,0 +1,17 @@ +package unit.issues; + +class Issue10783 extends Test { + function test() { + eq(4, log2Unsigned(16)); + } + + @:pure inline function log2Unsigned(n:Int):Int { + var res = 0; + + while ((n >>>= 1) != 0) { + res++; + } + + return res; + } +} From 15fb5830b50c79b8eac4398fd0bedf210200c822 Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Thu, 18 Jul 2024 11:19:33 +0200 Subject: [PATCH 23/35] error if we inline a static local closes #11725 --- src/optimization/inline.ml | 1 + tests/misc/projects/Issue11725/Main.hx | 6 ++++++ tests/misc/projects/Issue11725/compile-fail.hxml | 2 ++ tests/misc/projects/Issue11725/compile-fail.hxml.stderr | 1 + 4 files changed, 10 insertions(+) create mode 100644 tests/misc/projects/Issue11725/Main.hx create mode 100644 tests/misc/projects/Issue11725/compile-fail.hxml create mode 100644 tests/misc/projects/Issue11725/compile-fail.hxml.stderr diff --git a/src/optimization/inline.ml b/src/optimization/inline.ml index 727c0648a66..f9101167dd8 100644 --- a/src/optimization/inline.ml +++ b/src/optimization/inline.ml @@ -700,6 +700,7 @@ let rec type_inline ctx cf f ethis params tret config p ?(self_calling_closure=f typing_error "Could not inline `this` outside of an instance context" po ) | TVar (v,eo) -> + if has_var_flag v VStatic then typing_error "Inline functions cannot have static locals" v.v_pos; { e with eexpr = TVar ((state#declare v).i_subst,opt (map false false) eo)} | TReturn eo when not state#in_local_fun -> if not term then begin diff --git a/tests/misc/projects/Issue11725/Main.hx b/tests/misc/projects/Issue11725/Main.hx new file mode 100644 index 00000000000..308c279b2f2 --- /dev/null +++ b/tests/misc/projects/Issue11725/Main.hx @@ -0,0 +1,6 @@ +function main() foo(); + +inline function foo() { + static var count = 5; + trace(--count); +} \ No newline at end of file diff --git a/tests/misc/projects/Issue11725/compile-fail.hxml b/tests/misc/projects/Issue11725/compile-fail.hxml new file mode 100644 index 00000000000..b30a755894b --- /dev/null +++ b/tests/misc/projects/Issue11725/compile-fail.hxml @@ -0,0 +1,2 @@ +--main Main +--interp \ No newline at end of file diff --git a/tests/misc/projects/Issue11725/compile-fail.hxml.stderr b/tests/misc/projects/Issue11725/compile-fail.hxml.stderr new file mode 100644 index 00000000000..327d99785f1 --- /dev/null +++ b/tests/misc/projects/Issue11725/compile-fail.hxml.stderr @@ -0,0 +1 @@ +Main.hx:4: characters 13-18 : Inline functions cannot have static locals \ No newline at end of file From e095156f918082238c034d8a77b78ded97fb53a2 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Thu, 18 Jul 2024 14:11:12 +0200 Subject: [PATCH 24/35] Update to neko 2.4.0 final release --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0588e7c5eb1..6496e01b6f2 100644 --- a/Makefile +++ b/Makefile @@ -59,7 +59,7 @@ PACKAGE_FILE_NAME=haxe_$(COMMIT_DATE)_$(COMMIT_SHA) HAXE_VERSION=$(shell $(CURDIR)/$(HAXE_OUTPUT) -version 2>&1 | awk '{print $$1;}') HAXE_VERSION_SHORT=$(shell echo "$(HAXE_VERSION)" | grep -oE "^[0-9]+\.[0-9]+\.[0-9]+") -NEKO_VERSION=2.4.0-rc.1 +NEKO_VERSION=2.4.0 NEKO_MAJOR_VERSION=$(shell echo "$(NEKO_VERSION)" | grep -oE "^[0-9]+") NEKO_VERSION_TAG=v$(shell echo "$(NEKO_VERSION)" | sed "s/\./-/g") From ba5967ae3d51fa2c3a587df673040af6742231d6 Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Tue, 2 Jan 2024 10:08:16 +0100 Subject: [PATCH 25/35] [display] file diagnostics should be DFPOnly --- src/compiler/displayProcessing.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/displayProcessing.ml b/src/compiler/displayProcessing.ml index f08b091239c..05e45f4c3fd 100644 --- a/src/compiler/displayProcessing.ml +++ b/src/compiler/displayProcessing.ml @@ -48,7 +48,7 @@ let handle_display_argument_old com file_pos actx = | "diagnostics" -> com.report_mode <- RMLegacyDiagnostics [file_unique]; let dm = create DMNone in - {dm with dms_display_file_policy = DFPAlso; dms_per_file = true} + {dm with dms_display_file_policy = DFPOnly; dms_per_file = true} | "statistics" -> com.report_mode <- RMStatistics; let dm = create DMNone in From d710be3dad4baa998defbb5d7a012ffe2293f2f9 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Wed, 19 Jun 2024 15:22:55 +0200 Subject: [PATCH 26/35] Don't populate cache from legacy diagnostics (#11696) --- src/compiler/displayProcessing.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/displayProcessing.ml b/src/compiler/displayProcessing.ml index 05e45f4c3fd..b835226570c 100644 --- a/src/compiler/displayProcessing.ml +++ b/src/compiler/displayProcessing.ml @@ -48,7 +48,7 @@ let handle_display_argument_old com file_pos actx = | "diagnostics" -> com.report_mode <- RMLegacyDiagnostics [file_unique]; let dm = create DMNone in - {dm with dms_display_file_policy = DFPOnly; dms_per_file = true} + {dm with dms_display_file_policy = DFPOnly; dms_per_file = true; dms_populate_cache = false} | "statistics" -> com.report_mode <- RMStatistics; let dm = create DMNone in From 636bc29dcf9f1f70e2da7c0cd6f6cf68b00fc854 Mon Sep 17 00:00:00 2001 From: Yuxiao Mao Date: Thu, 18 Jul 2024 12:35:36 +0200 Subject: [PATCH 27/35] [hlc] Use uint64 instead of uint64_t for shift cast (#11721) --- src/generators/hl2c.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generators/hl2c.ml b/src/generators/hl2c.ml index daf452e4027..8c863f5535d 100644 --- a/src/generators/hl2c.ml +++ b/src/generators/hl2c.ml @@ -844,7 +844,7 @@ let generate_function ctx f = sexpr "%s = %s >> %s" (reg r) (reg a) (reg b) | OUShr (r,a,b) -> (match rtype r with - | HI64 -> sexpr "%s = ((uint64_t)%s) >> %s" (reg r) (reg a) (reg b) + | HI64 -> sexpr "%s = ((uint64)%s) >> %s" (reg r) (reg a) (reg b) | _ -> sexpr "%s = ((unsigned)%s) >> %s" (reg r) (reg a) (reg b) ); | OAnd (r,a,b) -> From bd79571b89d719a45db7860d239da2164147dd15 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Thu, 18 Jul 2024 14:08:27 +0200 Subject: [PATCH 28/35] 4.3.5 --- extra/CHANGES.txt | 30 ++++++++++++++++++++++++++++++ extra/release-checklist.txt | 2 +- haxe.opam | 2 +- src/core/globals.ml | 2 +- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/extra/CHANGES.txt b/extra/CHANGES.txt index 42bd5b671c7..a6155f8aa86 100644 --- a/extra/CHANGES.txt +++ b/extra/CHANGES.txt @@ -1,3 +1,33 @@ +2024-07-18 4.3.5 + + General improvements: + + all : macOS universal binaries + display : migrated diagnostics to Json RPC (#11707) + macro : expose TVar VStatic flag in macros. (#11683) + + Bugfixes: + + all : fix `@:structInit` with getter + setter (#11662) + all : add missing recursion when checking abstract casts (#11676) + all : fail nicer if unify_min can't find a common type (#11684) + all : fix pretty errors failure (#11700) + all : disallow local statics when inlining (#11725) + display : unused pattern variables should be marked as unused (#7282) + display : diagnostics miss "used without being initialized" errors (#7931) + display : recursive inline is not supported on enum abstract constructor (#11177) + display : Void as value error disappears on second compilation (#11184) + display : false positives of "This cast has no effect, but some of its sub-expressions" (#11203) + cpp : inherit `@:unreflective` on generic classes + hl : fix bit shift + assignment in while loop header (#10783) + hl : fix do-while loop in genhl+hlopt (#11461) + hl/c : use uint64 instead of uint64_t for shift cast (#11721) + macro : don't choke on namePos for reification pattern matching (#11671) + + Deprecation / future version handling: + + macro : `Compiler.include()` warning when used outside init macros + 2024-03-04 4.3.4 General improvements: diff --git a/extra/release-checklist.txt b/extra/release-checklist.txt index 81c3ef0f30d..dfd9a8eff8c 100644 --- a/extra/release-checklist.txt +++ b/extra/release-checklist.txt @@ -9,7 +9,7 @@ - Make sure CHANGES.txt has a proper date set! - Make sure `version` in globals.ml has the correct value -- Update `version` in `./opam` +- Update `version` in `haxe.opam` - Check if the protocolVersion in displayJson.ml has to be updated - Make an empty GitHub release in https://github.com/HaxeFoundation/haxe/releases (do this first because we need the tag for the builds) - Wait for the CI to build (check https://build.haxe.org/builds/haxe/) diff --git a/haxe.opam b/haxe.opam index a5fd6d1ca6f..bb754406f45 100644 --- a/haxe.opam +++ b/haxe.opam @@ -1,6 +1,6 @@ opam-version: "2.0" name: "haxe" -version: "4.3.4" +version: "4.3.5" synopsis: "Multi-target universal programming language" description: """ Haxe is an open source toolkit based on a modern, diff --git a/src/core/globals.ml b/src/core/globals.ml index 38ec7c33fd1..511a3409167 100644 --- a/src/core/globals.ml +++ b/src/core/globals.ml @@ -27,7 +27,7 @@ type platform = | Hl | Eval -let version = 4304 +let version = 4305 let version_major = version / 1000 let version_minor = (version mod 1000) / 100 let version_revision = (version mod 100) From 729001353dae8f09a6419e655bb73f81a20613fb Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Mon, 29 Jul 2024 13:55:20 +0200 Subject: [PATCH 29/35] [4.3.6] Fix --java out -D jvm deprecation warning (#11739) * Fix detection of --java out -D jvm * [tests] add test for 11737 --- src/compiler/compiler.ml | 1 + src/compiler/generate.ml | 5 ++--- tests/misc/projects/Issue11737/Main.hx | 1 + tests/misc/projects/Issue11737/_setup.hxml | 1 + tests/misc/projects/Issue11737/compile.hxml | 3 +++ tests/misc/projects/Issue11737/compile.hxml.stderr | 1 + tests/misc/projects/Issue11737/compile1.hxml | 2 ++ tests/misc/projects/Issue11737/compile1.hxml.stderr | 0 tests/misc/projects/Issue11737/compile2.hxml | 2 ++ tests/misc/projects/Issue11737/compile2.hxml.stderr | 0 10 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 tests/misc/projects/Issue11737/Main.hx create mode 100644 tests/misc/projects/Issue11737/_setup.hxml create mode 100644 tests/misc/projects/Issue11737/compile.hxml create mode 100644 tests/misc/projects/Issue11737/compile.hxml.stderr create mode 100644 tests/misc/projects/Issue11737/compile1.hxml create mode 100644 tests/misc/projects/Issue11737/compile1.hxml.stderr create mode 100644 tests/misc/projects/Issue11737/compile2.hxml create mode 100644 tests/misc/projects/Issue11737/compile2.hxml.stderr diff --git a/src/compiler/compiler.ml b/src/compiler/compiler.ml index 2dcd61acfca..e9a682c8387 100644 --- a/src/compiler/compiler.ml +++ b/src/compiler/compiler.ml @@ -129,6 +129,7 @@ module Setup = struct | Java -> Java.before_generate com; if defined com Define.Jvm then begin + if not actx.jvm_flag then com.warning WDeprecated com.warning_options ("--java out.jar -D jvm is deprecated; use --jvm out.jar directly") null_pos; add_std "jvm"; com.package_rules <- PMap.remove "jvm" com.package_rules; end; diff --git a/src/compiler/generate.ml b/src/compiler/generate.ml index 0474ff95639..76e9f256dd5 100644 --- a/src/compiler/generate.ml +++ b/src/compiler/generate.ml @@ -81,10 +81,9 @@ let generate ctx tctx ext actx = | Cs -> Gencs.generate,"cs" | Java -> - if Common.defined com Jvm then begin - com.warning WDeprecated com.warning_options ("--java out.jar -D jvm is deprecated; use --jvm out.jar directly") null_pos; + if Common.defined com Jvm then Genjvm.generate actx.jvm_flag,"java" - end else + else Genjava.generate,"java" | Python -> Genpy.generate,"python" diff --git a/tests/misc/projects/Issue11737/Main.hx b/tests/misc/projects/Issue11737/Main.hx new file mode 100644 index 00000000000..a71cf3b3e00 --- /dev/null +++ b/tests/misc/projects/Issue11737/Main.hx @@ -0,0 +1 @@ +function main() {} diff --git a/tests/misc/projects/Issue11737/_setup.hxml b/tests/misc/projects/Issue11737/_setup.hxml new file mode 100644 index 00000000000..07f836f0c9a --- /dev/null +++ b/tests/misc/projects/Issue11737/_setup.hxml @@ -0,0 +1 @@ +--cmd haxelib install --quiet hxjava diff --git a/tests/misc/projects/Issue11737/compile.hxml b/tests/misc/projects/Issue11737/compile.hxml new file mode 100644 index 00000000000..e19b1a71b09 --- /dev/null +++ b/tests/misc/projects/Issue11737/compile.hxml @@ -0,0 +1,3 @@ +--main Main +--java bin +-D jvm diff --git a/tests/misc/projects/Issue11737/compile.hxml.stderr b/tests/misc/projects/Issue11737/compile.hxml.stderr new file mode 100644 index 00000000000..1443766f776 --- /dev/null +++ b/tests/misc/projects/Issue11737/compile.hxml.stderr @@ -0,0 +1 @@ +Warning : (WDeprecated) --java out.jar -D jvm is deprecated; use --jvm out.jar directly diff --git a/tests/misc/projects/Issue11737/compile1.hxml b/tests/misc/projects/Issue11737/compile1.hxml new file mode 100644 index 00000000000..2f5182c6cf9 --- /dev/null +++ b/tests/misc/projects/Issue11737/compile1.hxml @@ -0,0 +1,2 @@ +--main Main +--jvm bin/jvm.jar diff --git a/tests/misc/projects/Issue11737/compile1.hxml.stderr b/tests/misc/projects/Issue11737/compile1.hxml.stderr new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/misc/projects/Issue11737/compile2.hxml b/tests/misc/projects/Issue11737/compile2.hxml new file mode 100644 index 00000000000..9e99a0fd81f --- /dev/null +++ b/tests/misc/projects/Issue11737/compile2.hxml @@ -0,0 +1,2 @@ +--main Main +--java bin diff --git a/tests/misc/projects/Issue11737/compile2.hxml.stderr b/tests/misc/projects/Issue11737/compile2.hxml.stderr new file mode 100644 index 00000000000..e69de29bb2d From 710a98778443a12e88a4c15c6fbe1403609015db Mon Sep 17 00:00:00 2001 From: Zeta <53486764+Apprentice-Alchemist@users.noreply.github.com> Date: Thu, 25 Jul 2024 15:40:56 +0200 Subject: [PATCH 30/35] [hl] Ignore WANT_READ/WANT_WRITE errors when the socket is known to be blocking. (#11655) --- std/hl/_std/sys/ssl/Socket.hx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/std/hl/_std/sys/ssl/Socket.hx b/std/hl/_std/sys/ssl/Socket.hx index f16818b9f14..d8fa1b39424 100644 --- a/std/hl/_std/sys/ssl/Socket.hx +++ b/std/hl/_std/sys/ssl/Socket.hx @@ -50,7 +50,10 @@ private class SocketInput extends haxe.io.Input { __s.handshake(); var r = @:privateAccess __s.ssl.recv(buf, pos, len); if (r == -1) - throw haxe.io.Error.Blocked; + if (@:privateAccess __s.isBlocking) + return 0 + else + throw haxe.io.Error.Blocked; else if (r <= 0) throw new haxe.io.Eof(); return r; @@ -85,7 +88,10 @@ private class SocketOutput extends haxe.io.Output { __s.handshake(); var r = @:privateAccess __s.ssl.send(buf, pos, len); if (r == -1) - throw haxe.io.Error.Blocked; + if (@:privateAccess __s.isBlocking) + return 0 + else + throw haxe.io.Error.Blocked; else if (r < 0) throw new haxe.io.Eof(); return r; From 2a082c7e15f10b48613cec28898c78f20b10ddc5 Mon Sep 17 00:00:00 2001 From: Zeta <53486764+Apprentice-Alchemist@users.noreply.github.com> Date: Thu, 25 Jul 2024 14:29:40 +0200 Subject: [PATCH 31/35] [hl] Fix weird compiler error (#11690) --- src/generators/hl2c.ml | 2 +- tests/misc/hl/projects/Issue11689/Main.hx | 2 ++ tests/misc/hl/projects/Issue11689/compile.hxml | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 tests/misc/hl/projects/Issue11689/Main.hx create mode 100644 tests/misc/hl/projects/Issue11689/compile.hxml diff --git a/src/generators/hl2c.ml b/src/generators/hl2c.ml index 8c863f5535d..4f7c458a7b5 100644 --- a/src/generators/hl2c.ml +++ b/src/generators/hl2c.ml @@ -1144,7 +1144,7 @@ let make_types_idents htypes = in let hashes = Hashtbl.create 0 in let make_sign d = - let dig = Digest.to_hex (Digest.bytes (Marshal.to_bytes d [Marshal.Compat_32])) in + let dig = Digest.to_hex (Digest.bytes (Marshal.to_bytes d [Marshal.Closures])) in let h = String.sub dig 0 7 in let h = if Hashtbl.mem hashes h then dig else h in Hashtbl.add hashes h (); diff --git a/tests/misc/hl/projects/Issue11689/Main.hx b/tests/misc/hl/projects/Issue11689/Main.hx new file mode 100644 index 00000000000..f641935105d --- /dev/null +++ b/tests/misc/hl/projects/Issue11689/Main.hx @@ -0,0 +1,2 @@ +function foo(val:hl.Ref) {} +function main() {} \ No newline at end of file diff --git a/tests/misc/hl/projects/Issue11689/compile.hxml b/tests/misc/hl/projects/Issue11689/compile.hxml new file mode 100644 index 00000000000..0af07fc89cf --- /dev/null +++ b/tests/misc/hl/projects/Issue11689/compile.hxml @@ -0,0 +1,2 @@ +-m Main +-hl out/main.c \ No newline at end of file From 00947ede25e7307e775c58d558b9459277213384 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Wed, 31 Jul 2024 19:05:08 +0200 Subject: [PATCH 32/35] [4.3.6] Context.reportError should not abort build macros (#11741) * [macro] flush pass before altering error reporting * [tests] add test showing Context.reportError vs build macro issue --- src/typing/macroContext.ml | 9 +++-- tests/misc/projects/Issue11741/Macro.hx | 39 +++++++++++++++++++ tests/misc/projects/Issue11741/Main.hx | 7 ++++ tests/misc/projects/Issue11741/Test2.hx | 7 ++++ .../projects/Issue11741/compile-fail.hxml | 3 ++ .../Issue11741/compile-fail.hxml.stderr | 18 +++++++++ 6 files changed, 79 insertions(+), 4 deletions(-) create mode 100755 tests/misc/projects/Issue11741/Macro.hx create mode 100755 tests/misc/projects/Issue11741/Main.hx create mode 100755 tests/misc/projects/Issue11741/Test2.hx create mode 100755 tests/misc/projects/Issue11741/compile-fail.hxml create mode 100644 tests/misc/projects/Issue11741/compile-fail.hxml.stderr diff --git a/src/typing/macroContext.ml b/src/typing/macroContext.ml index 10b8cf8fe03..2babcc8dca2 100644 --- a/src/typing/macroContext.ml +++ b/src/typing/macroContext.ml @@ -94,14 +94,15 @@ let typing_timer ctx need_type f = | Stack stack -> (Stack (List.map located_to_error stack),null_pos) in - ctx.com.located_error <- (fun ?(depth=0) msg -> - let (e,p) = located_to_error msg in - raise (Error (e,p,depth))); - if need_type && ctx.pass < PTypeField then begin ctx.pass <- PTypeField; flush_pass ctx PBuildClass "typing_timer"; end; + + ctx.com.located_error <- (fun ?(depth=0) msg -> + let (e,p) = located_to_error msg in + raise (Error (e,p,depth))); + let exit() = t(); ctx.com.located_error <- old; diff --git a/tests/misc/projects/Issue11741/Macro.hx b/tests/misc/projects/Issue11741/Macro.hx new file mode 100755 index 00000000000..5b6240ec756 --- /dev/null +++ b/tests/misc/projects/Issue11741/Macro.hx @@ -0,0 +1,39 @@ + +import haxe.macro.Expr.Field; +import haxe.macro.Context; + +class Macro { + public static macro function buildMain(): Array { + final pos = Context.currentPos(); + final bf = Context.getBuildFields(); + + final type = Context.getType('Test2'); + + switch (type) { + case TInst(ctRef, _): + final ct = ctRef.get(); + + try { + final ctor = ct.constructor.get().expr(); + } catch (e: Dynamic) { + + } + + Context.warning('This does not show if printStuff() calls error() or reportError()', pos); + case _: + } + + return bf; + } + + public static macro function buildTest2(): Array { + final pos = Context.currentPos(); + final bf = Context.getBuildFields(); + + // Use error() or reportError() here -> Main Completion does not work, Eval crashes + // Use warning() or info() -> Everything works as expected + Context.reportError('Crashes HERE in eval.vm.callMacroApi', pos); + + return bf; + } +} diff --git a/tests/misc/projects/Issue11741/Main.hx b/tests/misc/projects/Issue11741/Main.hx new file mode 100755 index 00000000000..c451edace23 --- /dev/null +++ b/tests/misc/projects/Issue11741/Main.hx @@ -0,0 +1,7 @@ +// Should be a warning here, UNLESS Macro.printStuff() calls reportError()/error() +@:build(Macro.buildMain()) +class Main { + static function main() { + final x = 5 - ""; // No errors shown for this, completion/hover does not work + } +} \ No newline at end of file diff --git a/tests/misc/projects/Issue11741/Test2.hx b/tests/misc/projects/Issue11741/Test2.hx new file mode 100755 index 00000000000..c401f7f07b5 --- /dev/null +++ b/tests/misc/projects/Issue11741/Test2.hx @@ -0,0 +1,7 @@ + +@:autoBuild(Macro.buildTest2()) +class Test2 { + public function new(a: Int, b: Int) {} +} + +class Test2Ext extends Test2 {} \ No newline at end of file diff --git a/tests/misc/projects/Issue11741/compile-fail.hxml b/tests/misc/projects/Issue11741/compile-fail.hxml new file mode 100755 index 00000000000..87112a7dc43 --- /dev/null +++ b/tests/misc/projects/Issue11741/compile-fail.hxml @@ -0,0 +1,3 @@ +--main Main +-D message.reporting=pretty +-D message.no-color diff --git a/tests/misc/projects/Issue11741/compile-fail.hxml.stderr b/tests/misc/projects/Issue11741/compile-fail.hxml.stderr new file mode 100644 index 00000000000..bfdbdaac314 --- /dev/null +++ b/tests/misc/projects/Issue11741/compile-fail.hxml.stderr @@ -0,0 +1,18 @@ +[ERROR] Test2.hx:7: character 1 + + 7 | class Test2Ext extends Test2 {} + | ^ + | Crashes HERE in eval.vm.callMacroApi + +[WARNING] Main.hx:2: characters 1-8 + + 2 | @:build(Macro.buildMain()) + | ^^^^^^^ + | This does not show if printStuff() calls error() or reportError() + +[ERROR] Main.hx:5: characters 19-21 + + 5 | final x = 5 - ""; // No errors shown for this, completion/hover does not work + | ^^ + | String should be Int + From 313ffef477a0cbe910fc66748dad6a3385f6099e Mon Sep 17 00:00:00 2001 From: Aidan Lee Date: Fri, 2 Aug 2024 07:27:33 +0100 Subject: [PATCH 33/35] [cpp] Null Check Interfaces (#11743) * Add a IsNull check * escape quote * Add new line and remove unneeded dynamic * Guard interface null checks behind the same defines as class access * Add null interface exception test * move target guard to the right place... --- src/generators/gencpp.ml | 6 ++++++ tests/unit/src/unit/issues/Issue11743.hx | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/unit/src/unit/issues/Issue11743.hx diff --git a/src/generators/gencpp.ml b/src/generators/gencpp.ml index 8156bfe837c..8908ef476dc 100644 --- a/src/generators/gencpp.ml +++ b/src/generators/gencpp.ml @@ -4719,6 +4719,12 @@ let gen_member_def ctx class_def is_static is_interface field = let cast = "::hx::interface_cast< ::" ^ join_class_path_remap class_def.cl_path "::" ^ "_obj *>" in output (" " ^ returnType ^ " (::hx::Object :: *_hx_" ^ remap_name ^ ")(" ^ argList ^ "); \n"); output (" static inline " ^ returnType ^ " " ^ remap_name ^ "( ::Dynamic _hx_" ^ commaArgList ^ ") {\n"); + output (" #ifdef HXCPP_CHECK_POINTER\n"); + output (" if (::hx::IsNull(_hx_)) ::hx::NullReference(\"Object\", false);\n"); + output (" #ifdef HXCPP_GC_CHECK_POINTER\n"); + output (" GCCheckPointer(_hx_.mPtr);\n"); + output (" #endif\n"); + output (" #endif\n"); output (" " ^ returnStr ^ "(_hx_.mPtr->*( " ^ cast ^ "(_hx_.mPtr->_hx_getInterface(" ^ (cpp_class_hash class_def) ^ ")))->_hx_" ^ remap_name ^ ")(" ^ cpp_arg_names args ^ ");\n }\n" ); end | _ -> ( ) diff --git a/tests/unit/src/unit/issues/Issue11743.hx b/tests/unit/src/unit/issues/Issue11743.hx new file mode 100644 index 00000000000..7750ef0e882 --- /dev/null +++ b/tests/unit/src/unit/issues/Issue11743.hx @@ -0,0 +1,18 @@ +package unit.issues; + +import utest.Assert; + +private interface IFoo { + function foo():Void; +} + +class Issue11743 extends Test { + + #if cpp + function test() { + final o : IFoo = null; + + Assert.raises(() -> o.foo()); + } + #end +} \ No newline at end of file From 458833c5f6795954eb5caeb6b651c0087434c81e Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Wed, 7 Aug 2024 11:22:43 +0200 Subject: [PATCH 34/35] [diagnostics] do not define display for json rpc diagnostics (#11746) --- src/context/display/displayJson.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/context/display/displayJson.ml b/src/context/display/displayJson.ml index 917d5cd4e15..72d7876da4b 100644 --- a/src/context/display/displayJson.ml +++ b/src/context/display/displayJson.ml @@ -50,10 +50,10 @@ class display_handler (jsonrpc : jsonrpc_handler) com (cs : CompilationCache.t) method get_cs = cs - method enable_display mode = + method enable_display ?(skip_define=false) mode = com.display <- create mode; Parser.display_mode := mode; - Common.define_value com Define.Display "1" + if not skip_define then Common.define_value com Define.Display "1" method set_display_file was_auto_triggered requires_offset = let file = jsonrpc#get_opt_param (fun () -> @@ -159,7 +159,7 @@ let handler = ); "display/diagnostics", (fun hctx -> hctx.display#set_display_file false false; - hctx.display#enable_display DMNone; + hctx.display#enable_display ~skip_define:true DMNone; hctx.com.display <- { hctx.com.display with dms_display_file_policy = DFPAlso; dms_per_file = true; dms_populate_cache = true }; hctx.com.report_mode <- RMDiagnostics (List.map (fun (f,_) -> f) hctx.com.file_contents); ); From 760c0dd9972abadceba4e72edb1db13b2a4fb315 Mon Sep 17 00:00:00 2001 From: Rudy Ges Date: Wed, 7 Aug 2024 11:29:26 +0200 Subject: [PATCH 35/35] 4.3.6 --- extra/CHANGES.txt | 11 +++++++++++ haxe.opam | 2 +- src/core/globals.ml | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/extra/CHANGES.txt b/extra/CHANGES.txt index a6155f8aa86..532657fa114 100644 --- a/extra/CHANGES.txt +++ b/extra/CHANGES.txt @@ -1,3 +1,14 @@ +2024-08-07 4.3.6 + + Bugfixes: + + display : do not define "display" for json rpc diagnostics (#11746) + cpp : null check interfaces (#11743) + hl : ignore WANT_READ/WANT_WRITE errors when the socket is known to be blocking (#11655) + hl : fix weird compiler error (#11690) + jvm : fix --java out -D jvm deprecation warning (#11739) + macro : Context.reportError should not abort build macros (#11741) + 2024-07-18 4.3.5 General improvements: diff --git a/haxe.opam b/haxe.opam index bb754406f45..54bb8e31f03 100644 --- a/haxe.opam +++ b/haxe.opam @@ -1,6 +1,6 @@ opam-version: "2.0" name: "haxe" -version: "4.3.5" +version: "4.3.6" synopsis: "Multi-target universal programming language" description: """ Haxe is an open source toolkit based on a modern, diff --git a/src/core/globals.ml b/src/core/globals.ml index 511a3409167..344b4683753 100644 --- a/src/core/globals.ml +++ b/src/core/globals.ml @@ -27,7 +27,7 @@ type platform = | Hl | Eval -let version = 4305 +let version = 4306 let version_major = version / 1000 let version_minor = (version mod 1000) / 100 let version_revision = (version mod 100)