From ad94d963ed4eec40a96672cb269fa0eed2d5a940 Mon Sep 17 00:00:00 2001 From: Alexander Markov Date: Tue, 10 Sep 2024 14:37:00 +0000 Subject: [PATCH] [dart2bytecode] Remove the requirement for dynamic module to have 'main' TEST=DART_CONFIGURATION=DebugX64 out/DebugX64/dart-sdk/bin/dart pkg/dynamic_modules/test/runner/main.dart -r aot --verbose Change-Id: I8647822982b051b4846dfe4ed7e51a19ef466cf9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384311 Commit-Queue: Alexander Markov Reviewed-by: Sigmund Cherem --- pkg/dart2bytecode/lib/dart2bytecode.dart | 1 + .../test/data/duplicate_library/modules/entry1.dart | 4 ---- .../test/data/extend_class/modules/entry1.dart | 4 ---- .../test/data/implement_interface/modules/entry1.dart | 4 ---- .../test/data/load_twice/modules/entry1.dart | 4 ---- .../test/data/shared_const/modules/entry1.dart | 4 ---- .../test/data/shared_const/modules/entry2.dart | 4 ---- .../test/data/update_top_level/modules/entry1.dart | 4 ---- pkg/vm/lib/kernel_front_end.dart | 10 ++++++++-- 9 files changed, 9 insertions(+), 30 deletions(-) diff --git a/pkg/dart2bytecode/lib/dart2bytecode.dart b/pkg/dart2bytecode/lib/dart2bytecode.dart index bd139f003f53..f52adc55be9c 100644 --- a/pkg/dart2bytecode/lib/dart2bytecode.dart +++ b/pkg/dart2bytecode/lib/dart2bytecode.dart @@ -176,6 +176,7 @@ Future runCompiler(ArgResults options) async { final results = await compileToKernel(KernelCompilationArguments( source: mainUri, options: compilerOptions, + requireMain: false, includePlatform: false, environmentDefines: environmentDefines, enableAsserts: enableAsserts)); diff --git a/pkg/dynamic_modules/test/data/duplicate_library/modules/entry1.dart b/pkg/dynamic_modules/test/data/duplicate_library/modules/entry1.dart index f8f0ca011152..f887ceeb0a01 100644 --- a/pkg/dynamic_modules/test/data/duplicate_library/modules/entry1.dart +++ b/pkg/dynamic_modules/test/data/duplicate_library/modules/entry1.dart @@ -6,7 +6,3 @@ import 'common.dart'; @pragma('dyn-module:entry-point') Object? entrypoint() => const A(); - -// TODO(sigmund): remove or reconcile. W/O a main dart2bytecode produces -// a compile-time error. -main() {} diff --git a/pkg/dynamic_modules/test/data/extend_class/modules/entry1.dart b/pkg/dynamic_modules/test/data/extend_class/modules/entry1.dart index 47352e1c6261..2a57d29bc7f4 100644 --- a/pkg/dynamic_modules/test/data/extend_class/modules/entry1.dart +++ b/pkg/dynamic_modules/test/data/extend_class/modules/entry1.dart @@ -11,7 +11,3 @@ class Child extends Base { @pragma('dyn-module:entry-point') Object? dynamicModuleEntrypoint() => Child(); - -// TODO(sigmund): remove or reconcile. W/O a main dart2bytecode produces -// a compile-time error. -main() {} diff --git a/pkg/dynamic_modules/test/data/implement_interface/modules/entry1.dart b/pkg/dynamic_modules/test/data/implement_interface/modules/entry1.dart index 36344889c36c..e72267cf4eaf 100644 --- a/pkg/dynamic_modules/test/data/implement_interface/modules/entry1.dart +++ b/pkg/dynamic_modules/test/data/implement_interface/modules/entry1.dart @@ -14,7 +14,3 @@ class Child implements Base { @pragma('dyn-module:entry-point') Object? dynamicModuleEntrypoint() => Child(); - -// TODO(sigmund): remove or reconcile. W/O a main dart2bytecode produces -// a compile-time error. -main() {} diff --git a/pkg/dynamic_modules/test/data/load_twice/modules/entry1.dart b/pkg/dynamic_modules/test/data/load_twice/modules/entry1.dart index bcfe4555b3c5..2dff12633094 100644 --- a/pkg/dynamic_modules/test/data/load_twice/modules/entry1.dart +++ b/pkg/dynamic_modules/test/data/load_twice/modules/entry1.dart @@ -6,7 +6,3 @@ class A {} @pragma('dyn-module:entry-point') Object? dynamicModuleEntrypoint() => A(); - -// TODO(sigmund): remove or reconcile. W/O a main dart2bytecode produces -// a compile-time error. -main() {} diff --git a/pkg/dynamic_modules/test/data/shared_const/modules/entry1.dart b/pkg/dynamic_modules/test/data/shared_const/modules/entry1.dart index f6b65d907b61..ab084dc6d3c6 100644 --- a/pkg/dynamic_modules/test/data/shared_const/modules/entry1.dart +++ b/pkg/dynamic_modules/test/data/shared_const/modules/entry1.dart @@ -6,7 +6,3 @@ import '../main.dart'; @pragma('dyn-module:entry-point') Object? dynamicModuleEntrypoint() => const B(1); - -// TODO(sigmund): remove or reconcile. W/O a main dart2bytecode produces -// a compile-time error. -main() {} diff --git a/pkg/dynamic_modules/test/data/shared_const/modules/entry2.dart b/pkg/dynamic_modules/test/data/shared_const/modules/entry2.dart index f6b65d907b61..ab084dc6d3c6 100644 --- a/pkg/dynamic_modules/test/data/shared_const/modules/entry2.dart +++ b/pkg/dynamic_modules/test/data/shared_const/modules/entry2.dart @@ -6,7 +6,3 @@ import '../main.dart'; @pragma('dyn-module:entry-point') Object? dynamicModuleEntrypoint() => const B(1); - -// TODO(sigmund): remove or reconcile. W/O a main dart2bytecode produces -// a compile-time error. -main() {} diff --git a/pkg/dynamic_modules/test/data/update_top_level/modules/entry1.dart b/pkg/dynamic_modules/test/data/update_top_level/modules/entry1.dart index c4e9af209ee6..64e5c26d1c7b 100644 --- a/pkg/dynamic_modules/test/data/update_top_level/modules/entry1.dart +++ b/pkg/dynamic_modules/test/data/update_top_level/modules/entry1.dart @@ -8,7 +8,3 @@ import '../shared/shared.dart'; void dynamicModuleEntrypoint() { topLevel = 'updated'; } - -// TODO(sigmund): remove or reconcile. W/O a main dart2bytecode produces -// a compile-time error. -main() {} diff --git a/pkg/vm/lib/kernel_front_end.dart b/pkg/vm/lib/kernel_front_end.dart index 7c2c8328c4aa..61ec5e60d2a5 100644 --- a/pkg/vm/lib/kernel_front_end.dart +++ b/pkg/vm/lib/kernel_front_end.dart @@ -29,6 +29,7 @@ import 'package:front_end/src/api_unstable/vm.dart' StandardFileSystem, Verbosity, getMessageUri, + kernelForModule, kernelForProgram, parseExperimentalArguments, parseExperimentalFlags, @@ -449,6 +450,7 @@ class KernelCompilationArguments { final List additionalSources; final Uri? nativeAssets; final Uri? resourcesFile; + final bool requireMain; final bool includePlatform; final List deleteToStringPackageUris; final List keepClassNamesImplementing; @@ -470,6 +472,7 @@ class KernelCompilationArguments { this.additionalSources = const [], this.nativeAssets, this.resourcesFile, + this.requireMain = true, this.includePlatform = false, this.deleteToStringPackageUris = const [], this.keepClassNamesImplementing = const [], @@ -521,8 +524,11 @@ Future compileToKernel( compilerResult = await loadKernel(options.fileSystem, resolveInputUri(fromDillFile)); } else { - compilerResult = await kernelForProgram(args.source!, options, - additionalSources: args.additionalSources); + compilerResult = args.requireMain + ? await kernelForProgram(args.source!, options, + additionalSources: args.additionalSources) + : await kernelForModule( + [args.source!, ...args.additionalSources], options); } final Component? component = compilerResult?.component;