From 6cec0a02bbe995e585e4c8941deaf9506913f31b Mon Sep 17 00:00:00 2001 From: Nicholas Shahan Date: Fri, 13 Sep 2024 15:49:21 +0000 Subject: [PATCH] [ddc] Create types for normalization once Create these types in the SDK module. Previously they were created in every module but they are cached in the RTI library on creation for use later. Change-Id: Ic9bef3d7b43935be79a55b74672e68c1dd89a33d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384942 Commit-Queue: Nicholas Shahan Reviewed-by: Mark Zhou --- pkg/dev_compiler/lib/src/kernel/compiler.dart | 26 +++++++++--------- .../lib/src/kernel/compiler_new.dart | 27 ++++++++++--------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/pkg/dev_compiler/lib/src/kernel/compiler.dart b/pkg/dev_compiler/lib/src/kernel/compiler.dart index cbfd537b141e..73381151013e 100644 --- a/pkg/dev_compiler/lib/src/kernel/compiler.dart +++ b/pkg/dev_compiler/lib/src/kernel/compiler.dart @@ -732,18 +732,20 @@ class ProgramCompiler extends ComputeOnceConstantVisitor // Certain RTIs must be emitted during RTI normalization. We cache these // eagerly with 'findType' (without normalization) to avoid infinite loops. // See normalization functions in: sdk/lib/_internal/js_shared/lib/rti.dart - var prerequisiteRtiTypes = [ - _coreTypes.objectLegacyRawType, - _coreTypes.objectNullableRawType, - NeverType.legacy() - ]; - prerequisiteRtiTypes.forEach((type) { - var recipe = _typeRecipeGenerator - .recipeInEnvironment(type, EmptyTypeEnvironment()) - .recipe; - _moduleItems.add(js.call('#.findType("$recipe")', - [_emitLibraryName(_rtiLibrary)]).toStatement()); - }); + if (_isBuildingSdk) { + var prerequisiteRtiTypes = [ + _coreTypes.objectLegacyRawType, + _coreTypes.objectNullableRawType, + NeverType.legacy() + ]; + prerequisiteRtiTypes.forEach((type) { + var recipe = _typeRecipeGenerator + .recipeInEnvironment(type, EmptyTypeEnvironment()) + .recipe; + _moduleItems.add(js.call('#.findType("$recipe")', + [_emitLibraryName(_rtiLibrary)]).toStatement()); + }); + } // Visit directives (for exports) libraries.forEach(_emitExports); diff --git a/pkg/dev_compiler/lib/src/kernel/compiler_new.dart b/pkg/dev_compiler/lib/src/kernel/compiler_new.dart index e05c61867fe0..c071c687d4c9 100644 --- a/pkg/dev_compiler/lib/src/kernel/compiler_new.dart +++ b/pkg/dev_compiler/lib/src/kernel/compiler_new.dart @@ -829,19 +829,20 @@ class LibraryCompiler extends ComputeOnceConstantVisitor // Certain RTIs must be emitted during RTI normalization. We cache these // eagerly with 'findType' (without normalization) to avoid infinite loops. // See normalization functions in: sdk/lib/_internal/js_shared/lib/rti.dart - var prerequisiteRtiTypes = [ - _coreTypes.objectLegacyRawType, - _coreTypes.objectNullableRawType, - NeverType.legacy() - ]; - prerequisiteRtiTypes.forEach((type) { - var recipe = _typeRecipeGenerator - .recipeInEnvironment(type, EmptyTypeEnvironment()) - .recipe; - _moduleItems.add(js.call('#.findType("$recipe")', - [_emitLibraryName(_rtiLibrary)]).toStatement()); - }); - + if (_isSdkInternalRuntime(_currentLibrary!)) { + var prerequisiteRtiTypes = [ + _coreTypes.objectLegacyRawType, + _coreTypes.objectNullableRawType, + NeverType.legacy() + ]; + prerequisiteRtiTypes.forEach((type) { + var recipe = _typeRecipeGenerator + .recipeInEnvironment(type, EmptyTypeEnvironment()) + .recipe; + _currentLibraryLinkFunctionBody.add(js.call('#.findType("$recipe")', + [_emitLibraryName(_rtiLibrary)]).toStatement()); + }); + } // Visit directives (for exports) _emitExports(library); _ticker?.logMs('Emitted exports');