Skip to content

Commit 878e2ca

Browse files
jensjohacommit-bot@chromium.org
authored andcommitted
[CFE] Don't issue an initialization error when trying to initialize when not having a platform
This CL would have reduced the number of errors given in #42378 Namely the "Warning: Tried to initialize from a previous compilation (build/cache.dill), but couldn't." part wouldn't have been issued. Change-Id: I3e7f2f0115a13a23522643b6f4c9ad8c57bc0d5e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153141 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent 34f5c9d commit 878e2ca

File tree

7 files changed

+194
-1
lines changed

7 files changed

+194
-1
lines changed

pkg/front_end/lib/src/fasta/incremental_compiler.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1438,9 +1438,9 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
14381438
dillLoadedData = new DillTarget(ticker, uriTranslator, c.options.target);
14391439
int bytesLength = 0;
14401440

1441+
data.component = c.options.target.configureComponent(new Component());
14411442
if (summaryBytes != null) {
14421443
ticker.logMs("Read ${c.options.sdkSummary}");
1443-
data.component = c.options.target.configureComponent(new Component());
14441444
new BinaryBuilderWithMetadata(summaryBytes,
14451445
disableLazyReading: false, disableLazyClassReading: true)
14461446
.readComponent(data.component);

pkg/front_end/test/incremental_load_from_dill_suite.dart

+33
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,9 @@ class NewWorldTest {
469469
options.fileSystem = fs;
470470
options.sdkRoot = null;
471471
options.sdkSummary = sdkSummaryUri;
472+
if (world["badSdk"] == true) {
473+
options.sdkSummary = sdkSummaryUri.resolve("nonexisting.dill");
474+
}
472475
options.omitPlatform = omitPlatform != false;
473476
if (world["experiments"] != null) {
474477
Map<ExperimentalFlag, bool> experimentalFlags =
@@ -486,8 +489,12 @@ class NewWorldTest {
486489
final Set<String> formattedErrors = Set<String>();
487490
bool gotWarning = false;
488491
final Set<String> formattedWarnings = Set<String>();
492+
final Set<String> seenDiagnosticCodes = Set<String>();
489493

490494
options.onDiagnostic = (DiagnosticMessage message) {
495+
String code = getMessageCodeObject(message)?.name;
496+
if (code != null) seenDiagnosticCodes.add(code);
497+
491498
String stringId = message.ansiFormatted.join("\n");
492499
if (message is FormattedMessage) {
493500
stringId = message.toJsonString();
@@ -581,6 +588,27 @@ class NewWorldTest {
581588
}
582589
performErrorAndWarningCheck(
583590
world, gotError, formattedErrors, gotWarning, formattedWarnings);
591+
if (world["expectInitializationError"] != null) {
592+
Set<String> seenInitializationError = seenDiagnosticCodes.intersection({
593+
"InitializeFromDillNotSelfContainedNoDump",
594+
"InitializeFromDillNotSelfContained",
595+
"InitializeFromDillUnknownProblem",
596+
"InitializeFromDillUnknownProblemNoDump",
597+
});
598+
if (world["expectInitializationError"] == true) {
599+
if (seenInitializationError.isEmpty) {
600+
throw "Expected to see an initialization error but didn't.";
601+
}
602+
} else if (world["expectInitializationError"] == false) {
603+
if (seenInitializationError.isNotEmpty) {
604+
throw "Expected not to see an initialization error but did: "
605+
"$seenInitializationError.";
606+
}
607+
} else {
608+
throw "Unsupported value for 'expectInitializationError': "
609+
"${world["expectInitializationError"]}";
610+
}
611+
}
584612
util.throwOnEmptyMixinBodies(component);
585613
await util.throwOnInsufficientUriToSource(component,
586614
fileSystem: gotError ? null : fs);
@@ -1594,6 +1622,11 @@ class TestIncrementalCompiler extends IncrementalCompiler {
15941622
}
15951623
return result;
15961624
}
1625+
1626+
void recordTemporaryFileForTesting(Uri uri) {
1627+
File f = new File.fromUri(uri);
1628+
if (f.existsSync()) f.deleteSync();
1629+
}
15971630
}
15981631

15991632
void doSimulateTransformer(Component c) {

pkg/front_end/test/incremental_utils.dart

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Future<void> throwOnInsufficientUriToSource(Component component,
6767
component.accept(uriFinder);
6868
Set<Uri> uris = uriFinder.seenUris.toSet();
6969
uris.removeAll(component.uriToSource.keys);
70+
uris.remove(null);
7071
if (uris.length != 0) {
7172
throw "Expected 0 uris with no source, but found ${uris.length} ($uris)";
7273
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2+
# for details. All rights reserved. Use of this source code is governed by a
3+
# BSD-style license that can be found in the LICENSE.md file.
4+
5+
# Give a bad SDK URI, and try to initialize from dill.
6+
7+
type: newworld
8+
worlds:
9+
- entry: main.dart
10+
sources:
11+
main.dart: |
12+
import 'lib.dart';
13+
class A extends B {}
14+
lib.dart: |
15+
class B {
16+
void bMethod() {}
17+
}
18+
expectedLibraryCount: 2
19+
20+
- entry: main.dart
21+
expectInitializeFromDill: true
22+
invalidate:
23+
- main.dart
24+
sources:
25+
main.dart: |
26+
import 'lib.dart';
27+
class A extends B {}
28+
lib.dart: |
29+
class B {
30+
void bMethod() {}
31+
}
32+
expectedLibraryCount: 2
33+
34+
- entry: main.dart
35+
badSdk: true
36+
errors: true
37+
expectInitializeFromDill: false
38+
expectInitializationError: false
39+
40+
# this skips a check that fails (shouldn't matter considering this is an
41+
# exceptional case).
42+
checkInvalidatedFiles: false
43+
44+
# this skips re-compiling several times which fails to produce the same
45+
# result (shouldn't matter considering this is an exceptional case).
46+
noFullComponent: true
47+
48+
invalidate:
49+
- main.dart
50+
sources:
51+
main.dart: |
52+
import 'lib.dart';
53+
class A extends B {}
54+
lib.dart: |
55+
class B {
56+
void bMethod() {}
57+
}
58+
expectedLibraryCount: 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
main = <No Member>;
2+
library from "org-dartlang-test:///lib.dart" as lib {
3+
4+
class B extends dart.core::Object {
5+
synthetic constructor •() → lib::B*
6+
: super dart.core::Object::•()
7+
;
8+
method bMethod() → void {}
9+
abstract member-signature get _identityHashCode() → dart.core::int*;
10+
abstract member-signature method _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → dart.core::bool*;
11+
abstract member-signature method _simpleInstanceOf(dynamic type) → dart.core::bool*;
12+
abstract member-signature method _simpleInstanceOfTrue(dynamic type) → dart.core::bool*;
13+
abstract member-signature method _simpleInstanceOfFalse(dynamic type) → dart.core::bool*;
14+
abstract member-signature operator ==(dynamic other) → dart.core::bool*;
15+
abstract member-signature get hashCode() → dart.core::int*;
16+
abstract member-signature method toString() → dart.core::String*;
17+
abstract member-signature method noSuchMethod(dart.core::Invocation* invocation) → dynamic;
18+
abstract member-signature get runtimeType() → dart.core::Type*;
19+
}
20+
}
21+
library from "org-dartlang-test:///main.dart" as main {
22+
23+
import "org-dartlang-test:///lib.dart";
24+
25+
class A extends lib::B {
26+
synthetic constructor •() → main::A*
27+
: super lib::B::•()
28+
;
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
main = <No Member>;
2+
library from "org-dartlang-test:///lib.dart" as lib {
3+
4+
class B extends dart.core::Object {
5+
synthetic constructor •() → lib::B*
6+
: super dart.core::Object::•()
7+
;
8+
method bMethod() → void {}
9+
abstract member-signature get _identityHashCode() → dart.core::int*;
10+
abstract member-signature method _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → dart.core::bool*;
11+
abstract member-signature method _simpleInstanceOf(dynamic type) → dart.core::bool*;
12+
abstract member-signature method _simpleInstanceOfTrue(dynamic type) → dart.core::bool*;
13+
abstract member-signature method _simpleInstanceOfFalse(dynamic type) → dart.core::bool*;
14+
abstract member-signature operator ==(dynamic other) → dart.core::bool*;
15+
abstract member-signature get hashCode() → dart.core::int*;
16+
abstract member-signature method toString() → dart.core::String*;
17+
abstract member-signature method noSuchMethod(dart.core::Invocation* invocation) → dynamic;
18+
abstract member-signature get runtimeType() → dart.core::Type*;
19+
}
20+
}
21+
library from "org-dartlang-test:///main.dart" as main {
22+
23+
import "org-dartlang-test:///lib.dart";
24+
25+
class A extends lib::B {
26+
synthetic constructor •() → main::A*
27+
: super lib::B::•()
28+
;
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
main = <No Member>;
2+
library from "org-dartlang-test:///lib.dart" as lib {
3+
4+
class B extends #lib1::Object {
5+
synthetic constructor •() → lib::B*
6+
: super #lib1::Object::•()
7+
;
8+
method bMethod() → void {}
9+
abstract member-signature operator ==(dynamic dynamic) → #lib1::bool*;
10+
}
11+
}
12+
library from "org-dartlang-test:///main.dart" as main {
13+
14+
import "org-dartlang-test:///lib.dart";
15+
16+
class A extends lib::B {
17+
synthetic constructor •() → main::A*
18+
: super lib::B::•()
19+
;
20+
}
21+
}
22+
23+
And 18 platform libraries:
24+
- dart:_builtin
25+
- dart:_internal
26+
- dart:_vmservice
27+
- dart:async
28+
- dart:cli
29+
- dart:collection
30+
- dart:convert
31+
- dart:core
32+
- dart:developer
33+
- dart:ffi
34+
- dart:io
35+
- dart:isolate
36+
- dart:math
37+
- dart:mirrors
38+
- dart:nativewrappers
39+
- dart:typed_data
40+
- dart:vmservice_io
41+
- dart:wasm

0 commit comments

Comments
 (0)