Browse Source

slightly improved cl_build ordering by using delay_late

Nicolas Cannasse 9 years ago
parent
commit
569c5dc612
2 changed files with 14 additions and 1 deletions
  1. 11 0
      typecore.ml
  2. 3 1
      typeload.ml

+ 11 - 0
typecore.ml

@@ -365,6 +365,17 @@ let delay ctx p f =
 	in
 	ctx.g.delayed <- loop ctx.g.delayed
 
+let delay_late ctx p f =
+	let rec loop = function
+		| [] -> [p,[f]]
+		| (p2,l) :: rest ->
+			if p2 <= p then
+				(p2,l) :: loop rest
+			else
+				(p,[f]) :: (p2,l) :: rest
+	in
+	ctx.g.delayed <- loop ctx.g.delayed
+
 let rec flush_pass ctx p (where:string) =
 	match ctx.g.delayed with
 	| (p2,l) :: rest when p2 <= p ->

+ 3 - 1
typeload.ml

@@ -91,6 +91,8 @@ let module_pass_1 com m tdecls loadp =
 			let priv = List.mem HPrivate d.d_flags in
 			let path = make_path d.d_name priv in
 			let c = mk_class m path p in
+			(* we shouldn't load any other type until we propertly set cl_build *)
+			c.cl_build <- (fun() -> assert false);
 			c.cl_module <- m;
 			c.cl_private <- priv;
 			c.cl_doc <- d.d_doc;
@@ -2957,7 +2959,7 @@ let init_module_type ctx context_init do_init (decl,p) =
 				true;
 			with Exit ->
 				c.cl_build <- make_pass ctx build;
-				delay ctx PTypeField (fun() -> ignore(c.cl_build())); (* delay after PBuildClass, not very good but better than forgotten *)
+				delay_late ctx PBuildClass (fun() -> ignore(c.cl_build()));
 				false
 			| exn ->
 				c.cl_build <- (fun()-> true);