@@ -363,7 +363,8 @@ class IncrementalCompilerWrapper extends Compiler {
363
363
suppressWarnings: suppressWarnings,
364
364
enableAsserts: enableAsserts,
365
365
experimentalFlags: experimentalFlags,
366
- bytecode: bytecode);
366
+ bytecode: bytecode,
367
+ packageConfig: packageConfig);
367
368
result.generator = new IncrementalCompiler .forExpressionCompilationOnly (
368
369
component,
369
370
result.options,
@@ -538,27 +539,28 @@ void invalidateSources(IncrementalCompilerWrapper compiler, List sourceFiles) {
538
539
Future _processExpressionCompilationRequest (request) async {
539
540
final SendPort port = request[1 ];
540
541
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 ];
551
553
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 ];
554
556
555
557
IncrementalCompilerWrapper compiler = isolateCompilers[isolateId];
556
558
557
559
_ExpressionCompilationFromDillSettings isolateLoadDillData =
558
560
isolateLoadNotifies[isolateId];
559
561
if (isolateLoadDillData != null ) {
560
562
// Check if we can reuse the compiler.
561
- if (isolateLoadDillData.hotReloadCount != hotReloadCount ||
563
+ if (isolateLoadDillData.blobLoadCount != blobLoadCount ||
562
564
isolateLoadDillData.prevDillCount != dillData.length) {
563
565
compiler = isolateCompilers[isolateId] = null ;
564
566
}
@@ -571,43 +573,82 @@ Future _processExpressionCompilationRequest(request) async {
571
573
}
572
574
isolateLoadNotifies[isolateId] =
573
575
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);
584
577
585
578
// Create Component initialized from the bytes.
586
579
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) {
588
585
// TODO(jensj): There might be an issue if main has changed.
589
586
new BinaryBuilderWithMetadata (bytes, alwaysCreateNewNamedNodes: true )
590
587
.readComponent (component);
591
588
}
592
589
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
+
593
625
FileSystem fileSystem =
594
626
_buildFileSystem ([dotPackagesFile, < int > []], null , null , null );
595
627
596
628
// TODO(aam): IncrementalCompilerWrapper instance created below have to be
597
629
// destroyed when corresponding isolate is shut down. To achieve that
598
630
// kernel isolate needs to receive a message indicating that particular
599
631
// 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
+ }
611
652
}
612
653
}
613
654
@@ -1179,9 +1220,9 @@ void _debugDumpKernel(Uint8List bytes) {
1179
1220
}
1180
1221
1181
1222
class _ExpressionCompilationFromDillSettings {
1182
- int hotReloadCount ;
1223
+ int blobLoadCount ;
1183
1224
int prevDillCount;
1184
1225
1185
1226
_ExpressionCompilationFromDillSettings (
1186
- this .hotReloadCount , this .prevDillCount);
1227
+ this .blobLoadCount , this .prevDillCount);
1187
1228
}
0 commit comments