-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Allow compile-time constant index operations on constant string, list and maps. #3059
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 this to the Later milestone. |
Removed this from the Later milestone. |
Removed Oldschool-Milestone-Later label. |
Issue #8885 has been merged into this issue. |
+1 |
Here's a concrete use case where this would be quite nice. Not entirely fleshed out, but it seems like it would be workable. With Intl, you write the message text directly in the code. e.g.
The desc parameter is only used at message extraction time, and the library is written so that dart2js knows it can completely remove it during compilation. But the actual text is used as a lookup key for the translation, so we can't remove it. And that wastes a bunch of space, because we have the English text included in every version, even if it's never going to be displayed. We could avoid this by instead having you write the English text in a separate resource file, create some ID for it, and use that in the code. But that's a lot worse experience. However, I can compute some known value based on the text, and probably do for translation purposes. And if I was able to de-reference a const, then it seems like I could do something like
and have generated code
And if the system allowed me to do that dereference in an initializer, and was smart enough to know that the messageHashes map was never referenced from anywhere except a const constructor and could be discarded, then we could optimize away all that English text and just store ids. |
Hi! Any progress on this? I think it's kinda reasonable to expect a const string on a const Map to be const. |
It's been awhile since this feature has been talked about -- any updates on the progress? |
There are no current plans to extend the scope of compile-time constant expressions. When we do something in this context, it's driven by necessity from other changes to the language, not a wish to actually make more expressions compile-time constant. Incrementally adding small syntax extensions to the constant rules is not something that is giving the most bang for the buck. I think that, with the current priorities for Dart, a complete revamp of the constant sub-language and behavior is worth investigating, rather than incrementally growing the existing one on a case-by-case basis. |
…3 revisions) https://dart.googlesource.com/dartdoc/+log/f5bcc4bd46f4..b61647bc3833 2022-06-08 [email protected] Pin github actions to a hash (#3056) 2022-06-06 49699333+dependabot[bot]@users.noreply.github.com Bump ossf/scorecard-action from 1.1.0 to 1.1.1 (#3059) 2022-06-06 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 2.1.11 to 2.1.12 (#3057) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/dart-doc-dart-sdk Please CC [email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Dart Documentation Generator: https://github.com/dart-lang/dartdoc/issues To file a bug in Dart SDK: https://github.com/dart-lang/sdk/issues To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md Tbr: [email protected] Change-Id: Ia70e7e622ec520a5f8f19d3bfc51608c8d6f5c70 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/247469 Reviewed-by: Devon Carew <[email protected]> Commit-Queue: Devon Carew <[email protected]>
With constant maps, and to a lesser degree lists, it's sometimes relevant to do refer to a constant entry of such a map.
I suggest allowing expressions on the form a[b] as compile-time constants when either a is a List or String and b is an integer, or a is a Map and b is a String.
The text was updated successfully, but these errors were encountered: