Jelajahi Sumber

CfOverride (#9531)

* start replacing `cl_overrides` with `CfOverride`

* more changes

* try to get fixOverrides right

* purge more usages

* fix remark

* remove

* fix remark

* don't remove extern fields if they override something

* fix
Simon Krajewski 5 tahun lalu
induk
melakukan
052a1c3e62

+ 1 - 1
src/codegen/gencommon/closuresToClass.ml

@@ -524,7 +524,7 @@ let configure gen ft =
 		(* add invoke function to the class *)
 		cls.cl_ordered_fields <- invoke_field :: cls.cl_ordered_fields;
 		cls.cl_fields <- PMap.add invoke_field.cf_name invoke_field cls.cl_fields;
-		cls.cl_overrides <- invoke_field :: cls.cl_overrides;
+		add_class_field_flag invoke_field CfOverride;
 
 		(match tvar with
 		| None -> ()

+ 1 - 1
src/codegen/gencommon/enumToClass.ml

@@ -204,7 +204,7 @@ struct
 
 		cl.cl_ordered_fields <- getTag_cf :: cl.cl_ordered_fields ;
 		cl.cl_fields <- PMap.add "getTag" getTag_cf cl.cl_fields;
-		cl.cl_overrides <- getTag_cf :: cl.cl_overrides;
+		add_class_field_flag getTag_cf CfOverride;
 		cl.cl_meta <- (Meta.NativeGen,[],cl.cl_pos) :: cl.cl_meta;
 		gen.gadd_to_module (TClassDecl cl) (max_dep);
 

+ 1 - 1
src/codegen/gencommon/enumToClass2.ml

@@ -30,7 +30,7 @@ let add_static c cf =
 let add_field c cf override =
 	c.cl_fields <- PMap.add cf.cf_name cf c.cl_fields;
 	c.cl_ordered_fields <- cf :: c.cl_ordered_fields;
-	if override then c.cl_overrides <- cf :: c.cl_overrides
+	if override then add_class_field_flag cf CfOverride
 
 let add_meta com en cl_enum =
 	Option.may (fun expr ->

+ 7 - 1
src/codegen/gencommon/fixOverrides.ml

@@ -255,7 +255,13 @@ let run ~explicit_fn_name ~get_vmtype gen =
 				| _ -> f
 			in
 			if not c.cl_extern then
-				c.cl_overrides <- List.map (fun f -> check_f f) c.cl_overrides;
+				List.iter (fun f ->
+					if has_class_field_flag f CfOverride then begin
+						remove_class_field_flag f CfOverride;
+						let f2 = check_f f in
+						add_class_field_flag f2 CfOverride
+					end
+				) c.cl_ordered_fields;
 			md
 		| _ -> md
 	in

+ 2 - 2
src/codegen/gencommon/initFunction.ml

@@ -126,7 +126,7 @@ let handle_class com cl =
 				let var = mk (TField ((mk (TConst TThis) (TInst (cl, List.map snd cl.cl_params)) cf.cf_pos), FInstance(cl, List.map snd cl.cl_params, cf))) cf.cf_type cf.cf_pos in
 				let ret = binop Ast.OpAssign var e cf.cf_type cf.cf_pos in
 				cf.cf_expr <- None;
-				let is_override = List.memq cf cl.cl_overrides in
+				let is_override = has_class_field_flag cf CfOverride in
 
 				if is_override then begin
 					cl.cl_ordered_fields <- List.filter (fun f -> f.cf_name <> cf.cf_name) cl.cl_ordered_fields;
@@ -146,7 +146,7 @@ let handle_class com cl =
 
 				let ret = binop Ast.OpAssign var (change_expr e) (fn cf.cf_type) cf.cf_pos in
 				cf.cf_expr <- None;
-				let is_override = List.memq cf cl.cl_overrides in
+				let is_override = has_class_field_flag cf CfOverride in
 
 				if is_override then begin
 					cl.cl_ordered_fields <- List.filter (fun f -> f.cf_name <> cf.cf_name) cl.cl_ordered_fields;

+ 2 - 2
src/codegen/gencommon/realTypeParams.ml

@@ -430,7 +430,7 @@ struct
 					gen.gafter_filters_ended <- delay :: gen.gafter_filters_ended; (* do not let filters alter this expression content *)
 					cl.cl_ordered_fields <- cfield :: cl.cl_ordered_fields;
 					cl.cl_fields <- PMap.add cfield.cf_name cfield cl.cl_fields;
-					if level <> 0 then cl.cl_overrides <- cfield :: cl.cl_overrides
+					if level <> 0 then add_class_field_flag cfield CfOverride
 				end
 			end;
 			let get_reverse super supertl =
@@ -708,7 +708,7 @@ struct
 					let fields = List.filter (fun cf -> match cf.cf_kind with
 						| Var _ | Method MethDynamic -> false
 						| _ ->
-							let is_override = List.memq cf cl.cl_overrides in
+							let is_override = has_class_field_flag cf CfOverride in
 							let cf_type = if is_override && not (Meta.has Meta.Overload cf.cf_meta) then
 								match find_first_declared_field gen cl cf.cf_name with
 									| Some(_,_,declared_t,_,_,_,_) -> declared_t

+ 11 - 16
src/codegen/gencommon/reflectionCFs.ml

@@ -777,7 +777,7 @@ let implement_final_lookup ctx cl =
 		cl.cl_ordered_fields <- cl.cl_ordered_fields @ cfs;
 		List.iter (fun cf ->
 			cl.cl_fields <- PMap.add cf.cf_name cf cl.cl_fields;
-			if is_override then cl.cl_overrides <- cf :: cl.cl_overrides
+			if is_override then add_class_field_flag cf CfOverride
 		) cfs
 	in
 	if not is_override then begin
@@ -1028,7 +1028,7 @@ let implement_get_set ctx cl =
 			cl.cl_ordered_fields <- cl.cl_ordered_fields @ [cfield];
 			cl.cl_fields <- PMap.add fun_name cfield cl.cl_fields;
 
-			(if is_override then cl.cl_overrides <- cfield	:: cl.cl_overrides)
+			(if is_override then add_class_field_flag cfield CfOverride)
 		end else ()
 	in
 	mk_cfield true true;
@@ -1065,7 +1065,7 @@ let implement_getFields ctx cl =
 		List.map (fun (_,cf) ->
 			match cf.cf_kind with
 				| Var _
-				| Method MethDynamic when not (List.memq cf cl.cl_overrides) ->
+				| Method MethDynamic when not (has_class_field_flag cf CfOverride) ->
 					has_value := true;
 					mk_push (make_string gen.gcon.basic cf.cf_name pos)
 				| _ -> null basic.tvoid pos
@@ -1100,7 +1100,7 @@ let implement_getFields ctx cl =
 	if !has_value || not (is_override cl) then begin
 		cl.cl_ordered_fields <- cl.cl_ordered_fields @ [cf];
 		cl.cl_fields <- PMap.add cf.cf_name cf cl.cl_fields;
-		(if is_override cl then cl.cl_overrides <- cf :: cl.cl_overrides)
+		(if is_override cl then add_class_field_flag cf CfOverride)
 	end
 
 
@@ -1194,7 +1194,7 @@ let implement_invokeField ctx slow_invoke cl =
 		in
 
 		let cfs = List.filter (fun (_,cf) -> match cf.cf_kind with
-			| Method _ -> if List.memq cf cl.cl_overrides then false else true
+			| Method _ -> if has_class_field_flag cf CfOverride then false else true
 			| _ -> true) cfs
 		in
 
@@ -1244,7 +1244,7 @@ let implement_invokeField ctx slow_invoke cl =
 
 		let nonstatics =
 			List.filter (fun (n,cf) ->
-				let is_old = not (PMap.mem cf.cf_name cl.cl_fields) || List.memq cf cl.cl_overrides in
+				let is_old = not (PMap.mem cf.cf_name cl.cl_fields) || has_class_field_flag cf CfOverride in
 				(if is_old then old_nonstatics := cf :: !old_nonstatics);
 				not is_old
 			) nonstatics
@@ -1267,7 +1267,7 @@ let implement_invokeField ctx slow_invoke cl =
 	if !is_override && not (!has_method) then () else begin
 		cl.cl_ordered_fields <- cl.cl_ordered_fields @ [dyn_fun];
 		cl.cl_fields <- PMap.add dyn_fun.cf_name dyn_fun cl.cl_fields;
-		(if !is_override then cl.cl_overrides <- dyn_fun :: cl.cl_overrides)
+		(if !is_override then add_class_field_flag dyn_fun CfOverride)
 	end
 
 let implement_varargs_cl ctx cl =
@@ -1322,7 +1322,7 @@ let implement_varargs_cl ctx cl =
 	) all_cfs;
 
 	List.iter (fun cf ->
-		cl.cl_overrides <- cf :: cl.cl_overrides
+		add_class_field_flag cf CfOverride
 	) cl.cl_ordered_fields
 
 let implement_closure_cl ctx cl =
@@ -1380,7 +1380,7 @@ let implement_closure_cl ctx cl =
 	let all_cfs = List.filter (fun cf -> cf.cf_name <> "new" && match cf.cf_kind with Method _ -> true | _ -> false) (ctx.rcf_ft.map_base_classfields cl map_fn) in
 
 	List.iter (fun cf ->
-		cl.cl_overrides <- cf :: cl.cl_overrides
+		add_class_field_flag cf CfOverride
 	) all_cfs;
 	let all_cfs = cfs @ all_cfs in
 
@@ -1502,15 +1502,10 @@ end;;
 *)
 let priority = solve_deps name [DAfter UniversalBaseClass.priority]
 
-let add_override cl cf =
-	if List.memq cf cl.cl_overrides then
-		cl.cl_overrides
-	else
-		cf :: cl.cl_overrides
-
 let has_field_override cl name =
 	try
-		cl.cl_overrides <- add_override cl (PMap.find name cl.cl_fields);
+		let cf = PMap.find name cl.cl_fields in
+		add_class_field_flag cf CfOverride;
 		true
 	with | Not_found ->
 		false

+ 17 - 17
src/context/display/statistics.ml

@@ -52,22 +52,20 @@ let collect_statistics ctx pfilter with_expressions =
 			Hashtbl.replace symbols p kind;
 		end
 	in
-	let collect_overrides c =
-		List.iter (fun cf ->
-			let rec loop c = match c.cl_super with
-				| Some (c,_) ->
-					begin try
-						let cf' = PMap.find cf.cf_name c.cl_fields in
-						add_relation cf'.cf_name_pos (Overridden,cf.cf_name_pos)
-					with Not_found ->
-						()
-					end;
-					loop c
-				| _ ->
+	let check_override c cf =
+		let rec loop c = match c.cl_super with
+			| Some (c,_) ->
+				begin try
+					let cf' = PMap.find cf.cf_name c.cl_fields in
+					add_relation cf'.cf_name_pos (Overridden,cf.cf_name_pos)
+				with Not_found ->
 					()
-			in
-			loop c
-		) c.cl_overrides
+				end;
+				loop c
+			| _ ->
+				()
+		in
+		loop c
 	in
 	let collect_implementations c =
 		let memo = Hashtbl.create 0 in
@@ -231,7 +229,6 @@ let collect_statistics ctx pfilter with_expressions =
 					in
 					loop c'
 			end;
-			collect_overrides c;
 			if c.cl_interface then
 				collect_implementations c;
 			let field cf =
@@ -242,7 +239,10 @@ let collect_statistics ctx pfilter with_expressions =
 				end
 			in
 			Option.may field c.cl_constructor;
-			List.iter field c.cl_ordered_fields;
+			List.iter (fun cf ->
+				if has_class_field_flag cf CfOverride then check_override c cf;
+				field cf;
+			) c.cl_ordered_fields;
 			List.iter field c.cl_ordered_statics;
 		| TEnumDecl en ->
 			check_module en.e_module;

+ 7 - 5
src/context/typecore.ml

@@ -377,11 +377,13 @@ let push_this ctx e = match e.eexpr with
 		er,fun () -> ctx.this_stack <- List.tl ctx.this_stack
 
 let is_removable_field ctx f =
-	has_class_field_flag f CfExtern || Meta.has Meta.Generic f.cf_meta
-	|| (match f.cf_kind with
-		| Var {v_read = AccRequire (s,_)} -> true
-		| Method MethMacro -> not ctx.in_macro
-		| _ -> false)
+	not (has_class_field_flag f CfOverride) && (
+		has_class_field_flag f CfExtern || Meta.has Meta.Generic f.cf_meta
+		|| (match f.cf_kind with
+			| Var {v_read = AccRequire (s,_)} -> true
+			| Method MethMacro -> not ctx.in_macro
+			| _ -> false)
+	)
 
 (** checks if we can access to a given class field using current context *)
 let rec can_access ctx ?(in_overload=false) c cf stat =

+ 1 - 1
src/core/json/genjson.ml

@@ -619,7 +619,7 @@ let generate_class ctx c =
 		"statics",jlist (generate_class_field ctx CFSStatic) c.cl_ordered_statics;
 		"constructor",jopt (generate_class_field ctx CFSConstructor) c.cl_constructor;
 		"init",jopt (generate_texpr ctx) c.cl_init;
-		"overrides",jlist (classfield_ref ctx) c.cl_overrides;
+		"overrides",jlist (classfield_ref ctx) (List.filter (fun cf -> has_class_field_flag cf CfOverride) c.cl_ordered_fields);
 		"isExtern",jbool c.cl_extern;
 		"isFinal",jbool c.cl_final;
 	]

+ 0 - 1
src/core/tFunctions.ml

@@ -108,7 +108,6 @@ let mk_class m path pos name_pos =
 		cl_array_access = None;
 		cl_constructor = None;
 		cl_init = None;
-		cl_overrides = [];
 		cl_build = (fun() -> Built);
 		cl_restore = (fun() -> ());
 		cl_descendants = [];

+ 0 - 1
src/core/tPrinting.ml

@@ -512,7 +512,6 @@ module Printer = struct
 			"cl_super",s_opt (fun (c,tl) -> s_type (TInst(c,tl))) c.cl_super;
 			"cl_implements",s_list ", " (fun (c,tl) -> s_type (TInst(c,tl))) c.cl_implements;
 			"cl_array_access",s_opt s_type c.cl_array_access;
-			"cl_overrides",s_list "," (fun cf -> cf.cf_name) c.cl_overrides;
 			"cl_init",s_opt (s_expr_ast true "" s_type) c.cl_init;
 			"cl_constructor",s_opt (s_tclass_field (tabs ^ "\t")) c.cl_constructor;
 			"cl_ordered_fields",s_list "\n\t" (s_tclass_field (tabs ^ "\t")) c.cl_ordered_fields;

+ 2 - 2
src/core/tType.ml

@@ -226,7 +226,6 @@ and tclass = {
 	mutable cl_array_access : t option;
 	mutable cl_constructor : tclass_field option;
 	mutable cl_init : texpr option;
-	mutable cl_overrides : tclass_field list;
 
 	mutable cl_build : unit -> build_state;
 	mutable cl_restore : unit -> unit;
@@ -372,4 +371,5 @@ type flag_tclass_field =
 	| CfStatic
 	| CfExtern (* This is only set if the field itself is extern, not just the class. *)
 	| CfFinal
-	| CfModifiesThis (* This is set for methods which reassign `this`. E.g. `this = value` *)
+	| CfModifiesThis (* This is set for methods which reassign `this`. E.g. `this = value` *)
+	| CfOverride

+ 1 - 2
src/filters/filters.ml

@@ -318,7 +318,7 @@ let save_class_state ctx t = match t with
 			List.fold_left (fun pmap f -> PMap.add f.cf_name f pmap) PMap.empty lst
 		in
 
-		let meta = c.cl_meta and path = c.cl_path and ext = c.cl_extern and over = c.cl_overrides in
+		let meta = c.cl_meta and path = c.cl_path and ext = c.cl_extern in
 		let sup = c.cl_super and impl = c.cl_implements in
 		let csr = Option.map (mk_field_restore) c.cl_constructor in
 		let ofr = List.map (mk_field_restore) c.cl_ordered_fields in
@@ -337,7 +337,6 @@ let save_class_state ctx t = match t with
 			c.cl_fields <- mk_pmap c.cl_ordered_fields;
 			c.cl_statics <- mk_pmap c.cl_ordered_statics;
 			c.cl_constructor <- Option.map restore_field csr;
-			c.cl_overrides <- over;
 			c.cl_descendants <- [];
 			List.iter (fun (v, t) -> v.v_type <- t) !vars;
 		)

+ 5 - 5
src/generators/gencpp.ml

@@ -4301,8 +4301,8 @@ let is_data_member field =
    | _ -> false;;
 
 
-let is_override class_def field =
-   List.exists (fun f -> f.cf_name = field) class_def.cl_overrides
+let is_override field =
+   has_class_field_flag field CfOverride
 ;;
 
 (*
@@ -4315,7 +4315,7 @@ let current_virtual_functions_rev clazz base_functions =
    List.fold_left (fun result elem -> match follow elem.cf_type, elem.cf_kind  with
       | _, Method MethDynamic -> result
       | TFun (args,return_type), Method _  ->
-          if (is_override clazz elem.cf_name ) then
+          if (is_override elem ) then
              List.map (fun (e,a,r) ->  if e.cf_name<>elem.cf_name then (e,a,r) else  (elem,args,return_type) ) result
           else
              (elem,args,return_type) :: result
@@ -4452,7 +4452,7 @@ let gen_field ctx class_def class_name ptr_name dot_name is_static is_interface
 
          output "\n\n";
          let nonVirtual = has_meta_key field.cf_meta Meta.NonVirtual in
-         let doDynamic =  (nonVirtual || not (is_override class_def field.cf_name ) ) && (reflective class_def field ) in
+         let doDynamic =  (nonVirtual || not (is_override field ) ) && (reflective class_def field ) in
          (* generate dynamic version too ... *)
          if ( doDynamic ) then begin
             let tcpp_args = List.map (fun (v,_) -> cpp_type_of ctx v.v_type  ) function_def.tf_args in
@@ -4626,7 +4626,7 @@ let gen_member_def ctx class_def is_static is_interface field =
       (match  field.cf_expr with
       | Some { eexpr = TFunction function_def } ->
          let nonVirtual = has_meta_key field.cf_meta Meta.NonVirtual in
-         let doDynamic =  (nonVirtual || not (is_override class_def field.cf_name ) ) && (reflective class_def field ) in
+         let doDynamic =  (nonVirtual || not (is_override field ) ) && (reflective class_def field ) in
          if ( is_dynamic_haxe_method field ) then begin
             if ( doDynamic ) then begin
                output ("::Dynamic " ^ remap_name ^ ";\n");

+ 5 - 5
src/generators/gencs.ml

@@ -2078,7 +2078,7 @@ let generate con =
 			let is_virtual = not (is_interface || is_final || (has_class_field_flag prop CfFinal) || fn_is_final get || fn_is_final set) in
 
 			let fn_is_override = function
-				| Some cf -> List.memq cf cl.cl_overrides
+				| Some cf -> has_class_field_flag cf CfOverride
 				| None -> false
 			in
 			let is_override = fn_is_override get || fn_is_override set in
@@ -2249,7 +2249,7 @@ let generate con =
 					) overloads;
 					let is_virtual = not is_final && match mkind with | MethInline -> false | _ when not is_new -> true | _ -> false in
 					let is_virtual = if not is_virtual || (has_class_field_flag cf CfFinal) then false else is_virtual in
-					let is_override = List.memq cf cl.cl_overrides in
+					let is_override = has_class_field_flag cf CfOverride in
 					let is_override = is_override || match cf.cf_name, follow cf.cf_type with
 						| "Equals", TFun([_,_,targ], tret) ->
 							(match follow targ, follow tret with
@@ -2455,7 +2455,7 @@ let generate con =
 			(try
 				if cl.cl_interface then raise Not_found;
 				let cf = PMap.find "toString" cl.cl_fields in
-				(if List.exists (fun c -> c.cf_name = "toString") cl.cl_overrides then raise Not_found);
+				(if has_class_field_flag cf CfOverride then raise Not_found);
 				(match cf.cf_type with
 					| TFun([], ret) ->
 						(match real_type ret with
@@ -2475,7 +2475,7 @@ let generate con =
 			(try
 				if cl.cl_interface then raise Not_found;
 				let cf = PMap.find "finalize" cl.cl_fields in
-				(if List.exists (fun c -> c.cf_name = "finalize") cl.cl_overrides then raise Not_found);
+				(if has_class_field_flag cf CfOverride then raise Not_found);
 				(match cf.cf_type with
 					| TFun([], ret) ->
 						(match real_type ret with
@@ -3124,7 +3124,7 @@ let generate con =
 
 		List.iter (fun cl ->
 			List.iter (fun cf ->
-				if cf.cf_name = dynamic_name then cl.cl_overrides <- cf :: cl.cl_overrides
+				if cf.cf_name = dynamic_name then add_class_field_flag cf CfOverride
 			) cl.cl_ordered_fields
 		) [closure_cl; varargs_cl];
 

+ 5 - 5
src/generators/genhl.ml

@@ -626,7 +626,7 @@ and class_type ?(tref=None) ctx c pl statics =
 			| Method m when m <> MethDynamic && not statics ->
 				let g = alloc_fid ctx c f in
 				p.pfunctions <- PMap.add f.cf_name g p.pfunctions;
-				let virt = if List.exists (fun ff -> ff.cf_name = f.cf_name) c.cl_overrides then
+				let virt = if has_class_field_flag f CfOverride then
 					let vid = (try -(fst (get_index f.cf_name p))-1 with Not_found -> die "" __LOC__) in
 					DynArray.set virtuals vid g;
 					Some vid
@@ -640,7 +640,7 @@ and class_type ?(tref=None) ctx c pl statics =
 				in
 				DynArray.add pa { fname = f.cf_name; fid = alloc_string ctx f.cf_name; fmethod = g; fvirtual = virt; };
 				None
-			| Method MethDynamic when List.exists (fun ff -> ff.cf_name = f.cf_name) c.cl_overrides ->
+			| Method MethDynamic when has_class_field_flag f CfOverride ->
 				Some (try fst (get_index f.cf_name p) with Not_found -> die "" __LOC__)
 			| _ ->
 				let fid = add_field f.cf_name (fun() -> to_type ctx f.cf_type) in
@@ -663,7 +663,7 @@ and class_type ?(tref=None) ctx c pl statics =
 			(* check toString *)
 			(try
 				let cf = PMap.find "toString" c.cl_fields in
-				if List.memq cf c.cl_overrides || PMap.mem "__string" c.cl_fields || not (is_to_string cf.cf_type) then raise Not_found;
+				if has_class_field_flag cf CfOverride || PMap.mem "__string" c.cl_fields || not (is_to_string cf.cf_type) then raise Not_found;
 				DynArray.add pa { fname = "__string"; fid = alloc_string ctx "__string"; fmethod = alloc_fun_path ctx c.cl_path "__string"; fvirtual = None; }
 			with Not_found ->
 				());
@@ -3359,7 +3359,7 @@ let rec generate_member ctx c f =
 			) c.cl_ordered_fields;
 		) in
 		ignore(make_fun ?gen_content ctx (s_type_path c.cl_path,f.cf_name) (alloc_fid ctx c f) (match f.cf_expr with Some { eexpr = TFunction f } -> f | _ -> abort "Missing function body" f.cf_pos) (Some c) None);
-		if f.cf_name = "toString" && not (List.memq f c.cl_overrides) && not (PMap.mem "__string" c.cl_fields) && is_to_string f.cf_type then begin
+		if f.cf_name = "toString" && not (has_class_field_flag f CfOverride) && not (PMap.mem "__string" c.cl_fields) && is_to_string f.cf_type then begin
 			let p = f.cf_pos in
 			(* function __string() return this.toString().bytes *)
 			let ethis = mk (TConst TThis) (TInst (c,List.map snd c.cl_params)) p in
@@ -4003,7 +4003,7 @@ let add_types ctx types =
 				| _ ->
 					false
 			in
-			if not ctx.is_macro then List.iter (fun f -> ignore(loop c.cl_super f)) c.cl_overrides;
+			if not ctx.is_macro then List.iter (fun f -> if has_class_field_flag f CfOverride then ignore(loop c.cl_super f)) c.cl_ordered_fields;
 			List.iter (fun (m,args,p) ->
 				if m = Meta.HlNative then
 					let lib, prefix = (match args with

+ 1 - 1
src/generators/genhxold.ml

@@ -234,7 +234,7 @@ let generate_type com t =
 		p "%s" (String.concat "" (List.rev ext));
 		p " {\n";
 		let sort l =
-			let a = Array.of_list (List.filter (fun f -> not (List.memq f c.cl_overrides)) l) in
+			let a = Array.of_list (List.filter (fun f -> not (has_class_field_flag f CfOverride)) l) in
 			let name = function "new" -> "" | n -> n in
 			Array.sort (fun f1 f2 ->
 				match f1.cf_kind, f2.cf_kind with

+ 5 - 5
src/generators/genjava.ml

@@ -1962,9 +1962,9 @@ let generate con =
 								(match (real_type t, real_type ret) with
 									| TDynamic _, TAbstract ({ a_path = ([], "Bool") },[])
 									| TAnon _, TAbstract ({ a_path = ([], "Bool") },[]) -> true
-									| _ -> List.memq cf cl.cl_overrides
+									| _ -> has_class_field_flag cf CfOverride
 								)
-							| _ -> List.memq cf cl.cl_overrides)
+							| _ -> has_class_field_flag cf CfOverride)
 					| "toString" when not is_static ->
 						(match cf.cf_type with
 							| TFun([], ret) ->
@@ -1972,7 +1972,7 @@ let generate con =
 									| TInst( { cl_path = ([], "String") }, []) -> true
 									| _ -> gen.gcon.error "A toString() function should return a String!" cf.cf_pos; false
 								)
-							| _ -> List.memq cf cl.cl_overrides
+							| _ -> has_class_field_flag cf CfOverride
 						)
 					| "hashCode" when not is_static ->
 						(match cf.cf_type with
@@ -1982,9 +1982,9 @@ let generate con =
 										true
 									| _ -> gen.gcon.error "A hashCode() function should return an Int!" cf.cf_pos; false
 								)
-							| _ -> List.memq cf cl.cl_overrides
+							| _ -> has_class_field_flag cf CfOverride
 						)
-					| _ -> List.memq cf cl.cl_overrides
+					| _ -> has_class_field_flag cf CfOverride
 				in
 				let visibility = if is_interface then "" else "public" in
 

+ 2 - 1
src/generators/genjvm.ml

@@ -2249,7 +2249,8 @@ class tclass_to_jvm gctx c = object(self)
 			) c_int.cl_implements
 		in
 		loop (fun t -> t) c;
-		begin match c.cl_overrides,c.cl_super with
+		let overrides = List.filter (fun cf -> has_class_field_flag cf CfOverride) c.cl_ordered_fields in
+		begin match overrides,c.cl_super with
 		| [],_ ->
 			()
 		| fields,Some(c_sup,tl) ->

+ 0 - 1
src/generators/genphp7.ml

@@ -919,7 +919,6 @@ class class_wrapper (cls) =
 								cl_ordered_fields  = [];
 								cl_ordered_statics  = [];
 								cl_constructor = None;
-								cl_overrides = [];
 								cl_init = Some body
 						} in
 						Some (TClassDecl additional_cls)

+ 1 - 1
src/generators/genshared.ml

@@ -364,7 +364,7 @@ class ['a] preprocessor (basic : basic_types) (convert : Type.t -> 'a) =
 			super_call_fields = DynArray.to_list super_call_fields;
 		}
 
-	method check_overrides c = match c.cl_overrides with
+	method check_overrides c = match List.filter (fun cf -> has_class_field_flag cf CfOverride) c.cl_ordered_fields with
 		| [] ->
 			()
 		| fields ->

+ 6 - 12
src/generators/genswf9.ml

@@ -2068,7 +2068,7 @@ let generate_field_kind ctx f c stat =
 				PMap.exists name c.cl_fields || loop c name
 		in
 		(match f.cf_kind with
-		| Method MethDynamic when List.memq f c.cl_overrides ->
+		| Method MethDynamic when has_class_field_flag f CfOverride ->
 			None
 		| Var _ | Method MethDynamic ->
 			Some (HFVar {
@@ -2080,7 +2080,7 @@ let generate_field_kind ctx f c stat =
 			let name, kind = method_kind() in
 			let m = generate_method ctx fdata stat f.cf_meta in
 			let is_override = not stat && (
-				if kind = MK3Normal then List.memq f c.cl_overrides
+				if kind = MK3Normal then has_class_field_flag f CfOverride
 				else (loop c name || loop c f.cf_name)
 			) in
 			Some (HFMethod {
@@ -2160,14 +2160,8 @@ let maybe_gen_instance_accessor ctx cl tl accessor_cf acc alloc_slot kind f_impl
 	| Some (_, _, prop_cf) ->
 		let accessor_cl = find_first_nonextern_accessor_implementor cl accessor_cf.cf_name in
 		if accessor_cl == cl then begin
-			let was_override = ref false in
-			cl.cl_overrides <- List.filter (fun f2 ->
-				if f2 == accessor_cf then
-					(was_override := true; false)
-				else
-					true
-			) cl.cl_overrides;
-
+			let was_override = has_class_field_flag accessor_cf CfOverride in
+			if was_override then remove_class_field_flag accessor_cf CfOverride;
 			let name, mtype =
 				if cl.cl_interface then begin
 					let (args,tret) = f_iface prop_cf in
@@ -2186,7 +2180,7 @@ let maybe_gen_instance_accessor ctx cl tl accessor_cf acc alloc_slot kind f_impl
 				hlf_kind = HFMethod {
 					hlm_type = mtype;
 					hlm_final = has_class_field_flag accessor_cf CfFinal;
-					hlm_override = !was_override;
+					hlm_override = was_override;
 					hlm_kind = kind;
 				};
 				hlf_metas = None;
@@ -2434,7 +2428,7 @@ let generate_class ctx c =
 		let rec find_meta c =
 			try
 				let f = PMap.find f.cf_name (if stat then c.cl_statics else c.cl_fields) in
-				if List.memq f c.cl_overrides then raise Not_found;
+				if has_class_field_flag f CfOverride then raise Not_found;
 				f.cf_meta
 			with Not_found ->
 				match c.cl_super with

+ 1 - 1
src/macro/eval/evalPrototype.ml

@@ -333,7 +333,7 @@ let add_types ctx types ready =
 				| _ ->
 					false
 			in
-			List.iter (fun f -> ignore(loop c.cl_super f)) c.cl_overrides;
+			List.iter (fun f -> if has_class_field_flag f CfOverride then ignore(loop c.cl_super f)) c.cl_ordered_fields;
 			create_constructor ctx c;
 			DynArray.add fl_instance (create_instance_prototype ctx c);
 			DynArray.add fl_static (create_static_prototype ctx mt);

+ 2 - 2
src/macro/macroApi.ml

@@ -674,7 +674,7 @@ and decode_meta_content m = decode_opt_array decode_meta_entry m
 
 and decode_doc = opt (fun s -> { doc_own = Some (decode_string s); doc_inherited = [] })
 
-and decode_class_field_kind v = 
+and decode_class_field_kind v =
 	match decode_enum v with
 	| 0, [t;e] ->
 		FVar (opt decode_ctype t, opt decode_expr e)
@@ -1003,7 +1003,7 @@ and encode_tclass c =
 		"statics", encode_ref c.cl_ordered_statics (encode_and_map_array encode_cfield) (fun() -> "class fields");
 		"constructor", (match c.cl_constructor with None -> vnull | Some cf -> encode_cfref cf);
 		"init", (match c.cl_init with None -> vnull | Some e -> encode_texpr e);
-		"overrides", (encode_array (List.map encode_cfref c.cl_overrides))
+		"overrides", (encode_array (List.map encode_cfref (List.filter (fun cf -> has_class_field_flag cf CfOverride) c.cl_ordered_fields)))
 	]
 
 and encode_ttype t =

+ 12 - 9
src/optimization/dce.ml

@@ -878,15 +878,18 @@ let run com main mode =
 	(* remove "override" from fields that do not override anything anymore *)
 	List.iter (fun mt -> match mt with
 		| TClassDecl c ->
-			c.cl_overrides <- List.filter (fun s ->
-				let rec loop c =
-					match c.cl_super with
-					| Some (csup,_) when PMap.mem s.cf_name csup.cl_fields -> true
-					| Some (csup,_) -> loop csup
-					| None -> false
-				in
-				loop c
-			) c.cl_overrides;
+			List.iter (fun cf ->
+				if has_class_field_flag cf CfOverride then begin
+					let rec loop c =
+						match c.cl_super with
+						| Some (csup,_) when PMap.mem cf.cf_name csup.cl_fields -> true
+						| Some (csup,_) -> loop csup
+						| None -> false
+					in
+					let b = loop c in
+					if not b then remove_class_field_flag cf CfOverride;
+				end
+			) c.cl_ordered_fields;
 		| _ -> ()
 	) com.types;
 

+ 2 - 2
src/typing/calls.ml

@@ -38,7 +38,7 @@ let make_call ctx e params t ?(force_inline=false) p =
 				(* Delay this to filters because that's when cl_descendants is set. *)
 				ctx.com.callbacks#add_before_save (fun () ->
 					let rec has_override c =
-						List.exists (fun cf -> cf.cf_name = f.cf_name) c.cl_overrides
+						PMap.mem f.cf_name c.cl_fields
 						|| List.exists has_override c.cl_descendants
 					in
 					if List.exists has_override c.cl_descendants then error (Printf.sprintf "Cannot force inline-call to %s because it is overridden" f.cf_name) p
@@ -460,7 +460,7 @@ let type_generic_function ctx (e,fa) el ?(using_param=None) with_type p =
 				end
 			end else begin
 				let cf2 = mk_cf2 name in
-				if List.memq cf c.cl_overrides then c.cl_overrides <- cf2 :: c.cl_overrides;
+				if has_class_field_flag cf CfOverride then add_class_field_flag cf2 CfOverride;
 				c.cl_fields <- PMap.add cf2.cf_name cf2 c.cl_fields;
 				c.cl_ordered_fields <- cf2 :: c.cl_ordered_fields;
 				finalize_field c cf2;

+ 0 - 3
src/typing/generic.ml

@@ -331,9 +331,6 @@ let rec build_generic ctx c p tl =
 			cg.cl_fields <- PMap.add f.cf_name f cg.cl_fields;
 			f
 		) c.cl_ordered_fields;
-		cg.cl_overrides <- List.map (fun f ->
-			try PMap.find f.cf_name cg.cl_fields with Not_found -> die "" __LOC__
-		) c.cl_overrides;
 		(* In rare cases the class name can become too long, so let's shorten it (issue #3090). *)
 		if String.length (snd cg.cl_path) > 254 then begin
 			let n = get_short_name () in

+ 1 - 1
src/typing/typeload.ml

@@ -906,7 +906,7 @@ let init_core_api ctx c =
 		) fcore;
 		PMap.iter (fun i f ->
 			let p = (match f.cf_expr with None -> c.cl_pos | Some e -> e.epos) in
-			if (has_class_field_flag f CfPublic) && not (Meta.has Meta.Hack f.cf_meta) && not (PMap.mem f.cf_name fcore) && not (List.memq f c.cl_overrides) then error ("Public field " ^ i ^ " is not part of core type") p;
+			if (has_class_field_flag f CfPublic) && not (Meta.has Meta.Hack f.cf_meta) && not (PMap.mem f.cf_name fcore) && not (has_class_field_flag f CfOverride) then error ("Public field " ^ i ^ " is not part of core type") p;
 		) fl;
 	in
 	check_fields ccore.cl_fields c.cl_fields;

+ 3 - 3
src/typing/typeloadCheck.ml

@@ -166,7 +166,7 @@ let check_native_name_override ctx child base =
 let check_overriding ctx c f =
 	match c.cl_super with
 	| None ->
-		if List.memq f c.cl_overrides then display_error ctx ("Field " ^ f.cf_name ^ " is declared 'override' but doesn't override any field") f.cf_pos
+		if has_class_field_flag f CfOverride then display_error ctx ("Field " ^ f.cf_name ^ " is declared 'override' but doesn't override any field") f.cf_pos
 	| _ when c.cl_extern && Meta.has Meta.CsNative c.cl_meta -> () (* -net-lib specific: do not check overrides on extern CsNative classes *)
 	| Some (csup,params) ->
 		let p = f.cf_name_pos in
@@ -182,7 +182,7 @@ let check_overriding ctx c f =
 			| _ -> ());
 			if ctx.com.config.pf_overload && (Meta.has Meta.Overload f2.cf_meta && not (Meta.has Meta.Overload f.cf_meta)) then
 				display_error ctx ("Field " ^ i ^ " should be declared with @:overload since it was already declared as @:overload in superclass") p
-			else if not (List.memq f c.cl_overrides) then
+			else if not (has_class_field_flag f CfOverride) then
 				display_error ctx ("Field " ^ i ^ " should be declared with 'override' since it is inherited from superclass " ^ s_type_path csup.cl_path) p
 			else if not (has_class_field_flag f CfPublic) && (has_class_field_flag f2 CfPublic) then
 				display_error ctx ("Field " ^ i ^ " has less visibility (public/private) than superclass one") p
@@ -205,7 +205,7 @@ let check_overriding ctx c f =
 					display_error ctx (error_msg (Unify l)) p;
 		with
 			Not_found ->
-				if List.memq f c.cl_overrides then
+				if has_class_field_flag f CfOverride then
 					let msg = if is_overload then
 						("Field " ^ i ^ " is declared 'override' but no compatible overload was found")
 					else begin

+ 3 - 2
src/typing/typeloadFields.ml

@@ -1407,7 +1407,7 @@ let init_field (ctx,cctx,fctx) f =
 		| Some a when fctx.is_abstract_member -> ctx.type_params <- a.a_params;
 		| _ -> ()
 	end;
-	let cf = 
+	let cf =
 		match f.cff_kind with
 		| FVar (t,e) ->
 			create_variable (ctx,cctx,fctx) c f t e p
@@ -1543,7 +1543,8 @@ let init_class ctx c p context_init herits fields =
 			| FKNormal ->
 				let dup = if fctx.is_static then PMap.exists cf.cf_name c.cl_fields || has_field cf.cf_name c.cl_super else PMap.exists cf.cf_name c.cl_statics in
 				if not cctx.is_native && not c.cl_extern && dup then error ("Same field name can't be used for both static and instance : " ^ cf.cf_name) p;
-				if fctx.override <> None then c.cl_overrides <- cf :: c.cl_overrides;
+				if fctx.override <> None then
+					add_class_field_flag cf CfOverride;
 				let is_var cf = match cf.cf_kind with | Var _ -> true | _ -> false in
 				if PMap.mem cf.cf_name (if fctx.is_static then c.cl_statics else c.cl_fields) then
 					if ctx.com.config.pf_overload && Meta.has Meta.Overload cf.cf_meta && not (is_var cf) then