Skip to content

Commit 8cc00f8

Browse files
rakudramacommit-bot@chromium.org
authored andcommitted
[dart2js] Move embedded globals earlier
In anticipation of adding type metadata for --experiment-new-rti, move the embedded globals earlier so they are available for generating constants. The metadata for custom elements is split out since it depends on constants. Change-Id: Ic99895bd1a1f7bf42a1f41948733ea001df8a8e2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106007 Reviewed-by: Mayank Patke <fishythefish@google.com> Commit-Queue: Stephen Adams <sra@google.com>
1 parent 070c755 commit 8cc00f8

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,15 @@ var #staticStateDeclaration = {};
432432
// Builds the inheritance structure.
433433
#inheritance;
434434
435+
// Emits the embedded globals. This needs to be before constants so the embedded
436+
// global type resources are available for generating constants.
437+
#embeddedGlobalsPart1;
438+
435439
// Instantiates all constants.
436440
#constants;
437441
438-
// Emits the embedded globals. Due to type checks in eager initializers this is
439-
// needed before static non-final fields initializers.
440-
#embeddedGlobals;
442+
// Adds to the embedded globals. A few globals refer to constants.
443+
#embeddedGlobalsPart2;
441444
442445
// Initializes the static non-final fields (with their constant values).
443446
#staticNonFinalFields;
@@ -660,7 +663,10 @@ class FragmentEmitter {
660663
'constants': emitConstants(fragment),
661664
'staticNonFinalFields': emitStaticNonFinalFields(fragment),
662665
'lazyStatics': emitLazilyInitializedStatics(fragment),
663-
'embeddedGlobals': emitEmbeddedGlobals(program, deferredLoadingState),
666+
'embeddedGlobalsPart1':
667+
emitEmbeddedGlobalsPart1(program, deferredLoadingState),
668+
'embeddedGlobalsPart2':
669+
emitEmbeddedGlobalsPart2(program, deferredLoadingState),
664670
'nativeSupport': program.needsNativeSupport
665671
? emitNativeSupport(fragment)
666672
: new js.EmptyStatement(),
@@ -1848,7 +1854,7 @@ class FragmentEmitter {
18481854
}
18491855

18501856
/// Emits all embedded globals.
1851-
js.Statement emitEmbeddedGlobals(
1857+
js.Statement emitEmbeddedGlobalsPart1(
18521858
Program program, DeferredLoadingState deferredLoadingState) {
18531859
List<js.Property> globals = [];
18541860

@@ -1858,8 +1864,10 @@ class FragmentEmitter {
18581864
}
18591865

18601866
if (program.typeToInterceptorMap != null) {
1867+
// This property is assigned later.
1868+
// Initialize property to avoid map transitions.
18611869
globals.add(new js.Property(
1862-
js.string(TYPE_TO_INTERCEPTOR_MAP), program.typeToInterceptorMap));
1870+
js.string(TYPE_TO_INTERCEPTOR_MAP), js.LiteralNull()));
18631871
}
18641872

18651873
globals.add(emitMangledGlobalNames());
@@ -1887,6 +1895,17 @@ class FragmentEmitter {
18871895
return js.js.statement('var init = #;', globalsObject);
18881896
}
18891897

1898+
/// Finish setting up embedded globals.
1899+
js.Statement emitEmbeddedGlobalsPart2(
1900+
Program program, DeferredLoadingState deferredLoadingState) {
1901+
List<js.Statement> statements = [];
1902+
if (program.typeToInterceptorMap != null) {
1903+
statements.add(js.js.statement('init.# = #;',
1904+
[js.string(TYPE_TO_INTERCEPTOR_MAP), program.typeToInterceptorMap]));
1905+
}
1906+
return js.Block(statements);
1907+
}
1908+
18901909
/// Emits data needed for native classes.
18911910
///
18921911
/// We don't try to reduce the size of the native data, but rather build

0 commit comments

Comments
 (0)