Jelajahi Sumber

[typer] use stored typed expressions for @:this this

see #10793
Simon Krajewski 2 tahun lalu
induk
melakukan
d42ce55f0b

+ 8 - 10
src/context/typecore.ml

@@ -101,7 +101,6 @@ and typer = {
 	g : typer_globals;
 	g : typer_globals;
 	mutable bypass_accessor : int;
 	mutable bypass_accessor : int;
 	mutable meta : metadata;
 	mutable meta : metadata;
-	mutable this_stack : texpr list;
 	mutable with_type_stack : WithType.t list;
 	mutable with_type_stack : WithType.t list;
 	mutable call_argument_stack : expr list list;
 	mutable call_argument_stack : expr list list;
 	(* variable *)
 	(* variable *)
@@ -440,14 +439,6 @@ let create_fake_module ctx file =
 	ctx.com.module_lut#add mdep.m_path mdep;
 	ctx.com.module_lut#add mdep.m_path mdep;
 	mdep
 	mdep
 
 
-let push_this ctx e = match e.eexpr with
-	| TConst ((TInt _ | TFloat _ | TString _ | TBool _) as ct) ->
-		(EConst (tconst_to_const ct),e.epos),fun () -> ()
-	| _ ->
-		ctx.this_stack <- e :: ctx.this_stack;
-		let er = EMeta((Meta.This,[],e.epos), (EConst(Ident "this"),e.epos)),e.epos in
-		er,fun () -> ctx.this_stack <- List.tl ctx.this_stack
-
 let is_removable_field com f =
 let is_removable_field com f =
 	not (has_class_field_flag f CfOverride) && (
 	not (has_class_field_flag f CfOverride) && (
 		has_class_field_flag f CfExtern || has_class_field_flag f CfGeneric
 		has_class_field_flag f CfExtern || has_class_field_flag f CfGeneric
@@ -713,7 +704,14 @@ let store_typed_expr com te p =
 	let id = get_next_stored_typed_expr_id() in
 	let id = get_next_stored_typed_expr_id() in
 	com.stored_typed_exprs#add id te;
 	com.stored_typed_exprs#add id te;
 	let eid = (EConst (Int (string_of_int id, None))), p in
 	let eid = (EConst (Int (string_of_int id, None))), p in
-	(EMeta ((Meta.StoredTypedExpr,[],p), eid)), p
+	id,((EMeta ((Meta.StoredTypedExpr,[],p), eid)),p)
+
+let push_this ctx e = match e.eexpr with
+| TConst ((TInt _ | TFloat _ | TString _ | TBool _) as ct) ->
+	(EConst (tconst_to_const ct),e.epos),fun () -> ()
+| _ ->
+	let id,er = store_typed_expr ctx.com e e.epos in
+	er,fun () -> ctx.com.stored_typed_exprs#remove id
 
 
 (* -------------- debug functions to activate when debugging typer passes ------------------------------- *)
 (* -------------- debug functions to activate when debugging typer passes ------------------------------- *)
 (*/*
 (*/*

+ 2 - 3
src/typing/callUnification.ml

@@ -585,10 +585,9 @@ object(self)
 			| [] ->
 			| [] ->
 				self#macro_call fa.fa_on fa.fa_field el
 				self#macro_call fa.fa_on fa.fa_field el
 			| el_typed ->
 			| el_typed ->
-				let cur = ctx.this_stack in
-				let el' = List.map (fun e -> fst (push_this ctx e)) el_typed in
+				let el',fl = List.split (List.map (fun e -> push_this ctx e) el_typed) in
 				let e = self#macro_call fa.fa_on fa.fa_field (el' @ el) in
 				let e = self#macro_call fa.fa_on fa.fa_field (el' @ el) in
-				ctx.this_stack <- cur;
+				List.iter (fun f -> f()) fl;
 				e
 				e
 			end;
 			end;
 		| Var v ->
 		| Var v ->

+ 1 - 1
src/typing/macroContext.ml

@@ -205,7 +205,7 @@ let make_macro_api ctx p =
 		);
 		);
 		MacroApi.store_typed_expr = (fun te ->
 		MacroApi.store_typed_expr = (fun te ->
 			let p = te.epos in
 			let p = te.epos in
-			Typecore.store_typed_expr ctx.com te p
+			snd (Typecore.store_typed_expr ctx.com te p)
 		);
 		);
 		MacroApi.allow_package = (fun v -> Common.allow_package ctx.com v);
 		MacroApi.allow_package = (fun v -> Common.allow_package ctx.com v);
 		MacroApi.type_patch = (fun t f s v ->
 		MacroApi.type_patch = (fun t f s v ->

+ 0 - 1
src/typing/typeloadModule.ml

@@ -715,7 +715,6 @@ let create_typer_context_for_module ctx m = {
 		is_display_file = (ctx.com.display.dms_kind <> DMNone && DisplayPosition.display_position#is_in_file (Path.UniqueKey.lazy_key m.m_extra.m_file));
 		is_display_file = (ctx.com.display.dms_kind <> DMNone && DisplayPosition.display_position#is_in_file (Path.UniqueKey.lazy_key m.m_extra.m_file));
 		bypass_accessor = 0;
 		bypass_accessor = 0;
 		meta = [];
 		meta = [];
-		this_stack = [];
 		with_type_stack = [];
 		with_type_stack = [];
 		call_argument_stack = [];
 		call_argument_stack = [];
 		pass = PBuildModule;
 		pass = PBuildModule;

+ 1 - 12
src/typing/typer.ml

@@ -1460,7 +1460,7 @@ and type_array_decl ctx el with_type p =
 and type_array_comprehension ctx e with_type p =
 and type_array_comprehension ctx e with_type p =
 	let v = gen_local ctx (spawn_monomorph ctx p) p in
 	let v = gen_local ctx (spawn_monomorph ctx p) p in
 	let ev = mk (TLocal v) v.v_type p in
 	let ev = mk (TLocal v) v.v_type p in
-	let e_ref = store_typed_expr ctx.com ev p in
+	let e_ref = snd (store_typed_expr ctx.com ev p) in
 	let et = ref (EConst(Ident "null"),p) in
 	let et = ref (EConst(Ident "null"),p) in
 	let comprehension_pos = p in
 	let comprehension_pos = p in
 	let rec map_compr (e,p) =
 	let rec map_compr (e,p) =
@@ -1616,16 +1616,6 @@ and type_meta ?(mode=MGet) ctx m e1 with_type p =
 				| _ -> e)
 				| _ -> e)
 		| (Meta.Markup,_,_) ->
 		| (Meta.Markup,_,_) ->
 			typing_error "Markup literals must be processed by a macro" p
 			typing_error "Markup literals must be processed by a macro" p
-		| (Meta.This,_,_) ->
-			let e = match ctx.this_stack with
-				| [] -> typing_error "Cannot type @:this this here" p
-				| e :: _ -> e
-			in
-			let rec loop e = match e.eexpr with
-				| TConst TThis -> get_this ctx e.epos
-				| _ -> Type.map_expr loop e
-			in
-			loop e
 		| (Meta.Analyzer,_,_) ->
 		| (Meta.Analyzer,_,_) ->
 			let e = e() in
 			let e = e() in
 			{e with eexpr = TMeta(m,e)}
 			{e with eexpr = TMeta(m,e)}
@@ -2056,7 +2046,6 @@ let rec create com =
 		is_display_file = false;
 		is_display_file = false;
 		bypass_accessor = 0;
 		bypass_accessor = 0;
 		meta = [];
 		meta = [];
-		this_stack = [];
 		with_type_stack = [];
 		with_type_stack = [];
 		call_argument_stack = [];
 		call_argument_stack = [];
 		pass = PBuildModule;
 		pass = PBuildModule;