Browse Source

separate variable assignments from read usage

Dan Korostelev 10 years ago
parent
commit
aebb87551d
2 changed files with 11 additions and 5 deletions
  1. 9 3
      filters.ml
  2. 2 2
      typer.ml

+ 9 - 3
filters.ml

@@ -278,9 +278,15 @@ type usage =
 	| Function of ((usage -> unit) -> unit)
 	| Function of ((usage -> unit) -> unit)
 	| Declare of tvar
 	| Declare of tvar
 	| Use of tvar
 	| Use of tvar
+	| Assign of tvar
 
 
 let rec local_usage f e =
 let rec local_usage f e =
 	match e.eexpr with
 	match e.eexpr with
+	| TBinop ((OpAssign | OpAssignOp _), { eexpr = TLocal v }, e2) ->
+		local_usage f e2;
+		f (Assign v)
+	| TUnop ((Increment | Decrement), _, { eexpr = TLocal v }) ->
+		f (Assign v)
 	| TLocal v ->
 	| TLocal v ->
 		f (Use v)
 		f (Use v)
 	| TVar (v,eo) ->
 	| TVar (v,eo) ->
@@ -405,7 +411,7 @@ let captured_vars com e =
 			let tmp_used = ref used in
 			let tmp_used = ref used in
 			let rec browse = function
 			let rec browse = function
 				| Block f | Loop f | Function f -> f browse
 				| Block f | Loop f | Function f -> f browse
-				| Use v ->
+				| Use v | Assign v ->
 					if PMap.mem v.v_id !tmp_used then fused := PMap.add v.v_id v !fused;
 					if PMap.mem v.v_id !tmp_used then fused := PMap.add v.v_id v !fused;
 				| Declare v ->
 				| Declare v ->
 					tmp_used := PMap.remove v.v_id !tmp_used
 					tmp_used := PMap.remove v.v_id !tmp_used
@@ -478,7 +484,7 @@ let captured_vars com e =
 					decr depth;
 					decr depth;
 				| Declare v ->
 				| Declare v ->
 					if in_loop then vars := PMap.add v.v_id !depth !vars;
 					if in_loop then vars := PMap.add v.v_id !depth !vars;
-				| Use v ->
+				| Use v | Assign v ->
 					try
 					try
 						let d = PMap.find v.v_id !vars in
 						let d = PMap.find v.v_id !vars in
 						if d <> !depth then used := PMap.add v.v_id v !used;
 						if d <> !depth then used := PMap.add v.v_id v !used;
@@ -508,7 +514,7 @@ let captured_vars com e =
 			decr depth;
 			decr depth;
 		| Declare v ->
 		| Declare v ->
 			vars := PMap.add v.v_id !depth !vars;
 			vars := PMap.add v.v_id !depth !vars;
-		| Use v ->
+		| Use v | Assign v ->
 			try
 			try
 				let d = PMap.find v.v_id !vars in
 				let d = PMap.find v.v_id !vars in
 				if d <> !depth then used := PMap.add v.v_id v !used;
 				if d <> !depth then used := PMap.add v.v_id v !used;

+ 2 - 2
typer.ml

@@ -3374,8 +3374,8 @@ and type_expr ctx (e,p) (with_type:with_type) =
 			if params <> [] || inline then v.v_extra <- Some (params,if inline then Some e else None);
 			if params <> [] || inline then v.v_extra <- Some (params,if inline then Some e else None);
 			let rec loop = function
 			let rec loop = function
 				| Filters.Block f | Filters.Loop f | Filters.Function f -> f loop
 				| Filters.Block f | Filters.Loop f | Filters.Function f -> f loop
-				| Filters.Use v2 when v == v2 -> raise Exit
-				| Filters.Use _ | Filters.Declare _ -> ()
+				| Filters.Use v2 | Filters.Assign v2 when v == v2 -> raise Exit
+				| Filters.Use _ | Filters.Assign _ | Filters.Declare _ -> ()
 			in
 			in
 			let is_rec = (try Filters.local_usage loop e; false with Exit -> true) in
 			let is_rec = (try Filters.local_usage loop e; false with Exit -> true) in
 			let decl = (if is_rec then begin
 			let decl = (if is_rec then begin