mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 02:07:06 +00:00
[ddc] Add --canary flag to expression compiler worker
Closes: https://github.com/dart-lang/sdk/issues/52776 Change-Id: I639fe7fbadf3e938cc686aa8dbd2320a4cc7af7d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311151 Reviewed-by: Mark Zhou <markzipan@google.com> Commit-Queue: Anna Gringauze <annagrin@google.com> Reviewed-by: Nicholas Shahan <nshahan@google.com>
This commit is contained in:
parent
4a6f9328a2
commit
d2f5b3bfab
|
@ -83,6 +83,7 @@ class ExpressionCompilerWorker {
|
||||||
final ProcessedOptions _processedOptions;
|
final ProcessedOptions _processedOptions;
|
||||||
final CompilerOptions _compilerOptions;
|
final CompilerOptions _compilerOptions;
|
||||||
final ModuleFormat _moduleFormat;
|
final ModuleFormat _moduleFormat;
|
||||||
|
final bool _canaryFeatures;
|
||||||
final Component _sdkComponent;
|
final Component _sdkComponent;
|
||||||
|
|
||||||
void Function()? onDone;
|
void Function()? onDone;
|
||||||
|
@ -91,6 +92,7 @@ class ExpressionCompilerWorker {
|
||||||
this._processedOptions,
|
this._processedOptions,
|
||||||
this._compilerOptions,
|
this._compilerOptions,
|
||||||
this._moduleFormat,
|
this._moduleFormat,
|
||||||
|
this._canaryFeatures,
|
||||||
this._sdkComponent,
|
this._sdkComponent,
|
||||||
this.requestStream,
|
this.requestStream,
|
||||||
this.sendResponse,
|
this.sendResponse,
|
||||||
|
@ -194,6 +196,7 @@ class ExpressionCompilerWorker {
|
||||||
trackWidgetCreation: parsedArgs['track-widget-creation'] as bool,
|
trackWidgetCreation: parsedArgs['track-widget-creation'] as bool,
|
||||||
soundNullSafety: parsedArgs['sound-null-safety'] as bool,
|
soundNullSafety: parsedArgs['sound-null-safety'] as bool,
|
||||||
moduleFormat: moduleFormat,
|
moduleFormat: moduleFormat,
|
||||||
|
canaryFeatures: parsedArgs['canary'] as bool,
|
||||||
verbose: parsedArgs['verbose'] as bool,
|
verbose: parsedArgs['verbose'] as bool,
|
||||||
requestStream: requestStream,
|
requestStream: requestStream,
|
||||||
sendResponse: sendResponse,
|
sendResponse: sendResponse,
|
||||||
|
@ -219,6 +222,7 @@ class ExpressionCompilerWorker {
|
||||||
bool trackWidgetCreation = false,
|
bool trackWidgetCreation = false,
|
||||||
bool soundNullSafety = false,
|
bool soundNullSafety = false,
|
||||||
ModuleFormat moduleFormat = ModuleFormat.amd,
|
ModuleFormat moduleFormat = ModuleFormat.amd,
|
||||||
|
bool canaryFeatures = false,
|
||||||
bool verbose = false,
|
bool verbose = false,
|
||||||
Stream<Map<String, dynamic>>? requestStream, // Defaults to read from stdin
|
Stream<Map<String, dynamic>>? requestStream, // Defaults to read from stdin
|
||||||
void Function(Map<String, dynamic>)?
|
void Function(Map<String, dynamic>)?
|
||||||
|
@ -258,8 +262,15 @@ class ExpressionCompilerWorker {
|
||||||
if (sdkComponent == null) {
|
if (sdkComponent == null) {
|
||||||
throw Exception('Could not load SDK component: $sdkSummary');
|
throw Exception('Could not load SDK component: $sdkSummary');
|
||||||
}
|
}
|
||||||
return ExpressionCompilerWorker._(processedOptions, compilerOptions,
|
return ExpressionCompilerWorker._(
|
||||||
moduleFormat, sdkComponent, requestStream, sendResponse, onDone)
|
processedOptions,
|
||||||
|
compilerOptions,
|
||||||
|
moduleFormat,
|
||||||
|
canaryFeatures,
|
||||||
|
sdkComponent,
|
||||||
|
requestStream,
|
||||||
|
sendResponse,
|
||||||
|
onDone)
|
||||||
.._updateCache(sdkComponent, dartSdkModule, true);
|
.._updateCache(sdkComponent, dartSdkModule, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,11 +447,13 @@ class ExpressionCompilerWorker {
|
||||||
finalComponent,
|
finalComponent,
|
||||||
hierarchy,
|
hierarchy,
|
||||||
SharedCompilerOptions(
|
SharedCompilerOptions(
|
||||||
sourceMap: true,
|
sourceMap: true,
|
||||||
summarizeApi: false,
|
summarizeApi: false,
|
||||||
moduleName: moduleName,
|
moduleName: moduleName,
|
||||||
soundNullSafety: _compilerOptions.nnbdMode == NnbdMode.Strong,
|
soundNullSafety: _compilerOptions.nnbdMode == NnbdMode.Strong,
|
||||||
enableAsserts: _enableAsserts),
|
enableAsserts: _enableAsserts,
|
||||||
|
canaryFeatures: _canaryFeatures,
|
||||||
|
),
|
||||||
_moduleCache.componentForLibrary,
|
_moduleCache.componentForLibrary,
|
||||||
_moduleCache.moduleNameForComponent,
|
_moduleCache.moduleNameForComponent,
|
||||||
coreTypes: coreTypes,
|
coreTypes: coreTypes,
|
||||||
|
@ -776,6 +789,7 @@ final argParser = ArgParser()
|
||||||
..addOption('module-format', defaultsTo: 'amd')
|
..addOption('module-format', defaultsTo: 'amd')
|
||||||
..addFlag('track-widget-creation', defaultsTo: false)
|
..addFlag('track-widget-creation', defaultsTo: false)
|
||||||
..addFlag('sound-null-safety', negatable: true, defaultsTo: true)
|
..addFlag('sound-null-safety', negatable: true, defaultsTo: true)
|
||||||
|
..addFlag('canary', negatable: true, defaultsTo: false)
|
||||||
..addFlag('verbose', defaultsTo: false);
|
..addFlag('verbose', defaultsTo: false);
|
||||||
|
|
||||||
Uri? _argToUri(String? uriArg) =>
|
Uri? _argToUri(String? uriArg) =>
|
||||||
|
|
|
@ -149,11 +149,13 @@ class TestCompiler {
|
||||||
|
|
||||||
var classHierarchy = compilerResult.classHierarchy!;
|
var classHierarchy = compilerResult.classHierarchy!;
|
||||||
var compilerOptions = SharedCompilerOptions(
|
var compilerOptions = SharedCompilerOptions(
|
||||||
replCompile: true,
|
replCompile: true,
|
||||||
moduleName: moduleName,
|
moduleName: moduleName,
|
||||||
experiments: experiments,
|
experiments: experiments,
|
||||||
soundNullSafety: setup.soundNullSafety,
|
soundNullSafety: setup.soundNullSafety,
|
||||||
emitDebugMetadata: true);
|
emitDebugMetadata: true,
|
||||||
|
canaryFeatures: false,
|
||||||
|
);
|
||||||
var coreTypes = compilerResult.coreTypes;
|
var coreTypes = compilerResult.coreTypes;
|
||||||
|
|
||||||
final importToSummary = Map<Library, Component>.identity();
|
final importToSummary = Map<Library, Component>.identity();
|
||||||
|
|
|
@ -114,10 +114,12 @@ class TestCompiler {
|
||||||
var moduleName = 'foo.dart';
|
var moduleName = 'foo.dart';
|
||||||
var classHierarchy = compilerResult.classHierarchy;
|
var classHierarchy = compilerResult.classHierarchy;
|
||||||
var compilerOptions = SharedCompilerOptions(
|
var compilerOptions = SharedCompilerOptions(
|
||||||
replCompile: true,
|
replCompile: true,
|
||||||
moduleName: moduleName,
|
moduleName: moduleName,
|
||||||
soundNullSafety: setup.soundNullSafety,
|
soundNullSafety: setup.soundNullSafety,
|
||||||
moduleFormats: [setup.moduleFormat]);
|
moduleFormats: [setup.moduleFormat],
|
||||||
|
canaryFeatures: false,
|
||||||
|
);
|
||||||
var coreTypes = compilerResult.coreTypes;
|
var coreTypes = compilerResult.coreTypes;
|
||||||
|
|
||||||
final importToSummary = Map<Library, Component>.identity();
|
final importToSummary = Map<Library, Component>.identity();
|
||||||
|
@ -277,11 +279,28 @@ void main() {
|
||||||
for (var moduleFormat in [ModuleFormat.amd, ModuleFormat.ddc]) {
|
for (var moduleFormat in [ModuleFormat.amd, ModuleFormat.ddc]) {
|
||||||
group('Module format: $moduleFormat |', () {
|
group('Module format: $moduleFormat |', () {
|
||||||
group('Unsound null safety |', () {
|
group('Unsound null safety |', () {
|
||||||
var options = SetupCompilerOptions(
|
runUnsoundTests(moduleFormat);
|
||||||
soundNullSafety: false, moduleFormat: moduleFormat);
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
group('Expression compilations on the same expression compiler |', () {
|
for (var moduleFormat in [ModuleFormat.amd, ModuleFormat.ddc]) {
|
||||||
var source = '''
|
group('Module format: $moduleFormat |', () {
|
||||||
|
group('Sound null safety |', () {
|
||||||
|
runSoundTests(moduleFormat);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void runUnsoundTests(ModuleFormat moduleFormat) {
|
||||||
|
var options = SetupCompilerOptions(
|
||||||
|
soundNullSafety: false,
|
||||||
|
moduleFormat: moduleFormat,
|
||||||
|
);
|
||||||
|
|
||||||
|
group('Expression compilations on the same expression compiler |', () {
|
||||||
|
var source = '''
|
||||||
${options.dartLangComment}
|
${options.dartLangComment}
|
||||||
main() {
|
main() {
|
||||||
}
|
}
|
||||||
|
@ -291,93 +310,93 @@ void main() {
|
||||||
}
|
}
|
||||||
''';
|
''';
|
||||||
|
|
||||||
late TestDriver driver;
|
late TestDriver driver;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
driver = TestDriver(options, source);
|
driver = TestDriver(options, source);
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() {
|
tearDown(() {
|
||||||
driver.delete();
|
driver.delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('successful expression compilations', () async {
|
test('successful expression compilations', () async {
|
||||||
var compiler = await driver.createCompiler();
|
var compiler = await driver.createCompiler();
|
||||||
await driver.check(
|
await driver.check(
|
||||||
compiler: compiler,
|
compiler: compiler,
|
||||||
scope: <String, String>{},
|
scope: <String, String>{},
|
||||||
expression: 'true',
|
expression: 'true',
|
||||||
expectedResult: '''
|
expectedResult: '''
|
||||||
(function() {
|
(function() {
|
||||||
return true;
|
return true;
|
||||||
}(
|
}(
|
||||||
|
|
||||||
))
|
))
|
||||||
''');
|
''');
|
||||||
await driver.check(
|
await driver.check(
|
||||||
compiler: compiler,
|
compiler: compiler,
|
||||||
scope: <String, String>{},
|
scope: <String, String>{},
|
||||||
expression: 'false',
|
expression: 'false',
|
||||||
expectedResult: '''
|
expectedResult: '''
|
||||||
(function() {
|
(function() {
|
||||||
return false;
|
return false;
|
||||||
}(
|
}(
|
||||||
|
|
||||||
))
|
))
|
||||||
''');
|
''');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('some successful expression compilations', () async {
|
test('some successful expression compilations', () async {
|
||||||
var compiler = await driver.createCompiler();
|
var compiler = await driver.createCompiler();
|
||||||
await driver.check(
|
await driver.check(
|
||||||
compiler: compiler,
|
compiler: compiler,
|
||||||
scope: <String, String>{},
|
scope: <String, String>{},
|
||||||
expression: 'true',
|
expression: 'true',
|
||||||
expectedResult: '''
|
expectedResult: '''
|
||||||
(function() {
|
(function() {
|
||||||
return true;
|
return true;
|
||||||
}(
|
}(
|
||||||
|
|
||||||
))
|
))
|
||||||
''');
|
''');
|
||||||
await driver.check(
|
await driver.check(
|
||||||
compiler: compiler,
|
compiler: compiler,
|
||||||
scope: <String, String>{},
|
scope: <String, String>{},
|
||||||
expression: 'blah',
|
expression: 'blah',
|
||||||
expectedError: "Undefined name 'blah'",
|
expectedError: "Undefined name 'blah'",
|
||||||
);
|
);
|
||||||
await driver.check(
|
await driver.check(
|
||||||
compiler: compiler,
|
compiler: compiler,
|
||||||
scope: <String, String>{},
|
scope: <String, String>{},
|
||||||
expression: 'false',
|
expression: 'false',
|
||||||
expectedResult: '''
|
expectedResult: '''
|
||||||
(function() {
|
(function() {
|
||||||
return false;
|
return false;
|
||||||
}(
|
}(
|
||||||
|
|
||||||
))
|
))
|
||||||
''');
|
''');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('failing expression compilations', () async {
|
test('failing expression compilations', () async {
|
||||||
var compiler = await driver.createCompiler();
|
var compiler = await driver.createCompiler();
|
||||||
await driver.check(
|
await driver.check(
|
||||||
compiler: compiler,
|
compiler: compiler,
|
||||||
scope: <String, String>{},
|
scope: <String, String>{},
|
||||||
expression: 'blah1',
|
expression: 'blah1',
|
||||||
expectedError: "Undefined name 'blah1'",
|
expectedError: "Undefined name 'blah1'",
|
||||||
);
|
);
|
||||||
await driver.check(
|
await driver.check(
|
||||||
compiler: compiler,
|
compiler: compiler,
|
||||||
scope: <String, String>{},
|
scope: <String, String>{},
|
||||||
expression: 'blah2',
|
expression: 'blah2',
|
||||||
expectedError: "Undefined name 'blah2'",
|
expectedError: "Undefined name 'blah2'",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Expression compiler import tests', () {
|
group('Expression compiler import tests', () {
|
||||||
var source = '''
|
var source = '''
|
||||||
${options.dartLangComment}
|
${options.dartLangComment}
|
||||||
import 'dart:io' show Directory;
|
import 'dart:io' show Directory;
|
||||||
import 'dart:io' as p;
|
import 'dart:io' as p;
|
||||||
|
@ -394,21 +413,21 @@ void main() {
|
||||||
}
|
}
|
||||||
''';
|
''';
|
||||||
|
|
||||||
late TestDriver driver;
|
late TestDriver driver;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
driver = TestDriver(options, source);
|
driver = TestDriver(options, source);
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() {
|
tearDown(() {
|
||||||
driver.delete();
|
driver.delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('expression referencing unnamed import', () async {
|
test('expression referencing unnamed import', () async {
|
||||||
await driver.check(
|
await driver.check(
|
||||||
scope: <String, String>{},
|
scope: <String, String>{},
|
||||||
expression: 'Directory.systemTemp',
|
expression: 'Directory.systemTemp',
|
||||||
expectedResult: '''
|
expectedResult: '''
|
||||||
(function() {
|
(function() {
|
||||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||||
const io = dart_sdk.io;
|
const io = dart_sdk.io;
|
||||||
|
@ -417,13 +436,13 @@ void main() {
|
||||||
|
|
||||||
))
|
))
|
||||||
''');
|
''');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('expression referencing named import', () async {
|
test('expression referencing named import', () async {
|
||||||
await driver.check(
|
await driver.check(
|
||||||
scope: <String, String>{},
|
scope: <String, String>{},
|
||||||
expression: 'p.Directory.systemTemp',
|
expression: 'p.Directory.systemTemp',
|
||||||
expectedResult: '''
|
expectedResult: '''
|
||||||
(function() {
|
(function() {
|
||||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||||
const io = dart_sdk.io;
|
const io = dart_sdk.io;
|
||||||
|
@ -432,15 +451,14 @@ void main() {
|
||||||
|
|
||||||
))
|
))
|
||||||
''');
|
''');
|
||||||
});
|
});
|
||||||
|
|
||||||
test(
|
test('expression referencing another library with the same named import',
|
||||||
'expression referencing another library with the same named import',
|
() async {
|
||||||
() async {
|
await driver.check(
|
||||||
await driver.check(
|
scope: <String, String>{},
|
||||||
scope: <String, String>{},
|
expression: 'p.utf8.decoder',
|
||||||
expression: 'p.utf8.decoder',
|
expectedResult: '''
|
||||||
expectedResult: '''
|
|
||||||
(function() {
|
(function() {
|
||||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||||
const convert = dart_sdk.convert;
|
const convert = dart_sdk.convert;
|
||||||
|
@ -449,13 +467,12 @@ void main() {
|
||||||
|
|
||||||
))
|
))
|
||||||
''');
|
''');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group(
|
group('Expression compiler tests for interactions with module containers:',
|
||||||
'Expression compiler tests for interactions with module containers:',
|
() {
|
||||||
() {
|
var source = '''
|
||||||
var source = '''
|
|
||||||
${options.dartLangComment}
|
${options.dartLangComment}
|
||||||
class A {
|
class A {
|
||||||
const A();
|
const A();
|
||||||
|
@ -473,22 +490,21 @@ void main() {
|
||||||
void main() => foo();
|
void main() => foo();
|
||||||
''';
|
''';
|
||||||
|
|
||||||
late TestDriver driver;
|
late TestDriver driver;
|
||||||
setUp(() {
|
setUp(() {
|
||||||
driver = TestDriver(options, source);
|
driver = TestDriver(options, source);
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() {
|
tearDown(() {
|
||||||
driver.delete();
|
driver.delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
test(
|
test('evaluation that non-destructively appends to the type container',
|
||||||
'evaluation that non-destructively appends to the type container',
|
() async {
|
||||||
() async {
|
await driver.check(
|
||||||
await driver.check(
|
scope: <String, String>{'a': 'null', 'check': 'null'},
|
||||||
scope: <String, String>{'a': 'null', 'check': 'null'},
|
expression: 'a is String',
|
||||||
expression: 'a is String',
|
expectedResult: '''
|
||||||
expectedResult: '''
|
|
||||||
(function(a, check) {
|
(function(a, check) {
|
||||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||||
const core = dart_sdk.core;
|
const core = dart_sdk.core;
|
||||||
|
@ -502,13 +518,13 @@ void main() {
|
||||||
null
|
null
|
||||||
))
|
))
|
||||||
''');
|
''');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('evaluation that reuses the type container', () async {
|
test('evaluation that reuses the type container', () async {
|
||||||
await driver.check(
|
await driver.check(
|
||||||
scope: <String, String>{'a': 'null', 'check': 'null'},
|
scope: <String, String>{'a': 'null', 'check': 'null'},
|
||||||
expression: 'a is int',
|
expression: 'a is int',
|
||||||
expectedResult: '''
|
expectedResult: '''
|
||||||
(function(a, check) {
|
(function(a, check) {
|
||||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||||
const core = dart_sdk.core;
|
const core = dart_sdk.core;
|
||||||
|
@ -522,15 +538,14 @@ void main() {
|
||||||
null
|
null
|
||||||
))
|
))
|
||||||
''');
|
''');
|
||||||
});
|
});
|
||||||
|
|
||||||
test(
|
test('evaluation that non-destructively appends to the constant container',
|
||||||
'evaluation that non-destructively appends to the constant container',
|
() async {
|
||||||
() async {
|
await driver.check(
|
||||||
await driver.check(
|
scope: <String, String>{'a': 'null', 'check': 'null'},
|
||||||
scope: <String, String>{'a': 'null', 'check': 'null'},
|
expression: 'const B()',
|
||||||
expression: 'const B()',
|
expectedResult: '''
|
||||||
expectedResult: '''
|
|
||||||
(function(a, check) {
|
(function(a, check) {
|
||||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||||
const dart = dart_sdk.dart;
|
const dart = dart_sdk.dart;
|
||||||
|
@ -550,15 +565,15 @@ void main() {
|
||||||
null
|
null
|
||||||
))
|
))
|
||||||
''');
|
''');
|
||||||
});
|
});
|
||||||
|
|
||||||
test(
|
test(
|
||||||
'evaluation that reuses the constant container and canonicalizes properly',
|
'evaluation that reuses the constant container and canonicalizes properly',
|
||||||
() async {
|
() async {
|
||||||
await driver.check(
|
await driver.check(
|
||||||
scope: <String, String>{'a': 'null', 'check': 'null'},
|
scope: <String, String>{'a': 'null', 'check': 'null'},
|
||||||
expression: 'a == const A()',
|
expression: 'a == const A()',
|
||||||
expectedResult: '''
|
expectedResult: '''
|
||||||
(function(a, check) {
|
(function(a, check) {
|
||||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||||
const dart = dart_sdk.dart;
|
const dart = dart_sdk.dart;
|
||||||
|
@ -578,11 +593,11 @@ void main() {
|
||||||
null
|
null
|
||||||
))
|
))
|
||||||
''');
|
''');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Expression compiler tests using extension symbols', () {
|
group('Expression compiler tests using extension symbols', () {
|
||||||
var source = '''
|
var source = '''
|
||||||
${options.dartLangComment}
|
${options.dartLangComment}
|
||||||
void bar() {
|
void bar() {
|
||||||
/* evaluation placeholder */
|
/* evaluation placeholder */
|
||||||
|
@ -591,21 +606,21 @@ void main() {
|
||||||
void main() => bar();
|
void main() => bar();
|
||||||
''';
|
''';
|
||||||
|
|
||||||
late TestDriver driver;
|
late TestDriver driver;
|
||||||
setUp(() {
|
setUp(() {
|
||||||
driver = TestDriver(options, source);
|
driver = TestDriver(options, source);
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() {
|
tearDown(() {
|
||||||
driver.delete();
|
driver.delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('map access', () async {
|
test('map access', () async {
|
||||||
await driver.check(
|
await driver.check(
|
||||||
scope: <String, String>{'inScope': '1', 'innerInScope': '0'},
|
scope: <String, String>{'inScope': '1', 'innerInScope': '0'},
|
||||||
expression:
|
expression:
|
||||||
'(Map<String, String> params) { return params["index"]; }({})',
|
'(Map<String, String> params) { return params["index"]; }({})',
|
||||||
expectedResult: '''
|
expectedResult: '''
|
||||||
(function() {
|
(function() {
|
||||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||||
const core = dart_sdk.core;
|
const core = dart_sdk.core;
|
||||||
|
@ -625,19 +640,18 @@ void main() {
|
||||||
|
|
||||||
))
|
))
|
||||||
''');
|
''');
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
|
||||||
for (var moduleFormat in [ModuleFormat.amd, ModuleFormat.ddc]) {
|
void runSoundTests(ModuleFormat moduleFormat) {
|
||||||
group('Module format: $moduleFormat |', () {
|
var options = SetupCompilerOptions(
|
||||||
group('Sound null safety |', () {
|
soundNullSafety: true,
|
||||||
var options = SetupCompilerOptions(soundNullSafety: true);
|
moduleFormat: moduleFormat,
|
||||||
|
);
|
||||||
|
|
||||||
group('Expression compilations on the same expression compiler |', () {
|
group('Expression compilations on the same expression compiler |', () {
|
||||||
var source = '''
|
var source = '''
|
||||||
${options.dartLangComment}
|
${options.dartLangComment}
|
||||||
main() {
|
main() {
|
||||||
}
|
}
|
||||||
|
@ -647,93 +661,93 @@ void main() {
|
||||||
}
|
}
|
||||||
''';
|
''';
|
||||||
|
|
||||||
late TestDriver driver;
|
late TestDriver driver;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
driver = TestDriver(options, source);
|
driver = TestDriver(options, source);
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() {
|
tearDown(() {
|
||||||
driver.delete();
|
driver.delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('successful expression compilations', () async {
|
test('successful expression compilations', () async {
|
||||||
var compiler = await driver.createCompiler();
|
var compiler = await driver.createCompiler();
|
||||||
await driver.check(
|
await driver.check(
|
||||||
compiler: compiler,
|
compiler: compiler,
|
||||||
scope: <String, String>{},
|
scope: <String, String>{},
|
||||||
expression: 'true',
|
expression: 'true',
|
||||||
expectedResult: '''
|
expectedResult: '''
|
||||||
(function() {
|
(function() {
|
||||||
return true;
|
return true;
|
||||||
}(
|
}(
|
||||||
|
|
||||||
))
|
))
|
||||||
''');
|
''');
|
||||||
await driver.check(
|
await driver.check(
|
||||||
compiler: compiler,
|
compiler: compiler,
|
||||||
scope: <String, String>{},
|
scope: <String, String>{},
|
||||||
expression: 'false',
|
expression: 'false',
|
||||||
expectedResult: '''
|
expectedResult: '''
|
||||||
(function() {
|
(function() {
|
||||||
return false;
|
return false;
|
||||||
}(
|
}(
|
||||||
|
|
||||||
))
|
))
|
||||||
''');
|
''');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('some successful expression compilations', () async {
|
test('some successful expression compilations', () async {
|
||||||
var compiler = await driver.createCompiler();
|
var compiler = await driver.createCompiler();
|
||||||
await driver.check(
|
await driver.check(
|
||||||
compiler: compiler,
|
compiler: compiler,
|
||||||
scope: <String, String>{},
|
scope: <String, String>{},
|
||||||
expression: 'true',
|
expression: 'true',
|
||||||
expectedResult: '''
|
expectedResult: '''
|
||||||
(function() {
|
(function() {
|
||||||
return true;
|
return true;
|
||||||
}(
|
}(
|
||||||
|
|
||||||
))
|
))
|
||||||
''');
|
''');
|
||||||
await driver.check(
|
await driver.check(
|
||||||
compiler: compiler,
|
compiler: compiler,
|
||||||
scope: <String, String>{},
|
scope: <String, String>{},
|
||||||
expression: 'blah',
|
expression: 'blah',
|
||||||
expectedError: "Undefined name 'blah'",
|
expectedError: "Undefined name 'blah'",
|
||||||
);
|
);
|
||||||
await driver.check(
|
await driver.check(
|
||||||
compiler: compiler,
|
compiler: compiler,
|
||||||
scope: <String, String>{},
|
scope: <String, String>{},
|
||||||
expression: 'false',
|
expression: 'false',
|
||||||
expectedResult: '''
|
expectedResult: '''
|
||||||
(function() {
|
(function() {
|
||||||
return false;
|
return false;
|
||||||
}(
|
}(
|
||||||
|
|
||||||
))
|
))
|
||||||
''');
|
''');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('failing expression compilations', () async {
|
test('failing expression compilations', () async {
|
||||||
var compiler = await driver.createCompiler();
|
var compiler = await driver.createCompiler();
|
||||||
await driver.check(
|
await driver.check(
|
||||||
compiler: compiler,
|
compiler: compiler,
|
||||||
scope: <String, String>{},
|
scope: <String, String>{},
|
||||||
expression: 'blah1',
|
expression: 'blah1',
|
||||||
expectedError: "Undefined name 'blah1'",
|
expectedError: "Undefined name 'blah1'",
|
||||||
);
|
);
|
||||||
await driver.check(
|
await driver.check(
|
||||||
compiler: compiler,
|
compiler: compiler,
|
||||||
scope: <String, String>{},
|
scope: <String, String>{},
|
||||||
expression: 'blah2',
|
expression: 'blah2',
|
||||||
expectedError: "Undefined name 'blah2'",
|
expectedError: "Undefined name 'blah2'",
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Expression compiler import tests', () {
|
group('Expression compiler import tests', () {
|
||||||
var source = '''
|
var source = '''
|
||||||
${options.dartLangComment}
|
${options.dartLangComment}
|
||||||
import 'dart:io' show Directory;
|
import 'dart:io' show Directory;
|
||||||
import 'dart:io' as p;
|
import 'dart:io' as p;
|
||||||
|
@ -750,21 +764,21 @@ void main() {
|
||||||
}
|
}
|
||||||
''';
|
''';
|
||||||
|
|
||||||
late TestDriver driver;
|
late TestDriver driver;
|
||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
driver = TestDriver(options, source);
|
driver = TestDriver(options, source);
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() {
|
tearDown(() {
|
||||||
driver.delete();
|
driver.delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('expression referencing unnamed import', () async {
|
test('expression referencing unnamed import', () async {
|
||||||
await driver.check(
|
await driver.check(
|
||||||
scope: <String, String>{},
|
scope: <String, String>{},
|
||||||
expression: 'Directory.systemTemp',
|
expression: 'Directory.systemTemp',
|
||||||
expectedResult: '''
|
expectedResult: '''
|
||||||
(function() {
|
(function() {
|
||||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||||
const io = dart_sdk.io;
|
const io = dart_sdk.io;
|
||||||
|
@ -773,13 +787,13 @@ void main() {
|
||||||
|
|
||||||
))
|
))
|
||||||
''');
|
''');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('expression referencing named import', () async {
|
test('expression referencing named import', () async {
|
||||||
await driver.check(
|
await driver.check(
|
||||||
scope: <String, String>{},
|
scope: <String, String>{},
|
||||||
expression: 'p.Directory.systemTemp',
|
expression: 'p.Directory.systemTemp',
|
||||||
expectedResult: '''
|
expectedResult: '''
|
||||||
(function() {
|
(function() {
|
||||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||||
const io = dart_sdk.io;
|
const io = dart_sdk.io;
|
||||||
|
@ -788,15 +802,14 @@ void main() {
|
||||||
|
|
||||||
))
|
))
|
||||||
''');
|
''');
|
||||||
});
|
});
|
||||||
|
|
||||||
test(
|
test('expression referencing another library with the same named import',
|
||||||
'expression referencing another library with the same named import',
|
() async {
|
||||||
() async {
|
await driver.check(
|
||||||
await driver.check(
|
scope: <String, String>{},
|
||||||
scope: <String, String>{},
|
expression: 'p.utf8.decoder',
|
||||||
expression: 'p.utf8.decoder',
|
expectedResult: '''
|
||||||
expectedResult: '''
|
|
||||||
(function() {
|
(function() {
|
||||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||||
const convert = dart_sdk.convert;
|
const convert = dart_sdk.convert;
|
||||||
|
@ -805,12 +818,11 @@ void main() {
|
||||||
|
|
||||||
))
|
))
|
||||||
''');
|
''');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Expression compiler expressions that import extension symbols',
|
group('Expression compiler expressions that import extension symbols', () {
|
||||||
() {
|
var source = '''
|
||||||
var source = '''
|
|
||||||
${options.dartLangComment}
|
${options.dartLangComment}
|
||||||
void bar() {
|
void bar() {
|
||||||
/* evaluation placeholder */
|
/* evaluation placeholder */
|
||||||
|
@ -819,21 +831,21 @@ void main() {
|
||||||
void main() => bar();
|
void main() => bar();
|
||||||
''';
|
''';
|
||||||
|
|
||||||
late TestDriver driver;
|
late TestDriver driver;
|
||||||
setUp(() {
|
setUp(() {
|
||||||
driver = TestDriver(options, source);
|
driver = TestDriver(options, source);
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() {
|
tearDown(() {
|
||||||
driver.delete();
|
driver.delete();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('map access', () async {
|
test('map access', () async {
|
||||||
await driver.check(
|
await driver.check(
|
||||||
scope: <String, String>{'inScope': '1', 'innerInScope': '0'},
|
scope: <String, String>{'inScope': '1', 'innerInScope': '0'},
|
||||||
expression:
|
expression:
|
||||||
'(Map<String, String> params) { return params["index"]; }({})',
|
'(Map<String, String> params) { return params["index"]; }({})',
|
||||||
expectedResult: '''
|
expectedResult: '''
|
||||||
(function() {
|
(function() {
|
||||||
const dart_sdk = ${options.loadModule}('dart_sdk');
|
const dart_sdk = ${options.loadModule}('dart_sdk');
|
||||||
const core = dart_sdk.core;
|
const core = dart_sdk.core;
|
||||||
|
@ -852,9 +864,6 @@ void main() {
|
||||||
|
|
||||||
))
|
))
|
||||||
''');
|
''');
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
|
||||||
|
// for details. All rights reserved. Use of this source code is governed by a
|
||||||
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:dev_compiler/dev_compiler.dart';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
import 'expression_compiler_worker_shared.dart';
|
||||||
|
|
||||||
|
void main() async {
|
||||||
|
// Set to true to enable debug output
|
||||||
|
var debug = false;
|
||||||
|
|
||||||
|
group('canary -', () {
|
||||||
|
group('amd module format -', () {
|
||||||
|
for (var soundNullSafety in [true, false]) {
|
||||||
|
group('${soundNullSafety ? "sound" : "unsound"} null safety -', () {
|
||||||
|
runTests(
|
||||||
|
moduleFormat: ModuleFormat.amd,
|
||||||
|
soundNullSafety: soundNullSafety,
|
||||||
|
canaryFeatures: true,
|
||||||
|
verbose: debug,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ void main() async {
|
||||||
runTests(
|
runTests(
|
||||||
moduleFormat: ModuleFormat.amd,
|
moduleFormat: ModuleFormat.amd,
|
||||||
soundNullSafety: soundNullSafety,
|
soundNullSafety: soundNullSafety,
|
||||||
|
canaryFeatures: false,
|
||||||
verbose: debug,
|
verbose: debug,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
|
||||||
|
// for details. All rights reserved. Use of this source code is governed by a
|
||||||
|
// BSD-style license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'package:dev_compiler/dev_compiler.dart';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
|
import 'expression_compiler_worker_shared.dart';
|
||||||
|
|
||||||
|
void main() async {
|
||||||
|
// Set to true to enable debug output
|
||||||
|
var debug = false;
|
||||||
|
|
||||||
|
group('canary -', () {
|
||||||
|
group('ddc module format -', () {
|
||||||
|
for (var soundNullSafety in [true, false]) {
|
||||||
|
group('${soundNullSafety ? "sound" : "unsound"} null safety -', () {
|
||||||
|
runTests(
|
||||||
|
moduleFormat: ModuleFormat.ddc,
|
||||||
|
soundNullSafety: soundNullSafety,
|
||||||
|
canaryFeatures: true,
|
||||||
|
verbose: debug,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ void main() async {
|
||||||
runTests(
|
runTests(
|
||||||
moduleFormat: ModuleFormat.ddc,
|
moduleFormat: ModuleFormat.ddc,
|
||||||
soundNullSafety: soundNullSafety,
|
soundNullSafety: soundNullSafety,
|
||||||
|
canaryFeatures: false,
|
||||||
verbose: debug,
|
verbose: debug,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -25,6 +25,7 @@ import 'package:test/test.dart';
|
||||||
void runTests({
|
void runTests({
|
||||||
required ModuleFormat moduleFormat,
|
required ModuleFormat moduleFormat,
|
||||||
required bool soundNullSafety,
|
required bool soundNullSafety,
|
||||||
|
required bool canaryFeatures,
|
||||||
bool verbose = false,
|
bool verbose = false,
|
||||||
}) {
|
}) {
|
||||||
group('expression compiler worker on startup', () {
|
group('expression compiler worker on startup', () {
|
||||||
|
@ -64,6 +65,7 @@ void runTests({
|
||||||
'--module-format',
|
'--module-format',
|
||||||
moduleFormat.name,
|
moduleFormat.name,
|
||||||
soundNullSafety ? '--sound-null-safety' : '--no-sound-null-safety',
|
soundNullSafety ? '--sound-null-safety' : '--no-sound-null-safety',
|
||||||
|
if (canaryFeatures) '--canary',
|
||||||
if (verbose) '--verbose',
|
if (verbose) '--verbose',
|
||||||
],
|
],
|
||||||
sendPort: receivePort.sendPort,
|
sendPort: receivePort.sendPort,
|
||||||
|
@ -75,18 +77,30 @@ void runTests({
|
||||||
});
|
});
|
||||||
|
|
||||||
group('reading assets using standard file system - ', () {
|
group('reading assets using standard file system - ', () {
|
||||||
runExpressionCompilationTests(
|
runExpressionCompilationTests(StandardFileSystemTestDriver(
|
||||||
StandardFileSystemTestDriver(soundNullSafety, moduleFormat, verbose));
|
soundNullSafety,
|
||||||
|
moduleFormat,
|
||||||
|
canaryFeatures,
|
||||||
|
verbose,
|
||||||
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
group('reading assets using multiroot file system - ', () {
|
group('reading assets using multiroot file system - ', () {
|
||||||
runExpressionCompilationTests(
|
runExpressionCompilationTests(MultiRootFileSystemTestDriver(
|
||||||
MultiRootFileSystemTestDriver(soundNullSafety, moduleFormat, verbose));
|
soundNullSafety,
|
||||||
|
moduleFormat,
|
||||||
|
canaryFeatures,
|
||||||
|
verbose,
|
||||||
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
group('reading assets using asset file system -', () {
|
group('reading assets using asset file system -', () {
|
||||||
runExpressionCompilationTests(
|
runExpressionCompilationTests(AssetFileSystemTestDriver(
|
||||||
AssetFileSystemTestDriver(soundNullSafety, moduleFormat, verbose));
|
soundNullSafety,
|
||||||
|
moduleFormat,
|
||||||
|
canaryFeatures,
|
||||||
|
verbose,
|
||||||
|
));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -950,6 +964,7 @@ class E {
|
||||||
abstract class TestDriver {
|
abstract class TestDriver {
|
||||||
final bool soundNullSafety;
|
final bool soundNullSafety;
|
||||||
final ModuleFormat moduleFormat;
|
final ModuleFormat moduleFormat;
|
||||||
|
final bool canaryFeatures;
|
||||||
final bool verbose;
|
final bool verbose;
|
||||||
|
|
||||||
late FileSystem fileSystem;
|
late FileSystem fileSystem;
|
||||||
|
@ -964,7 +979,8 @@ abstract class TestDriver {
|
||||||
ExpressionCompilerWorker? worker;
|
ExpressionCompilerWorker? worker;
|
||||||
Future<void>? workerDone;
|
Future<void>? workerDone;
|
||||||
|
|
||||||
TestDriver(this.soundNullSafety, this.moduleFormat, this.verbose);
|
TestDriver(this.soundNullSafety, this.moduleFormat, this.canaryFeatures,
|
||||||
|
this.verbose);
|
||||||
|
|
||||||
/// Initialize file systems, inputs, and start servers if needed.
|
/// Initialize file systems, inputs, and start servers if needed.
|
||||||
Future<void> start();
|
Future<void> start();
|
||||||
|
@ -1005,6 +1021,7 @@ abstract class TestDriver {
|
||||||
sendResponse: responseController.add,
|
sendResponse: responseController.add,
|
||||||
soundNullSafety: soundNullSafety,
|
soundNullSafety: soundNullSafety,
|
||||||
moduleFormat: moduleFormat,
|
moduleFormat: moduleFormat,
|
||||||
|
canaryFeatures: canaryFeatures,
|
||||||
verbose: verbose,
|
verbose: verbose,
|
||||||
);
|
);
|
||||||
workerDone = worker?.run();
|
workerDone = worker?.run();
|
||||||
|
@ -1022,8 +1039,9 @@ class StandardFileSystemTestDriver extends TestDriver {
|
||||||
StandardFileSystemTestDriver(
|
StandardFileSystemTestDriver(
|
||||||
bool soundNullSafety,
|
bool soundNullSafety,
|
||||||
ModuleFormat moduleFormat,
|
ModuleFormat moduleFormat,
|
||||||
|
bool canaryFeatures,
|
||||||
bool verbose,
|
bool verbose,
|
||||||
) : super(soundNullSafety, moduleFormat, verbose);
|
) : super(soundNullSafety, moduleFormat, canaryFeatures, verbose);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> start() async {
|
Future<void> start() async {
|
||||||
|
@ -1038,8 +1056,9 @@ class MultiRootFileSystemTestDriver extends TestDriver {
|
||||||
MultiRootFileSystemTestDriver(
|
MultiRootFileSystemTestDriver(
|
||||||
bool soundNullSafety,
|
bool soundNullSafety,
|
||||||
ModuleFormat moduleFormat,
|
ModuleFormat moduleFormat,
|
||||||
|
bool canaryFeatures,
|
||||||
bool verbose,
|
bool verbose,
|
||||||
) : super(soundNullSafety, moduleFormat, verbose);
|
) : super(soundNullSafety, moduleFormat, canaryFeatures, verbose);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> start() async {
|
Future<void> start() async {
|
||||||
|
@ -1057,8 +1076,9 @@ class AssetFileSystemTestDriver extends TestDriver {
|
||||||
AssetFileSystemTestDriver(
|
AssetFileSystemTestDriver(
|
||||||
bool soundNullSafety,
|
bool soundNullSafety,
|
||||||
ModuleFormat moduleFormat,
|
ModuleFormat moduleFormat,
|
||||||
|
bool canaryFeatures,
|
||||||
bool verbose,
|
bool verbose,
|
||||||
) : super(soundNullSafety, moduleFormat, verbose);
|
) : super(soundNullSafety, moduleFormat, canaryFeatures, verbose);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> start() async {
|
Future<void> start() async {
|
||||||
|
|
|
@ -74,10 +74,13 @@ class SetupCompilerOptions {
|
||||||
final String dartLangComment;
|
final String dartLangComment;
|
||||||
final ModuleFormat moduleFormat;
|
final ModuleFormat moduleFormat;
|
||||||
final bool soundNullSafety;
|
final bool soundNullSafety;
|
||||||
|
final bool canaryFeatures;
|
||||||
|
|
||||||
SetupCompilerOptions(
|
SetupCompilerOptions({
|
||||||
{this.soundNullSafety = true, this.moduleFormat = ModuleFormat.amd})
|
this.soundNullSafety = true,
|
||||||
: options = getOptions(soundNullSafety),
|
this.moduleFormat = ModuleFormat.amd,
|
||||||
|
this.canaryFeatures = false,
|
||||||
|
}) : options = getOptions(soundNullSafety),
|
||||||
dartLangComment =
|
dartLangComment =
|
||||||
soundNullSafety ? dartSoundComment : dartUnsoundComment {
|
soundNullSafety ? dartSoundComment : dartUnsoundComment {
|
||||||
options.onDiagnostic = (DiagnosticMessage m) {
|
options.onDiagnostic = (DiagnosticMessage m) {
|
||||||
|
|
Loading…
Reference in a new issue