瀏覽代碼

Revert "cache friendly debug line calculus"

This reverts commit f0aeb9bcfc9701c18f56058863d8c0ada919f037.
Simon Krajewski 9 年之前
父節點
當前提交
872cc9d483
共有 2 個文件被更改,包括 10 次插入45 次删除
  1. 7 29
      src/generators/genhl.ml
  2. 3 16
      src/syntax/lexer.mll

+ 7 - 29
src/generators/genhl.ml

@@ -44,13 +44,13 @@ type method_context = {
 	mregs : (int, ttype) lookup;
 	mops : opcode DynArray.t;
 	mret : ttype;
-	mdebug : Ast.pos DynArray.t;
+	mdebug : (int * int) DynArray.t;
 	mutable mcaptured : method_capture;
 	mutable mcontinues : (int -> unit) list;
 	mutable mbreaks : (int -> unit) list;
 	mutable mtrys : int;
 	mutable mcaptreg : int;
-	mutable mcurpos : Ast.pos;
+	mutable mcurpos : (int * int);
 }
 
 type array_impl = {
@@ -193,7 +193,7 @@ let method_context id t captured =
 		mtrys = 0;
 		mcaptreg = 0;
 		mdebug = DynArray.create();
-		mcurpos = Ast.null_pos;
+		mcurpos = (0,0);
 	}
 
 let field_name c f =
@@ -246,10 +246,7 @@ let rec unsigned t =
 	| _ -> false
 
 let set_curpos ctx p =
-	ctx.m.mcurpos <- p
-
-let make_debug ctx arr =
-	let get_relative_path p =
+	let get_relative_path() =
 		match Common.defined ctx.com Common.Define.AbsolutePath with
 		| true -> if (Filename.is_relative p.pfile)
 			then Filename.concat (Sys.getcwd()) p.pfile
@@ -266,26 +263,7 @@ let make_debug ctx arr =
 		with Not_found ->
 			p.pfile
 	in
-	let pos = ref (0,0) in
-	let cur_file = ref 0 in
-	let cur_line = ref 0 in
-	let cur = ref Ast.null_pos in
-	let out = Array.make (DynArray.length arr) !pos in
-	for i = 0 to DynArray.length arr - 1 do
-		let p = DynArray.unsafe_get arr i in
-		if p != !cur then begin
-			let file = if p.pfile == (!cur).pfile then !cur_file else lookup ctx.cdebug_files p.pfile (fun() -> get_relative_path p) in
-			let line = Lexer.get_error_line p in
-			if line <> !cur_line || file <> !cur_file then begin
-				cur_file := file;
-				cur_line := line;
-				pos := (file,line);
-			end;
-			cur := p;
-		end;
-		Array.unsafe_set out i !pos
-	done;
-	out
+	ctx.m.mcurpos <- (lookup ctx.cdebug_files p.pfile get_relative_path,Lexer.get_error_line p)
 
 let rec to_type ?tref ctx t =
 	match t with
@@ -2309,7 +2287,7 @@ and gen_method_wrapper ctx rt t p =
 			ftype = HFun (rt :: targs, tret);
 			regs = DynArray.to_array ctx.m.mregs.arr;
 			code = DynArray.to_array ctx.m.mops;
-			debug = make_debug ctx ctx.m.mdebug;
+			debug = DynArray.to_array ctx.m.mdebug;
 		} in
 		ctx.m <- old;
 		DynArray.add ctx.cfunctions f;
@@ -2434,7 +2412,7 @@ and make_fun ?gen_content ctx name fidx f cthis cparent =
 		ftype = HFun (fargs, tret);
 		regs = DynArray.to_array ctx.m.mregs.arr;
 		code = DynArray.to_array ctx.m.mops;
-		debug = make_debug ctx ctx.m.mdebug;
+		debug = DynArray.to_array ctx.m.mdebug;
 	} in
 	ctx.m <- old;
 	Hashtbl.add ctx.defined_funs fidx ();

+ 3 - 16
src/syntax/lexer.mll

@@ -49,8 +49,6 @@ type lexer_file = {
 	mutable llines : (int * int) list;
 	mutable lalines : (int * int) array;
 	mutable lstrings : int list;
-	mutable llast : int;
-	mutable llastindex : int;
 }
 
 let make_file file =
@@ -61,8 +59,6 @@ let make_file file =
 		llines = [0,1];
 		lalines = [|0,1|];
 		lstrings = [];
-		llast = 1000000;
-		llastindex = 0;
 	}
 
 
@@ -138,27 +134,18 @@ let find_line p f =
 	if f.lmaxline <> f.lline then begin
 		f.lmaxline <- f.lline;
 		f.lalines <- Array.of_list (List.rev f.llines);
-		f.llast <- 1000000;
-		f.llastindex <- 0;
 	end;
 	let rec loop min max =
 		let med = (min + max) lsr 1 in
 		let lp, line = Array.unsafe_get f.lalines med in
-		if med = min then begin
-			f.llast <- p;
-			f.llastindex <- med;
+		if med = min then
 			line, p - lp
-		end else if lp > p then
+		else if lp > p then
 			loop min med
 		else
 			loop med max
 	in
-	if p >= f.llast then begin
-		let lp, line = Array.unsafe_get f.lalines f.llastindex in
-		let lp2, _ = Array.unsafe_get f.lalines (f.llastindex + 1) in
-		if p >= lp && p < lp2 then line, p - lp else loop 0 (Array.length f.lalines)
-	end else
-		loop 0 (Array.length f.lalines)
+	loop 0 (Array.length f.lalines)
 
 (* resolve a position within a non-haxe file by counting newlines *)
 let resolve_pos file =