Skip to content

Commit

Permalink
Merry Christmas! New analyzer
Browse files Browse the repository at this point in the history
closes #3705
closes #3938
closes #3956
closes #4004
closes #4239
closes #4241
closes #4265
closes #4399
closes #4456
closes #4563
closes #4727
closes #4731
  • Loading branch information
Simn committed Dec 24, 2015
1 parent 5b0e37a commit d57112a
Show file tree
Hide file tree
Showing 24 changed files with 2,187 additions and 1,601 deletions.
3,341 changes: 1,822 additions & 1,519 deletions analyzer.ml

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions filters.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,6 @@ let run com tctx main =
check_local_vars_init;
Optimizer.inline_constructors tctx;
Optimizer.reduce_expression tctx;
blockify_ast;
captured_vars com;
] in
List.iter (run_expression_filters tctx filters) new_types;
Expand All @@ -1244,9 +1243,7 @@ let run com tctx main =
else
fun e ->
let save = save_locals tctx in
let timer = timer "analyzer-simplify-apply" in
let e = try snd (Analyzer.Simplifier.apply com e) with Exit -> e in
timer();
let e = try Analyzer.Run.roundtrip com (Analyzer.Config.get_base_config com) e with Exit -> e in
save();
e );
if com.foptimize then (fun e -> Optimizer.reduce_expression tctx e) else Optimizer.sanitize com;
Expand Down
10 changes: 10 additions & 0 deletions tests/misc/projects/Issue3956/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Main {
static function main() {
var i = getInt();
call(i++, i > 0 ? { call(0, 0); 1; } : 1);
}

static function getInt() { return 0; }

static function call(a:Int, b:Int) { Sys.stderr().writeString(a + " " + b + "\n"); }
}
3 changes: 3 additions & 0 deletions tests/misc/projects/Issue3956/compile.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-main Main
-D analyzer
-x neko.n
2 changes: 2 additions & 0 deletions tests/misc/projects/Issue3956/compile.hxml.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0 0
0 1
10 changes: 10 additions & 0 deletions tests/misc/projects/Issue4265/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Main {
static function main() {
var c = Std.int(Math.random() - 0.5); //0

Sys.stderr().writeString(switch (c) {
case 1: '1';
default: 'analyzer removed this ';
});
}
}
3 changes: 3 additions & 0 deletions tests/misc/projects/Issue4265/compile.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-main Main
-D analyzer
-x neko.n
1 change: 1 addition & 0 deletions tests/misc/projects/Issue4265/compile.hxml.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
analyzer removed this
19 changes: 19 additions & 0 deletions tests/misc/projects/Issue4399/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Main {
static function main() {
Sys.stderr().writeString("" + foo(2));
}

static var array:Array<Int> = [1,2,3,4,5];

static function foo(value:Int):Int {
var i:Int = 0;
var m:Int = 0;
while(i < array.length) {
if(array[i] == value) {
m = i;
}
++i;
}
return m;
}
}
3 changes: 3 additions & 0 deletions tests/misc/projects/Issue4399/compile.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-main Main
-D analyzer
-x neko.n
1 change: 1 addition & 0 deletions tests/misc/projects/Issue4399/compile.hxml.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
34 changes: 34 additions & 0 deletions tests/misc/projects/Issue4456/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class A {
public function f():Array<A> {
return [];
}

public function f2():A {
return this;
}
}

@:generic
class B<T:{function new():Void;}> {
var items:Map<Int,A>;

public function new() {
items = new Map();
}

public function f():Array<A> {
var a = [];
for (node in items)
a = a.concat(node.f());
return a;
}
}

class Main {
static function main() {
var b = new B<Main>();
Sys.stderr().writeString("" + b.f());
}

public function new() { }
}
3 changes: 3 additions & 0 deletions tests/misc/projects/Issue4456/compile.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-main Main
-D analyzer
-x neko.n
1 change: 1 addition & 0 deletions tests/misc/projects/Issue4456/compile.hxml.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
15 changes: 15 additions & 0 deletions tests/misc/projects/Issue4563/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Main {
static function main() {
Sys.stderr().writeString("" + test(get(true)));
Sys.stderr().writeString("" + test(get(false)));
}

static function get(b:Bool) return b;

static inline function test(a:Bool):Int {
if (a)
return 42;
else
return 43;
}
}
3 changes: 3 additions & 0 deletions tests/misc/projects/Issue4563/compile.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-main Main
-D analyzer
-x neko.n
1 change: 1 addition & 0 deletions tests/misc/projects/Issue4563/compile.hxml.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4243
13 changes: 5 additions & 8 deletions tests/optimization/src/Test.hx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class InlineCtor {
@:analyzer(no_local_dce)
@:analyzer(no_check_has_effect)
class Test {
@:js('3;')
@:js('')
static function testNoOpRemoval() {
1;
2;
Expand Down Expand Up @@ -119,20 +119,20 @@ class Test {

@:js('
var a = [1,2];
a[-1];
var b = a[-1];
')
static function testArrayInlineCancelNegative() {
var a = [1, 2];
a[-1];
var b = a[-1];
}

@:js('
var a = [1,2];
a[2];
var b = a[2];
')
static function testArrayInlineCancelExceeds() {
var a = [1, 2];
a[2];
var b = a[2];
}

@:js('
Expand All @@ -146,7 +146,6 @@ class Test {
var a = true;
var b = 0;
b = 1;
b;
')
static function testSwitch1() {
var a = true;
Expand All @@ -155,14 +154,12 @@ class Test {
case true: b = 1;
case false: b = 2;
}
b; // TODO: this should become 1
}

@:js('
var a = true;
var b = 0;
a = true;
a;
')
static function testSwitch2() {
var a = true;
Expand Down
Loading

5 comments on commit d57112a

@YellowAfterlife
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected. Merry Christmas!

@eliasku
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Merry Christmas!

@delahee
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Simn Wow it's very impressive. Is there any notation like C "volatile" to impeach a variable optimisation, ? An example use case is for Shared memories.

@nadako
Copy link
Member

@nadako nadako commented on d57112a Dec 24, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh my god... Simply wow!

@sledorze
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot simon!!! :)

Please sign in to comment.