ソースを参照

add MDR to deal with import to @:keep

Simon Krajewski 1 年間 前
コミット
7603234fd4

+ 3 - 0
src/compiler/hxb/hxbData.ml

@@ -27,6 +27,7 @@ type chunk_kind =
 	| MDF (* module foward *)
 	| MTF (* module types forward *)
 	(* Module type references *)
+	| MDR (* module references *)
 	| CLR (* class references *)
 	| ENR (* enum references *)
 	| ABR (* abstract references *)
@@ -65,6 +66,7 @@ let string_of_chunk_kind = function
 	| DOC -> "DOC"
 	| MDF -> "MDF"
 	| MTF -> "MTF"
+	| MDR -> "MDR"
 	| CLR -> "CLR"
 	| ENR -> "ENR"
 	| ABR -> "ABR"
@@ -89,6 +91,7 @@ let chunk_kind_of_string = function
 	| "DOC" -> DOC
 	| "MDF" -> MDF
 	| "MTF" -> MTF
+	| "MDR" -> MDR
 	| "CLR" -> CLR
 	| "ENR" -> ENR
 	| "ABR" -> ABR

+ 9 - 0
src/compiler/hxb/hxbReader.ml

@@ -1765,6 +1765,13 @@ class hxb_reader
 				error ("Unexpected type where typedef was expected: " ^ (s_type_path (pack,tname)))
 		))
 
+	method read_mdr =
+		let length = read_uleb128 ch in
+		for i = 0 to length - 1 do
+			let path = self#read_path in
+			ignore(api#resolve_module path)
+		done
+
 	method read_mtf =
 		self#read_list (fun () ->
 			let kind = read_byte ch in
@@ -1871,6 +1878,8 @@ class hxb_reader
 		| MTF ->
 			current_module.m_types <- self#read_mtf;
 			api#add_module current_module;
+		| MDR ->
+			self#read_mdr;
 		| CLR ->
 			self#read_clr;
 		| ENR ->

+ 1 - 0
src/compiler/hxb/hxbReaderApi.ml

@@ -5,6 +5,7 @@ class virtual hxb_reader_api = object(self)
 	method virtual make_module : path -> string -> module_def
 	method virtual add_module : module_def -> unit
 	method virtual resolve_type : string list -> string -> string -> module_type
+	method virtual resolve_module : path -> module_def
 	method virtual basic_types : basic_types
 	method virtual get_var_id : int -> int
 	method virtual read_expression_eagerly : tclass_field -> bool

+ 20 - 1
src/compiler/hxb/hxbWriter.ml

@@ -532,7 +532,7 @@ module HxbWriter = struct
 		let initial_size = match kind with
 			| EOT | EOF | EOM -> 0
 			| MDF -> 16
-			| MTF | CLR | END | ABD | ENR | ABR | TDR | EFR | CFR | AFD -> 64
+			| MTF | MDR | CLR | END | ABD | ENR | ABR | TDR | EFR | CFR | AFD -> 64
 			| AFR | CLD | TDD | EFD -> 128
 			| STR | DOC -> 256
 			| CFD | EXD -> 512
@@ -2204,6 +2204,25 @@ module HxbWriter = struct
 		Chunk.write_string writer.chunk (Path.UniqueKey.lazy_path m.m_extra.m_file);
 		Chunk.write_uleb128 writer.chunk (DynArray.length (Pool.items writer.anons));
 		Chunk.write_uleb128 writer.chunk (DynArray.length (IdentityPool.items writer.tmonos));
+
+		begin
+			let deps = DynArray.create () in
+			PMap.iter (fun _ (sign,path) ->
+				if sign = m.m_extra.m_sign then begin
+					(* TODO: We probably need module_kind in m_deps to handle this properly. *)
+					if not (ExtString.String.ends_with (snd path) "import.hx") then
+						DynArray.add deps path;
+				end
+			) m.m_extra.m_deps;
+			if DynArray.length deps > 0 then begin
+				start_chunk writer MDR;
+				Chunk.write_uleb128 writer.chunk (DynArray.length deps);
+				DynArray.iter (fun path ->
+					write_path writer path
+				) deps
+			end
+		end;
+
 		start_chunk writer EOT;
 		start_chunk writer EOF;
 		start_chunk writer EOM;

+ 25 - 23
src/compiler/server.ml

@@ -412,31 +412,33 @@ class hxb_reader_api_server
 
 	method resolve_type (pack : string list) (mname : string) (tname : string) =
 		let path = (pack,mname) in
-		let m = match self#find_module path with
-			| GoodModule m ->
-				m
-			| BinaryModule mc ->
-				let reader = new HxbReader.hxb_reader path ctx.com.hxb_reader_stats in
-				let f_next chunks until =
-					let t_hxb = Timer.timer ["server";"module cache";"hxb read"] in
-					let r = reader#read_chunks_until (self :> HxbReaderApi.hxb_reader_api) chunks until in
-					t_hxb();
-					r
-				in
-				let m,chunks = f_next mc.mc_chunks EOF in
-
-				(* We try to avoid reading expressions as much as possible, so we only do this for
-					 our current display file if we're in display mode. *)
-				let is_display_file = DisplayPosition.display_position#is_in_file (Path.UniqueKey.lazy_key m.m_extra.m_file) in
-				if is_display_file || ctx.com.display.dms_full_typing then ignore(f_next chunks EOM);
-				m
-			| BadModule reason ->
-				die (Printf.sprintf "Unexpected BadModule %s" (s_type_path path)) __LOC__
-			| NoModule ->
-				die (Printf.sprintf "Unexpected NoModule %s" (s_type_path path)) __LOC__
-		in
+		let m = self#resolve_module path in
 		List.find (fun t -> snd (t_path t) = tname) m.m_types
 
+	method resolve_module (path : path) =
+		match self#find_module path with
+		| GoodModule m ->
+			m
+		| BinaryModule mc ->
+			let reader = new HxbReader.hxb_reader path ctx.com.hxb_reader_stats in
+			let f_next chunks until =
+				let t_hxb = Timer.timer ["server";"module cache";"hxb read"] in
+				let r = reader#read_chunks_until (self :> HxbReaderApi.hxb_reader_api) chunks until in
+				t_hxb();
+				r
+			in
+			let m,chunks = f_next mc.mc_chunks EOF in
+
+			(* We try to avoid reading expressions as much as possible, so we only do this for
+				 our current display file if we're in display mode. *)
+			let is_display_file = DisplayPosition.display_position#is_in_file (Path.UniqueKey.lazy_key m.m_extra.m_file) in
+			if is_display_file || ctx.com.display.dms_full_typing then ignore(f_next chunks EOM);
+			m
+		| BadModule reason ->
+			die (Printf.sprintf "Unexpected BadModule %s" (s_type_path path)) __LOC__
+		| NoModule ->
+			die (Printf.sprintf "Unexpected NoModule %s" (s_type_path path)) __LOC__
+
 	method find_module (m_path : path) =
 		try
 			GoodModule (ctx.com.module_lut#find m_path)

+ 3 - 1
src/context/display/displayJson.ml

@@ -124,10 +124,12 @@ class hxb_reader_api_com
 
 	method resolve_type (pack : string list) (mname : string) (tname : string) =
 		let path = (pack,mname) in
-
 		let m = self#find_module path in
 		List.find (fun t -> snd (t_path t) = tname) m.m_types
 
+	method resolve_module (path : path) =
+		self#find_module path
+
 	method find_module (m_path : path) =
 		try
 			com.module_lut#find m_path

+ 3 - 0
src/typing/typeloadModule.ml

@@ -791,6 +791,9 @@ class hxb_reader_api_typeload
 		let m = load_module ctx (pack,mname) p in
 		List.find (fun t -> snd (t_path t) = tname) m.m_types
 
+	method resolve_module (path : path) =
+		load_module ctx path p
+
 	method basic_types =
 		ctx.com.basic
 

+ 0 - 2
std/jvm/Jvm.hx

@@ -40,8 +40,6 @@ import jvm.annotation.EnumValueReflectionInformation;
 @:keep
 @:native('haxe.jvm.Jvm')
 class Jvm {
-	extern static final init:java.Init;
-
 	extern static public function instanceof<S, T>(obj:S, type:T):Bool;
 
 	extern static public function referenceEquals<T>(v1:T, v2:T):Bool;