-
Notifications
You must be signed in to change notification settings - Fork 6k
Const finder missing static const list/map/set fields.
#16896
Conversation
|
|
||
| bool _matches(Class node) { | ||
| return node.enclosingLibrary.canonicalName.name == classLibraryUri && | ||
| return node.enclosingLibrary.importUri.toString() == classLibraryUri && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more correct than using canonicalName, per @alexmarkov offline discussion.
| if (_cache.add(node)) { | ||
| super.defaultConstant(node); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoids combinatorial explosion when viewing deeply nested constants.
|
|
||
| @override | ||
| void defaultConstantReference(Constant node) { | ||
| defaultConstant(node); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the actual critical change for this fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Putting some comments here as it looks like github doesn't allow me to attach them to the corresponding lines.
- We should probably also visit all children recursively in visitInstanceConstantReference, e.g. consider replacing L71 with
super.visitInstanceConstantReference(node);and removing L73. This will cover cases like an InstanceConstant which has ListConstant in its field which has InstanceConstant in its element.
-
Nit: typo in _visitedInstnaces
-
Consider replacing
kvp.key.canonicalName.nameat L82 withkvp.key.asField.name.name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done x3
| } | ||
|
|
||
| class StaticConstInitializer { | ||
| static const List<Target> targets = <Target>[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a test with deeper nesting to test the caching optimization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexmarkov - can you help suggest a test for this, or point me to one in the Kernel compiler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure what we'd test here either - we don't have benchmarks for this and I'm not sure we want to set them up, and otherwise I guess we could expose number of visits done, but that puts us at the mercy up upstream changes in the kernel pretty tightly...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have Dart tests for such cases:
https://github.com/dart-lang/sdk/blob/master/tests/language_2/canonicalize/hashing_memoize_array_test.dart
https://github.com/dart-lang/sdk/blob/master/tests/language_2/canonicalize/hashing_memoize_instance_test.dart
Traversal of such constants without caching will time out for any reasonable time limit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect, thanks - I took one of those and basically copied it into here with slight modifications for Flutter style.
alexmarkov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM w/nits.
|
|
||
| @override | ||
| void defaultConstantReference(Constant node) { | ||
| defaultConstant(node); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Putting some comments here as it looks like github doesn't allow me to attach them to the corresponding lines.
- We should probably also visit all children recursively in visitInstanceConstantReference, e.g. consider replacing L71 with
super.visitInstanceConstantReference(node);and removing L73. This will cover cases like an InstanceConstant which has ListConstant in its field which has InstanceConstant in its element.
-
Nit: typo in _visitedInstnaces
-
Consider replacing
kvp.key.canonicalName.nameat L82 withkvp.key.asField.name.name.
|
Going to land this on red to kick infra that flaked on a gsutil upload Also, the web failure has nothing to do with this change - /cc @yjbanov FYI, felt tests failed on this change. |
|
(I will wait for the build_and_test_linux_unopt_debug to pass, that one is relevant to this change) |
|
Thanks for the heads-up. |
* 38f497c Roll src/third_party/skia 9dd0bd78b2d7..470f0637aeea (11 commits) (flutter/engine#16887) * 5073cc7 Roll src/third_party/dart fbe9f6115d2f..0b819161d778 (3 commits) (flutter/engine#16888) * df94213 Revert "Try rasterizing images and layers only once , even when their rasterization fails. Further enforce the same access threshold on layers as on Pictures. Previously layers would always be cached. The latter is a semantic change. (#16545)" (flutter/engine#16889) * b230adb Roll src/third_party/skia 470f0637aeea..ded437003d0e (6 commits) (flutter/engine#16891) * 63bdf3e Roll fuchsia/sdk/core/mac-amd64 from q2DAy... to WmA2M... (flutter/engine#16892) * e54f2c8 Const finder missing `static const` list/map/set fields. (flutter/engine#16896) * 10275fe Roll fuchsia/sdk/core/linux-amd64 from 9NHsJ... to uiAI5... (flutter/engine#16893) * 8d046fa Roll src/third_party/skia ded437003d0e..b43cfa4d3f96 (7 commits) (flutter/engine#16894) * 9c53993 Roll src/third_party/dart 0b819161d778..ca3ad264a649 (18 commits) (flutter/engine#16898) * 6991dd9 Roll src/third_party/skia b43cfa4d3f96..8121d27b297c (10 commits) (flutter/engine#16899)
Fixes flutter/flutter#51800
/cc @alexmarkov @chingjun @ds84182