Browse Source

[inline] don't store full expressions in v_extra, we only care about the type

closes #6833
closes #7617
Simon Krajewski 6 years ago
parent
commit
2d9cf81a3e
2 changed files with 39 additions and 2 deletions
  1. 3 2
      src/optimization/inline.ml
  2. 36 0
      tests/unit/src/unit/issues/Issue6833.hx

+ 3 - 2
src/optimization/inline.ml

@@ -394,7 +394,8 @@ class inline_state ctx ethis params cf f p = object(self)
 					_had_side_effect <- true;
 					_had_side_effect <- true;
 					l.i_force_temp <- true;
 					l.i_force_temp <- true;
 				end;
 				end;
-				if l.i_abstract_this then l.i_subst.v_extra <- Some ([],Some e);
+				(* We use a null expression because we only care about the type (for abstract casts). *)
+				if l.i_abstract_this then l.i_subst.v_extra <- Some ([],Some {e with eexpr = TConst TNull});
 				loop ((l,e) :: acc) pl al false
 				loop ((l,e) :: acc) pl al false
 			| [], (v,opt) :: al ->
 			| [], (v,opt) :: al ->
 				let l = self#declare v in
 				let l = self#declare v in
@@ -510,7 +511,7 @@ class inline_state ctx ethis params cf f p = object(self)
 				if not (self#read v).i_outside then begin
 				if not (self#read v).i_outside then begin
 					v.v_type <- map_type v.v_type;
 					v.v_type <- map_type v.v_type;
 					match v.v_extra with
 					match v.v_extra with
-					| Some(tl,Some e) when ctx.com.platform <> Cs ->
+					| Some(tl,Some e) ->
 						v.v_extra <- Some(tl,Some (map_expr_type e));
 						v.v_extra <- Some(tl,Some (map_expr_type e));
 					| _ ->
 					| _ ->
 						()
 						()

+ 36 - 0
tests/unit/src/unit/issues/Issue6833.hx

@@ -0,0 +1,36 @@
+package unit.issues;
+
+class Issue6833 extends unit.Test {
+	function test() {
+		for(p in new KeyValueIterator([1 => 'hello'])) {}
+	}
+}
+
+private class KeyValueIterator<K,V> {
+	var map:Map<K,V>;
+	var keys:Iterator<K>;
+
+	public inline function new(map:Map<K,V>) {
+		this.map = map;
+		this.keys = map.keys();
+	}
+
+	public inline function hasNext():Bool {
+		return keys.hasNext();
+	}
+
+	public inline function next():KeyValuePair<K,V> {
+		var key = keys.next();
+		return new KeyValuePair<K,V>(key, map.get(key));
+	}
+}
+
+private class KeyValuePair<K,V> {
+	public var key (default,null):K;
+	public var value (default,null):Null<V>;
+
+	public inline function new(key:K, value:Null<V>) {
+		this.key = key;
+		this.value = value;
+	}
+}