Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method inlining to inline constructors filter #9599

Merged
merged 30 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7af8390
Remove unused decls array
basro Jun 6, 2020
f2dc439
Mark inline objects using metadata instead of identifying them by order.
basro Jun 12, 2020
bb3cbe9
Remove unused e.etype from match
basro Jun 12, 2020
aac7b34
Replace e with mark_ctors result.
basro Jun 12, 2020
4030cd9
Fix mark_ctors
basro Jun 12, 2020
4b837e8
Remove unused id_start and id_end
basro Jun 12, 2020
830b1a7
debug hacks
basro Jun 13, 2020
48ad141
Make handle field case handle inline methods too.
basro Jun 13, 2020
b808230
Implement inline constructor method inlining (Has known bugs marked w…
basro Jun 14, 2020
0a1a26b
Remove debug prints.
basro Jun 14, 2020
2e8291b
Fix typing of ethis on method inline.
basro Jun 14, 2020
1772ea9
For now don't forward captured to the inlined method analysis
basro Jun 14, 2020
3067808
Add missing result of this expression to inlined method.
basro Jun 14, 2020
7898077
Improve names of some variables.
basro Jun 15, 2020
41c345a
Analyze aliases in call args of inlined methods and cancel the result…
basro Jun 15, 2020
8fc0036
Remove commented code.
basro Jun 15, 2020
3c28c30
Support returning inline objects from inlined methods
basro Jun 15, 2020
5bd17d2
remove debug stuff.
basro Jun 16, 2020
d433d94
Factor out call arg analysis
basro Jun 16, 2020
61478d6
Some documentation.
basro Jun 16, 2020
121adcd
Add return type to mark_ctors
basro Jun 16, 2020
de2e708
Set io_has_untyped if inlined method had HasUntyped
basro Jun 16, 2020
98e3b6f
Add @:inlineObject to meta.json and use that instead of Meta.Custom
basro Jun 16, 2020
3347d33
Add more comments
basro Jun 16, 2020
9bbf182
Add inline constructor tests.
basro Jun 17, 2020
16313ea
Use record for IOKCtor data
basro Jun 17, 2020
570b672
Check that the expression has inline objects before doing any work.
basro Jun 17, 2020
b8719fc
Make sure the field we are inlining is a compatible function
basro Jun 17, 2020
fef40fc
Add test for incompatible method inline cancellations.
basro Jun 17, 2020
c51a36f
Check that the class method type unifies with the field expression ty…
basro Jun 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src-json/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,12 @@
"doc": "Internally used to mark expressions that were passed as arguments of an inlined constructor.",
"internal": true
},
{
"name": "InlineObject",
"metadata": ":inlineObject",
"doc": "Internally used by inline constructors filter to mark potentially inlineable objects.",
"internal": true
},
{
"name": "Internal",
"metadata": ":internal",
Expand Down
574 changes: 374 additions & 200 deletions src/optimization/inlineConstructors.ml

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions tests/misc/projects/inline-constructors/Extern.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Inl {
public var i : Int = 0;
public extern inline function new() {}
}

class Extern {
public static function main() {
var a = new Inl();
trace(a);
}
}
11 changes: 11 additions & 0 deletions tests/misc/projects/inline-constructors/ForceInline.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Inl {
public var i : Int = 0;
public function new() {}
}

class ForceInline {
public static function main() {
var a = inline new Inl();
trace(a);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Extern
-js extern.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Extern.hx:8: characters 11-20 : Forced inline constructor could not be inlined
Extern.hx:9: characters 9-10 : Cancellation happened here
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ForceInline
-js force-inline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ForceInline.hx:8: characters 11-27 : Forced inline constructor could not be inlined
ForceInline.hx:9: characters 9-10 : Cancellation happened here
1 change: 1 addition & 0 deletions tests/optimization/run.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
--macro Macro.register('TestJs')
--macro Macro.register('TestLocalDce')
--macro Macro.register('TestTreGeneration')
--macro Macro.register('TestInlineConstructors')
--macro Macro.register('issues')
--dce std
100 changes: 100 additions & 0 deletions tests/optimization/src/TestInlineConstructors.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
class InlineClass {
RealyUniqueName marked this conversation as resolved.
Show resolved Hide resolved
public var a = 1;
public var b = "";
public var c = "hello";
public inline function new() {
}

public inline function method() {
return a + b + c;
}
}

class NestedInlineClass {
public var a : InlineClass;
public var b : Array<Int>;
public var c : {a: Int};

public inline function new() {
a = new InlineClass();
b = [1,2,3];
c = {a:4};
}
}

class TestInlineConstructors extends TestBase {
@:js('return [1,2,3,3];')
static function testArrayInlining() {
var a = [1,2,3];
return [a[0], a[1], a[2], a.length];
}

@:js('return [2,"hello","world"];')
static function testAnonymousStructureInlining() {
var a = {a: 1, b: "", c: "hello"};
a.a = 2;
a.b = a.c;
a.c = "world";
return ([a.a,a.b,a.c] : Array<Dynamic>);
}

@:js('return [2,"hello","world"];')
static function testClassConstructorInlining() {
var a = new InlineClass();
a.a = 2;
a.b = a.c;
a.c = "world";
return return ([a.a,a.b,a.c] : Array<Dynamic>);
}

@:js('return [1,2,4,"test",2,1,4,3,4];')
static function testNestedInlining() {
var a = {
a: new NestedInlineClass(),
b: [new NestedInlineClass()],
c: {test: new NestedInlineClass()}
};
a.b[0].a.c = "test";
return ([a.a.a.a, a.a.b[1], a.a.c.a, a.b[0].a.c, a.b[0].b[1], a.b.length, a.c.test.c.a, a.c.test.b[2], a.c.test.c.a]:Dynamic);
}

@:js('return [1,"hello","world"];')
static function testMultipleAliasingVariables() {
var a = new InlineClass();
var b = a;
var d = [b,a];
d[1].b = "hello";
a.c = "world";
return ([a.a, a.b, d[1].c]:Array<Dynamic>);
}

@:js('return [1,"","hello"];')
static function testUnassignedVariables() {
var a;
a = new InlineClass();
return ([a.a, a.b, a.c]:Array<Dynamic>);
}

@:js('return [1,3,"hello"];')
static function testNoExplicitVariables() {
return ([
new InlineClass().a,
[1,2,3][2],
new NestedInlineClass().a.c
]:Array<Dynamic>);
}

@:js('return 1 + "" + "hello";')
static function testMethodInlining() {
var a : {function method() : String;} = new InlineClass();
return a.method();
}

@:js('var b = new InlineClass();return [new InlineClass().method(1),b.method(2)];')
static function testIncompatibleMethodCancelling() {
// InlineClass.method doesn't take any arguments, the method should not be inlined.
var a : {function method(arg : Int) : String;} = cast new InlineClass();
var b : Dynamic = new InlineClass();
return [a.method(1), b.method(2)];
}
}