@@ -363,7 +363,8 @@ class IncrementalCompilerWrapper extends Compiler {
363363 suppressWarnings: suppressWarnings,
364364 enableAsserts: enableAsserts,
365365 experimentalFlags: experimentalFlags,
366- bytecode: bytecode);
366+ bytecode: bytecode,
367+ packageConfig: packageConfig);
367368 result.generator = new IncrementalCompiler .forExpressionCompilationOnly (
368369 component,
369370 result.options,
@@ -538,27 +539,28 @@ void invalidateSources(IncrementalCompilerWrapper compiler, List sourceFiles) {
538539Future _processExpressionCompilationRequest (request) async {
539540 final SendPort port = request[1 ];
540541 final int isolateId = request[2 ];
541- final String expression = request[3 ];
542- final List <String > definitions = request[4 ].cast <String >();
543- final List <String > typeDefinitions = request[5 ].cast <String >();
544- final String libraryUri = request[6 ];
545- final String klass = request[7 ]; // might be null
546- final bool isStatic = request[8 ];
547- final List dillData = request[9 ];
548- final int hotReloadCount = request[10 ];
549- final bool suppressWarnings = request[11 ];
550- final bool enableAsserts = request[12 ];
542+ final dynamic dart_platform_kernel = request[3 ];
543+ final String expression = request[4 ];
544+ final List <String > definitions = request[5 ].cast <String >();
545+ final List <String > typeDefinitions = request[6 ].cast <String >();
546+ final String libraryUri = request[7 ];
547+ final String klass = request[8 ]; // might be null
548+ final bool isStatic = request[9 ];
549+ final List dillData = request[10 ];
550+ final int blobLoadCount = request[11 ];
551+ final bool suppressWarnings = request[12 ];
552+ final bool enableAsserts = request[13 ];
551553 final List <String > experimentalFlags =
552- request[13 ] != null ? request[13 ].cast <String >() : null ;
553- final bool bytecode = request[14 ];
554+ request[14 ] != null ? request[14 ].cast <String >() : null ;
555+ final bool bytecode = request[15 ];
554556
555557 IncrementalCompilerWrapper compiler = isolateCompilers[isolateId];
556558
557559 _ExpressionCompilationFromDillSettings isolateLoadDillData =
558560 isolateLoadNotifies[isolateId];
559561 if (isolateLoadDillData != null ) {
560562 // Check if we can reuse the compiler.
561- if (isolateLoadDillData.hotReloadCount != hotReloadCount ||
563+ if (isolateLoadDillData.blobLoadCount != blobLoadCount ||
562564 isolateLoadDillData.prevDillCount != dillData.length) {
563565 compiler = isolateCompilers[isolateId] = null ;
564566 }
@@ -571,43 +573,82 @@ Future _processExpressionCompilationRequest(request) async {
571573 }
572574 isolateLoadNotifies[isolateId] =
573575 new _ExpressionCompilationFromDillSettings (
574- hotReloadCount, dillData.length);
575-
576- Uri platformUri =
577- computePlatformBinariesLocation ().resolve ('vm_platform_strong.dill' );
578-
579- List <List <int >> data = [];
580- data.add (new File .fromUri (platformUri).readAsBytesSync ());
581- for (int i = 0 ; i < dillData.length; i++ ) {
582- data.add (dillData[i]);
583- }
576+ blobLoadCount, dillData.length);
584577
585578 // Create Component initialized from the bytes.
586579 Component component = new Component ();
587- for (List <int > bytes in data) {
580+
581+ // First try to just load all "dillData". This *might* include the
582+ // platform (and we might have the (same) platform both here and in
583+ // dart_platform_kernel).
584+ for (List <int > bytes in dillData) {
588585 // TODO(jensj): There might be an issue if main has changed.
589586 new BinaryBuilderWithMetadata (bytes, alwaysCreateNewNamedNodes: true )
590587 .readComponent (component);
591588 }
592589
590+ // Check if the loaded component has the platform.
591+ // If it does not, try to load from dart_platform_kernel or from file.
592+ bool foundDartCore = false ;
593+ for (Library library in component.libraries) {
594+ if (library.importUri.scheme == "dart" &&
595+ library.importUri.path == "core" &&
596+ ! library.isSynthetic) {
597+ foundDartCore = true ;
598+ break ;
599+ }
600+ }
601+ if (! foundDartCore) {
602+ List <int > platformKernel = null ;
603+ if (dart_platform_kernel is List <int >) {
604+ platformKernel = dart_platform_kernel;
605+ } else {
606+ final Uri platformUri = computePlatformBinariesLocation ()
607+ .resolve ('vm_platform_strong.dill' );
608+ final File platformFile = new File .fromUri (platformUri);
609+ if (platformFile.existsSync ()) {
610+ platformKernel = platformFile.readAsBytesSync ();
611+ } else {
612+ port.send (new CompilationResult .errors (
613+ ["No platform found to initialize incremental compiler." ],
614+ null )
615+ .toResponse ());
616+ return ;
617+ }
618+ }
619+
620+ new BinaryBuilderWithMetadata (platformKernel,
621+ alwaysCreateNewNamedNodes: true )
622+ .readComponent (component);
623+ }
624+
593625 FileSystem fileSystem =
594626 _buildFileSystem ([dotPackagesFile, < int > []], null , null , null );
595627
596628 // TODO(aam): IncrementalCompilerWrapper instance created below have to be
597629 // destroyed when corresponding isolate is shut down. To achieve that
598630 // kernel isolate needs to receive a message indicating that particular
599631 // isolate was shut down. Message should be handled here in this script.
600- compiler = new IncrementalCompilerWrapper .forExpressionCompilationOnly (
601- component, isolateId, fileSystem, null ,
602- suppressWarnings: suppressWarnings,
603- enableAsserts: enableAsserts,
604- experimentalFlags: experimentalFlags,
605- bytecode: bytecode,
606- packageConfig: dotPackagesFile);
607- isolateCompilers[isolateId] = compiler;
608- await compiler.compile (
609- component.mainMethod? .enclosingLibrary? .importUri ??
610- component.libraries.last.importUri);
632+ try {
633+ compiler = new IncrementalCompilerWrapper .forExpressionCompilationOnly (
634+ component, isolateId, fileSystem, null ,
635+ suppressWarnings: suppressWarnings,
636+ enableAsserts: enableAsserts,
637+ experimentalFlags: experimentalFlags,
638+ bytecode: bytecode,
639+ packageConfig: dotPackagesFile);
640+ isolateCompilers[isolateId] = compiler;
641+ await compiler.compile (
642+ component.mainMethod? .enclosingLibrary? .importUri ??
643+ component.libraries.last.importUri);
644+ } catch (e) {
645+ port.send (new CompilationResult .errors ([
646+ "Error when trying to create a compiler for expression compilation: "
647+ "'$e '."
648+ ], null )
649+ .toResponse ());
650+ return ;
651+ }
611652 }
612653 }
613654
@@ -1179,9 +1220,9 @@ void _debugDumpKernel(Uint8List bytes) {
11791220}
11801221
11811222class _ExpressionCompilationFromDillSettings {
1182- int hotReloadCount ;
1223+ int blobLoadCount ;
11831224 int prevDillCount;
11841225
11851226 _ExpressionCompilationFromDillSettings (
1186- this .hotReloadCount , this .prevDillCount);
1227+ this .blobLoadCount , this .prevDillCount);
11871228}
0 commit comments