Skip to content

Commit 2015c55

Browse files
nshahancommit-bot@chromium.org
authored andcommitted
[dartdevc] Remove ability to run analyzer based DDC
This is the first step in deleting legacy DDC! * Default all invocations of DDC to run the kernel version. * Disable all tests that run analyzer DDC. * Detect the most likely case when invoked with an analyzer summary and print instruction to update build_web_compilers dependency. I will follow up with deletions, and a rename of the test configurations/ builders to reclaim the names (ddc vs ddk, dartdevc vs dartdevk). Issue #38777 Change-Id: I1477f0274b6b7f345a5e19d2b3f93797c454a09e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127067 Commit-Queue: Nicholas Shahan <nshahan@google.com> Reviewed-by: Mark Zhou <markzipan@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com>
1 parent 2a1fadb commit 2015c55

8 files changed

Lines changed: 46 additions & 400 deletions

File tree

pkg/dev_compiler/lib/src/compiler/shared_command.dart

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44

55
import 'dart:async';
66
import 'dart:io';
7-
import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine;
87
import 'package:args/args.dart';
98
import 'package:front_end/src/api_unstable/ddc.dart'
109
show InitializedCompilerState, parseExperimentalArguments;
1110
import 'package:path/path.dart' as p;
1211
import 'module_builder.dart';
13-
import '../analyzer/command.dart' as analyzer_compiler;
1412
import '../analyzer/driver.dart' show CompilerAnalysisDriver;
1513
import '../kernel/command.dart' as kernel_compiler;
1614

@@ -400,33 +398,31 @@ Future<CompilerResult> compile(ParsedArguments args,
400398
throw ArgumentError(
401399
'previousResult requires --batch or --bazel_worker mode/');
402400
}
403-
if (args.isKernel) {
404-
return kernel_compiler.compile(args.rest,
405-
compilerState: previousResult?.kernelState,
406-
isWorker: args.isWorker,
407-
useIncrementalCompiler: args.useIncrementalCompiler,
408-
inputDigests: inputDigests);
409-
} else {
410-
var result = analyzer_compiler.compile(args.rest,
411-
compilerState: previousResult?.analyzerState);
412-
if (args.isBatchOrWorker) {
413-
AnalysisEngine.instance.clearCaches();
414-
}
415-
return Future.value(result);
401+
402+
// TODO(38777) Cleanup when we delete all the DDC code.
403+
if (!args.isKernel) {
404+
throw ArgumentError(
405+
'Compiling with analyzer based DDC is no longer supported.');
416406
}
407+
408+
return kernel_compiler.compile(args.rest,
409+
compilerState: previousResult?.kernelState,
410+
isWorker: args.isWorker,
411+
useIncrementalCompiler: args.useIncrementalCompiler,
412+
inputDigests: inputDigests);
417413
}
418414

419415
/// The result of a single `dartdevc` compilation.
420416
///
421-
/// Typically used for exiting the proceess with [exitCode] or checking the
417+
/// Typically used for exiting the process with [exitCode] or checking the
422418
/// [success] of the compilation.
423419
///
424-
/// For batch/worker compilations, the [compilerState] provides an opprotunity
420+
/// For batch/worker compilations, the [compilerState] provides an opportunity
425421
/// to reuse state from the previous run, if the options/input summaries are
426-
/// equiavlent. Otherwise it will be discarded.
422+
/// equivalent. Otherwise it will be discarded.
427423
class CompilerResult {
428424
/// Optionally provides the front_end state from the previous compilation,
429-
/// which can be passed to [compile] to potentially speeed up the next
425+
/// which can be passed to [compile] to potentially speed up the next
430426
/// compilation.
431427
///
432428
/// This field is unused when using the Analyzer-backend for DDC.
@@ -437,6 +433,7 @@ class CompilerResult {
437433
/// compilation.
438434
///
439435
/// This field is unused when using the Kernel-backend for DDC.
436+
// TODO(38777) Cleanup when we delete all the DDC code.
440437
final CompilerAnalysisDriver analyzerState;
441438

442439
/// The process exit code of the compiler.
@@ -454,7 +451,7 @@ class CompilerResult {
454451
/// [exitCode] == 0).
455452
bool get success => exitCode == 0;
456453

457-
/// Whether the compiler crashed (i.e. threw an unhandled exeception,
454+
/// Whether the compiler crashed (i.e. threw an unhandled exception,
458455
/// typically indicating an internal error in DDC itself or its front end).
459456
bool get crashed => exitCode == 70;
460457
}
@@ -506,7 +503,7 @@ class ParsedArguments {
506503
ParsedArguments._(this.rest,
507504
{this.isBatch = false,
508505
this.isWorker = false,
509-
this.isKernel = false,
506+
this.isKernel = true,
510507
this.reuseResult = false,
511508
this.useIncrementalCompiler = false});
512509

@@ -525,7 +522,7 @@ class ParsedArguments {
525522
var newArgs = <String>[];
526523
bool isWorker = false;
527524
bool isBatch = false;
528-
bool isKernel = false;
525+
bool isKernel = true;
529526
bool reuseResult = false;
530527
bool useIncrementalCompiler = false;
531528

pkg/dev_compiler/lib/src/kernel/command.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,16 @@ Future<CompilerResult> _compile(List<String> args,
116116
try {
117117
argResults = argParser.parse(filterUnknownArguments(args, argParser));
118118
} on FormatException catch (error) {
119+
if (args.any((arg) => arg.contains('ddc_sdk.sum'))) {
120+
print('Compiling with analyzer based DDC is no longer supported.\n');
121+
print('The most likely reason you are seeing this message is due to an '
122+
'old version of build_web_compilers.');
123+
print('Update your package pubspec.yaml to depend on a newer version of '
124+
'build_web_compilers:\n\n'
125+
'dev_dependency:\n'
126+
' build_web_compilers: ^2.0.0\n');
127+
return CompilerResult(64);
128+
}
119129
print(error);
120130
print(_usageMessage(argParser));
121131
return CompilerResult(64);

pkg/dev_compiler/test/worker/worker_test.dart

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,7 @@ Directory tmp = Directory.systemTemp.createTempSync('ddc_worker_test');
1717
File file(String path) => File(join(tmp.path, joinAll(path.split('/'))));
1818

1919
void main() {
20-
runTests(false);
21-
runTests(true);
22-
}
23-
24-
void runTests(bool isKernel) {
25-
String mode = isKernel ? 'DDK' : 'DDC';
26-
List<String> baseArgs = isKernel ? ['-k'] : [];
27-
String ext = isKernel ? 'dill' : 'sum';
20+
List<String> baseArgs = [];
2821
final binDir = dirname(Platform.resolvedExecutable);
2922
// Note, the bots use the dart binary in the top-level build directory.
3023
// On windows, this is a .bat file.
@@ -33,7 +26,7 @@ void runTests(bool isKernel) {
3326
? join(binDir, dartdevc)
3427
: join(binDir, 'dart-sdk', 'bin', dartdevc);
3528
final executableArgs = <String>[];
36-
group('$mode: Hello World', () {
29+
group('DDC: Hello World', () {
3730
final argsFile = file('hello_world.args');
3831
final inputDartFile = file('hello_world.dart');
3932
final outputJsFile = file('out/hello_world.js');
@@ -165,16 +158,16 @@ void runTests(bool isKernel) {
165158
});
166159
});
167160

168-
group('$mode: Hello World with Summaries', () {
161+
group('DDC: Hello World with Summaries', () {
169162
final greetingDart = file('greeting.dart');
170163
final helloDart = file('hello.dart');
171164

172165
final greetingJS = file('greeting.js');
173-
final greetingSummary = file('greeting.$ext');
166+
final greetingSummary = file('greeting.dill');
174167
final helloJS = file('hello_world.js');
175168

176169
final greeting2JS = file('greeting2.js');
177-
final greeting2Summary = file('greeting2.$ext');
170+
final greeting2Summary = file('greeting2.dill');
178171

179172
setUp(() {
180173
greetingDart.writeAsStringSync('String greeting = "hello";');
@@ -285,7 +278,7 @@ void runTests(bool isKernel) {
285278
});
286279
});
287280

288-
group('$mode: Error handling', () {
281+
group('DDC: Error handling', () {
289282
final badFileDart = file('bad.dart');
290283
final badFileJs = file('bad.js');
291284

@@ -325,7 +318,7 @@ void runTests(bool isKernel) {
325318
});
326319
});
327320

328-
group('$mode: Parts', () {
321+
group('DDC: Parts', () {
329322
final partFile = file('greeting.dart');
330323
final libraryFile = file('hello.dart');
331324

@@ -381,27 +374,6 @@ void runTests(bool isKernel) {
381374
expect(result.exitCode, 0);
382375
expect(outJS.existsSync(), isTrue);
383376
});
384-
385-
if (!isKernel) {
386-
// TODO(vsm): Consider dropping this test. Kernel behavior is better.
387-
test('part without library is silently ignored', () {
388-
var result = Process.runSync(
389-
executable,
390-
executableArgs +
391-
baseArgs +
392-
[
393-
'--no-summarize',
394-
'--no-source-map',
395-
'-o',
396-
outJS.path,
397-
partFile.path,
398-
]);
399-
expect(result.stdout, isEmpty);
400-
expect(result.stderr, isEmpty);
401-
expect(result.exitCode, 0);
402-
expect(outJS.existsSync(), isTrue);
403-
});
404-
}
405377
});
406378
}
407379

pkg/dev_compiler/tool/ddb

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void main(List<String> args) async {
2828
var parser = ArgParser()
2929
..addFlag('help', abbr: 'h', help: 'Display this message.')
3030
..addFlag('kernel',
31-
abbr: 'k', help: 'Compile with the new kernel-based front end.')
31+
abbr: 'k', help: 'Ignored. The kernel based DDC is always used.')
3232
..addMultiOption('summary',
3333
abbr: 's',
3434
help: 'summary file(s) of imported libraries, optionally\n'
@@ -44,9 +44,7 @@ void main(List<String> args) async {
4444
..addOption('vm-service-port',
4545
help: 'Specify the observatory port. Implied --observe.')
4646
..addFlag('summarize-text',
47-
help: 'Emit API summary in a .js.txt file.\n'
48-
'Ignored when not passed with --kernel.',
49-
defaultsTo: false)
47+
help: 'Emit API summary in a .js.txt file.', defaultsTo: false)
5048
..addOption('runtime',
5149
abbr: 'r',
5250
help: 'Platform to run on (node|d8|chrome). Default is node.',
@@ -65,10 +63,8 @@ void main(List<String> args) async {
6563
defaultsTo: 'all')
6664
..addOption('compile-vm-options',
6765
help: 'DART_VM_OPTIONS for the compilation VM.')
68-
..addOption('packages',
69-
help: 'Where to find a package spec file.')
70-
..addOption('out',
71-
help: 'Output file.');
66+
..addOption('packages', help: 'Where to find a package spec file.')
67+
..addOption('out', help: 'Output file.');
7268

7369
var options = parser.parse(args);
7470
if (options['help'] as bool) {
@@ -85,7 +81,6 @@ void main(List<String> args) async {
8581
var debug = options['debug'] as bool ||
8682
options['observe'] as bool ||
8783
options.wasParsed('vm-service-port');
88-
var kernel = options['kernel'] as bool;
8984
var summarizeText = options['summarize-text'] as bool;
9085
var binary = options['binary'] as String;
9186
var experiments = options['enable-experiment'] as List;
@@ -99,9 +94,7 @@ void main(List<String> args) async {
9994
var out = (options['out'] as String) ?? p.setExtension(entry, '.js');
10095
var libRoot = p.dirname(entry);
10196
var basename = p.basenameWithoutExtension(entry);
102-
var libname = kernel
103-
? p.relative(p.withoutExtension(entry)).replaceAll('/', '__')
104-
: basename;
97+
var libname = p.relative(p.withoutExtension(entry)).replaceAll('/', '__');
10598
libname = libname.replaceAll('-', '_');
10699

107100
// By default (no `-d`), we use the `dartdevc` binary on the user's path to
@@ -178,22 +171,17 @@ void main(List<String> args) async {
178171
var buildDir = p.join(sdkRoot, Platform.isMacOS ? 'xcodebuild' : 'out');
179172
dartSdk = p.join(buildDir, 'ReleaseX64', 'dart-sdk');
180173
}
181-
var suffix = kernel ? p.join('kernel', mod) : mod;
174+
var suffix = p.join('kernel', mod);
182175
sdkJsPath = p.join(dartSdk, 'lib', 'dev_compiler', suffix);
183176
requirePath = sdkJsPath;
184-
ddcSdk = p.join(
185-
dartSdk, 'lib', '_internal', kernel ? 'ddc_sdk.dill' : 'ddc_sdk.sum');
177+
ddcSdk = p.join(dartSdk, 'lib', '_internal', 'ddc_sdk.dill');
186178

187179
if (compile) {
188180
var ddcArgs = [
189-
if (kernel) '--kernel',
190-
if (kernel && summarizeText)
191-
'--summarize-text',
181+
'--kernel',
182+
if (summarizeText) '--summarize-text',
192183
'--modules=$mod',
193184
'--dart-sdk-summary=$ddcSdk',
194-
// TODO(nshahan) Cleanup when we settle on using or removing library-root.
195-
if (!kernel)
196-
'--library-root=$libRoot',
197185
for (var summary in summaries) '--summary=$summary',
198186
for (var experiment in experiments) '--enable-experiment=$experiment',
199187
if (options['packages'] != null) '--packages=${options['packages']}',

sdk/BUILD.gn

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -691,72 +691,15 @@ copy("copy_dev_compiler_summary") {
691691
deps = [
692692
":copy_libraries",
693693
"../utils/dartdevc:dartdevc_platform",
694-
"../utils/dartdevc:dartdevc_sdk",
695694
]
696-
gen_dir = get_label_info("../utils/dartdevc:dartdevc_sdk", "target_gen_dir")
697695
sources = [
698-
# TODO(vsm): Remove post CFE.
699-
"$gen_dir/ddc_sdk.sum",
700696
"$root_out_dir/ddc_sdk.dill",
701697
]
702698
outputs = [
703699
"$root_out_dir/dart-sdk/lib/_internal/{{source_file_part}}",
704700
]
705701
}
706702

707-
# TODO(vsm): Remove the old non-CFE versions of the SDK once we've completed
708-
# DDC to Kernel (DDK) migration.
709-
710-
# This rule copies DDC's JS SDK and require.js to lib/dev_compiler/amd.
711-
copy("copy_dev_compiler_js_amd") {
712-
visibility = [ ":copy_dev_compiler_js" ]
713-
deps = [
714-
"../utils/dartdevc:dartdevc_sdk",
715-
]
716-
gen_dir = get_label_info("../utils/dartdevc:dartdevc_sdk", "target_gen_dir")
717-
sources = [
718-
"$gen_dir/js/amd/dart_sdk.js",
719-
"$gen_dir/js/amd/dart_sdk.js.map",
720-
"../third_party/requirejs/require.js",
721-
]
722-
outputs = [
723-
"$root_out_dir/dart-sdk/lib/dev_compiler/amd/{{source_file_part}}",
724-
]
725-
}
726-
727-
# This rule copies DDC's JS SDK and run.js to lib/dev_compiler/common.
728-
copy("copy_dev_compiler_js_common") {
729-
visibility = [ ":copy_dev_compiler_js" ]
730-
deps = [
731-
"../utils/dartdevc:dartdevc_sdk",
732-
]
733-
gen_dir = get_label_info("../utils/dartdevc:dartdevc_sdk", "target_gen_dir")
734-
sources = [
735-
"$gen_dir/js/common/dart_sdk.js",
736-
"$gen_dir/js/common/dart_sdk.js.map",
737-
"../pkg/dev_compiler/lib/js/common/run.js",
738-
]
739-
outputs = [
740-
"$root_out_dir/dart-sdk/lib/dev_compiler/common/{{source_file_part}}",
741-
]
742-
}
743-
744-
# This rule copies DDC's JS SDK to lib/dev_compiler/es6.
745-
copy("copy_dev_compiler_js_es6") {
746-
visibility = [ ":copy_dev_compiler_js" ]
747-
deps = [
748-
"../utils/dartdevc:dartdevc_sdk",
749-
]
750-
gen_dir = get_label_info("../utils/dartdevc:dartdevc_sdk", "target_gen_dir")
751-
sources = [
752-
"$gen_dir/js/es6/dart_sdk.js",
753-
"$gen_dir/js/es6/dart_sdk.js.map",
754-
]
755-
outputs = [
756-
"$root_out_dir/dart-sdk/lib/dev_compiler/es6/{{source_file_part}}",
757-
]
758-
}
759-
760703
# This rule copies DDK's JS SDK and require.js to lib/dev_compiler/kernel/amd.
761704
copy("copy_dev_compiler_js_amd_kernel") {
762705
visibility = [ ":copy_dev_compiler_js" ]
@@ -817,11 +760,8 @@ group("copy_dev_compiler_js") {
817760
":copy_dev_compiler_tools",
818761
]
819762
public_deps = [
820-
":copy_dev_compiler_js_amd",
821763
":copy_dev_compiler_js_amd_kernel",
822-
":copy_dev_compiler_js_common",
823764
":copy_dev_compiler_js_common_kernel",
824-
":copy_dev_compiler_js_es6",
825765
":copy_dev_compiler_js_es6_kernel",
826766
]
827767
}

0 commit comments

Comments
 (0)