-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[dart2js] Unused fields are not tree-shaken off, sensitive to type annotations #11558
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
Comments
Added Area-Dart2Dart, Triaged labels. |
This issue was misclassified. Reopening and moving to dart2js. |
I just ran into the issue, only I was seeing it where unused fields from the superclass overridden by getters/setters in a subclass are not completely tree-shaken, and are still present in the JS constructor initializer list. For example, class A {
int a;
}
class B extends A {
int get a => ...;
set a(int value) => ...;
} For more context on my use-case, see the "Leaving behind fields" section here: dart-lang/build#897 (comment) I was thinking #21450 may mitigate this issue, but it would be nice to solve the issue and eliminate these fields completely. Looks like the above example still reproduces on Dart 1.24.3, with some tweaks to prevent the main() {
var foo = new Foo();
print('$foo ${foo.hello}');
}
class Bar {
String txt = " World";
}
class Foo {
String _hello;
Bar _world; // never initialized
String get hello {
if (_hello == null) {
_hello = "Hello";
}
return _hello;
}
String get world {
if (_world == null) {
_world = new Bar();
}
return _world.txt;
}
} dart2js output ["", "reduced.dart",, T, {
"^": "",
main: function() {
H.printString(H.Primitives_objectToHumanReadableString(new T.Foo(null, null)) + " hello");
},
Foo: {
"^": "Object;_hello,_world"
}
}, 1] dart2js constructor retrieved by stepping into it at runtime function Foo(p__hello, p__world) {
this._hello = p__hello;
this._world = p__world;
}
Foo.builtin$cls="Foo";
$desc=$collectedClasses.Foo[1];
Foo.prototype = $desc; |
/cc @matanlurey who has been looking into tree-shaking issues not long ago |
These examples no longe reproduce in Dart2JS. Closing |
INPUT:
main() {
print(new Foo().hello);
}
class Bar {
String txt = " World";
}
class Foo {
String _hello;
Bar _world; // never initialized
String get hello {
if (_hello == null) {
_hello = "Hello";
}
return _hello;
}
String get world {
if (_world == null) {
_world = new Bar();
}
return _world.txt;
}
}
OUTPUT (reformatted):
main(){
print(new Foo().hello);
}
class Bar{} // Expected Bar to be gone.
// However, it will be gone if I change type of _world to "var".
// Nice to see txt tree-shaken off.
class Foo{
String _hello; // Used, so it stays.
Bar _world; // Not used, expected to be gone
String get hello{
if(_hello==null) {
_hello="Hello";
}
return _hello;
}
}
The text was updated successfully, but these errors were encountered: