Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 64ed4bf

Browse files
sigmundchcommit-bot@chromium.org
authored andcommitted
Changes to bazel worker to support modular testing.
This includes: * accepting null values like sdk-summary or .packages (which are not used when building kernel for the sdk itself) * allow enabling language experiments * only exclude-non-sources on the non-incremental code path if that's requested Change-Id: I08eeb643676f1f1406f0f3030c341d68179d42a2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103574 Reviewed-by: Nate Bosch <[email protected]>
1 parent fc6954f commit 64ed4bf

File tree

5 files changed

+72
-64
lines changed

5 files changed

+72
-64
lines changed

pkg/front_end/lib/src/api_unstable/bazel_worker.dart

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ import 'package:kernel/kernel.dart' show Component, CanonicalName;
1111

1212
import 'package:kernel/target/targets.dart' show Target;
1313

14-
import '../api_prototype/compiler_options.dart' show CompilerOptions;
14+
import '../api_prototype/compiler_options.dart'
15+
show CompilerOptions, parseExperimentalFlags;
1516

1617
import '../api_prototype/diagnostic_message.dart' show DiagnosticMessageHandler;
1718

19+
import '../api_prototype/experimental_flags.dart' show ExperimentalFlag;
20+
1821
import '../api_prototype/file_system.dart' show FileSystem;
1922

2023
import '../base/processed_options.dart' show ProcessedOptions;
@@ -41,6 +44,8 @@ export '../fasta/severity.dart' show Severity;
4144

4245
export 'compiler_state.dart' show InitializedCompilerState;
4346

47+
import 'util.dart' show equalMaps;
48+
4449
/// Initializes the compiler for a modular build.
4550
///
4651
/// Re-uses cached components from [_workerInputCache], and reloads them
@@ -54,6 +59,7 @@ Future<InitializedCompilerState> initializeIncrementalCompiler(
5459
Map<Uri, List<int>> workerInputDigests,
5560
Target target,
5661
FileSystem fileSystem,
62+
Iterable<String> experiments,
5763
bool outlineOnly) async {
5864
final List<int> sdkDigest = workerInputDigests[sdkSummary];
5965
if (sdkDigest == null) {
@@ -66,10 +72,13 @@ Future<InitializedCompilerState> initializeIncrementalCompiler(
6672
Map<Uri, WorkerInputComponent> workerInputCache =
6773
oldState?.workerInputCache ?? new Map<Uri, WorkerInputComponent>();
6874
bool startOver = false;
75+
Map<ExperimentalFlag, bool> experimentalFlags =
76+
parseExperimentalFlags(experiments, (e) => throw e);
6977

7078
if (oldState == null ||
7179
oldState.incrementalCompiler == null ||
72-
oldState.incrementalCompiler.outlineOnly != outlineOnly) {
80+
oldState.incrementalCompiler.outlineOnly != outlineOnly ||
81+
!equalMaps(oldState.options.experimentalFlags, experimentalFlags)) {
7382
// No - or immediately not correct - previous state.
7483
startOver = true;
7584

@@ -184,7 +193,8 @@ Future<InitializedCompilerState> initializeCompiler(
184193
List<Uri> summaryInputs,
185194
List<Uri> linkedInputs,
186195
Target target,
187-
FileSystem fileSystem) async {
196+
FileSystem fileSystem,
197+
Iterable<String> experiments) async {
188198
// TODO(sigmund): use incremental compiler when it supports our use case.
189199
// Note: it is common for the summary worker to invoke the compiler with the
190200
// same input summary URIs, but with different contents, so we'd need to be
@@ -198,7 +208,8 @@ Future<InitializedCompilerState> initializeCompiler(
198208
..linkedDependencies = linkedInputs
199209
..target = target
200210
..fileSystem = fileSystem
201-
..environmentDefines = const {};
211+
..environmentDefines = const {}
212+
..experimentalFlags = parseExperimentalFlags(experiments, (e) => throw e);
202213

203214
ProcessedOptions processedOpts = new ProcessedOptions(options: options);
204215

pkg/front_end/lib/src/api_unstable/dart2js.dart

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import '../fasta/scanner.dart' show ErrorToken, StringToken, Token;
3232

3333
import 'compiler_state.dart' show InitializedCompilerState;
3434

35+
import 'util.dart' show equalLists, equalMaps;
36+
3537
export '../api_prototype/compiler_options.dart'
3638
show CompilerOptions, parseExperimentalFlags;
3739

@@ -116,30 +118,13 @@ InitializedCompilerState initializeCompiler(
116118
Map<ExperimentalFlag, bool> experimentalFlags,
117119
bool verify: false,
118120
bool enableAsserts: false}) {
119-
bool mapEqual(Map<ExperimentalFlag, bool> a, Map<ExperimentalFlag, bool> b) {
120-
if (a == null || b == null) return a == b;
121-
if (a.length != b.length) return false;
122-
for (var flag in a.keys) {
123-
if (!b.containsKey(flag) || a[flag] != b[flag]) return false;
124-
}
125-
return true;
126-
}
127-
128-
bool listEqual(List<Uri> a, List<Uri> b) {
129-
if (a.length != b.length) return false;
130-
for (int i = 0; i < a.length; ++i) {
131-
if (a[i] != b[i]) return false;
132-
}
133-
return true;
134-
}
135-
136121
linkedDependencies.sort((a, b) => a.toString().compareTo(b.toString()));
137122

138123
if (oldState != null &&
139124
oldState.options.packagesFileUri == packagesFileUri &&
140125
oldState.options.librariesSpecificationUri == librariesSpecificationUri &&
141-
listEqual(oldState.options.linkedDependencies, linkedDependencies) &&
142-
mapEqual(oldState.options.experimentalFlags, experimentalFlags)) {
126+
equalLists(oldState.options.linkedDependencies, linkedDependencies) &&
127+
equalMaps(oldState.options.experimentalFlags, experimentalFlags)) {
143128
return oldState;
144129
}
145130

pkg/front_end/lib/src/api_unstable/ddc.dart

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import '../kernel_generator_impl.dart' show generateKernel;
2929
import 'compiler_state.dart'
3030
show InitializedCompilerState, WorkerInputComponent, digestsEqual;
3131

32+
import 'util.dart' show equalLists, equalMaps;
33+
3234
export '../api_prototype/compiler_options.dart' show CompilerOptions;
3335

3436
export '../api_prototype/diagnostic_message.dart' show DiagnosticMessage;
@@ -79,29 +81,13 @@ Future<InitializedCompilerState> initializeCompiler(
7981
{FileSystem fileSystem,
8082
Map<ExperimentalFlag, bool> experiments}) async {
8183
inputSummaries.sort((a, b) => a.toString().compareTo(b.toString()));
82-
bool listEqual(List<Uri> a, List<Uri> b) {
83-
if (a.length != b.length) return false;
84-
for (int i = 0; i < a.length; ++i) {
85-
if (a[i] != b[i]) return false;
86-
}
87-
return true;
88-
}
89-
90-
bool mapEqual(Map<ExperimentalFlag, bool> a, Map<ExperimentalFlag, bool> b) {
91-
if (a == null || b == null) return a == b;
92-
if (a.length != b.length) return false;
93-
for (var flag in a.keys) {
94-
if (!b.containsKey(flag) || a[flag] != b[flag]) return false;
95-
}
96-
return true;
97-
}
9884

9985
if (oldState != null &&
10086
oldState.options.sdkSummary == sdkSummary &&
10187
oldState.options.packagesFileUri == packagesFile &&
10288
oldState.options.librariesSpecificationUri == librariesSpecificationUri &&
103-
listEqual(oldState.options.inputSummaries, inputSummaries) &&
104-
mapEqual(oldState.options.experimentalFlags, experiments)) {
89+
equalLists(oldState.options.inputSummaries, inputSummaries) &&
90+
equalMaps(oldState.options.experimentalFlags, experiments)) {
10591
// Reuse old state.
10692

10793
// These libraries are marked external when compiling. If not un-marking
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) 2019, 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 file.
4+
5+
bool equalLists<T>(List<T> a, List<T> b) {
6+
if (identical(a, b)) return true;
7+
if (a == null || b == null) return false;
8+
if (a.length != b.length) return false;
9+
for (int i = 0; i < a.length; ++i) {
10+
if (a[i] != b[i]) return false;
11+
}
12+
return true;
13+
}
14+
15+
bool equalMaps<K, V>(Map<K, V> a, Map<K, V> b) {
16+
if (identical(a, b)) return true;
17+
if (a == null || b == null) return false;
18+
if (a.length != b.length) return false;
19+
for (K key in a.keys) {
20+
if (!b.containsKey(key) || a[key] != b[key]) return false;
21+
}
22+
return true;
23+
}

utils/bazel/kernel_worker.dart

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ final summaryArgsParser = new ArgParser()
128128
..addOption('output')
129129
..addFlag('reuse-compiler-result', defaultsTo: false)
130130
..addFlag('use-incremental-compiler', defaultsTo: false)
131-
..addFlag('track-widget-creation', defaultsTo: false);
131+
..addFlag('track-widget-creation', defaultsTo: false)
132+
..addMultiOption('enable-experiment',
133+
help: 'Enable a language experiment when invoking the CFE.');
132134

133135
class ComputeKernelResult {
134136
final bool succeeded;
@@ -167,8 +169,7 @@ Future<ComputeKernelResult> computeKernel(List<String> args,
167169
if (multiRoots.isEmpty) multiRoots.add(Uri.base);
168170
var fileSystem = new MultiRootFileSystem(parsedArgs['multi-root-scheme'],
169171
multiRoots, fe.StandardFileSystem.instance);
170-
var sources =
171-
(parsedArgs['source'] as List<String>).map(Uri.base.resolve).toList();
172+
var sources = (parsedArgs['source'] as List<String>).map(_toUri).toList();
172173
var excludeNonSources = parsedArgs['exclude-non-sources'] as bool;
173174

174175
var summaryOnly = parsedArgs['summary-only'] as bool;
@@ -222,19 +223,11 @@ Future<ComputeKernelResult> computeKernel(List<String> args,
222223
out.writeln('error: unsupported target: $targetName');
223224
}
224225

225-
// TODO(sigmund,jakemac): make it mandatory. We allow null while we migrate
226-
// existing clients of this tool.
227-
var librariesSpec = parsedArgs['libraries-file'] == null
228-
? null
229-
: Uri.base.resolve(parsedArgs['libraries-file']);
226+
List<Uri> linkedInputs =
227+
(parsedArgs['input-linked'] as List<String>).map(_toUri).toList();
230228

231-
List<Uri> linkedInputs = (parsedArgs['input-linked'] as List<String>)
232-
.map(Uri.base.resolve)
233-
.toList();
234-
235-
List<Uri> summaryInputs = (parsedArgs['input-summary'] as List<String>)
236-
.map(Uri.base.resolve)
237-
.toList();
229+
List<Uri> summaryInputs =
230+
(parsedArgs['input-summary'] as List<String>).map(_toUri).toList();
238231

239232
fe.InitializedCompilerState state;
240233
bool usingIncrementalCompiler = false;
@@ -253,27 +246,30 @@ Future<ComputeKernelResult> computeKernel(List<String> args,
253246
inputDigests[uri] = input.digest;
254247
}
255248

249+
// TODO(sigmund): add support for experiments with the incremental compiler.
256250
state = await fe.initializeIncrementalCompiler(
257251
previousState,
258-
Uri.base.resolve(parsedArgs['dart-sdk-summary']),
259-
Uri.base.resolve(parsedArgs['packages-file']),
260-
librariesSpec,
252+
_toUri(parsedArgs['dart-sdk-summary']),
253+
_toUri(parsedArgs['packages-file']),
254+
_toUri(parsedArgs['libraries-file']),
261255
summaryInputs,
262256
inputDigests,
263257
target,
264258
fileSystem,
259+
(parsedArgs['enable-experiment'] as List<String>),
265260
summaryOnly);
266261
} else {
267262
state = await fe.initializeCompiler(
268263
// TODO(sigmund): pass an old state once we can make use of it.
269264
null,
270-
Uri.base.resolve(parsedArgs['dart-sdk-summary']),
271-
librariesSpec,
272-
Uri.base.resolve(parsedArgs['packages-file']),
265+
_toUri(parsedArgs['dart-sdk-summary']),
266+
_toUri(parsedArgs['libraries-file']),
267+
_toUri(parsedArgs['packages-file']),
273268
summaryInputs,
274269
linkedInputs,
275270
target,
276-
fileSystem);
271+
fileSystem,
272+
(parsedArgs['enable-experiment'] as List<String>));
277273
}
278274

279275
void onDiagnostic(fe.DiagnosticMessage message) {
@@ -308,7 +304,9 @@ Future<ComputeKernelResult> computeKernel(List<String> args,
308304
Component component =
309305
await fe.compileComponent(state, sources, onDiagnostic);
310306
kernel = fe.serializeComponent(component,
311-
filter: (library) => sources.contains(library.importUri),
307+
filter: excludeNonSources
308+
? (library) => sources.contains(library.importUri)
309+
: null,
312310
includeOffsets: true);
313311
}
314312

@@ -365,3 +363,8 @@ class DevCompilerSummaryTarget extends DevCompilerTarget {
365363
}
366364
}
367365
}
366+
367+
Uri _toUri(String uriString) {
368+
if (uriString == null) return null;
369+
return Uri.base.resolve(uriString);
370+
}

0 commit comments

Comments
 (0)