| 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..994508ee68673ef1aa6d3b913b8a7cd64015f58a 100644
|
| --- a/pkg/compiler/lib/src/kernel/world_builder.dart
|
| +++ b/pkg/compiler/lib/src/kernel/world_builder.dart
|
| @@ -49,7 +49,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 +81,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 +91,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 +602,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);
|
| }
|
| }
|
| }
|
|
|