| Index: pkg/compiler/lib/src/kernel/world_builder.dart
|
| diff --git a/pkg/compiler/lib/src/kernel/world_builder.dart b/pkg/compiler/lib/src/kernel/world_builder.dart
|
| index 519b33f585de80d48e628fdd505ccba91faa1500..beeb5c9580a8a224b45d8fcbaaacb7507ad5a04b 100644
|
| --- a/pkg/compiler/lib/src/kernel/world_builder.dart
|
| +++ b/pkg/compiler/lib/src/kernel/world_builder.dart
|
| @@ -18,6 +18,7 @@ import '../common_elements.dart';
|
| import '../elements/elements.dart';
|
| import '../elements/entities.dart';
|
| import '../elements/types.dart';
|
| +import '../frontend_strategy.dart';
|
| import '../js_backend/constant_system_javascript.dart';
|
| import '../js_backend/native_data.dart';
|
| import '../js_backend/no_such_method_registry.dart';
|
| @@ -49,7 +50,7 @@ class KernelWorldBuilder extends KernelElementAdapterMixin {
|
| _KernelDartTypes _types;
|
|
|
| /// Library environment. Used for fast lookup.
|
| - KEnv _env;
|
| + KEnv _env = new KEnv();
|
|
|
| /// List of library environments by `KLibrary.libraryIndex`. This is used for
|
| /// fast lookup into library classes and members.
|
| @@ -81,8 +82,7 @@ class KernelWorldBuilder extends KernelElementAdapterMixin {
|
| Map<ir.TreeNode, KLocalFunction> _localFunctionMap =
|
| <ir.TreeNode, KLocalFunction>{};
|
|
|
| - KernelWorldBuilder(this.reporter, ir.Program program)
|
| - : _env = new KEnv(program) {
|
| + KernelWorldBuilder(this.reporter) {
|
| _elementEnvironment = new KernelElementEnvironment(this);
|
| _commonElements = new CommonElements(_elementEnvironment);
|
| _constantEnvironment = new KernelConstantEnvironment(this);
|
| @@ -92,15 +92,21 @@ class KernelWorldBuilder extends KernelElementAdapterMixin {
|
| _typeConverter = new DartTypeConverter(this);
|
| }
|
|
|
| + /// Adds libraries in [program] to the set of libraries.
|
| + ///
|
| + /// The main method of the first program is used as the main method for the
|
| + /// compilation.
|
| + void addProgram(ir.Program program) {
|
| + _env.addProgram(program);
|
| + }
|
| +
|
| KMethod get _mainFunction {
|
| - return _env.program.mainMethod != null
|
| - ? _getMethod(_env.program.mainMethod)
|
| - : null;
|
| + return _env.mainMethod != null ? _getMethod(_env.mainMethod) : null;
|
| }
|
|
|
| KLibrary get _mainLibrary {
|
| - return _env.program.mainMethod != null
|
| - ? _getLibrary(_env.program.mainMethod.enclosingLibrary)
|
| + return _env.mainMethod != null
|
| + ? _getLibrary(_env.mainMethod.enclosingLibrary)
|
| : null;
|
| }
|
|
|
| @@ -597,17 +603,32 @@ class KernelWorldBuilder extends KernelElementAdapterMixin {
|
|
|
| /// Environment for fast lookup of program libraries.
|
| class KEnv {
|
| - final ir.Program program;
|
| + final Set<ir.Program> programs = new Set<ir.Program>();
|
|
|
| Map<Uri, KLibraryEnv> _libraryMap;
|
|
|
| - KEnv(this.program);
|
| + /// TODO(johnniwinther): Handle arbitrary load order if needed.
|
| + ir.Member get mainMethod => programs.first?.mainMethod;
|
| +
|
| + void addProgram(ir.Program program) {
|
| + if (programs.add(program)) {
|
| + if (_libraryMap != null) {
|
| + _addLibraries(program);
|
| + }
|
| + }
|
| + }
|
| +
|
| + void _addLibraries(ir.Program program) {
|
| + for (ir.Library library in program.libraries) {
|
| + _libraryMap[library.importUri] = new KLibraryEnv(library);
|
| + }
|
| + }
|
|
|
| void _ensureLibraryMap() {
|
| if (_libraryMap == null) {
|
| _libraryMap = <Uri, KLibraryEnv>{};
|
| - for (ir.Library library in program.libraries) {
|
| - _libraryMap[library.importUri] = new KLibraryEnv(library);
|
| + for (ir.Program program in programs) {
|
| + _addLibraries(program);
|
| }
|
| }
|
| }
|
|
|