From d9fc90a8501a02580fa2dbf7492a30ef785cc913 Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Sat, 3 Feb 2024 09:20:47 +0100 Subject: [PATCH 1/2] [hxb] remove writer stats I broke parts of it already anyway. --- src/compiler/compilationCache.ml | 4 +- src/compiler/generate.ml | 2 +- src/compiler/hxb/hxbWriter.ml | 83 ++------------------------------ src/context/common.ml | 3 -- src/context/commonCache.ml | 3 +- 5 files changed, 9 insertions(+), 86 deletions(-) diff --git a/src/compiler/compilationCache.ml b/src/compiler/compilationCache.ml index b7c8ea854cc..0b4b2a0b455 100644 --- a/src/compiler/compilationCache.ml +++ b/src/compiler/compilationCache.ml @@ -69,12 +69,12 @@ class context_cache (index : int) (sign : Digest.t) = object(self) method find_module_extra path = try (Hashtbl.find modules path).m_extra with Not_found -> (Hashtbl.find binary_cache path).mc_extra - method cache_module config warn anon_identification hxb_writer_stats path m = + method cache_module config warn anon_identification path m = match m.m_extra.m_kind with | MImport -> Hashtbl.add modules m.m_path m | _ -> - let writer = HxbWriter.create config warn anon_identification hxb_writer_stats in + let writer = HxbWriter.create config warn anon_identification in HxbWriter.write_module writer m; let chunks = HxbWriter.get_chunks writer in Hashtbl.replace binary_cache path { diff --git a/src/compiler/generate.ml b/src/compiler/generate.ml index e12e22e372b..04718ece5e0 100644 --- a/src/compiler/generate.ml +++ b/src/compiler/generate.ml @@ -42,7 +42,7 @@ let export_hxb com config cc platform zip m = with Not_found -> let anon_identification = new tanon_identification in let warn w s p = com.Common.warning w com.warning_options s p in - let writer = HxbWriter.create config warn anon_identification com.hxb_writer_stats in + let writer = HxbWriter.create config warn anon_identification in HxbWriter.write_module writer m; let out = IO.output_string () in HxbWriter.export writer out; diff --git a/src/compiler/hxb/hxbWriter.ml b/src/compiler/hxb/hxbWriter.ml index 39cde88c266..cc2d1c1065c 100644 --- a/src/compiler/hxb/hxbWriter.ml +++ b/src/compiler/hxb/hxbWriter.ml @@ -45,63 +45,6 @@ let unop_index op flag = match op,flag with | NegBits,Postfix -> 10 | Spread,Postfix -> 11 -type hxb_writer_stats = { - type_instance_kind_writes : int array; - texpr_writes : int array; - type_instance_immediate : int ref; - type_instance_cache_hits : int ref; - type_instance_cache_misses : int ref; - pos_writes_full : int ref; - pos_writes_min : int ref; - pos_writes_max : int ref; - pos_writes_minmax : int ref; - pos_writes_eq : int ref; - chunk_sizes : (string,int ref * int ref) Hashtbl.t; -} - -let create_hxb_writer_stats () = { - type_instance_kind_writes = Array.make 255 0; - texpr_writes = Array.make 255 0; - type_instance_immediate = ref 0; - type_instance_cache_hits = ref 0; - type_instance_cache_misses = ref 0; - pos_writes_full = ref 0; - pos_writes_min = ref 0; - pos_writes_max = ref 0; - pos_writes_minmax = ref 0; - pos_writes_eq = ref 0; - chunk_sizes = Hashtbl.create 0; -} - -let dump_stats name stats = - let sort_and_filter_array a = - let _,kind_writes = Array.fold_left (fun (index,acc) writes -> - (index + 1,if writes = 0 then acc else (index,writes) :: acc) - ) (0,[]) a in - let kind_writes = List.sort (fun (_,writes1) (_,writes2) -> compare writes2 writes1) kind_writes in - List.map (fun (index,writes) -> Printf.sprintf " %3i: %9i" index writes) kind_writes - in - let t_kind_writes = sort_and_filter_array stats.type_instance_kind_writes in - print_endline (Printf.sprintf "hxb_writer stats for %s" name); - print_endline " type instance kind writes:"; - List.iter print_endline t_kind_writes; - let texpr_writes = sort_and_filter_array stats.texpr_writes in - print_endline " texpr writes:"; - List.iter print_endline texpr_writes; - - print_endline " type instance writes:"; - print_endline (Printf.sprintf " immediate: %9i" !(stats.type_instance_immediate)); - print_endline (Printf.sprintf " cache hits: %9i" !(stats.type_instance_cache_hits)); - print_endline (Printf.sprintf " cache miss: %9i" !(stats.type_instance_cache_misses)); - print_endline " pos writes:"; - print_endline (Printf.sprintf " full: %9i\n min: %9i\n max: %9i\n minmax: %9i\n equal: %9i" !(stats.pos_writes_full) !(stats.pos_writes_min) !(stats.pos_writes_max) !(stats.pos_writes_minmax) !(stats.pos_writes_eq)); - (* let chunk_sizes = Hashtbl.fold (fun name (imin,imax) acc -> (name,!imin,!imax) :: acc) stats.chunk_sizes [] in - let chunk_sizes = List.sort (fun (_,imin1,imax1) (_,imin2,imax2) -> compare imax1 imax2) chunk_sizes in - print_endline "chunk sizes:"; - List.iter (fun (name,imin,imax) -> - print_endline (Printf.sprintf " %s: %i - %i" name imin imax) - ) chunk_sizes *) - module StringHashtbl = Hashtbl.Make(struct type t = string @@ -400,17 +343,10 @@ module Chunk = struct let write_bool io b = write_u8 io (if b then 1 else 0) - let export : 'a . hxb_writer_stats -> t -> 'a IO.output -> unit = fun stats io chex -> + let export : 'a . t -> 'a IO.output -> unit = fun io chex -> let bytes = get_bytes io in let length = Bytes.length bytes in write_chunk_prefix io.kind length chex; - (* begin try - let (imin,imax) = Hashtbl.find stats.chunk_sizes io.name in - if length < !imin then imin := length; - if length > !imax then imax := length - with Not_found -> - Hashtbl.add stats.chunk_sizes io.name (ref length,ref length); - end; *) IO.nwrite chex bytes let write_string chunk s = @@ -438,22 +374,19 @@ end module PosWriter = struct type t = { - stats : hxb_writer_stats; mutable p_file : string; mutable p_min : int; mutable p_max : int; } let do_write_pos (chunk : Chunk.t) (p : pos) = - (* incr stats.pos_writes_full; *) Chunk.write_string chunk p.pfile; Chunk.write_leb128 chunk p.pmin; Chunk.write_leb128 chunk p.pmax - let create stats chunk p = + let create chunk p = do_write_pos chunk p; { - stats; p_file = p.pfile; p_min = p.pmin; p_max = p.pmax; @@ -470,7 +403,6 @@ module PosWriter = struct end else if p.pmin <> pw.p_min then begin if p.pmax <> pw.p_max then begin (* pmin and pmax changed *) - (* incr stats.pos_writes_minmax; *) Chunk.write_u8 chunk (3 + offset); Chunk.write_leb128 chunk p.pmin; Chunk.write_leb128 chunk p.pmax; @@ -478,19 +410,16 @@ module PosWriter = struct pw.p_max <- p.pmax; end else begin (* pmin changed *) - (* incr stats.pos_writes_min; *) Chunk.write_u8 chunk (1 + offset); Chunk.write_leb128 chunk p.pmin; pw.p_min <- p.pmin; end end else if p.pmax <> pw.p_max then begin (* pmax changed *) - (* incr stats.pos_writes_max; *) Chunk.write_u8 chunk (2 + offset); Chunk.write_leb128 chunk p.pmax; pw.p_max <- p.pmax; end else begin - (* incr stats.pos_writes_eq; *) if write_equal then Chunk.write_u8 chunk offset; end @@ -514,7 +443,6 @@ type hxb_writer = { config : HxbWriterConfig.writer_target_config; warn : Warning.warning -> string -> Globals.pos -> unit; anon_id : Type.t Tanon_identification.tanon_identification; - stats : hxb_writer_stats; mutable current_module : module_def; chunks : Chunk.t DynArray.t; cp : StringPool.t; @@ -1794,7 +1722,7 @@ module HxbWriter = struct and start_texpr writer (p: pos) = let restore = start_temporary_chunk writer 512 in - let fctx = create_field_writer_context (PosWriter.create writer.stats writer.chunk p) in + let fctx = create_field_writer_context (PosWriter.create writer.chunk p) in fctx,(fun () -> restore(fun new_chunk -> let restore = start_temporary_chunk writer 512 in @@ -2287,13 +2215,12 @@ module HxbWriter = struct l end -let create config warn anon_id stats = +let create config warn anon_id = let cp = StringPool.create () in { config; warn; anon_id; - stats; current_module = null_module; chunks = DynArray.create (); cp = cp; @@ -2333,5 +2260,5 @@ let export : 'a . hxb_writer -> 'a IO.output -> unit = fun writer ch -> write_header ch; let l = HxbWriter.get_sorted_chunks writer in List.iter (fun io -> - Chunk.export writer.stats io ch + Chunk.export io ch ) l diff --git a/src/context/common.ml b/src/context/common.ml index e1e3577f8b0..db30ae055ee 100644 --- a/src/context/common.ml +++ b/src/context/common.ml @@ -420,7 +420,6 @@ type context = { mutable basic : basic_types; memory_marker : float array; hxb_reader_stats : HxbReader.hxb_reader_stats; - hxb_writer_stats : HxbWriter.hxb_writer_stats; mutable hxb_writer_config : HxbWriterConfig.t option; } @@ -883,7 +882,6 @@ let create compilation_step cs version args display_mode = report_mode = RMNone; is_macro_context = false; hxb_reader_stats = HxbReader.create_hxb_reader_stats (); - hxb_writer_stats = HxbWriter.create_hxb_writer_stats (); hxb_writer_config = None; } in com @@ -935,7 +933,6 @@ let clone com is_macro_context = overload_cache = new hashtbl_lookup; module_lut = new module_lut; hxb_reader_stats = HxbReader.create_hxb_reader_stats (); - hxb_writer_stats = HxbWriter.create_hxb_writer_stats (); std = null_class; empty_class_path = new ClassPath.directory_class_path "" User; class_paths = new ClassPaths.class_paths; diff --git a/src/context/commonCache.ml b/src/context/commonCache.ml index 312d5cc723c..d2c7db7796c 100644 --- a/src/context/commonCache.ml +++ b/src/context/commonCache.ml @@ -95,7 +95,7 @@ let rec cache_context cs com = (* If we have a signature mismatch, look-up cache for module. Physical equality check is fine as a heueristic. *) let cc = if m.m_extra.m_sign = sign then cc else cs#get_context m.m_extra.m_sign in let warn w s p = com.warning w com.warning_options s p in - cc#cache_module config warn anon_identification com.hxb_writer_stats m.m_path m; + cc#cache_module config warn anon_identification m.m_path m; in List.iter cache_module com.modules; begin match com.get_macros() with @@ -104,7 +104,6 @@ let rec cache_context cs com = end; if Define.raw_defined com.defines "hxb.stats" then begin HxbReader.dump_stats (platform_name com.platform) com.hxb_reader_stats; - HxbWriter.dump_stats (platform_name com.platform) com.hxb_writer_stats end let maybe_add_context_sign cs com desc = From 4260da3c6f98dd55b64c001f4ae7896531d5e864 Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Sat, 3 Feb 2024 09:48:23 +0100 Subject: [PATCH 2/2] Remove some API from haxe.macro.Compiler (#11540) * remove some API from haxe.macro.Compiler * js fixes * never mind --- src/context/typecore.ml | 1 - src/macro/macroApi.ml | 10 -- src/typing/macroContext.ml | 46 ------- src/typing/typeloadFields.ml | 70 ----------- src/typing/typeloadModule.ml | 6 - src/typing/typerEntry.ml | 1 - std/haxe/macro/Compiler.hx | 115 +----------------- tests/misc/es6/Test.hx | 2 +- .../user-defined-define-json-fail.hxml.stderr | 2 +- .../user-defined-meta-json-fail.hxml.stderr | 2 +- ...-defined-meta-json-indent-fail.hxml.stderr | 2 +- ...-defined-meta-json-pretty-fail.hxml.stderr | 4 +- tests/misc/projects/Issue4660/Include.hx | 2 +- tests/misc/projects/Issue8567/compile.hxml | 3 - tests/misc/projects/Issue8567/src/Main.hx | 4 - tests/misc/projects/Issue8567/src/test.txt | 0 16 files changed, 12 insertions(+), 258 deletions(-) delete mode 100644 tests/misc/projects/Issue8567/compile.hxml delete mode 100644 tests/misc/projects/Issue8567/src/Main.hx delete mode 100644 tests/misc/projects/Issue8567/src/test.txt diff --git a/src/context/typecore.ml b/src/context/typecore.ml index 180b14daaf7..730c05259b8 100644 --- a/src/context/typecore.ml +++ b/src/context/typecore.ml @@ -114,7 +114,6 @@ type typer_globals = { mutable core_api : typer option; mutable macros : ((unit -> unit) * typer) option; mutable std_types : module_def; - type_patches : (path, (string * bool, type_patch) Hashtbl.t * type_patch) Hashtbl.t; mutable module_check_policies : (string list * module_check_policy list * bool) list; mutable global_using : (tclass * pos) list; (* Indicates that Typer.create() finished building this instance *) diff --git a/src/macro/macroApi.ml b/src/macro/macroApi.ml index d7b1b8f97eb..155ed8c08ce 100644 --- a/src/macro/macroApi.ml +++ b/src/macro/macroApi.ml @@ -38,8 +38,6 @@ type 'value compiler_api = { resolve_complex_type : Ast.type_hint -> Ast.type_hint; store_typed_expr : Type.texpr -> Ast.expr; allow_package : string -> unit; - type_patch : string -> string -> bool -> string option -> unit; - meta_patch : string -> string -> string option -> bool -> pos -> unit; set_js_generator : (Genjs.ctx -> unit) -> unit; get_local_type : unit -> t option; get_expected_type : unit -> t option; @@ -1953,14 +1951,6 @@ let macro_api ccom get_api = (get_api()).allow_package (decode_string s); vnull ); - "type_patch", vfun4 (fun t f s v -> - (get_api()).type_patch (decode_string t) (decode_string f) (decode_bool s) (opt decode_string v); - vnull - ); - "meta_patch", vfun4 (fun m t f s -> - (get_api()).meta_patch (decode_string m) (decode_string t) (opt decode_string f) (decode_bool s) (get_api_call_pos ()); - vnull - ); "add_global_metadata_impl", vfun5 (fun s1 s2 b1 b2 b3 -> (get_api()).add_global_metadata (decode_string s1) (decode_string s2) (decode_bool b1,decode_bool b2,decode_bool b3) (get_api_call_pos()); vnull diff --git a/src/typing/macroContext.ml b/src/typing/macroContext.ml index b76ddbec32c..b17f1a2b103 100644 --- a/src/typing/macroContext.ml +++ b/src/typing/macroContext.ml @@ -51,28 +51,6 @@ let safe_decode com v expected t p f = close_out ch; raise_typing_error (Printf.sprintf "Expected %s but got %s (see %s.txt for details)" expected (Interp.value_string v) (String.concat "/" path)) p -let get_type_patch ctx t sub = - let new_patch() = - { tp_type = None; tp_remove = false; tp_meta = [] } - in - let path = Ast.parse_path t in - let h, tp = (try - Hashtbl.find ctx.g.type_patches path - with Not_found -> - let h = Hashtbl.create 0 in - let tp = new_patch() in - Hashtbl.add ctx.g.type_patches path (h,tp); - h, tp - ) in - match sub with - | None -> tp - | Some k -> - try - Hashtbl.find h k - with Not_found -> - let tp = new_patch() in - Hashtbl.add h k tp; - tp let macro_timer com l = Timer.timer (if Common.defined com Define.MacroTimes then ("macro" :: l) else ["macro"]) @@ -222,12 +200,6 @@ let make_macro_com_api com mcom p = snd (Typecore.store_typed_expr com te p) ); allow_package = (fun v -> Common.allow_package com v); - type_patch = (fun t f s v -> - Interp.exc_string "unsupported" - ); - meta_patch = (fun m t f s p -> - Interp.exc_string "unsupported" - ); set_js_generator = (fun gen -> com.js_gen <- Some (fun() -> Path.mkdir_from_path com.file; @@ -434,24 +406,6 @@ let make_macro_api ctx mctx p = MacroApi.flush_context = (fun f -> typing_timer ctx true f ); - MacroApi.type_patch = (fun t f s v -> - typing_timer ctx false (fun() -> - let v = (match v with None -> None | Some s -> - match ParserEntry.parse_string Grammar.parse_complex_type ctx.com.defines s null_pos raise_typing_error false with - | ParseSuccess((ct,_),_,_) -> Some ct - | ParseError(_,(msg,p),_) -> Parser.error msg p (* p is null_pos, but we don't have anything else here... *) - ) in - let tp = get_type_patch ctx t (Some (f,s)) in - match v with - | None -> tp.tp_remove <- true - | Some t -> tp.tp_type <- Some t - ); - ); - MacroApi.meta_patch = (fun m t f s p -> - let ml = parse_metadata m p in - let tp = get_type_patch ctx t (match f with None -> None | Some f -> Some (f,s)) in - tp.tp_meta <- tp.tp_meta @ (List.map (fun (m,el,_) -> (m,el,p)) ml); - ); MacroApi.get_local_type = (fun() -> match ctx.c.get_build_infos() with | Some (mt,tl,_) -> diff --git a/src/typing/typeloadFields.ml b/src/typing/typeloadFields.ml index 1c335511c76..f49140384ff 100644 --- a/src/typing/typeloadFields.ml +++ b/src/typing/typeloadFields.ml @@ -282,75 +282,6 @@ let transform_abstract_field com this_t a_t a f = | _ -> f -let patch_class ctx c fields = - let path = match c.cl_kind with - | KAbstractImpl a -> a.a_path - | _ -> c.cl_path - in - let h = (try Some (Hashtbl.find ctx.g.type_patches path) with Not_found -> None) in - match h with - | None -> fields - | Some (h,hcl) -> - c.cl_meta <- c.cl_meta @ hcl.tp_meta; - let patch_getter t fn = - { fn with f_type = t } - in - let patch_setter t fn = - match fn.f_args with - | [(name,opt,meta,_,expr)] -> - { fn with f_args = [(name,opt,meta,t,expr)]; f_type = t } - | _ -> fn - in - let rec loop acc accessor_acc = function - | [] -> acc, accessor_acc - | f :: l -> - (* patch arguments types *) - (match f.cff_kind with - | FFun ff -> - let param (((n,pn),opt,m,_,e) as p) = - try - let t2 = (try Hashtbl.find h (("$" ^ (fst f.cff_name) ^ "__" ^ n),false) with Not_found -> Hashtbl.find h (("$" ^ n),false)) in - (n,pn), opt, m, (match t2.tp_type with None -> None | Some t -> Some (t,null_pos)), e - with Not_found -> - p - in - f.cff_kind <- FFun { ff with f_args = List.map param ff.f_args } - | _ -> ()); - (* other patches *) - match (try Some (Hashtbl.find h (fst f.cff_name,List.mem_assoc AStatic f.cff_access)) with Not_found -> None) with - | None -> loop (f :: acc) accessor_acc l - | Some { tp_remove = true } -> loop acc accessor_acc l - | Some p -> - f.cff_meta <- f.cff_meta @ p.tp_meta; - let accessor_acc = - match p.tp_type with - | None -> accessor_acc - | Some t -> - match f.cff_kind with - | FVar (_,e) -> - f.cff_kind <- FVar (Some (t,null_pos),e); accessor_acc - | FProp (get,set,_,eo) -> - let typehint = Some (t,null_pos) in - let accessor_acc = if fst get = "get" then ("get_" ^ fst f.cff_name, patch_getter typehint) :: accessor_acc else accessor_acc in - let accessor_acc = if fst set = "set" then ("set_" ^ fst f.cff_name, patch_setter typehint) :: accessor_acc else accessor_acc in - f.cff_kind <- FProp (get,set,typehint,eo); accessor_acc - | FFun fn -> - f.cff_kind <- FFun { fn with f_type = Some (t,null_pos) }; accessor_acc - in - loop (f :: acc) accessor_acc l - in - let fields, accessor_patches = loop [] [] fields in - List.iter (fun (accessor_name, patch) -> - try - let f_accessor = List.find (fun f -> fst f.cff_name = accessor_name) fields in - match f_accessor.cff_kind with - | FFun fn -> f_accessor.cff_kind <- FFun (patch fn) - | _ -> () - with Not_found -> - () - ) accessor_patches; - List.rev fields - let lazy_display_type ctx f = f () @@ -1710,7 +1641,6 @@ let check_functional_interface ctx c = let init_class ctx_c cctx c p herits fields = let com = ctx_c.com in if cctx.is_class_debug then print_endline ("Created class context: " ^ dump_class_context cctx); - let fields = patch_class ctx_c c fields in let fields = build_fields (ctx_c,cctx) c fields in if cctx.is_core_api && com.display.dms_check_core_api then delay ctx_c PForce (fun() -> init_core_api ctx_c c); if not cctx.is_lib then begin diff --git a/src/typing/typeloadModule.ml b/src/typing/typeloadModule.ml index 1966c5eb1d5..35889603d3a 100644 --- a/src/typing/typeloadModule.ml +++ b/src/typing/typeloadModule.ml @@ -450,13 +450,7 @@ module TypeLevel = struct if ctx_m.m.is_display_file && DisplayPosition.display_position#enclosed_in (pos d.d_name) then DisplayEmitter.display_module_type ctx_m (TEnumDecl e) (pos d.d_name); let ctx_en = TyperManager.clone_for_enum ctx_m e in - let h = (try Some (Hashtbl.find ctx_en.g.type_patches e.e_path) with Not_found -> None) in TypeloadCheck.check_global_metadata ctx_en e.e_meta (fun m -> e.e_meta <- m :: e.e_meta) e.e_module.m_path e.e_path None; - (match h with - | None -> () - | Some (h,hcl) -> - Hashtbl.iter (fun _ _ -> raise_typing_error "Field type patch not supported for enums" e.e_pos) h; - e.e_meta <- e.e_meta @ hcl.tp_meta); let constructs = ref d.d_data in let get_constructs() = List.map (fun c -> diff --git a/src/typing/typerEntry.ml b/src/typing/typerEntry.ml index a624db3b880..72ae8d3bf57 100644 --- a/src/typing/typerEntry.ml +++ b/src/typing/typerEntry.ml @@ -13,7 +13,6 @@ let create com macros = g = { core_api = None; macros = macros; - type_patches = Hashtbl.create 0; module_check_policies = []; delayed = Array.init all_typer_passes_length (fun _ -> { tasks = []}); delayed_min_index = 0; diff --git a/std/haxe/macro/Compiler.hx b/std/haxe/macro/Compiler.hx index 03701de4b96..1ba1ed88e6f 100644 --- a/std/haxe/macro/Compiler.hx +++ b/std/haxe/macro/Compiler.hx @@ -77,64 +77,9 @@ class Compiler { } #if (!neko && !eval) - private static function typePatch(cl:String, f:String, stat:Bool, t:String) {} - - private static function metaPatch(meta:String, cl:String, f:String, stat:Bool) {} - private static function addGlobalMetadataImpl(pathFilter:String, meta:String, recursive:Bool, toTypes:Bool, toFields:Bool) {} #end - /** - Removes a (static) field from a given class by name. - An error is thrown when `className` or `field` is invalid. - **/ - @:deprecated - public static function removeField(className:String, field:String, ?isStatic:Bool) { - if (!path.match(className)) - throw "Invalid " + className; - if (!ident.match(field)) - throw "Invalid " + field; - #if (neko || eval) - Context.onAfterInitMacros(() -> load("type_patch", 4)(className, field, isStatic == true, null)); - #else - typePatch(className, field, isStatic == true, null); - #end - } - - /** - Set the type of a (static) field at a given class by name. - An error is thrown when `className` or `field` is invalid. - **/ - @:deprecated - public static function setFieldType(className:String, field:String, type:String, ?isStatic:Bool) { - if (!path.match(className)) - throw "Invalid " + className; - if (!ident.match((field.charAt(0) == "$") ? field.substr(1) : field)) - throw "Invalid " + field; - #if (neko || eval) - Context.onAfterInitMacros(() -> load("type_patch", 4)(className, field, isStatic == true, type)); - #else - typePatch(className, field, isStatic == true, type); - #end - } - - /** - Add metadata to a (static) field or class by name. - An error is thrown when `className` or `field` is invalid. - **/ - @:deprecated - public static function addMetadata(meta:String, className:String, ?field:String, ?isStatic:Bool) { - if (!path.match(className)) - throw "Invalid " + className; - if (field != null && !ident.match(field)) - throw "Invalid " + field; - #if (neko || eval) - Context.onAfterInitMacros(() -> load("meta_patch", 4)(meta, className, field, isStatic == true)); - #else - metaPatch(meta, className, field, isStatic == true); - #end - } - /** Add a class path where ".hx" source files or packages (sub-directories) can be found. @@ -374,61 +319,6 @@ class Compiler { }); } - /** - Load a type patch file that can modify the field types within declared classes and enums. - **/ - public static function patchTypes(file:String):Void { - var file = Context.resolvePath(file); - var f = sys.io.File.read(file, true); - try { - while (true) { - var r = StringTools.trim(f.readLine()); - if (r == "" || r.substr(0, 2) == "//") - continue; - if (StringTools.endsWith(r, ";")) - r = r.substr(0, -1); - if (r.charAt(0) == "-") { - r = r.substr(1); - var isStatic = StringTools.startsWith(r, "static "); - if (isStatic) - r = r.substr(7); - var p = r.split("."); - var field = p.pop(); - removeField(p.join("."), field, isStatic); - continue; - } - if (r.charAt(0) == "@") { - var rp = r.split(" "); - var type = rp.pop(); - var isStatic = rp[rp.length - 1] == "static"; - if (isStatic) - rp.pop(); - var meta = rp.join(" "); - var p = type.split("."); - var field = if (p.length > 1 && p[p.length - 2].charAt(0) >= "a") null else p.pop(); - addMetadata(meta, p.join("."), field, isStatic); - continue; - } - if (StringTools.startsWith(r, "enum ")) { - define("enumAbstract:" + r.substr(5)); - continue; - } - var rp = r.split(" : "); - if (rp.length > 1) { - r = rp.shift(); - var isStatic = StringTools.startsWith(r, "static "); - if (isStatic) - r = r.substr(7); - var p = r.split("."); - var field = p.pop(); - setFieldType(p.join("."), field, rp.join(" : "), isStatic); - continue; - } - throw "Invalid type patch " + r; - } - } catch (e:haxe.io.Eof) {} - } - /** Marks types or packages to be kept by DCE. @@ -487,6 +377,11 @@ class Compiler { #end } + public static function addMetadata(meta:String, className:String, ?field:String, ?isStatic:Bool) { + var pathFilter = field == null ? className : '$className.$field'; + addGlobalMetadata(pathFilter, meta, true, field == null, field != null); + } + /** Reference a json file describing user-defined metadata See https://github.com/HaxeFoundation/haxe/blob/development/src-json/meta.json diff --git a/tests/misc/es6/Test.hx b/tests/misc/es6/Test.hx index 4fec1638c16..7592383dc77 100644 --- a/tests/misc/es6/Test.hx +++ b/tests/misc/es6/Test.hx @@ -32,7 +32,7 @@ class F extends E { } extern class ExtNoCtor { - static function __init__():Void haxe.macro.Compiler.includeFile("./extern.js", "top"); + static function __init__():Void haxe.macro.Compiler.includeFile("./extern.js"); } class Base extends ExtNoCtor { diff --git a/tests/misc/projects/Issue10844/user-defined-define-json-fail.hxml.stderr b/tests/misc/projects/Issue10844/user-defined-define-json-fail.hxml.stderr index 1e7dc411b9f..71888302865 100644 --- a/tests/misc/projects/Issue10844/user-defined-define-json-fail.hxml.stderr +++ b/tests/misc/projects/Issue10844/user-defined-define-json-fail.hxml.stderr @@ -1,3 +1,3 @@ (unknown) : Uncaught exception Could not read file define.jsno -$$normPath(::std::)/haxe/macro/Compiler.hx:506: characters 11-39 : Called from here +$$normPath(::std::)/haxe/macro/Compiler.hx:401: characters 11-39 : Called from here (unknown) : Called from here diff --git a/tests/misc/projects/Issue10844/user-defined-meta-json-fail.hxml.stderr b/tests/misc/projects/Issue10844/user-defined-meta-json-fail.hxml.stderr index 3e26bc6c365..9f77e04b2fb 100644 --- a/tests/misc/projects/Issue10844/user-defined-meta-json-fail.hxml.stderr +++ b/tests/misc/projects/Issue10844/user-defined-meta-json-fail.hxml.stderr @@ -1,3 +1,3 @@ (unknown) : Uncaught exception Could not read file meta.jsno -$$normPath(::std::)/haxe/macro/Compiler.hx:495: characters 11-39 : Called from here +$$normPath(::std::)/haxe/macro/Compiler.hx:390: characters 11-39 : Called from here (unknown) : Called from here diff --git a/tests/misc/projects/Issue10844/user-defined-meta-json-indent-fail.hxml.stderr b/tests/misc/projects/Issue10844/user-defined-meta-json-indent-fail.hxml.stderr index 4e87b73bfb0..5a81672cb2a 100644 --- a/tests/misc/projects/Issue10844/user-defined-meta-json-indent-fail.hxml.stderr +++ b/tests/misc/projects/Issue10844/user-defined-meta-json-indent-fail.hxml.stderr @@ -1,3 +1,3 @@ (unknown) : Uncaught exception Could not read file meta.jsno - $$normPath(::std::)/haxe/macro/Compiler.hx:495: characters 11-39 : Called from here + $$normPath(::std::)/haxe/macro/Compiler.hx:390: characters 11-39 : Called from here (unknown) : Called from here diff --git a/tests/misc/projects/Issue10844/user-defined-meta-json-pretty-fail.hxml.stderr b/tests/misc/projects/Issue10844/user-defined-meta-json-pretty-fail.hxml.stderr index 29619b177df..6c235767c49 100644 --- a/tests/misc/projects/Issue10844/user-defined-meta-json-pretty-fail.hxml.stderr +++ b/tests/misc/projects/Issue10844/user-defined-meta-json-pretty-fail.hxml.stderr @@ -2,9 +2,9 @@ | Uncaught exception Could not read file meta.jsno - -> $$normPath(::std::)/haxe/macro/Compiler.hx:495: characters 11-39 + -> $$normPath(::std::)/haxe/macro/Compiler.hx:390: characters 11-39 - 495 | var f = sys.io.File.getContent(path); + 390 | var f = sys.io.File.getContent(path); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | Called from here diff --git a/tests/misc/projects/Issue4660/Include.hx b/tests/misc/projects/Issue4660/Include.hx index f738186b431..90825a58f7e 100644 --- a/tests/misc/projects/Issue4660/Include.hx +++ b/tests/misc/projects/Issue4660/Include.hx @@ -1,5 +1,5 @@ class Include { static function use() { - haxe.macro.Compiler.includeFile("include.js", Top); + haxe.macro.Compiler.includeFile("include.js"); } } diff --git a/tests/misc/projects/Issue8567/compile.hxml b/tests/misc/projects/Issue8567/compile.hxml deleted file mode 100644 index eb9ce292099..00000000000 --- a/tests/misc/projects/Issue8567/compile.hxml +++ /dev/null @@ -1,3 +0,0 @@ --cp src --main Main ---macro patchTypes("src/test.txt") \ No newline at end of file diff --git a/tests/misc/projects/Issue8567/src/Main.hx b/tests/misc/projects/Issue8567/src/Main.hx deleted file mode 100644 index 17c7d3e7b5d..00000000000 --- a/tests/misc/projects/Issue8567/src/Main.hx +++ /dev/null @@ -1,4 +0,0 @@ -class Main { - static function main() { - } -} diff --git a/tests/misc/projects/Issue8567/src/test.txt b/tests/misc/projects/Issue8567/src/test.txt deleted file mode 100644 index e69de29bb2d..00000000000