Selaa lähdekoodia

Merge pull request #3412 from Simn/ssa_prepare

SSA preparation part 2
Simon Krajewski 11 vuotta sitten
vanhempi
commit
accdada204

+ 1 - 1
codegen.ml

@@ -1637,7 +1637,7 @@ module UnificationCallback = struct
 		| TFun(args,_) ->
 		| TFun(args,_) ->
 			check_call_params f el args
 			check_call_params f el args
 		| _ ->
 		| _ ->
-			el
+			List.map (fun e -> f e t_dynamic) el
 
 
 	let rec run f e =
 	let rec run f e =
 		let f e t =
 		let f e t =

+ 1 - 1
filters.ml

@@ -1092,7 +1092,7 @@ let run com tctx main =
 				save();
 				save();
 				e)
 				e)
 			| _ -> fun e -> e);
 			| _ -> fun e -> e);
-		if com.foptimize then (fun e -> Optimizer.reduce_expression tctx (Optimizer.inline_constructors tctx e)) else Optimizer.sanitize tctx;
+		if com.foptimize then (fun e -> Optimizer.reduce_expression tctx (Optimizer.inline_constructors tctx e)) else Optimizer.sanitize com;
 		check_local_vars_init;
 		check_local_vars_init;
 		captured_vars com;
 		captured_vars com;
 	] in
 	] in

+ 0 - 13
matcher.ml

@@ -783,19 +783,6 @@ let column_sigma mctx st pmat =
 	loop pmat;
 	loop pmat;
 	List.rev_map (fun con -> con,not (Hashtbl.mem unguarded con.c_def)) !acc,!bindings
 	List.rev_map (fun con -> con,not (Hashtbl.mem unguarded con.c_def)) !acc,!bindings
 
 
-(* Determines if we have a Null<T>. Unlike is_null, this returns true even if the wrapped type is nullable itself. *)
-let rec is_explicit_null = function
-	| TMono r ->
-		(match !r with None -> false | Some t -> is_null t)
-	| TType ({ t_path = ([],"Null") },[t]) ->
-		true
-	| TLazy f ->
-		is_null (!f())
-	| TType (t,tl) ->
-		is_null (apply_params t.t_params tl t.t_type)
-	| _ ->
-		false
-
 let rec all_ctors mctx t =
 let rec all_ctors mctx t =
 	let h = ref PMap.empty in
 	let h = ref PMap.empty in
 	if is_explicit_null t then h := PMap.add (CConst TNull) Ast.null_pos !h;
 	if is_explicit_null t then h := PMap.add (CConst TNull) Ast.null_pos !h;

+ 5 - 5
optimizer.ml

@@ -35,9 +35,9 @@ let has_side_effect e =
 		| TConst _ | TLocal _ | TTypeExpr _ | TFunction _ -> ()
 		| TConst _ | TLocal _ | TTypeExpr _ | TFunction _ -> ()
 		| TCall ({ eexpr = TField(_,FStatic({ cl_path = ([],"Std") },{ cf_name = "string" })) },args) -> Type.iter loop e
 		| TCall ({ eexpr = TField(_,FStatic({ cl_path = ([],"Std") },{ cf_name = "string" })) },args) -> Type.iter loop e
 		| TNew _ | TCall _ | TBinop ((OpAssignOp _ | OpAssign),_,_) | TUnop ((Increment|Decrement),_,_) -> raise Exit
 		| TNew _ | TCall _ | TBinop ((OpAssignOp _ | OpAssign),_,_) | TUnop ((Increment|Decrement),_,_) -> raise Exit
-		| TReturn _ | TBreak | TContinue | TThrow _ | TCast (_,Some _) -> raise Exit
+		| TReturn _ | TBreak | TContinue | TThrow _ | TCast (_,Some _) | TVar _ -> raise Exit
 		| TArray _ | TEnumParameter _ | TCast (_,None) | TBinop _ | TUnop _ | TParenthesis _ | TMeta _ | TWhile _ | TFor _
 		| TArray _ | TEnumParameter _ | TCast (_,None) | TBinop _ | TUnop _ | TParenthesis _ | TMeta _ | TWhile _ | TFor _
-		| TField _ | TIf _ | TTry _ | TSwitch _ | TArrayDecl _ | TVar _ | TBlock _ | TObjectDecl _ -> Type.iter loop e
+		| TField _ | TIf _ | TTry _ | TSwitch _ | TArrayDecl _ | TBlock _ | TObjectDecl _ -> Type.iter loop e
 	in
 	in
 	try
 	try
 		loop e; false
 		loop e; false
@@ -873,7 +873,7 @@ let sanitize_expr com e =
 	| _ ->
 	| _ ->
 		e
 		e
 
 
-let reduce_expr ctx e =
+let reduce_expr com e =
 	match e.eexpr with
 	match e.eexpr with
 	| TSwitch (_,cases,_) ->
 	| TSwitch (_,cases,_) ->
 		List.iter (fun (cl,_) ->
 		List.iter (fun (cl,_) ->
@@ -906,8 +906,8 @@ let reduce_expr ctx e =
 	| _ ->
 	| _ ->
 		e
 		e
 
 
-let rec sanitize ctx e =
-	sanitize_expr ctx.com (reduce_expr ctx (Type.map_expr (sanitize ctx) e))
+let rec sanitize com e =
+	sanitize_expr com (reduce_expr com (Type.map_expr (sanitize com) e))
 
 
 (* ---------------------------------------------------------------------- *)
 (* ---------------------------------------------------------------------- *)
 (* REDUCE *)
 (* REDUCE *)

+ 0 - 1
std/cpp/_std/Date.hx

@@ -78,7 +78,6 @@
 			default:
 			default:
 				throw "Invalid date format : " + s;
 				throw "Invalid date format : " + s;
 		}
 		}
-		return null;
 	}
 	}
 }
 }
 
 

+ 1 - 1
std/cpp/_std/Reflect.hx

@@ -62,7 +62,7 @@
 	}
 	}
 
 
 	public static function compare<T>( a : T, b : T ) : Int {
 	public static function compare<T>( a : T, b : T ) : Int {
-		return ( a == b ) ? 0 : (((cast a) > (cast b)) ? 1 : -1);
+		return ( a == b ) ? 0 : (((a:Dynamic) > (b:Dynamic)) ? 1 : -1);
 	}
 	}
 
 
 	public static function compareMethods( f1 : Dynamic, f2 : Dynamic ) : Bool {
 	public static function compareMethods( f1 : Dynamic, f2 : Dynamic ) : Bool {

+ 0 - 1
std/cs/internal/Function.hx

@@ -40,7 +40,6 @@ package cs.internal;
 	public function __hx_invokeDynamic(dynArgs:Array<Dynamic>):Dynamic
 	public function __hx_invokeDynamic(dynArgs:Array<Dynamic>):Dynamic
 	{
 	{
 		throw "Abstract implementation";
 		throw "Abstract implementation";
-		return null;
 	}
 	}
 }
 }
 
 

+ 0 - 2
std/cs/internal/Runtime.hx

@@ -397,7 +397,6 @@ import cs.system.Object;
 	{
 	{
 		//not implemented yet;
 		//not implemented yet;
 		throw "Not implemented";
 		throw "Not implemented";
-		return null;
 	}
 	}
 
 
 	public static function callMethod(obj:Dynamic, methods:NativeArray<MethodBase>, methodLength:Int, args:Array<Dynamic>):Dynamic
 	public static function callMethod(obj:Dynamic, methods:NativeArray<MethodBase>, methodLength:Int, args:Array<Dynamic>):Dynamic
@@ -587,7 +586,6 @@ import cs.system.Object;
 	public static function slowCallField(obj:Dynamic, field:String, args:Array<Dynamic>):Dynamic
 	public static function slowCallField(obj:Dynamic, field:String, args:Array<Dynamic>):Dynamic
 	{
 	{
 		throw "not implemented";
 		throw "not implemented";
-		return null;
 	}
 	}
 
 
 	@:functionCode('
 	@:functionCode('

+ 0 - 1
std/flash/_std/Xml.hx

@@ -114,7 +114,6 @@ extern enum XmlType {
 		default :
 		default :
 			throw "unimplemented node type: " + node.nodeType;
 			throw "unimplemented node type: " + node.nodeType;
 		}
 		}
-		return null;
 	}
 	}
 
 
 	private function get_nodeName() : String {
 	private function get_nodeName() : String {

+ 0 - 1
std/haxe/Resource.hx

@@ -158,7 +158,6 @@ class Resource {
         #else
         #else
         return Bytes.ofData(content.get(name,null));
         return Bytes.ofData(content.get(name,null));
         #end
         #end
-		return null;
 		#else
 		#else
 		for( x in content )
 		for( x in content )
 			if( x.name == name ) {
 			if( x.name == name ) {

+ 0 - 2
std/haxe/Utf8.hx

@@ -63,7 +63,6 @@ class Utf8 {
 	**/
 	**/
 	public static function encode( s : String ) : String {
 	public static function encode( s : String ) : String {
 		throw "Not implemented";
 		throw "Not implemented";
-		return s;
 	}
 	}
 
 
 	/**
 	/**
@@ -72,7 +71,6 @@ class Utf8 {
 	**/
 	**/
 	public static function decode( s : String ) : String {
 	public static function decode( s : String ) : String {
 		throw "Not implemented";
 		throw "Not implemented";
-		return s;
 	}
 	}
 
 
 	/**
 	/**

+ 0 - 1
std/haxe/io/Input.hx

@@ -46,7 +46,6 @@ class Input {
 	public function readByte() : Int {
 	public function readByte() : Int {
 	#if cpp
 	#if cpp
 		throw "Not implemented";
 		throw "Not implemented";
-		return 0;
 	#else
 	#else
 		return throw "Not implemented";
 		return throw "Not implemented";
 	#end
 	#end

+ 0 - 1
std/java/_std/sys/FileSystem.hx

@@ -65,7 +65,6 @@ class FileSystem {
 			return new File(relPath).getCanonicalPath();
 			return new File(relPath).getCanonicalPath();
 		} catch (e: java.io.IOException) {
 		} catch (e: java.io.IOException) {
 			throw new java.lang.RuntimeException(e);
 			throw new java.lang.RuntimeException(e);
-			return null;
 		}
 		}
 	}
 	}
 
 

+ 0 - 1
std/java/db/Jdbc.hx

@@ -307,7 +307,6 @@ private class JdbcResultSet implements sys.db.ResultSet
     {
     {
   		return rs.getString(n);
   		return rs.getString(n);
     } catch(e:Dynamic) throw e;
     } catch(e:Dynamic) throw e;
-    return null;
 	}
 	}
 
 
 	public function getIntResult( n : Int ) : Int
 	public function getIntResult( n : Int ) : Int

+ 0 - 1
std/java/internal/Function.hx

@@ -42,7 +42,6 @@ import java.internal.Runtime;
 	public function __hx_invokeDynamic(dynArgs:Array<Dynamic>):Dynamic
 	public function __hx_invokeDynamic(dynArgs:Array<Dynamic>):Dynamic
 	{
 	{
 		throw "Abstract implementation";
 		throw "Abstract implementation";
-		return null;
 	}
 	}
 }
 }
 
 

+ 3 - 4
std/python/_std/EReg.hx

@@ -155,14 +155,13 @@ class EReg {
 				lastEnd = x.end();
 				lastEnd = x.end();
 			}
 			}
 			ret.push(s.substr(lastEnd));
 			ret.push(s.substr(lastEnd));
-			return ret;
+			ret;
 		} else {
 		} else {
 			this.match(s);
 			this.match(s);
 			if (matchObj == null) {
 			if (matchObj == null) {
-
-				return [s];
+				[s];
 			} else {
 			} else {
-				return [ s.substring(0, matchObj.start()), s.substr(matchObj.end()) ];
+				[ s.substring(0, matchObj.start()), s.substr(matchObj.end()) ];
 			}
 			}
 
 
 		}
 		}

+ 7 - 7
std/python/_std/Type.hx

@@ -1,9 +1,3 @@
-import python.internal.AnonObject;
-import python.internal.EnumImpl;
-import python.internal.Internal;
-import python.lib.Builtin;
-import python.Syntax;
-
 /*
 /*
  * Copyright (C)2005-2012 Haxe Foundation
  * Copyright (C)2005-2012 Haxe Foundation
  *
  *
@@ -25,6 +19,13 @@ import python.Syntax;
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  * DEALINGS IN THE SOFTWARE.
  * DEALINGS IN THE SOFTWARE.
  */
  */
+
+import python.internal.AnonObject;
+import python.internal.EnumImpl;
+import python.internal.Internal;
+import python.lib.Builtin;
+import python.Syntax;
+
 enum ValueType {
 enum ValueType {
 	TNull;
 	TNull;
 	TInt;
 	TInt;
@@ -137,7 +138,6 @@ enum ValueType {
 			default:
 			default:
 				throw "Too many arguments";
 				throw "Too many arguments";
 		}
 		}
-		return null;
 	}
 	}
 
 
 	public static function createEmptyInstance<T>( cl : Class<T> ) : T
 	public static function createEmptyInstance<T>( cl : Class<T> ) : T

+ 0 - 1
tests/unit/issues/Issue2907.hx

@@ -14,7 +14,6 @@ class Issue2907 extends Test {
 		} catch(e:Dynamic) {
 		} catch(e:Dynamic) {
 			return null;
 			return null;
 		}
 		}
-		return null;
 	}
 	}
 
 
 	function test<T>() {
 	function test<T>() {

+ 13 - 0
type.ml

@@ -595,6 +595,19 @@ let rec is_null = function
 	| _ ->
 	| _ ->
 		false
 		false
 
 
+(* Determines if we have a Null<T>. Unlike is_null, this returns true even if the wrapped type is nullable itself. *)
+let rec is_explicit_null = function
+	| TMono r ->
+		(match !r with None -> false | Some t -> is_null t)
+	| TType ({ t_path = ([],"Null") },[t]) ->
+		true
+	| TLazy f ->
+		is_null (!f())
+	| TType (t,tl) ->
+		is_null (apply_params t.t_params tl t.t_type)
+	| _ ->
+		false
+
 let rec has_mono t = match t with
 let rec has_mono t = match t with
 	| TMono r ->
 	| TMono r ->
 		(match !r with None -> true | Some t -> has_mono t)
 		(match !r with None -> true | Some t -> has_mono t)