Ver código fonte

move is_removable_class/field

Simon Krajewski 5 meses atrás
pai
commit
9ae0d276d9

+ 0 - 9
src/context/typecore.ml

@@ -500,15 +500,6 @@ let make_lazy ctx t_proc f where =
 	delay ctx PForce (fun () -> ignore(lazy_type r));
 	r
 
-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 com.is_macro_context
-			| _ -> false)
-	)
-
 let is_forced_inline c cf =
 	match c with
 	| Some { cl_kind = KAbstractImpl _ } -> true

+ 28 - 1
src/filters/filterContext.ml

@@ -1,3 +1,30 @@
 let with_timer timer_ctx level label identifier f =
 	let id = Timer.determine_id level ["filters"] [label] identifier in
-	Timer.time timer_ctx id f ()
+	Timer.time timer_ctx id f ()
+
+open Type
+
+let rec is_removable_class c =
+	match c.cl_kind with
+	| KGeneric ->
+		(Meta.has Meta.Remove c.cl_meta ||
+		(match c.cl_super with
+			| Some (c,_) -> is_removable_class c
+			| _ -> false) ||
+		List.exists (fun tp ->
+			has_ctor_constraint tp.ttp_class || Meta.has Meta.Const tp.ttp_class.cl_meta
+		) c.cl_params)
+	| KTypeParameter _ ->
+		(* this shouldn't happen, have to investigate (see #4092) *)
+		true
+	| _ ->
+		false
+
+let is_removable_field is_macro_context 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 is_macro_context
+			| _ -> false)
+	)

+ 2 - 2
src/filters/filters.ml

@@ -267,12 +267,12 @@ let remove_extern_fields com t = match t with
 	| TClassDecl c ->
 		if not (Common.defined com Define.DocGen) then begin
 			c.cl_ordered_fields <- List.filter (fun f ->
-				let b = is_removable_field com f in
+				let b = FilterContext.is_removable_field com.is_macro_context 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 com f in
+				let b = FilterContext.is_removable_field com.is_macro_context f in
 				if b then c.cl_statics <- PMap.remove f.cf_name c.cl_statics;
 				not b
 			) c.cl_ordered_statics;

+ 3 - 19
src/filters/filtersCommon.ml

@@ -21,24 +21,8 @@ open Type
 open Common
 open Typecore
 
-let rec is_removable_class c =
-	match c.cl_kind with
-	| KGeneric ->
-		(Meta.has Meta.Remove c.cl_meta ||
-		(match c.cl_super with
-			| Some (c,_) -> is_removable_class c
-			| _ -> false) ||
-		List.exists (fun tp ->
-			has_ctor_constraint tp.ttp_class || Meta.has Meta.Const tp.ttp_class.cl_meta
-		) c.cl_params)
-	| KTypeParameter _ ->
-		(* this shouldn't happen, have to investigate (see #4092) *)
-		true
-	| _ ->
-		false
-
 let remove_generic_base t = match t with
-	| TClassDecl c when is_removable_class c ->
+	| TClassDecl c when FilterContext.is_removable_class c ->
 		add_class_flag c CExtern;
 	| _ ->
 		()
@@ -65,7 +49,7 @@ let run_expression_filters ?(ignore_processed_status=false) ctx detail_times fil
 		) e filters
 	in
 	match t with
-	| TClassDecl c when is_removable_class c -> ()
+	| TClassDecl c when FilterContext.is_removable_class c -> ()
 	| TClassDecl c ->
 		let ctx = TyperManager.clone_for_module ctx (TypeloadModule.make_curmod ctx.com ctx.g c.cl_module) in
 		let ctx = TyperManager.clone_for_class ctx c in
@@ -73,7 +57,7 @@ let run_expression_filters ?(ignore_processed_status=false) ctx detail_times fil
 			if ignore_processed_status || not (has_class_field_flag cf CfPostProcessed) then begin
 				let ctx = TyperManager.clone_for_field ctx cf cf.cf_params in
 				(match cf.cf_expr with
-				| Some e when not (is_removable_field com cf) ->
+				| Some e when not (FilterContext.is_removable_field com.is_macro_context cf) ->
 					let identifier = Printf.sprintf "%s.%s" (s_type_path c.cl_path) cf.cf_name in
 					cf.cf_expr <- Some (run ctx (Some identifier) e);
 				| _ -> ());

+ 1 - 1
src/optimization/analyzer.ml

@@ -1113,7 +1113,7 @@ module Run = struct
 		Optimizer.reduce_control_flow com e
 
 	let run_on_field' com exc_out config c cf = match cf.cf_expr with
-		| Some e when not (is_ignored cf.cf_meta) && not (Typecore.is_removable_field com cf) && not (has_class_field_flag cf CfPostProcessed) ->
+		| Some e when not (is_ignored cf.cf_meta) && not (FilterContext.is_removable_field com.Common.is_macro_context cf) && not (has_class_field_flag cf CfPostProcessed) ->
 			let config = update_config_from_meta com config cf.cf_meta in
 			let actx = create_analyzer_context com config (Printf.sprintf "%s.%s" (s_type_path c.cl_path) cf.cf_name) e in
 			let debug() =