Skip to content

Commit

Permalink
Merge branch 'development' of https://github.com/HaxeFoundation/haxe
Browse files Browse the repository at this point in the history
…into development
  • Loading branch information
0b1kn00b committed Aug 28, 2023
2 parents d963287 + d033a09 commit 6485922
Show file tree
Hide file tree
Showing 66 changed files with 913 additions and 561 deletions.
9 changes: 5 additions & 4 deletions src/codegen/codegen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ let add_property_field com c =
c.cl_statics <- PMap.add cf.cf_name cf c.cl_statics;
c.cl_ordered_statics <- cf :: c.cl_ordered_statics

let escape_res_name name allow_dirs =
let escape_res_name name allowed =
ExtString.String.replace_chars (fun chr ->
if (chr >= 'a' && chr <= 'z') || (chr >= 'A' && chr <= 'Z') || (chr >= '0' && chr <= '9') || chr = '_' || chr = '.' then
Char.escaped chr
else if chr = '/' && allow_dirs then
"/"
else if List.mem chr allowed then
Char.escaped chr
else
"-x" ^ (string_of_int (Char.code chr))) name

Expand Down Expand Up @@ -387,7 +387,8 @@ module Dump = struct
let dep = Hashtbl.create 0 in
List.iter (fun m ->
print "%s:\n" (Path.UniqueKey.lazy_path m.m_extra.m_file);
PMap.iter (fun _ m2 ->
PMap.iter (fun _ (sign,mpath) ->
let m2 = (com.cs#get_context sign)#find_module mpath in
let file = Path.UniqueKey.lazy_path m2.m_extra.m_file in
print "\t%s\n" file;
let l = try Hashtbl.find dep file with Not_found -> [] in
Expand Down
9 changes: 8 additions & 1 deletion src/compiler/compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,14 @@ module Setup = struct
"python"
| Hl ->
add_std "hl";
if not (Common.defined com Define.HlVer) then Define.define_value com.defines Define.HlVer (try Std.input_file (Common.find_file com "hl/hl_version") with Not_found -> die "" __LOC__);
if not (Common.defined com Define.HlVer) then begin
let hl_ver = try
Std.input_file (Common.find_file com "hl/hl_version")
with Not_found ->
failwith "The file hl_version could not be found. Please make sure HAXE_STD_PATH is set to the standard library corresponding to the used compiler version."
in
Define.define_value com.defines Define.HlVer hl_ver
end;
"hl"
| Eval ->
add_std "eval";
Expand Down
9 changes: 7 additions & 2 deletions src/compiler/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ let check_module sctx ctx m p =
end
in
let check_dependencies () =
PMap.iter (fun _ m2 -> match check m2 with
PMap.iter (fun _ (sign,mpath) ->
let m2 = (com.cs#get_context sign)#find_module mpath in
match check m2 with
| None -> ()
| Some reason -> raise (Dirty (DependencyDirty(m2.m_path,reason)))
) m.m_extra.m_deps;
Expand Down Expand Up @@ -407,7 +409,10 @@ let add_modules sctx ctx m p =
) m.m_types;
TypeloadModule.ModuleLevel.add_module ctx m p;
PMap.iter (Hashtbl.replace com.resources) m.m_extra.m_binded_res;
PMap.iter (fun _ m2 -> add_modules (tabs ^ " ") m0 m2) m.m_extra.m_deps
PMap.iter (fun _ (sign,mpath) ->
let m2 = (com.cs#get_context sign)#find_module mpath in
add_modules (tabs ^ " ") m0 m2
) m.m_extra.m_deps
)
end
in
Expand Down
3 changes: 1 addition & 2 deletions src/context/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,7 @@ exception Abort of Error.error

let ignore_error com =
let b = com.display.dms_error_policy = EPIgnore in
if b then
if b then com.has_error <- true;
if b then com.has_error <- true;
b

(* Defines *)
Expand Down
34 changes: 19 additions & 15 deletions src/context/display/displayFields.ml
Original file line number Diff line number Diff line change
Expand Up @@ -228,21 +228,25 @@ let collect ctx e_ast e dk with_type p =
| TAnon an ->
(* @:forwardStatics *)
let items = match !(an.a_status) with
| Statics { cl_kind = KAbstractImpl { a_meta = meta; a_this = TInst (c,_) }} when Meta.has Meta.ForwardStatics meta ->
let items = List.fold_left (fun acc cf ->
if should_access c cf true && is_new_item acc cf.cf_name then begin
let origin = Self(TClassDecl c) in
let item = make_class_field origin cf in
PMap.add cf.cf_name item acc
end else
acc
) items c.cl_ordered_statics in
PMap.foldi (fun name item acc ->
if is_new_item acc name then
PMap.add name item acc
else
acc
) PMap.empty items
| Statics { cl_kind = KAbstractImpl { a_meta = meta; a_this}} when Meta.has Meta.ForwardStatics meta ->
begin match follow a_this with
| TInst (c,_) ->
let items = List.fold_left (fun acc cf ->
if should_access c cf true && is_new_item acc cf.cf_name then begin
let origin = Self(TClassDecl c) in
let item = make_class_field origin cf in
PMap.add cf.cf_name item acc
end else
acc
) items c.cl_ordered_statics in
PMap.foldi (fun name item acc ->
if is_new_item acc name then
PMap.add name item acc
else
acc
) PMap.empty items
| _ -> items
end
| _ -> items
in
(* Anon own fields *)
Expand Down
5 changes: 3 additions & 2 deletions src/context/display/displayJson.ml
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,14 @@ let handler =
"server/module", (fun hctx ->
let sign = Digest.from_hex (hctx.jsonrpc#get_string_param "signature") in
let path = Path.parse_path (hctx.jsonrpc#get_string_param "path") in
let cc = hctx.display#get_cs#get_context sign in
let cs = hctx.display#get_cs in
let cc = cs#get_context sign in
let m = try
cc#find_module path
with Not_found ->
hctx.send_error [jstring "No such module"]
in
hctx.send_result (generate_module cc m)
hctx.send_result (generate_module cs cc m)
);
"server/type", (fun hctx ->
let sign = Digest.from_hex (hctx.jsonrpc#get_string_param "signature") in
Expand Down
13 changes: 8 additions & 5 deletions src/context/memory.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ let update_module_type_deps deps md =
) md.m_types;
!deps

let rec scan_module_deps m h =
let rec scan_module_deps cs m h =
if Hashtbl.mem h m.m_id then
()
else begin
Hashtbl.add h m.m_id m;
PMap.iter (fun _ m -> scan_module_deps m h) m.m_extra.m_deps
PMap.iter (fun _ (sign,mpath) ->
let m = (cs#get_context sign)#find_module mpath in
scan_module_deps cs m h) m.m_extra.m_deps
end

let module_sign key md =
Expand All @@ -61,7 +63,7 @@ let get_out out =

let get_module_memory cs all_modules m =
let mdeps = Hashtbl.create 0 in
scan_module_deps m mdeps;
scan_module_deps cs m mdeps;
let deps = ref [Obj.repr null_module] in
let out = ref all_modules in
let deps = Hashtbl.fold (fun _ md deps ->
Expand Down Expand Up @@ -272,8 +274,9 @@ let display_memory com =
());
if verbose then begin
print (Printf.sprintf " %d total deps" (List.length deps));
PMap.iter (fun _ md ->
print (Printf.sprintf " dep %s%s" (s_type_path md.m_path) (module_sign key md));
PMap.iter (fun _ (sign,mpath) ->
let md = (com.cs#get_context sign)#find_module mpath in
print (Printf.sprintf " dep %s%s" (s_type_path mpath) (module_sign key md));
) m.m_extra.m_deps;
end;
flush stdout
Expand Down
2 changes: 1 addition & 1 deletion src/context/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ let add_local_with_origin ctx origin n t p =
check_local_variable_name ctx n origin p;
add_local ctx (VUser origin) n t p

let gen_local_prefix = "_g"
let gen_local_prefix = "`"

let gen_local ctx t p =
add_local ctx VGenerated gen_local_prefix t p
Expand Down
12 changes: 7 additions & 5 deletions src/core/json/genjson.ml
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ let generate_module_type ctx mt =

(* module *)

let generate_module cc m =
let generate_module cs cc m =
jobject [
"id",jint m.m_id;
"path",generate_module_path m.m_path;
Expand All @@ -718,10 +718,12 @@ let generate_module cc m =
| MSGood -> "Good"
| MSBad reason -> Printer.s_module_skip_reason reason
| MSUnknown -> "Unknown");
"dependencies",jarray (PMap.fold (fun m acc -> (jobject [
"path",jstring (s_type_path m.m_path);
"sign",jstring (Digest.to_hex m.m_extra.m_sign);
]) :: acc) m.m_extra.m_deps []);
"dependencies",jarray (PMap.fold (fun (sign,mpath) acc ->
(jobject [
"path",jstring (s_type_path mpath);
"sign",jstring (Digest.to_hex ((cs#get_context sign)#find_module mpath).m_extra.m_sign);
]) :: acc
) m.m_extra.m_deps []);
"dependents",jarray (List.map (fun m -> (jobject [
"path",jstring (s_type_path m.m_path);
"sign",jstring (Digest.to_hex m.m_extra.m_sign);
Expand Down
4 changes: 2 additions & 2 deletions src/core/tFunctions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ let null_abstract = {
}

let add_dependency ?(skip_postprocess=false) m mdep =
if m != null_module && m != mdep then begin
m.m_extra.m_deps <- PMap.add mdep.m_id mdep m.m_extra.m_deps;
if m != null_module && (m.m_path != mdep.m_path || m.m_extra.m_sign != mdep.m_extra.m_sign) then begin
m.m_extra.m_deps <- PMap.add mdep.m_id (mdep.m_extra.m_sign, mdep.m_path) m.m_extra.m_deps;
(* In case the module is cached, we'll have to run post-processing on it again (issue #10635) *)
if not skip_postprocess then m.m_extra.m_processed <- 0
end
Expand Down
2 changes: 1 addition & 1 deletion src/core/tPrinting.ml
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ module Printer = struct
"m_cache_state",s_module_cache_state me.m_cache_state;
"m_added",string_of_int me.m_added;
"m_checked",string_of_int me.m_checked;
"m_deps",s_pmap string_of_int (fun m -> snd m.m_path) me.m_deps;
"m_deps",s_pmap string_of_int (fun (_,m) -> snd m) me.m_deps;
"m_processed",string_of_int me.m_processed;
"m_kind",s_module_kind me.m_kind;
"m_binded_res",""; (* TODO *)
Expand Down
2 changes: 1 addition & 1 deletion src/core/tType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ and module_def_extra = {
mutable m_added : int;
mutable m_checked : int;
mutable m_processed : int;
mutable m_deps : (int,module_def) PMap.t;
mutable m_deps : (int,(string (* sign *) * path)) PMap.t;
mutable m_kind : module_kind;
mutable m_binded_res : (string, string) PMap.t;
mutable m_if_feature : (string *(tclass * tclass_field * bool)) list;
Expand Down
2 changes: 1 addition & 1 deletion src/core/texpr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ let map_expr_type f ft fv e =
| TFunction fu ->
let fu = {
tf_expr = f fu.tf_expr;
tf_args = List.map (fun (v,o) -> fv v, o) fu.tf_args;
tf_args = List.map (fun (v,o) -> fv v, (Option.map f o)) fu.tf_args;
tf_type = ft fu.tf_type;
} in
{ e with eexpr = TFunction fu; etype = ft e.etype }
Expand Down
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
13 changes: 11 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 Expand Up @@ -358,11 +361,17 @@ and collect_ignore_block ?(in_block=false) rc scope e =
(**
Rename `v` if needed
*)
let trailing_numbers = Str.regexp "[0-9]+$"
let maybe_rename_var rc reserved (v,overlaps) =
let commit name =
v.v_meta <- (Meta.RealPath,[EConst (String(v.v_name,SDoubleQuotes)),null_pos],null_pos) :: v.v_meta;
v.v_name <- name
in
(* chop escape char for all local variables generated *)
if String.unsafe_get v.v_name 0 = String.unsafe_get Typecore.gen_local_prefix 0 then begin
let name = String.sub v.v_name 1 (String.length v.v_name - 1) in
commit ("_g" ^ (Str.replace_first trailing_numbers "" name))
end;
let rec loop name count =
if StringMap.mem name !reserved || Overlaps.has_name name overlaps then begin
let count = count + 1 in
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
2 changes: 1 addition & 1 deletion src/generators/gencs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3421,7 +3421,7 @@ let generate con =
gen.gcon.file ^ "/src/Resources"
in
Hashtbl.iter (fun name v ->
let name = Codegen.escape_res_name name true in
let name = Codegen.escape_res_name name ['/'] in
let full_path = src ^ "/" ^ name in
Path.mkdir_from_path full_path;

Expand Down
Loading

0 comments on commit 6485922

Please sign in to comment.