Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development' into module_resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Jul 7, 2023
2 parents f0b0447 + d1ef1a3 commit d9d0eba
Show file tree
Hide file tree
Showing 22 changed files with 220 additions and 38 deletions.
6 changes: 4 additions & 2 deletions src/filters/exceptions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,11 @@ let catch_native ctx catches t p =
)
(* Haxe-specific wildcard catches should go to if-fest because they need additional handling *)
| (v,_) :: _ when is_haxe_wildcard_catch ctx v.v_type ->
(match handle_as_value_exception with
| [] ->
(match handle_as_value_exception, value_exception_catch with
| [], None ->
catches_to_ifs ctx catches t p
| [], Some catch ->
catches_to_ifs ctx [catch] t p
| _ ->
catches_as_value_exception ctx handle_as_value_exception None t p
:: catches_to_ifs ctx catches t p
Expand Down
7 changes: 5 additions & 2 deletions src/filters/renameVars.ml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ let declare_var rc scope v =
let will_be_reserved rc v =
rc.rc_no_shadowing || (has_var_flag v VCaptured && rc.rc_hoisting)

let unbound_variable v =
raise (Failure (Printf.sprintf "Unbound variable: %s<%i>" v.v_name v.v_id))

(**
Invoked for each `TLocal v` texr_expr
*)
Expand All @@ -234,7 +237,7 @@ let rec determine_overlaps rc scope v =
Overlaps.add v scope.foreign_vars;
(match scope.parent with
| Some parent -> determine_overlaps rc parent v
| None -> raise (Failure "Failed to locate variable declaration")
| None -> unbound_variable v
)
| (d, _) :: _ when d == v ->
()
Expand All @@ -261,7 +264,7 @@ let use_var rc scope v =
| Some parent ->
loop parent
| None ->
raise (Failure "Failed to locate variable declaration")
unbound_variable v
end
in
loop scope
Expand Down
7 changes: 6 additions & 1 deletion src/generators/gencpp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,12 @@ let keyword_remap name =
| "HX_" | "HXLINE" | "HXDLIN"
| "NO" | "YES"
| "abstract" | "decltype" | "finally" | "nullptr" | "static_assert"
| "struct" -> "_hx_" ^ name
| "struct" | "_Atomic"
| "constexpr" | "consteval" | "constinit"
| "co_await" | "co_return" | "co_yield"
| "alignas" | "alignof"
| "_Alignas" | "_Alignof"
| "requires" -> "_hx_" ^ name
| x -> x
;;

Expand Down
9 changes: 7 additions & 2 deletions src/generators/genhl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3329,15 +3329,20 @@ let generate_static ctx c f =
let gen_content() =
op ctx (OThrow (make_string ctx ("Requires compiling with -D hl-ver=" ^ ver ^ ".0 or higher") null_pos));
in
ignore(make_fun ctx ~gen_content (s_type_path c.cl_path,f.cf_name) (alloc_fid ctx c f) (match f.cf_expr with Some { eexpr = TFunction f } -> f | _ -> abort "Missing function body" f.cf_pos) None None)
(match f.cf_expr with
| Some { eexpr = TFunction fn } -> ignore(make_fun ctx ~gen_content (s_type_path c.cl_path,f.cf_name) (alloc_fid ctx c f) fn None None)
| _ -> if not (Meta.has Meta.NoExpr f.cf_meta) then abort "Missing function body" f.cf_pos)

else
add_native "std" f.cf_name
| (Meta.HlNative,[] ,_ ) :: _ ->
add_native "std" f.cf_name
| (Meta.HlNative,_ ,p) :: _ ->
abort "Invalid @:hlNative decl" p
| [] ->
ignore(make_fun ctx (s_type_path c.cl_path,f.cf_name) (alloc_fid ctx c f) (match f.cf_expr with Some { eexpr = TFunction f } -> f | _ -> abort "Missing function body" f.cf_pos) None None)
(match f.cf_expr with
| Some { eexpr = TFunction fn } -> ignore(make_fun ctx (s_type_path c.cl_path,f.cf_name) (alloc_fid ctx c f) fn None None)
| _ -> if not (Meta.has Meta.NoExpr f.cf_meta) then abort "Missing function body" f.cf_pos)
| _ :: l ->
loop l
in
Expand Down
13 changes: 11 additions & 2 deletions src/macro/macroApi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1664,10 +1664,19 @@ let decode_type_def v =
EClass (mk flags fields)
| 3, [t] ->
ETypedef (mk (if isExtern then [EExtern] else []) (decode_ctype t))
| 4, [tthis;tfrom;tto] ->
let flags = match opt decode_array tfrom with None -> [] | Some ta -> List.map (fun t -> AbFrom (decode_ctype t)) ta in
| 4, [tthis;tflags;tfrom;tto] ->
let flags = match opt decode_array tflags with
| None -> []
| Some ta -> List.map (fun f -> match decode_enum f with
| 0, [] -> AbEnum
| 1, [ct] -> AbFrom (decode_ctype ct)
| 2, [ct] -> AbTo (decode_ctype ct)
| _ -> raise Invalid_expr
) ta in
let flags = match opt decode_array tfrom with None -> flags | Some ta -> List.map (fun t -> AbFrom (decode_ctype t)) ta @ flags in
let flags = match opt decode_array tto with None -> flags | Some ta -> (List.map (fun t -> AbTo (decode_ctype t)) ta) @ flags in
let flags = match opt decode_ctype tthis with None -> flags | Some t -> (AbOver t) :: flags in
let flags = if isExtern then AbExtern :: flags else flags in
EAbstract(mk flags fields)
| 5, [fk;al] ->
let fk = decode_class_field_kind fk in
Expand Down
3 changes: 3 additions & 0 deletions src/typing/matcher/exprToPattern.ml
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ let rec make pctx toplevel t e =
restore();
let pat = make pctx toplevel e1.etype e2 in
PatExtractor {ex_var = v; ex_expr = e1; ex_pattern = pat}
| EBinop((OpEq | OpNotEq | OpLt | OpLte | OpGt | OpGte | OpBoolAnd | OpBoolOr),_,_) ->
let e_rhs = (EConst (Ident "true"),null_pos) in
loop (EBinop(OpArrow,e,e_rhs),(pos e))
(* Special case for completion on a pattern local: We don't want to add the local to the context
while displaying (#7319) *)
| EDisplay((EConst (Ident _),_ as e),dk) when pctx.ctx.com.display.dms_kind = DMDefault ->
Expand Down
2 changes: 2 additions & 0 deletions src/typing/nullSafety.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,8 @@ class expr_checker mode immediate_execution report =
| TMeta (_, e) -> self#is_nullable_expr e
| TThrow _ -> false
| TReturn _ -> false
| TContinue -> false
| TBreak -> false
| TBinop ((OpAssign | OpAssignOp _), _, right) -> self#is_nullable_expr right
| TBlock exprs ->
local_safety#block_declared;
Expand Down
17 changes: 6 additions & 11 deletions src/typing/operators.ml
Original file line number Diff line number Diff line change
Expand Up @@ -704,18 +704,15 @@ let type_assign_op ctx op e1 e2 with_type p =
let cf_get,tf_get,r_get,ekey = AbstractCast.find_array_read_access ctx a tl ekey p in
(* bind complex keys to a variable so they do not make it into the output twice *)
let save = save_locals ctx in
let maybe_bind_to_temp e = match Optimizer.make_constant_expression ctx e with
| Some e -> e,None
| None ->
let v = gen_local ctx e.etype p in
let e' = mk (TLocal v) e.etype p in
e', Some (mk (TVar (v,Some e)) ctx.t.tvoid p)
let vr = new value_reference ctx in
let maybe_bind_to_temp name e = match Optimizer.make_constant_expression ctx e with
| Some e -> e
| None -> vr#as_var name e
in
let ekey,ekey' = maybe_bind_to_temp ekey in
let ebase,ebase' = maybe_bind_to_temp ebase in
let ebase = maybe_bind_to_temp "base" ebase in
let ekey = maybe_bind_to_temp "key" ekey in
let eget = mk_array_get_call ctx (cf_get,tf_get,r_get,ekey) c ebase p in
let eget = type_binop2 ctx op eget e2 true WithType.value p in
let vr = new value_reference ctx in
let eget = BinopResult.to_texpr vr eget (fun e -> e) in
unify ctx eget.etype r_get p;
let cf_set,tf_set,r_set,ekey,eget = AbstractCast.find_array_write_access ctx a tl ekey eget p in
Expand All @@ -727,8 +724,6 @@ let type_assign_op ctx op e1 e2 with_type p =
| Some _,Some _ ->
let ef_set = mk (TField(et,(FStatic(c,cf_set)))) tf_set p in
let el = [make_call ctx ef_set [ebase;ekey;eget] r_set p] in
let el = match ebase' with None -> el | Some ebase -> ebase :: el in
let el = match ekey' with None -> el | Some ekey -> ekey :: el in
begin match el with
| [e] -> e
| el -> mk (TBlock el) r_set p
Expand Down
11 changes: 10 additions & 1 deletion std/cpp/_std/haxe/Exception.hx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class Exception {
if(Std.isOfType(value, Exception)) {
return value;
} else {
return new ValueException(value, null, value);
var e = new ValueException(value, null, value);
// Undo automatic __shiftStack()
e.__unshiftStack();
return e;
}
}

Expand Down Expand Up @@ -63,6 +66,12 @@ class Exception {
__skipStack++;
}

@:noCompletion
@:ifFeature("haxe.Exception.get_stack")
inline function __unshiftStack():Void {
__skipStack--;
}

function get_message():String {
return __exceptionMessage;
}
Expand Down
11 changes: 10 additions & 1 deletion std/eval/_std/haxe/Exception.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ class Exception {
if(Std.isOfType(value, Exception)) {
return value;
} else {
return new ValueException(value, null, value);
var e = new ValueException(value, null, value);
// Undo automatic __shiftStack()
e.__unshiftStack();
return e;
}
}

Expand Down Expand Up @@ -63,6 +66,12 @@ class Exception {
__skipStack++;
}

@:noCompletion
@:ifFeature("haxe.Exception.get_stack")
inline function __unshiftStack():Void {
__skipStack--;
}

function get_message():String {
return __exceptionMessage;
}
Expand Down
24 changes: 23 additions & 1 deletion std/haxe/macro/Expr.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ enum TypeDefKind {
/**
Represents an abstract kind.
**/
TDAbstract(tthis:Null<ComplexType>, ?from:Array<ComplexType>, ?to:Array<ComplexType>);
TDAbstract(tthis:Null<ComplexType>, ?flags:Array<AbstractFlag>, ?from:Array<ComplexType>, ?to:Array<ComplexType>);

/**
Represents a module-level field.
Expand All @@ -1013,6 +1013,28 @@ enum TypeDefKind {

}

/**
Represents an abstract flag.
**/
enum AbstractFlag {
/**
Indicates that this abstract is an `enum abstract`
**/
AbEnum;

/**
Indicates that this abstract can be assigned from `ct`.
This flag can be added several times to add multiple "from" types.
**/
AbFrom(ct:ComplexType);

/**
Indicates that this abstract can be assigned to `ct`.
This flag can be added several times to add multiple "to" types.
**/
AbTo(ct:ComplexType);
}

/**
This error can be used to handle or produce compilation errors in macros.
**/
Expand Down
6 changes: 5 additions & 1 deletion std/haxe/macro/MacroStringTools.hx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ class MacroStringTools {

static public function toComplex(path:String):ComplexType {
var pack = path.split(".");
return TPath({pack: pack, name: pack.pop(), params: []});
if(pack.length >= 2 && ~/^[A-Z]/.match(pack[pack.length - 2])) {
return TPath({pack: pack, sub: pack.pop(), name: pack.pop(), params: []});
} else {
return TPath({pack: pack, name: pack.pop(), params: []});
}
}
}
21 changes: 17 additions & 4 deletions std/haxe/macro/Printer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,26 @@ class Printer {
case _: printComplexType(ct);
})
+ ";";
case TDAbstract(tthis, from, to):
"abstract "
case TDAbstract(tthis, tflags, from, to):
var from = from == null ? [] : from.copy();
var to = to == null ? [] : to.copy();
var isEnum = false;

for (flag in tflags) {
switch (flag) {
case AbEnum: isEnum = true;
case AbFrom(ct): from.push(ct);
case AbTo(ct): to.push(ct);
}
}

(isEnum ? "enum " : "")
+ "abstract "
+ t.name
+ ((t.params != null && t.params.length > 0) ? "<" + t.params.map(printTypeParamDecl).join(", ") + ">" : "")
+ (tthis == null ? "" : "(" + printComplexType(tthis) + ")")
+ (from == null ? "" : [for (f in from) " from " + printComplexType(f)].join(""))
+ (to == null ? "" : [for (t in to) " to " + printComplexType(t)].join(""))
+ [for (f in from) " from " + printComplexType(f)].join("")
+ [for (f in to) " to " + printComplexType(f)].join("")
+ " {\n"
+ [
for (f in t.fields) {
Expand Down
11 changes: 10 additions & 1 deletion std/hl/_std/haxe/Exception.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ class Exception {
if(Std.isOfType(value, Exception)) {
return value;
} else {
return new ValueException(value, null, value);
var e = new ValueException(value, null, value);
// Undo automatic __shiftStack()
e.__unshiftStack();
return e;
}
}

Expand Down Expand Up @@ -62,6 +65,12 @@ class Exception {
__skipStack++;
}

@:noCompletion
@:ifFeature("haxe.Exception.get_stack")
inline function __unshiftStack():Void {
__skipStack--;
}

function get_message():String {
return __exceptionMessage;
}
Expand Down
2 changes: 1 addition & 1 deletion std/hl/_std/haxe/NativeStackTrace.hx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class NativeStackTrace {
var count = callStackRaw(null);
var arr = new NativeArray(count);
callStackRaw(arr);
return arr;
return arr.sub(1, arr.length - 1);
}

@:hlNative("std", "exception_stack_raw")
Expand Down
11 changes: 10 additions & 1 deletion std/neko/_std/haxe/Exception.hx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ class Exception {
if(Std.isOfType(value, Exception)) {
return value;
} else {
return new ValueException(value, null, value);
var e = new ValueException(value, null, value);
// Undo automatic __shiftStack()
e.__unshiftStack();
return e;
}
}

Expand Down Expand Up @@ -63,6 +66,12 @@ class Exception {
__skipStack++;
}

@:noCompletion
@:ifFeature("haxe.Exception.get_stack")
inline function __unshiftStack():Void {
__skipStack--;
}

function get_message():String {
return __exceptionMessage;
}
Expand Down
3 changes: 3 additions & 0 deletions tests/misc/hl/projects/Issue11196/Issue11196.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function main() {
var a:hl.I64 = 5;
}
3 changes: 3 additions & 0 deletions tests/misc/hl/projects/Issue11196/compile.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-m Issue11196
-hl out.hl
-dce no
7 changes: 7 additions & 0 deletions tests/nullsafety/src/cases/TestLoose.hx
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,11 @@ class TestLoose {
}
shouldFail(if (foo()) {});
}

static function nullCoal_continue_shouldPass():Void {
for (i in 0...1) {
var i:String = staticVar ?? continue;
var i2:String = staticVar ?? break;
}
}
}
Loading

0 comments on commit d9d0eba

Please sign in to comment.