Skip to content

[cfe] Knowledge of whether a ConstantExpression(<constant>) is from a deferred library or not #61764

@mkustermann

Description

@mkustermann

One may have code like this:

import 'foo.dart' deferred as foo;
main() {
 ...
 print(foo.topLevelConst);
}

It seems currently this gets lowered into something like this

let
  _ = StaticInvocation(_checkLibraryIsLoaded(...))   // <-- this is modular dart2wasm lowering of `CheckLibraryIsLoaded()` AST node
in
  ConstantExpresion(<constant>)

Now when one visits the AST and hits a ConstantExpression the code generator may want to do something different.

  • Normally the code generator has to assume the constant is needed by the main module and has to bundle related data/code in the main module.

  • If it knows the constant access is guaranteed to happen after the deferred library was loaded, it can move the constant related data/code into the deferred library.

Right now one needs to match this particular lowering pattern to detect this guarantee, it would be nice if it was more readily available on ConstantExpression.

/cc @johnniwinther

Metadata

Metadata

Labels

area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.cfe-encodingsEncoding related CFE issues.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions