Browse Source

fixed inlining : setting a local var prevent direct replacement

Nicolas Cannasse 17 years ago
parent
commit
b467a26f74
2 changed files with 13 additions and 1 deletions
  1. 1 0
      doc/CHANGES.txt
  2. 12 1
      typer.ml

+ 1 - 0
doc/CHANGES.txt

@@ -16,6 +16,7 @@
 	optimized line calculus from ast position
 	optimized line calculus from ast position
 	allow identifiers starting with _[0-9]
 	allow identifiers starting with _[0-9]
 	fixed access to flash.Vector methods : use AS3 namespace (faster)
 	fixed access to flash.Vector methods : use AS3 namespace (faster)
+	bugfix in inline functions : modifying a parameter can't modify a real local var anymore
 
 
 2008-10-04: 2.01
 2008-10-04: 2.01
 	fixed php.Sys
 	fixed php.Sys

+ 12 - 1
typer.ml

@@ -1427,6 +1427,7 @@ and type_call ctx e el p =
 and type_inline ctx f ethis params tret p =
 and type_inline ctx f ethis params tret p =
 	let locals = save_locals ctx in
 	let locals = save_locals ctx in
 	let hcount = Hashtbl.create 0 in
 	let hcount = Hashtbl.create 0 in
+	let lsets = Hashtbl.create 0 in
 	let pnames = List.map (fun (name,_,t) ->
 	let pnames = List.map (fun (name,_,t) ->
 		let name = add_local ctx name t in
 		let name = add_local ctx name t in
 		Hashtbl.add hcount name (ref 0);
 		Hashtbl.add hcount name (ref 0);
@@ -1487,6 +1488,16 @@ and type_inline ctx f ethis params tret p =
 			{ e with eexpr = TBlock l }
 			{ e with eexpr = TBlock l }
 		| TParenthesis _ | TIf (_,_,Some _) | TSwitch (_,_,Some _) ->
 		| TParenthesis _ | TIf (_,_,Some _) | TSwitch (_,_,Some _) ->
 			Type.map_expr (map term) e
 			Type.map_expr (map term) e
+		| TUnop (op,pref,({ eexpr = TLocal s } as e1)) ->
+			(match op with
+			| Increment | Decrement -> Hashtbl.add lsets s ()
+			| _ -> ());
+			{ e with eexpr = TUnop (op,pref,map false e1) }
+		| TBinop (op,({ eexpr = TLocal s } as e1),e2) ->
+			(match op with
+			| OpAssign | OpAssignOp _ -> Hashtbl.add lsets s ()
+			| _ -> ());
+			{ e with eexpr = TBinop (op,map false e1,map false e2) }
 		| TConst TSuper ->
 		| TConst TSuper ->
 			error "Cannot inline function containing super" e.epos
 			error "Cannot inline function containing super" e.epos
 		| TFunction _ ->
 		| TFunction _ ->
@@ -1499,7 +1510,7 @@ and type_inline ctx f ethis params tret p =
 	let subst = ref PMap.empty in
 	let subst = ref PMap.empty in
 	Hashtbl.add hcount vthis this_count;
 	Hashtbl.add hcount vthis this_count;
 	let vars = List.map2 (fun n e ->
 	let vars = List.map2 (fun n e ->
-		let flag = (match e.eexpr with
+		let flag = not (Hashtbl.mem lsets n) && (match e.eexpr with
 			| TLocal _ | TConst _ -> true
 			| TLocal _ | TConst _ -> true
 			| _ ->
 			| _ ->
 				let used = !(Hashtbl.find hcount n) in
 				let used = !(Hashtbl.find hcount n) in