Skip to content

Commit da14b16

Browse files
a-sivaCommit Queue
authored andcommitted
[Web/DDC] - Convert the kernel_worker and dartdevc snapshots to an AOT snapshot
Converts kernel_worker.dart.snapshot and dartdevc.dart.snapshot to AOT snapshots. Fixes tests and paths in the code accordingly. TESTS=ci Change-Id: Ib99b2a3343e23252c3a6b5295b0d20f0f486aede Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381388 Reviewed-by: Nicholas Shahan <[email protected]> Commit-Queue: Siva Annamalai <[email protected]>
1 parent 15ab569 commit da14b16

File tree

15 files changed

+293
-88
lines changed

15 files changed

+293
-88
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,23 @@ main() {
3131
}
3232
```
3333

34-
###### Dart to Javascript Compiler (dart2js)
34+
#### Dart to Javascript Compiler (dart2js)
3535

3636
- The dart2js compiler which is invoked when the command
3737
'dart compile js' is used has been switched to use an AOT snapshot
3838
instead of a JIT snapshot.
3939

4040
[#53576]: https://github.com/dart-lang/sdk/issues/53576
4141

42+
#### Dart Development Compiler (dartdevc)
43+
44+
- The dartdevc compiler and kernel_worker utility have been switched to use
45+
an AOT snapshot instead of a JIT snapshot, the SDK build still includes a
46+
JIT snapshot of these tools as package build/build_web_compiler depends
47+
on it. The AOT snapshot can be used as follows to run DDC
48+
<dart-sdk>/bin/dartaotruntime <dart-sdk>/bin/snapshots/dartdevc_aot.dart.snapshot <options>
49+
50+
[#53576]: https://github.com/dart-lang/sdk/issues/53576
4251

4352
## 3.6.0
4453

pkg/compiler/tool/modular_test_suite_helper.dart

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ import 'package:modular_test/src/runner.dart';
2020
import 'package:modular_test/src/suite.dart';
2121
import 'package:modular_test/src/steps/macro_precompile_aot.dart';
2222
import 'package:modular_test/src/steps/util.dart';
23+
import 'package:path/path.dart' as p;
2324

2425
String packageConfigJsonPath = ".dart_tool/package_config.json";
2526
Uri sdkRoot = Platform.script.resolve("../../../");
2627
Uri packageConfigUri = sdkRoot.resolve(packageConfigJsonPath);
2728
late Options _options;
2829
late String _dart2jsScript;
30+
late String _kernelWorkerAotScript;
2931
late String _kernelWorkerScript;
3032

3133
const dillSummaryId = DataId("summary.dill");
@@ -118,8 +120,22 @@ abstract class CFEStep extends IOModularStep {
118120
sources = getSources(module);
119121
}
120122

123+
var isAot = File(_kernelWorkerAotScript).existsSync();
124+
var script = _kernelWorkerAotScript;
125+
var sdkPath = p.dirname(p.dirname(Platform.resolvedExecutable));
126+
var executable = p.absolute(
127+
sdkPath,
128+
'bin',
129+
Platform.isWindows ? 'dartaotruntime.exe' : 'dartaotruntime',
130+
);
131+
if (!isAot) {
132+
// This can be removed once we stop supporting ia32 architecture.
133+
script = _kernelWorkerScript;
134+
executable = Platform.resolvedExecutable;
135+
}
136+
121137
List<String> args = [
122-
_kernelWorkerScript,
138+
script,
123139
'--sound-null-safety',
124140
...stepArguments,
125141
'--exclude-non-sources',
@@ -140,8 +156,8 @@ abstract class CFEStep extends IOModularStep {
140156
...(flags.expand((String flag) => ['--enable-experiment', flag])),
141157
];
142158

143-
var result = await runProcess(
144-
Platform.resolvedExecutable, args, root.toFilePath(), _options.verbose);
159+
var result =
160+
await runProcess(executable, args, root.toFilePath(), _options.verbose);
145161
checkExitCode(result, this, module, _options.verbose);
146162
}
147163

@@ -635,6 +651,8 @@ Future<void> resolveScripts(Options options) async {
635651
_options = options;
636652
_dart2jsScript = await resolve(
637653
'package:compiler/src/dart2js.dart', 'snapshots/dart2js.dart.snapshot');
654+
_kernelWorkerAotScript = await resolve('utils/bazel/kernel_worker.dart',
655+
'snapshots/kernel_worker_aot.dart.snapshot');
638656
_kernelWorkerScript = await resolve('utils/bazel/kernel_worker.dart',
639657
'snapshots/kernel_worker.dart.snapshot');
640658
}

pkg/dev_compiler/test/expression_compiler/expression_compiler_worker_shared.dart

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,15 +1191,28 @@ class DDCKernelGenerator {
11911191
static final dart = Platform.resolvedExecutable;
11921192
static final sdkPath =
11931193
computePlatformBinariesLocation(forceBuildDir: true).toFilePath();
1194-
1195-
static final dartdevc =
1196-
p.join(sdkPath, 'dart-sdk', 'bin', 'snapshots', 'dartdevc.dart.snapshot');
1197-
static final kernelWorker = p.join(
1198-
sdkPath, 'dart-sdk', 'bin', 'snapshots', 'kernel_worker.dart.snapshot');
1194+
static var dartExecutable = p.join(
1195+
sdkPath,
1196+
'dart-sdk',
1197+
'bin',
1198+
Platform.isWindows ? 'dartaotruntime.exe' : 'dartaotruntime',
1199+
);
1200+
static var dartdevc = p.join(
1201+
sdkPath, 'dart-sdk', 'bin', 'snapshots', 'dartdevc_aot.dart.snapshot');
1202+
static var kernelWorker = p.join(sdkPath, 'dart-sdk', 'bin', 'snapshots',
1203+
'kernel_worker_aot.dart.snapshot');
11991204

12001205
DDCKernelGenerator(this.config, this.verbose);
12011206

12021207
Future<int> generate() async {
1208+
if (!File(dartdevc).existsSync()) {
1209+
// This can be removed once we stop supporting ia32 architecture.
1210+
dartdevc = p.join(
1211+
sdkPath, 'dart-sdk', 'bin', 'snapshots', 'dartdevc.dart.snapshot');
1212+
kernelWorker = p.join(sdkPath, 'dart-sdk', 'bin', 'snapshots',
1213+
'kernel_worker.dart.snapshot');
1214+
dartExecutable = Platform.resolvedExecutable;
1215+
}
12031216
Directory.fromUri(config.outputPath).createSync();
12041217

12051218
// generate summaries
@@ -1238,7 +1251,7 @@ class DDCKernelGenerator {
12381251
if (!config.soundNullSafety) '--no-sound-null-safety',
12391252
];
12401253

1241-
return runProcess(dart, args, config.rootPath, verbose);
1254+
return runProcess(dartExecutable, args, config.rootPath, verbose);
12421255
}
12431256

12441257
Future<int> _generateFullDill(ModuleConfiguration module) async {
@@ -1270,7 +1283,7 @@ class DDCKernelGenerator {
12701283
'--no-summarize',
12711284
];
12721285

1273-
return await runProcess(dart, args, config.rootPath, verbose);
1286+
return await runProcess(dartExecutable, args, config.rootPath, verbose);
12741287
}
12751288
}
12761289

pkg/dev_compiler/test/macros/macros_test.dart

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:dev_compiler/ddc.dart' as ddc;
99
import 'package:frontend_server/compute_kernel.dart';
1010
import 'package:macros/src/bootstrap.dart';
1111
import 'package:macros/src/executor/serialization.dart';
12+
import 'package:path/path.dart' as p;
1213
import 'package:test/test.dart';
1314

1415
Directory tmp = Directory.systemTemp.createTempSync('ddc_worker_test');
@@ -22,12 +23,14 @@ String _resolvePath(String executableRelativePath) {
2223
void main() {
2324
group('DDC: Macros', timeout: Timeout(Duration(minutes: 2)), () {
2425
late File testMacroDart;
25-
late File bootstrapDillFileVm;
26+
late String bootstrapDillPathVm;
27+
late String bootstrapAotPathVm;
2628
late File bootstrapDillFileDdc;
2729
late Uri testMacroUri;
2830
late File packageConfig;
2931
late List<String> ddcArgs;
3032
late List<String> executableArgs;
33+
late String dartAot;
3134

3235
final applyTestMacroDart = file('apply_test_macro.dart');
3336
final testMacroJS = file('test_macro.js');
@@ -99,20 +102,32 @@ macro class TestMacro implements ClassDeclarationsMacro {
99102
'lib/_internal/vm_platform_strong_product.dill'));
100103
var ddcPlatformDill = File(_resolvePath('../'
101104
'lib/_internal/ddc_outline.dill'));
102-
bootstrapDillFileVm = file('bootstrap.dart.dill');
105+
bootstrapDillPathVm = 'bootstrap.dart.dill';
103106
var bootstrapResult = await computeKernel([
104107
'--enable-experiment=macros',
105108
'--no-summary',
106109
'--no-summary-only',
107110
'--target=vm',
108111
'--dart-sdk-summary=${productPlatformDill.uri}',
109-
'--output=${bootstrapDillFileVm.path}',
112+
'--output=$bootstrapDillPathVm',
110113
'--source=${bootstrapFile.uri}',
111114
'--source=${testMacroDart.uri}',
112115
'--packages-file=${packageConfig.uri}',
113116
]);
114117
expect(bootstrapResult.succeeded, true);
115118

119+
// Compile the macro to vm AOT executable to be run by the CFE.
120+
bootstrapAotPathVm = 'bootstrap.dart.exe';
121+
var bootstrapAotResult = Process.runSync(Platform.resolvedExecutable, [
122+
'compile',
123+
'exe',
124+
'--enable-experiment=macros',
125+
'-o',
126+
bootstrapAotPathVm,
127+
bootstrapFile.path,
128+
]);
129+
expect(bootstrapAotResult.exitCode, EXIT_CODE_OK);
130+
116131
// Compile the macro to ddc dill for the ddc build.
117132
bootstrapDillFileDdc = file('bootstrap_ddc.dart.dill');
118133
var bootstrapResultDdc = await computeKernel([
@@ -146,11 +161,6 @@ void main() {
146161
_resolvePath('../../ddc_outline.dill'),
147162
'--packages=${packageConfig.uri}',
148163
];
149-
150-
executableArgs = [
151-
_resolvePath('../../gen/dartdevc.dart.snapshot'),
152-
...ddcArgs
153-
];
154164
});
155165

156166
tearDown(() {
@@ -175,7 +185,7 @@ void main() {
175185
await ddc.internalMain([
176186
...ddcArgs,
177187
'--precompiled-macro',
178-
'${bootstrapDillFileVm.path};$testMacroUri',
188+
'$bootstrapDillPathVm;$testMacroUri',
179189
'--no-source-map',
180190
'--no-summarize',
181191
'-s',
@@ -193,7 +203,15 @@ void main() {
193203
});
194204

195205
test('compile using dartdevc snapshot', () {
196-
var result = Process.runSync(Platform.executable, [
206+
executableArgs = [
207+
_resolvePath('snapshots/dartdevc_aot.dart.snapshot'),
208+
...ddcArgs
209+
];
210+
211+
dartAot = p.absolute(p.dirname(Platform.resolvedExecutable),
212+
Platform.isWindows ? 'dartaotruntime.exe' : 'dartaotruntime');
213+
214+
var result = Process.runSync(dartAot, [
197215
...executableArgs,
198216
'--no-source-map',
199217
'-o',
@@ -207,10 +225,10 @@ void main() {
207225
expect(testMacroJS.existsSync(), isTrue);
208226
expect(testMacroSummary.existsSync(), isTrue);
209227

210-
result = Process.runSync(Platform.executable, [
228+
result = Process.runSync(dartAot, [
211229
...executableArgs,
212230
'--precompiled-macro',
213-
'${bootstrapDillFileVm.path};$testMacroUri',
231+
'$bootstrapAotPathVm;$testMacroUri',
214232
'--no-source-map',
215233
'--no-summarize',
216234
'-s',

pkg/dev_compiler/test/modular_helpers.dart

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import 'package:modular_test/src/runner.dart';
1212
import 'package:modular_test/src/steps/macro_precompile_aot.dart';
1313
import 'package:modular_test/src/steps/util.dart';
1414
import 'package:modular_test/src/suite.dart';
15+
import 'package:path/path.dart' as p;
1516

1617
String packageConfigJsonPath = '.dart_tool/package_config.json';
1718
Uri sdkRoot = Platform.script.resolve('../../../');
1819
Uri packageConfigUri = sdkRoot.resolve(packageConfigJsonPath);
1920
late Options _options;
2021
late String _dartdevcScript;
2122
late String _kernelWorkerScript;
23+
late String _dartExecutable;
2224

2325
const dillId = DataId('dill');
2426
const jsId = DataId('js');
@@ -120,7 +122,7 @@ class SourceToSummaryDillStep implements IOModularStep {
120122
];
121123

122124
var result = await runProcess(
123-
Platform.resolvedExecutable, args, root.toFilePath(), _options.verbose);
125+
_dartExecutable, args, root.toFilePath(), _options.verbose);
124126
checkExitCode(result, this, module, _options.verbose);
125127
}
126128

@@ -219,7 +221,7 @@ class DDCStep implements IOModularStep {
219221
'$output',
220222
];
221223
var result = await runProcess(
222-
Platform.resolvedExecutable, args, root.toFilePath(), _options.verbose);
224+
_dartExecutable, args, root.toFilePath(), _options.verbose);
223225
checkExitCode(result, this, module, _options.verbose);
224226
}
225227

@@ -337,8 +339,23 @@ Future<void> resolveScripts(Options options) async {
337339
return result;
338340
}
339341

340-
_dartdevcScript = await resolve(
341-
'pkg/dev_compiler/bin/dartdevc.dart', 'snapshots/dartdevc.dart.snapshot');
342-
_kernelWorkerScript = await resolve('utils/bazel/kernel_worker.dart',
343-
'snapshots/kernel_worker.dart.snapshot');
342+
_dartdevcScript = await resolve('pkg/dev_compiler/bin/dartdevc.dart',
343+
'snapshots/dartdevc_aot.dart.snapshot');
344+
if (File(_dartdevcScript).existsSync()) {
345+
_kernelWorkerScript = await resolve('utils/bazel/kernel_worker.dart',
346+
'snapshots/kernel_worker_aot.dart.snapshot');
347+
var sdkPath = p.dirname(p.dirname(Platform.resolvedExecutable));
348+
_dartExecutable = p.absolute(
349+
sdkPath,
350+
'bin',
351+
Platform.isWindows ? 'dartaotruntime.exe' : 'dartaotruntime',
352+
);
353+
} else {
354+
// This can be removed once we stop supporting ia32 architecture.
355+
_dartdevcScript = await resolve('pkg/dev_compiler/bin/dartdevc.dart',
356+
'snapshots/dartdevc.dart.snapshot');
357+
_kernelWorkerScript = await resolve('utils/bazel/kernel_worker.dart',
358+
'snapshots/kernel_worker.dart.snapshot');
359+
_dartExecutable = Platform.resolvedExecutable;
360+
}
344361
}

0 commit comments

Comments
 (0)