Ver código fonte

[filters] remove some typecore dependencies

Simon Krajewski 3 anos atrás
pai
commit
67324b5647

+ 1 - 10
src/compiler/compiler.ml

@@ -331,7 +331,7 @@ let generate tctx ext actx =
 	end;
 	if Common.defined com Define.DumpDependencies then begin
 		Codegen.Dump.dump_dependencies com;
-		if not tctx.Typecore.in_macro then match tctx.Typecore.g.Typecore.macros with
+		if not com.is_macro_context then match tctx.Typecore.g.Typecore.macros with
 			| None -> ()
 			| Some(_,ctx) -> Codegen.Dump.dump_dependencies ~target_override:(Some "macro") ctx.Typecore.com
 	end;
@@ -663,15 +663,6 @@ with
 		error ctx ("Error: " ^ msg) null_pos
 	| Helper.HelpMessage msg ->
 		com.info msg null_pos
-	(* | Parser.TypePath (_,_,_,p) when ctx.com.json_out <> None ->
-		begin match com.json_out with
-		| Some (f,_) ->
-			let tctx = Typer.create ctx.com in
-			let fields = DisplayToplevel.collect tctx true Typecore.NoValue in
-			let jctx = Genjson.create_context Genjson.GMMinimum in
-			f (DisplayException.fields_to_json jctx fields CRImport (Some (Parser.cut_pos_at_display p)) false)
-		| _ -> die "" __LOC__
-		end *)
 	| Parser.TypePath (p,c,is_import,pos) ->
 		let fields =
 			try begin match c with

+ 2 - 2
src/compiler/server.ml

@@ -341,7 +341,7 @@ let check_module sctx ctx m p =
 				loop com.load_extern_type
 			| MCode ->
 				check_module_shadowing directories m
-			| MMacro when ctx.Typecore.in_macro ->
+			| MMacro when com.is_macro_context ->
 				check_module_shadowing directories m
 			| MMacro ->
 				(*
@@ -350,7 +350,7 @@ let check_module sctx ctx m p =
 					Prevents spending another 5 hours for debugging.
 					@see https://github.com/HaxeFoundation/haxe/issues/8174
 				*)
-				if not ctx.g.complete && ctx.in_macro then
+				if not ctx.g.complete && ctx.com.is_macro_context then
 					raise (ServerError ("Infinite loop in Haxe server detected. "
 						^ "Probably caused by shadowing a module of the standard library. "
 						^ "Make sure shadowed module does not pull macro context."));

+ 4 - 1
src/context/common.ml

@@ -350,6 +350,7 @@ type context = {
 	mutable c_args : string list;
 	mutable js_gen : (unit -> unit) option;
 	mutable json_out : json_api option;
+	is_macro_context : bool;
 	(* typing *)
 	mutable basic : basic_types;
 	memory_marker : float array;
@@ -788,6 +789,7 @@ let create compilation_step cs version args =
 		json_out = None;
 		has_error = false;
 		report_mode = RMNone;
+		is_macro_context = false;
 	}
 
 let is_diagnostics com = match com.report_mode with
@@ -802,7 +804,7 @@ let disable_report_mode com =
 let log com str =
 	if com.verbose then com.print (str ^ "\n")
 
-let clone com =
+let clone com is_macro_context =
 	let t = com.basic in
 	{ com with
 		cache = None;
@@ -825,6 +827,7 @@ let clone com =
 		};
 		native_libs = create_native_libs();
 		overload_cache = Hashtbl.create 0;
+		is_macro_context = is_macro_context;
 	}
 
 let file_time file = Extc.filetime file

+ 3 - 4
src/context/typecore.ml

@@ -125,7 +125,6 @@ and typer = {
 	mutable in_function : bool;
 	mutable in_loop : bool;
 	mutable in_display : bool;
-	mutable in_macro : bool;
 	mutable macro_depth : int;
 	mutable curfun : current_fun;
 	mutable ret : t;
@@ -462,12 +461,12 @@ let push_this ctx e = match e.eexpr with
 		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 ctx f =
+let is_removable_field com f =
 	not (has_class_field_flag f CfOverride) && (
 		has_class_field_flag f CfExtern || has_class_field_flag f CfGeneric
 		|| (match f.cf_kind with
 			| Var {v_read = AccRequire (s,_)} -> true
-			| Method MethMacro -> not ctx.in_macro
+			| Method MethMacro -> not com.is_macro_context
 			| _ -> false)
 	)
 
@@ -648,7 +647,7 @@ let relative_path ctx file =
 	loop ctx.com.Common.class_path
 
 let mk_infos ctx p params =
-	let file = if ctx.in_macro then p.pfile else if Common.defined ctx.com Define.AbsolutePath then Path.get_full_path p.pfile else relative_path ctx p.pfile in
+	let file = if ctx.com.is_macro_context then p.pfile else if Common.defined ctx.com Define.AbsolutePath then Path.get_full_path p.pfile else relative_path ctx p.pfile in
 	(EObjectDecl (
 		(("fileName",null_pos,NoQuotes) , (EConst (String(file,SDoubleQuotes)) , p)) ::
 		(("lineNumber",null_pos,NoQuotes) , (EConst (Int (string_of_int (Lexer.get_error_line p), None)),p)) ::

+ 17 - 17
src/filters/filters.ml

@@ -416,16 +416,16 @@ let remove_generic_base ctx t = match t with
 
 (* Removes extern and macro fields, also checks for Void fields *)
 
-let remove_extern_fields ctx t = match t with
+let remove_extern_fields com t = match t with
 	| TClassDecl c ->
-		if not (Common.defined ctx.com Define.DocGen) then begin
+		if not (Common.defined com Define.DocGen) then begin
 			c.cl_ordered_fields <- List.filter (fun f ->
-				let b = is_removable_field ctx f in
+				let b = is_removable_field com f in
 				if b then c.cl_fields <- PMap.remove f.cf_name c.cl_fields;
 				not b
 			) c.cl_ordered_fields;
 			c.cl_ordered_statics <- List.filter (fun f ->
-				let b = is_removable_field ctx f in
+				let b = is_removable_field com f in
 				if b then c.cl_statics <- PMap.remove f.cf_name c.cl_statics;
 				not b
 			) c.cl_ordered_statics;
@@ -526,7 +526,7 @@ let add_rtti ctx t =
 		()
 
 (* Adds member field initializations as assignments to the constructor *)
-let add_field_inits locals ctx t =
+let add_field_inits cl_path locals com t =
 	let apply c =
 		let ethis = mk (TConst TThis) (TInst (c,extract_param_types c.cl_params)) c.cl_pos in
 		(* TODO: we have to find a variable name which is not used in any of the functions *)
@@ -552,11 +552,11 @@ let add_field_inits locals ctx t =
 			let el = if !need_this then (mk (TVar((v, Some ethis))) ethis.etype ethis.epos) :: el else el in
 			let cf = match c.cl_constructor with
 			| None ->
-				let ct = TFun([],ctx.com.basic.tvoid) in
+				let ct = TFun([],com.basic.tvoid) in
 				let ce = mk (TFunction {
 					tf_args = [];
-					tf_type = ctx.com.basic.tvoid;
-					tf_expr = mk (TBlock el) ctx.com.basic.tvoid c.cl_pos;
+					tf_type = com.basic.tvoid;
+					tf_expr = mk (TBlock el) com.basic.tvoid c.cl_pos;
 				}) ct c.cl_pos in
 				let ctor = mk_field "new" ct c.cl_pos null_pos in
 				ctor.cf_kind <- Method MethNormal;
@@ -565,18 +565,18 @@ let add_field_inits locals ctx t =
 				match cf.cf_expr with
 				| Some { eexpr = TFunction f } ->
 					let bl = match f.tf_expr with {eexpr = TBlock b } -> b | x -> [x] in
-					let ce = mk (TFunction {f with tf_expr = mk (TBlock (el @ bl)) ctx.com.basic.tvoid c.cl_pos }) cf.cf_type cf.cf_pos in
+					let ce = mk (TFunction {f with tf_expr = mk (TBlock (el @ bl)) com.basic.tvoid c.cl_pos }) cf.cf_type cf.cf_pos in
 					{cf with cf_expr = Some ce };
 				| _ ->
 					die "" __LOC__
 			in
-			let config = AnalyzerConfig.get_field_config ctx.com c cf in
-			Analyzer.Run.run_on_field ctx config c cf;
+			let config = AnalyzerConfig.get_field_config com c cf in
+			Analyzer.Run.run_on_field com config c cf;
 			(match cf.cf_expr with
 			| Some e ->
 				(* This seems a bit expensive, but hopefully constructor expressions aren't that massive. *)
-				let e = RenameVars.run ctx locals e in
-				let e = Optimizer.sanitize ctx.com e in
+				let e = RenameVars.run cl_path locals e in
+				let e = Optimizer.sanitize com e in
 				cf.cf_expr <- Some e
 			| _ ->
 				());
@@ -839,7 +839,7 @@ let run com tctx main =
 	List.iter (fun f -> List.iter f new_types) filters;
 	t();
 	com.stage <- CAnalyzerStart;
-	if com.platform <> Cross then Analyzer.Run.run_on_types tctx new_types;
+	if com.platform <> Cross then Analyzer.Run.run_on_types com new_types;
 	com.stage <- CAnalyzerDone;
 	let locals = RenameVars.init com in
 	let filters = [
@@ -847,7 +847,7 @@ let run com tctx main =
 		"add_final_return",if com.config.pf_add_final_return then add_final_return else (fun e -> e);
 		"RenameVars",(match com.platform with
 		| Eval -> (fun e -> e)
-		| _ -> RenameVars.run tctx locals);
+		| _ -> (fun e -> RenameVars.run tctx.curclass.cl_path locals e));
 		"mark_switch_break_loops",mark_switch_break_loops;
 	] in
 	List.iter (run_expression_filters (timer_label detail_times ["expr 2"]) tctx filters) new_types;
@@ -866,7 +866,7 @@ let run com tctx main =
 	(* PASS 2: type filters pre-DCE *)
 	List.iter (fun t ->
 		remove_generic_base tctx t;
-		remove_extern_fields tctx t;
+		remove_extern_fields com t;
 		Codegen.update_cache_dependencies t;
 		(* check @:remove metadata before DCE so it is ignored there (issue #2923) *)
 		check_remove_metadata tctx t;
@@ -898,7 +898,7 @@ let run com tctx main =
 		check_private_path;
 		apply_native_paths;
 		add_rtti;
-		(match com.platform with | Java | Cs -> (fun _ _ -> ()) | _ -> add_field_inits locals);
+		(match com.platform with | Java | Cs -> (fun _ _ -> ()) | _ -> (fun ctx -> add_field_inits ctx.curclass.cl_path locals ctx.com));
 		(match com.platform with Hl -> (fun _ _ -> ()) | _ -> add_meta_field);
 		check_void_field;
 		(match com.platform with | Cpp -> promote_first_interface_to_super | _ -> (fun _ _ -> ()) );

+ 1 - 1
src/filters/filtersCommon.ml

@@ -69,7 +69,7 @@ let run_expression_filters time_details ctx filters t =
 		let rec process_field f =
 			ctx.curfield <- f;
 			(match f.cf_expr with
-			| Some e when not (is_removable_field ctx f) ->
+			| Some e when not (is_removable_field ctx.com f) ->
 				f.cf_expr <- Some (rec_stack_loop AbstractCast.cast_stack f run e);
 			| _ -> ());
 			List.iter process_field f.cf_overloads

+ 2 - 2
src/filters/renameVars.ml

@@ -311,7 +311,7 @@ let rec rename_vars rc scope =
 (**
 	Rename local variables in `e` expression if needed.
 *)
-let run ctx ri e =
+let run cl_path ri e =
 	(try
 		let rc = {
 			rc_scope = ri.ri_scope;
@@ -322,7 +322,7 @@ let run ctx ri e =
 			rc_reserved = ri.ri_reserved;
 		} in
 		if ri.ri_reserve_current_top_level_symbol then begin
-			match ctx.curclass.cl_path with
+			match cl_path with
 			| s :: _,_ | [],s -> reserve_ctx rc s
 		end;
 		let scope = create_scope None in

+ 20 - 21
src/optimization/analyzer.ml

@@ -1053,14 +1053,14 @@ module Run = struct
 		end;
 		back_again actx is_real_function
 
-	let rec reduce_control_flow ctx e =
-		let e = Type.map_expr (reduce_control_flow ctx) e in
-		Optimizer.reduce_control_flow ctx e
-
-	let run_on_field ctx config c cf = match cf.cf_expr with
-		| Some e when not (is_ignored cf.cf_meta) && not (Typecore.is_removable_field ctx cf) ->
-			let config = update_config_from_meta ctx.Typecore.com config cf.cf_meta in
-			let actx = create_analyzer_context ctx.Typecore.com config e in
+	let rec reduce_control_flow com e =
+		let e = Type.map_expr (reduce_control_flow com) e in
+		Optimizer.reduce_control_flow com e
+
+	let run_on_field com config c cf = match cf.cf_expr with
+		| Some e when not (is_ignored cf.cf_meta) && not (Typecore.is_removable_field com cf) ->
+			let config = update_config_from_meta com config cf.cf_meta in
+			let actx = create_analyzer_context com config e in
 			let debug() =
 				print_endline (Printf.sprintf "While analyzing %s.%s" (s_type_path c.cl_path) cf.cf_name);
 				List.iter (fun (s,e) ->
@@ -1080,7 +1080,7 @@ module Run = struct
 				debug();
 				raise exc
 			in
-			let e = reduce_control_flow ctx e in
+			let e = reduce_control_flow com e in
 			begin match config.debug_kind with
 				| DebugNone -> ()
 				| DebugDot -> Debug.dot_debug actx c cf;
@@ -1089,15 +1089,15 @@ module Run = struct
 			cf.cf_expr <- Some e;
 		| _ -> ()
 
-	let run_on_field ctx config c cf =
-		run_on_field ctx config c cf;
-		List.iter (run_on_field ctx config c) cf.cf_overloads
+	let run_on_field com config c cf =
+		run_on_field com config c cf;
+		List.iter (run_on_field com config c) cf.cf_overloads
 
-	let run_on_class ctx config c =
-		let config = update_config_from_meta ctx.Typecore.com config c.cl_meta in
+	let run_on_class com config c =
+		let config = update_config_from_meta com config c.cl_meta in
 		let process_field stat cf = match cf.cf_kind with
 			| Var _ when not stat -> ()
-			| _ -> run_on_field ctx config c cf
+			| _ -> run_on_field com config c cf
 		in
 		List.iter (process_field false) c.cl_ordered_fields;
 		List.iter (process_field true) c.cl_ordered_statics;
@@ -1111,7 +1111,7 @@ module Run = struct
 			| Some e ->
 				let tf = { tf_args = []; tf_type = e.etype; tf_expr = e; } in
 				let e = mk (TFunction tf) (tfun [] e.etype) e.epos in
-				let actx = create_analyzer_context ctx.Typecore.com {config with optimize = false} e in
+				let actx = create_analyzer_context com {config with optimize = false} e in
 				let e = run_on_expr actx e in
 				let e = match e.eexpr with
 					| TFunction tf -> tf.tf_expr
@@ -1120,21 +1120,20 @@ module Run = struct
 				c.cl_init <- Some e
 		end
 
-	let run_on_type ctx config t =
+	let run_on_type com config t =
 		match t with
 		| TClassDecl c when (is_ignored c.cl_meta) -> ()
-		| TClassDecl c -> run_on_class ctx config c
+		| TClassDecl c -> run_on_class com config c
 		| TEnumDecl _ -> ()
 		| TTypeDecl _ -> ()
 		| TAbstractDecl _ -> ()
 
-	let run_on_types ctx types =
-		let com = ctx.Typecore.com in
+	let run_on_types com types =
 		let config = get_base_config com in
 		with_timer config.detail_times ["other"] (fun () ->
 			if config.optimize && config.purity_inference then
 				with_timer config.detail_times ["optimize";"purity-inference"] (fun () -> Purity.infer com);
-			List.iter (run_on_type ctx config) types
+			List.iter (run_on_type com config) types
 		)
 end
 ;;

+ 5 - 5
src/optimization/optimizer.ml

@@ -266,7 +266,7 @@ in
 			else
 				None
 
-let reduce_control_flow ctx e = match e.eexpr with
+let reduce_control_flow com e = match e.eexpr with
 	| TIf ({ eexpr = TConst (TBool t) },e1,e2) ->
 		(if t then e1 else match e2 with None -> { e with eexpr = TBlock [] } | Some e -> e)
 	| TWhile ({ eexpr = TConst (TBool false) },sub,flag) ->
@@ -291,10 +291,10 @@ let reduce_control_flow ctx e = match e.eexpr with
 		(try List.nth el i with Failure _ -> e)
 	| TCast(e1,None) ->
 		(* TODO: figure out what's wrong with these targets *)
-		let require_cast = match ctx.com.platform with
+		let require_cast = match com.platform with
 			| Cpp | Flash -> true
-			| Java -> defined ctx.com Define.Jvm
-			| Cs -> defined ctx.com Define.EraseGenerics || defined ctx.com Define.FastCast
+			| Java -> defined com Define.Jvm
+			| Cs -> defined com Define.EraseGenerics || defined com Define.FastCast
 			| _ -> false
 		in
 		Texpr.reduce_unsafe_casts ~require_cast e e.etype
@@ -337,7 +337,7 @@ let rec reduce_loop ctx e =
 				reduce_expr ctx e
 		end
 	| _ ->
-		reduce_expr ctx (reduce_control_flow ctx e))
+		reduce_expr ctx (reduce_control_flow ctx.com e))
 
 let reduce_expression ctx e =
 	if ctx.com.foptimize then

+ 1 - 1
src/typing/generic.ml

@@ -314,7 +314,7 @@ let rec build_generic ctx c p tl =
 		in
 		if c.cl_init <> None then typing_error "This class can't be generic" p;
 		List.iter (fun cf -> match cf.cf_kind with
-			| Method MethMacro when not ctx.in_macro -> ()
+			| Method MethMacro when not ctx.com.is_macro_context -> ()
 			| _ -> typing_error "A generic class can't have static fields" cf.cf_pos
 		) c.cl_ordered_statics;
 		cg.cl_super <- (match c.cl_super with

+ 5 - 5
src/typing/macroContext.ml

@@ -309,7 +309,7 @@ let make_macro_api ctx p =
 			in
 			add false ctx;
 			(* if we are adding a class which has a macro field, we also have to add it to the macro context (issue #1497) *)
-			if not ctx.in_macro then match tdef with
+			if not ctx.com.is_macro_context then match tdef with
 			| EClass c when List.exists (fun cff -> (Meta.has Meta.Macro cff.cff_meta || List.mem_assoc AMacro cff.cff_access)) c.d_data ->
 				add true mctx
 			| _ ->
@@ -474,7 +474,7 @@ and flush_macro_context mint ctx =
 	let type_filters = [
 		Filters.remove_generic_base mctx;
 		Exceptions.patch_constructors mctx;
-		Filters.add_field_inits (RenameVars.init mctx.com) mctx;
+		(fun mt -> Filters.add_field_inits mctx.curclass.cl_path (RenameVars.init mctx.com) mctx.com mt);
 		minimal_restore;
 		Filters.apply_native_paths mctx
 	] in
@@ -516,7 +516,7 @@ let get_macro_context ctx p =
 		select();
 		api, ctx
 	| None ->
-		let com2 = Common.clone ctx.com in
+		let com2 = Common.clone ctx.com true in
 		ctx.com.get_macros <- (fun() -> Some com2);
 		com2.package_rules <- PMap.empty;
 		com2.main_class <- None;
@@ -584,7 +584,7 @@ let load_macro' ctx display cpath f p =
 		api.MacroApi.current_macro_module <- (fun() -> mloaded);
 		let meth = (match follow meth.cf_type with TFun (args,ret) -> (args,ret,cl,meth),mloaded | _ -> typing_error "Macro call should be a method" p) in
 		restore();
-		if not ctx.in_macro then flush_macro_context mint ctx;
+		if not ctx.com.is_macro_context then flush_macro_context mint ctx;
 		Hashtbl.add mctx.com.cached_macros (cpath,f) meth;
 		mctx.m <- {
 			curmod = null_module;
@@ -791,7 +791,7 @@ let type_macro ctx mode cpath f (el:Ast.expr list) p =
 			in
 			safe_decode ctx v expected mret p process
 	in
-	let e = if ctx.in_macro then
+	let e = if ctx.com.is_macro_context then
 		Some (EThrow((EConst(String("macro-in-macro",SDoubleQuotes))),p),p)
 	else
 		call()

+ 2 - 2
src/typing/matcher.ml

@@ -1474,7 +1474,7 @@ module TexprConverter = struct
 		let p = dt.dt_pos in
 		let c_type = match follow (Typeload.load_instance ctx (mk_type_path (["std"],"Type"),p) true) with TInst(c,_) -> c | t -> die "" __LOC__ in
 		let mk_index_call e =
-			if not ctx.in_macro && not ctx.com.display.DisplayMode.dms_full_typing then
+			if not ctx.com.is_macro_context && not ctx.com.display.DisplayMode.dms_full_typing then
 				(* If we are in display mode there's a chance that these fields don't exist. Let's just use a
 				   (correctly typed) neutral value because it doesn't actually matter. *)
 				mk (TConst (TInt (Int32.of_int 0))) ctx.t.tint e.epos
@@ -1482,7 +1482,7 @@ module TexprConverter = struct
 				mk (TEnumIndex e) com.basic.tint e.epos
 		in
 		let mk_name_call e =
-			if not ctx.in_macro && not ctx.com.display.DisplayMode.dms_full_typing then
+			if not ctx.com.is_macro_context && not ctx.com.display.DisplayMode.dms_full_typing then
 				mk (TConst (TString "")) ctx.t.tstring e.epos
 			else
 				let cf = PMap.find "enumConstructor" c_type.cl_statics in

+ 2 - 2
src/typing/typeload.ml

@@ -857,12 +857,12 @@ and type_type_params ctx host path get_params p tpl =
 let load_core_class ctx c =
 	let ctx2 = (match ctx.g.core_api with
 		| None ->
-			let com2 = Common.clone ctx.com in
+			let com2 = Common.clone ctx.com ctx.com.is_macro_context in
 			com2.defines.Define.values <- PMap.empty;
 			Common.define com2 Define.CoreApi;
 			Common.define com2 Define.Sys;
 			Define.raw_define_value com2.defines "target.threaded" "true"; (* hack because we check this in sys.thread classes *)
-			if ctx.in_macro then Common.define com2 Define.Macro;
+			if ctx.com.is_macro_context then Common.define com2 Define.Macro;
 			com2.class_path <- ctx.com.std_path;
 			if com2.display.dms_check_core_api then com2.display <- {com2.display with dms_check_core_api = false};
 			CommonCache.lock_signature com2 "load_core_class";

+ 9 - 9
src/typing/typeloadFields.ml

@@ -462,7 +462,7 @@ let build_module_def ctx mt meta fvars context_init fbuild =
 					| _ -> typing_error "Invalid build parameters" p
 				) in
 				let s = try String.concat "." (List.rev (string_list_of_expr_path epath)) with Error (_,p) -> typing_error "Build call parameter must be a class path" p in
-				if ctx.in_macro then typing_error "You cannot use @:build inside a macro : make sure that your type is not used in macro" p;
+				if ctx.com.is_macro_context then typing_error "You cannot use @:build inside a macro : make sure that your type is not used in macro" p;
 				let old = ctx.get_build_infos in
 				ctx.get_build_infos <- (fun() -> Some (mt, extract_param_types (t_infos mt).mt_params, fvars()));
 				context_init#run;
@@ -773,7 +773,7 @@ module TypeBinding = struct
 			)
 		in
 		let handle_display_field () =
-			if fctx.is_macro && not ctx.in_macro then
+			if fctx.is_macro && not ctx.com.is_macro_context then
 				force_macro true
 			else begin
 				cf.cf_type <- TLazy r;
@@ -781,14 +781,14 @@ module TypeBinding = struct
 			end
 		in
 		if ctx.com.display.dms_full_typing then begin
-			if fctx.is_macro && not ctx.in_macro then
+			if fctx.is_macro && not ctx.com.is_macro_context then
 				force_macro false
 			else begin
 				cf.cf_type <- TLazy r;
 				(* is_lib ? *)
 				cctx.delayed_expr <- (ctx,Some r) :: cctx.delayed_expr;
 			end
-		end else if ctx.com.display.dms_force_macro_typing && fctx.is_macro && not ctx.in_macro then
+		end else if ctx.com.display.dms_force_macro_typing && fctx.is_macro && not ctx.com.is_macro_context then
 			force_macro true
 		else begin
 			if fctx.is_display_field then begin
@@ -852,7 +852,7 @@ module TypeBinding = struct
 			if not !return_partial_type || (match fst e with EConst _ -> true | _ -> false) then begin
 				r := lazy_processing (fun() -> t);
 				cctx.context_init#run;
-				if ctx.com.verbose then Common.log ctx.com ("Typing " ^ (if ctx.in_macro then "macro " else "") ^ s_type_path c.cl_path ^ "." ^ cf.cf_name);
+				if ctx.com.verbose then Common.log ctx.com ("Typing " ^ (if ctx.com.is_macro_context then "macro " else "") ^ s_type_path c.cl_path ^ "." ^ cf.cf_name);
 				let e = type_var_field ctx t e fctx.is_static fctx.is_display_field p in
 				let maybe_run_analyzer e = match e.eexpr with
 					| TConst _ | TLocal _ | TFunction _ -> e
@@ -930,7 +930,7 @@ module TypeBinding = struct
 			r := lazy_processing (fun() -> t);
 			cctx.context_init#run;
 			incr stats.s_methods_typed;
-			if ctx.com.verbose then Common.log ctx.com ("Typing " ^ (if ctx.in_macro then "macro " else "") ^ s_type_path c.cl_path ^ "." ^ cf.cf_name);
+			if ctx.com.verbose then Common.log ctx.com ("Typing " ^ (if ctx.com.is_macro_context then "macro " else "") ^ s_type_path c.cl_path ^ "." ^ cf.cf_name);
 			let fmode = (match cctx.abstract with
 				| Some _ ->
 					if fctx.is_abstract_member then FunMemberAbstract else FunStatic
@@ -1209,7 +1209,7 @@ let create_method (ctx,cctx,fctx) c f fd p =
 	if fctx.is_generic then begin
 		if params = [] then typing_error (fst f.cff_name ^ ": Generic functions must have type parameters") p;
 	end;
-	let fd = if fctx.is_macro && not ctx.in_macro && not fctx.is_static then
+	let fd = if fctx.is_macro && not ctx.com.is_macro_context && not fctx.is_static then
 		(* remove display of first argument which will contain the "this" expression *)
 		{ fd with f_args = match fd.f_args with [] -> [] | _ :: l -> l }
 	else
@@ -1218,7 +1218,7 @@ let create_method (ctx,cctx,fctx) c f fd p =
 	let fd = if not fctx.is_macro then
 		fd
 	else begin
-		if ctx.in_macro then begin
+		if ctx.com.is_macro_context then begin
 			(* a class with a macro cannot be extern in macro context (issue #2015) *)
 			remove_class_flag c CExtern;
 			let texpr = CTPath (mk_type_path (["haxe";"macro"],"Expr")) in
@@ -1610,7 +1610,7 @@ let init_field (ctx,cctx,fctx) f =
 		| FProp (get,set,t,eo) ->
 			create_property (ctx,cctx,fctx) c f (get,set,t,eo) p
 	in
-	(if (fctx.is_static || fctx.is_macro && ctx.in_macro) then add_class_field_flag cf CfStatic);
+	(if (fctx.is_static || fctx.is_macro && ctx.com.is_macro_context) then add_class_field_flag cf CfStatic);
 	if Meta.has Meta.InheritDoc cf.cf_meta then
 		delay ctx PTypeField (fun() -> InheritDoc.build_class_field_doc ctx (Some c) cf);
 	cf

+ 2 - 3
src/typing/typeloadModule.ml

@@ -40,7 +40,7 @@ let make_module ctx mpath file loadp =
 		m_path = mpath;
 		m_types = [];
 		m_statics = None;
-		m_extra = module_extra (Path.get_full_path file) (Define.get_signature ctx.com.defines) (file_time file) (if ctx.in_macro then MMacro else MCode) (get_policy ctx mpath);
+		m_extra = module_extra (Path.get_full_path file) (Define.get_signature ctx.com.defines) (file_time file) (if ctx.com.is_macro_context then MMacro else MCode) (get_policy ctx mpath);
 	} in
 	m
 
@@ -773,7 +773,7 @@ let module_pass_2 ctx m decls tdecls p =
 			c.cl_params <- type_type_params ctx TPHType c.cl_path (fun() -> c.cl_params) p d.d_params;
 			if Meta.has Meta.Generic c.cl_meta && c.cl_params <> [] then c.cl_kind <- KGeneric;
 			if Meta.has Meta.GenericBuild c.cl_meta then begin
-				if ctx.in_macro then typing_error "@:genericBuild cannot be used in macros" c.cl_pos;
+				if ctx.com.is_macro_context then typing_error "@:genericBuild cannot be used in macros" c.cl_pos;
 				c.cl_kind <- KGenericBuild d.d_data;
 			end;
 			if c.cl_path = (["haxe";"macro"],"MacroType") then c.cl_kind <- KMacroType;
@@ -831,7 +831,6 @@ let type_types_into_module ?(check=true) ctx m tdecls p =
 		type_params = [];
 		curfun = FunStatic;
 		untyped = false;
-		in_macro = ctx.in_macro;
 		in_display = false;
 		in_function = false;
 		in_loop = false;

+ 0 - 1
src/typing/typer.ml

@@ -1997,7 +1997,6 @@ let rec create com =
 		in_loop = false;
 		in_display = false;
 		get_build_infos = (fun() -> None);
-		in_macro = Common.defined com Define.Macro;
 		ret = mk_mono();
 		locals = PMap.empty;
 		type_params = [];