Explorar o código

change mono byte to 1, avoid extra 1 byte for immediate type instance values

Simon Krajewski hai 1 ano
pai
achega
cc3d24a4b8
Modificáronse 2 ficheiros con 37 adicións e 41 borrados
  1. 7 13
      src/compiler/hxb/hxbReader.ml
  2. 30 28
      src/compiler/hxb/hxbWriter.ml

+ 7 - 13
src/compiler/hxb/hxbReader.ml

@@ -622,19 +622,15 @@ class hxb_reader
 			die "" __LOC__
 
 	method read_type_instance =
-		let kind = self#read_u8 in
+		self#process_type_instance (self#read_u8)
 
+	method process_type_instance (kind : int) =
 		match kind with
-		| 0 ->
+		| 1 ->
 			let i = self#read_uleb128 in
 			tmonos.(i)
-		(* Bound monomorphs directly write their underlying type *)
-		(* | 1 -> *)
-		(* 	let t = self#read_type_instance in *)
-		(* 	let tmono = !monomorph_create_ref () in (1* TODO identity *1) *)
-		(* 	tmono.tm_type <- Some t; *)
-		(* 	TMono tmono; *)
-		| 5 | 6 | 7 -> (self#resolve_ttp_ref kind).ttp_type
+		| 5 | 6 | 7 ->
+			(self#resolve_ttp_ref kind).ttp_type
 		| 8 ->
 			let e = self#read_expr in
 			let c = {null_class with cl_kind = KExpr e; cl_module = current_module } in
@@ -835,12 +831,10 @@ class hxb_reader
 			let t = match self#read_u8 with
 				| 0 ->
 					DynArray.get fctx.t_pool self#read_uleb128
-				| 1 ->
-					let t = self#read_type_instance in
+				| i ->
+					let t = self#process_type_instance i in
 					DynArray.add fctx.t_pool t;
 					t
-				| _ ->
-					die "" __LOC__
 			in
 			let rec loop2 () =
 				match IO.read_byte ch with

+ 30 - 28
src/compiler/hxb/hxbWriter.ml

@@ -921,7 +921,7 @@ class hxb_writer
 			Monomorph.close r;
 			begin match r.tm_type with
 			| None ->
-				self#write_type_instance_byte 0;
+				self#write_type_instance_byte 1;
 				self#write_tmono_ref r
 			| Some t ->
 				(* Don't write bound monomorphs, write underlying type directly *)
@@ -1031,7 +1031,33 @@ class hxb_writer
 		self#write_metadata v.v_meta;
 		self#write_pos v.v_pos
 
-	method write_texpr fctx (e : texpr) =
+	method write_texpr_type_instance (fctx : field_writer_context) (t: Type.t) =
+		let ring = fctx.t_rings#get_ring t in
+		try
+			let index = fctx.t_rings#find ring t in
+			incr stats.type_instance_ring_hits;
+			chunk#write_u8 0;
+			chunk#write_uleb128 index;
+		with Not_found ->
+			let restore = self#start_temporary_chunk in
+			self#write_type_instance t;
+			let t_bytes = restore (fun chunk new_chunk ->
+				new_chunk#get_bytes
+			) in
+			let index = try
+				let index = fctx.t_pool#get t_bytes in
+				incr stats.type_instance_cache_hits;
+				chunk#write_u8 0;
+				chunk#write_uleb128 index;
+				index
+			with Not_found ->
+				incr stats.type_instance_cache_misses;
+				chunk#write_bytes t_bytes;
+				fctx.t_pool#add t_bytes ()
+			in
+			Ring.push ring (t,index)
+
+	method write_texpr (fctx : field_writer_context) (e : texpr) =
 		let declare_var v =
 			chunk#write_uleb128 (fctx.vars#add v.v_id v);
 			chunk#write_option v.v_extra (fun ve ->
@@ -1044,32 +1070,8 @@ class hxb_writer
 			self#write_type_instance v.v_type;
 		in
 		let rec loop e =
-			let ring = fctx.t_rings#get_ring e.etype in
-			begin try
-				let index = fctx.t_rings#find ring e.etype in
-				incr stats.type_instance_ring_hits;
-				chunk#write_u8 0;
-				chunk#write_uleb128 index;
-			with Not_found ->
-				let restore = self#start_temporary_chunk in
-				self#write_type_instance e.etype;
-				let t_bytes = restore (fun chunk new_chunk ->
-					new_chunk#get_bytes
-				) in
-				let index = try
-					let index = fctx.t_pool#get t_bytes in
-					incr stats.type_instance_cache_hits;
-					chunk#write_u8 0;
-					chunk#write_uleb128 index;
-					index
-				with Not_found ->
-					incr stats.type_instance_cache_misses;
-					chunk#write_u8 1;
-					chunk#write_bytes t_bytes;
-					fctx.t_pool#add t_bytes ()
-				in
-				Ring.push ring (e.etype,index)
-			end;
+
+			self#write_texpr_type_instance fctx e.etype;
 			fctx.pos_writer#write_pos 240 e.epos;
 
 			match e.eexpr with