Enable Dart2 in dart2js by default

Change-Id: Id197fc734bcb45f0805e49e89c0d03419384bb0b
Reviewed-on: https://dart-review.googlesource.com/60448
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
This commit is contained in:
Sigmund Cherem 2018-06-19 19:20:36 +00:00 committed by commit-bot@chromium.org
parent 6b96e65c5b
commit c96f23243b
27 changed files with 133 additions and 53 deletions

View file

@ -36,6 +36,21 @@ allowed when `exp` has type `void`.
#### Pub
#### Dart2js
* Dart2js now compiles programs by default with Dart 2.0 semantics. Apps are
expected to be bigger than before, because Dart 2.0 has many more implicit
checks (similar to the `--checked` flag in Dart 1.0). Other relevant flags:
* `--omit-implicit-checks`: is a flag that removes most of the extra implicit
checks. Only use this if you have enough test coverage to know that the app
will work well without the checks. If a check would have failed and it is
omitted, your app may crash or behave in unexpected ways.
* `--no-preview-dart-2`: a temporary flag to revert to Dart 1.0. This flag is
temporary and only meant to help users in the migration process. The flag
will go away in a future dev release, when we no longer support Dart 1.0.
#### Other Tools
### Core library changes

View file

@ -124,7 +124,8 @@ Future<api.CompilationResult> compile(List<String> argv,
bool analyzeOnly = false;
bool trustTypeAnnotations = false;
bool checkedMode = false;
bool strongMode = false;
bool strongMode = true;
bool forceStrongMode = true;
List<String> hints = <String>[];
bool verbose;
bool throwOnError;
@ -219,11 +220,16 @@ Future<api.CompilationResult> compile(List<String> argv,
passThrough(argument);
}
void setStrongMode(_) {
strongMode = true;
void setForceStrongMode(_) {
strongMode = forceStrongMode = true;
passThrough(Flags.strongMode);
}
void setLegacyMode(_) {
if (!forceStrongMode) strongMode = false;
passThrough(Flags.noPreviewDart2);
}
void addInEnvironment(String argument) {
int eqIndex = argument.indexOf('=');
String name = argument.substring(2, eqIndex);
@ -357,9 +363,14 @@ Future<api.CompilationResult> compile(List<String> argv,
new OptionHandler(Flags.useContentSecurityPolicy, passThrough),
new OptionHandler(Flags.enableExperimentalMirrors, passThrough),
new OptionHandler(Flags.enableAssertMessage, passThrough),
new OptionHandler(Flags.strongMode, setStrongMode),
new OptionHandler(Flags.previewDart2, setStrongMode),
new OptionHandler(Flags.noPreviewDart2, ignoreOption),
// TODO(sigmund): ignore this option after we update our test bot
// configurations or stop testing Dart1.
// At the time this was added, some bots invoked dart2js with
// --no-preview-dart-2, but some test files contain extra dart2js options,
// including --strong. We want to make sure --strong takes precedence.
new OptionHandler(Flags.strongMode, setForceStrongMode),
new OptionHandler(Flags.previewDart2, setForceStrongMode),
new OptionHandler(Flags.noPreviewDart2, setLegacyMode),
new OptionHandler(Flags.omitImplicitChecks, passThrough),
new OptionHandler(Flags.laxRuntimeTypeToString, passThrough),
new OptionHandler(Flags.benchmarkingProduction, passThrough),
@ -653,9 +664,13 @@ Supported options:
Produce JavaScript that can be parsed more quickly by VMs. This option
usually results in larger JavaScript files with faster startup.
--preview-dart-2
Preview of all Dart 2.0 semantics, this includes generic methods and strong
mode type checks. This will be enabled by default very soon.
--no-preview-dart-2
Temporarily revert to Dart 1.0 semantics.
By default dart2js compiles programs in Dart 2.0 semantics, which includes
generic methods and strong mode type checks. Since apps may have additional
checks that fail at runtime, this temporary flag may help in the migration
process. See also '--omit-implicit-checks'.
The following advanced options can help reduce the size of the generated code,
but they may cause programs to behave unexpectedly if assumptions are not met.

View file

@ -231,7 +231,7 @@ class CompilerOptions implements DiagnosticOptions {
bool useContentSecurityPolicy = false;
/// Enables strong mode in dart2js.
bool strongMode = false;
bool strongMode = true;
/// When obfuscating for minification, whether to use the frequency of a name
/// as an heuristic to pick shorter names.
@ -325,7 +325,8 @@ class CompilerOptions implements DiagnosticOptions {
..platformBinaries =
platformBinaries ?? _extractUriOption(options, '--platform-binaries=')
..sourceMapUri = _extractUriOption(options, '--source-map=')
..strongMode = _hasOption(options, Flags.strongMode)
..strongMode = _hasOption(options, Flags.strongMode) ||
!_hasOption(options, Flags.noPreviewDart2)
..omitImplicitChecks = _hasOption(options, Flags.omitImplicitChecks)
..laxRuntimeTypeToString =
_hasOption(options, Flags.laxRuntimeTypeToString)

View file

@ -4,6 +4,7 @@
import 'package:expect/expect.dart';
import 'package:async_helper/async_helper.dart';
import 'package:compiler/src/commandline_options.dart';
import 'package:compiler/src/compiler.dart';
import 'package:compiler/src/elements/entities.dart';
import 'package:compiler/src/inferrer/typemasks/masks.dart';
@ -56,8 +57,8 @@ main() {
}
runTest() async {
CompilationResult result =
await runCompiler(memorySourceFiles: MEMORY_SOURCE_FILES);
CompilationResult result = await runCompiler(
memorySourceFiles: MEMORY_SOURCE_FILES, options: [Flags.noPreviewDart2]);
Compiler compiler = result.compiler;
JClosedWorld closedWorld = compiler.backendClosedWorldForTesting;
Expect.isFalse(compiler.compilationFailed, 'Unsuccessful compilation');

View file

@ -33,9 +33,9 @@ main() {
main() {
asyncTest(() async {
print('--test from kernel------------------------------------------------');
await runTest([]);
await runTest([Flags.noPreviewDart2]);
print('--test from kernel (trust-type-annotations)-----------------------');
await runTest([Flags.trustTypeAnnotations]);
await runTest([Flags.noPreviewDart2, Flags.trustTypeAnnotations]);
print('--test from kernel (strong mode)----------------------------------');
await runTest([Flags.strongMode]);
print('--test from kernel (strong mode, omit-implicit.checks)------------');

View file

@ -51,7 +51,7 @@ main () {
void main() {
runTest() async {
var options = [Flags.trustTypeAnnotations];
var options = [Flags.noPreviewDart2, Flags.trustTypeAnnotations];
var result = await runCompiler(
memorySourceFiles: {'main.dart': TEST}, options: options);
var compiler = result.compiler;

View file

@ -49,7 +49,11 @@ Future<String> compile(String code,
void check(String generatedEntry),
bool returnAll: false}) async {
OutputCollector outputCollector = returnAll ? new OutputCollector() : null;
List<String> options = <String>[Flags.disableTypeInference];
// TODO(sigmund): use strong-mode.
List<String> options = <String>[
Flags.noPreviewDart2,
Flags.disableTypeInference
];
if (enableTypeAssertions) {
options.add(Flags.enableCheckedMode);
}
@ -101,7 +105,7 @@ Future<String> compileAll(String code,
int expectedWarnings}) async {
OutputCollector outputCollector = new OutputCollector();
DiagnosticCollector diagnosticCollector = new DiagnosticCollector();
List<String> options = <String>[];
List<String> options = <String>[Flags.noPreviewDart2];
if (disableInlining) {
options.add(Flags.disableInlining);
}

View file

@ -577,7 +577,7 @@ Future checkTests(
print('--skipped for kernel--------------------------------------------');
} else {
print('--from kernel---------------------------------------------------');
List<String> options = []..addAll(testOptions);
List<String> options = [Flags.noPreviewDart2]..addAll(testOptions);
if (trustTypeAnnotations) {
options.add(Flags.trustTypeAnnotations);
}

View file

@ -49,8 +49,8 @@ show(ArgResults argResults, ComputeMemberDataFunction computeKernelData,
}
options = new List<String>.from(options);
if (strongMode) {
options.add(Flags.strongMode);
if (!strongMode) {
options.add(Flags.noPreviewDart2);
}
if (trustTypeAnnotations) {
options.add(Flags.trustTypeAnnotations);

View file

@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:async_helper/async_helper.dart';
import 'package:compiler/src/commandline_options.dart';
import 'package:compiler/src/inferrer/typemasks/masks.dart';
import 'package:expect/expect.dart';
@ -208,7 +209,9 @@ void main() {
doTest(String allocation, {bool nullify}) async {
String source = generateTest(allocation);
var result = await runCompiler(memorySourceFiles: {'main.dart': source});
var result = await runCompiler(
memorySourceFiles: {'main.dart': source},
options: [Flags.noPreviewDart2]);
Expect.isTrue(result.isSuccess);
var compiler = result.compiler;
var typesInferrer = compiler.globalInference.typesInferrerInternal;

View file

@ -30,9 +30,9 @@ callLoadLibrary() => expect.loadLibrary();
main() async {
asyncTest(() async {
print('--test Dart 1 ----------------------------------------------------');
await runTest([], trust: false);
await runTest([Flags.noPreviewDart2], trust: false);
print('--test Dart 1 --trust-type-annotations ---------------------------');
await runTest([Flags.trustTypeAnnotations]);
await runTest([Flags.noPreviewDart2, Flags.trustTypeAnnotations]);
print('--test Dart 2 ----------------------------------------------------');
await runTest([Flags.strongMode], trust: false);
print('--test Dart 2 --omit-implicit-checks -----------------------------');

View file

@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:async_helper/async_helper.dart';
import 'package:compiler/src/commandline_options.dart';
import 'package:compiler/src/compiler.dart';
import 'package:compiler/src/elements/entities.dart';
import 'package:compiler/src/inferrer/type_graph_inferrer.dart';
@ -227,7 +228,9 @@ void main() {
doTest(String allocation,
{String keyElementName, String valueElementName}) async {
String source = generateTest(allocation);
var result = await runCompiler(memorySourceFiles: {'main.dart': source});
var result = await runCompiler(
memorySourceFiles: {'main.dart': source},
options: [Flags.noPreviewDart2]);
Expect.isTrue(result.isSuccess);
Compiler compiler = result.compiler;
TypeMask keyType, valueType;

View file

@ -4,6 +4,7 @@
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
import 'package:compiler/src/commandline_options.dart';
import 'package:compiler/src/common_elements.dart';
import 'package:compiler/src/compiler.dart';
import 'package:compiler/src/elements/entities.dart';
@ -745,8 +746,9 @@ void main() {
}
runTests() async {
CompilationResult result = await runCompiler(memorySourceFiles: {
'main.dart': r'''
CompilationResult result = await runCompiler(
memorySourceFiles: {
'main.dart': r'''
import 'dart:collection';
class AList<E> extends ListBase<E> {}
main() {
@ -755,7 +757,9 @@ runTests() async {
print('${const []}${const {}}${(){}}${new AList()}');
}
'''
}, beforeRun: (compiler) => compiler.stopAfterTypeInference = true);
},
beforeRun: (compiler) => compiler.stopAfterTypeInference = true,
options: [Flags.noPreviewDart2]);
Expect.isTrue(result.isSuccess);
Compiler compiler = result.compiler;
JClosedWorld closedWorld = compiler.backendClosedWorldForTesting;

View file

@ -6,6 +6,7 @@ library jsinterop.world_test;
import 'package:expect/expect.dart';
import 'package:async_helper/async_helper.dart';
import 'package:compiler/src/commandline_options.dart';
import 'package:compiler/src/common_elements.dart';
import 'package:compiler/src/compiler.dart';
import 'package:compiler/src/elements/entities.dart' show ClassEntity;
@ -18,7 +19,7 @@ import '../memory_compiler.dart';
void main() {
asyncTest(() async {
print('--test from kernel------------------------------------------------');
await testClasses([]);
await testClasses([Flags.noPreviewDart2]);
print('--test from kernel (strong mode)----------------------------------');
// TODO(johnniwinther): Update the test to be strong mode compliant.
//await testClasses([Flags.strongMode]);

View file

@ -601,7 +601,7 @@ testClosures({bool strongMode}) async {
local() {}
}
""",
options: strongMode ? [Flags.strongMode] : [],
options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2],
testBackendWorld: true);
JClosedWorld world = env.jClosedWorld;

View file

@ -671,7 +671,8 @@ Future testData(TestData data) async {
if (!skipKernelList.contains(data.name) && !data.strongModeOnly) {
print(
'--test kernel-------------------------------------------------------');
await runTest([], (Compiler compiler, FieldEntity field) {
await runTest([Flags.noPreviewDart2],
(Compiler compiler, FieldEntity field) {
KernelFrontEndStrategy frontendStrategy = compiler.frontendStrategy;
KernelToElementMap elementMap = frontendStrategy.elementMap;
return new KernelEvaluationEnvironment(elementMap, null, field,

View file

@ -355,7 +355,7 @@ Future testData(TestData data, {bool strongMode}) async {
String source = sb.toString();
CompilationResult result = await runCompiler(
memorySourceFiles: {'main.dart': source},
options: strongMode ? [Flags.strongMode] : []);
options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2]);
Compiler compiler = result.compiler;
var elementEnvironment = compiler.frontendStrategy.elementEnvironment;

View file

@ -140,7 +140,7 @@ main() {
r = new R(); // Create R after call.
}
'''
}, options: strongMode ? [Flags.strongMode] : []);
}, options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2]);
Expect.isTrue(result.isSuccess);
Compiler compiler = result.compiler;

View file

@ -93,7 +93,7 @@ main() {
ImpactCacheDeleter.retainCachesForTesting = true;
CompilationResult result = await runCompiler(
memorySourceFiles: {'main.dart': source},
options: strongMode ? [Flags.strongMode] : []);
options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2]);
Expect.isTrue(result.isSuccess);
Compiler compiler = result.compiler;

View file

@ -59,7 +59,9 @@ Future testInterfaceSubtype({bool strongMode}) async {
// TODO(johnniwinther): Inheritance with different type arguments is
// currently not supported by the implementation.
class C<T1, T2> extends B<T2, T1> /*implements A<A<T1>>*/ {}
""", options: strongMode ? [Flags.strongMode] : []).then((env) {
""",
options:
strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2]).then((env) {
void expect(bool expectSubtype, DartType T, DartType S,
{bool expectMoreSpecific}) {
testTypes(env, T, S, expectSubtype, expectMoreSpecific);
@ -311,7 +313,9 @@ Future testCallableSubtype({bool strongMode}) async {
int m4(V v, U u) => null;
void m5(V v, int i) => null;
}
""", options: strongMode ? [Flags.strongMode] : []).then((env) {
""",
options:
strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2]).then((env) {
void expect(bool expectSubtype, DartType T, DartType S,
{bool expectMoreSpecific}) {
testTypes(env, T, S, expectSubtype, expectMoreSpecific);
@ -361,14 +365,14 @@ const List<FunctionTypeData> functionTypesData = const <FunctionTypeData>[
Future testFunctionSubtyping({bool strongMode}) async {
await TypeEnvironment
.create(createMethods(functionTypesData),
options: strongMode ? [Flags.strongMode] : [])
options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2])
.then(functionSubtypingHelper);
}
Future testTypedefSubtyping({bool strongMode}) async {
await TypeEnvironment
.create(createTypedefs(functionTypesData),
options: strongMode ? [Flags.strongMode] : [])
options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2])
.then(functionSubtypingHelper);
}
@ -447,14 +451,14 @@ const List<FunctionTypeData> optionalFunctionTypesData =
Future testFunctionSubtypingOptional({bool strongMode}) async {
await TypeEnvironment
.create(createMethods(optionalFunctionTypesData),
options: strongMode ? [Flags.strongMode] : [])
options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2])
.then((env) => functionSubtypingOptionalHelper(env, strongMode));
}
Future testTypedefSubtypingOptional({bool strongMode}) async {
await TypeEnvironment
.create(createTypedefs(optionalFunctionTypesData),
options: strongMode ? [Flags.strongMode] : [])
options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2])
.then((env) => functionSubtypingOptionalHelper(env, strongMode));
}
@ -521,14 +525,14 @@ const List<FunctionTypeData> namedFunctionTypesData = const <FunctionTypeData>[
Future testFunctionSubtypingNamed({bool strongMode}) async {
await TypeEnvironment
.create(createMethods(namedFunctionTypesData),
options: strongMode ? [Flags.strongMode] : [])
options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2])
.then((env) => functionSubtypingNamedHelper(env, strongMode));
}
Future testTypedefSubtypingNamed({bool strongMode}) async {
await TypeEnvironment
.create(createTypedefs(namedFunctionTypesData),
options: strongMode ? [Flags.strongMode] : [])
options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2])
.then((env) => functionSubtypingNamedHelper(env, strongMode));
}
@ -580,7 +584,9 @@ Future testTypeVariableSubtype({bool strongMode}) async {
class H<T extends S, S extends T> {}
class I<T extends S, S extends U, U extends T> {}
class J<T extends S, S extends U, U extends S> {}
""", options: strongMode ? [Flags.strongMode] : []).then((env) {
""",
options:
strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2]).then((env) {
void expect(bool expectSubtype, DartType T, DartType S,
{bool expectMoreSpecific}) {
testTypes(env, T, S, expectSubtype, expectMoreSpecific);
@ -804,7 +810,9 @@ Future testStrongModeSubtyping({bool strongMode}) async {
takeInt(int o) => null;
takeVoid(void o) => null;
takeObject(Object o) => null;
""", options: strongMode ? [Flags.strongMode] : []).then((env) {
""",
options:
strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2]).then((env) {
void expect(bool expectSubtype, DartType T, DartType S) {
Expect.equals(expectSubtype, env.isSubtype(T, S), '$T <: $S');
if (expectSubtype) {

View file

@ -51,7 +51,7 @@ runTests({bool strongMode: false}) async {
new F();
new G();
}
""", options: strongMode ? [Flags.strongMode] : []);
""", options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2]);
KClosedWorld world = env.kClosedWorld;
ClassEntity A = env.getElement("A");

View file

@ -5,6 +5,7 @@
import 'dart:async';
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
import 'package:compiler/src/commandline_options.dart';
import 'package:compiler/src/elements/entities.dart';
import 'package:compiler/src/elements/names.dart';
import 'package:compiler/src/universe/call_structure.dart';
@ -47,7 +48,9 @@ testClassSets() async {
testMode = '$instantiated';
var env = await TypeEnvironment.create(CLASSES,
mainSource: main.toString(), testBackendWorld: true);
mainSource: main.toString(),
testBackendWorld: true,
options: [Flags.noPreviewDart2]);
foo = new Selector.call(const PublicName('foo'), CallStructure.NO_ARGS);
bar = new Selector.call(const PublicName('bar'), CallStructure.NO_ARGS);
baz = new Selector.call(const PublicName('baz'), CallStructure.NO_ARGS);

View file

@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:async_helper/async_helper.dart';
import 'package:compiler/src/commandline_options.dart';
import 'package:compiler/src/common_elements.dart';
import 'package:compiler/src/compiler.dart';
import 'package:compiler/src/elements/entities.dart';
@ -209,8 +210,9 @@ main() {
for (NoSuchMethodTest test in TESTS) {
print('---- testing -------------------------------------------------');
print(test.code);
CompilationResult result =
await runCompiler(memorySourceFiles: {'main.dart': test.code});
CompilationResult result = await runCompiler(
memorySourceFiles: {'main.dart': test.code},
options: [Flags.noPreviewDart2]);
Compiler compiler = result.compiler;
checkTest(compiler, test);
}

View file

@ -57,9 +57,13 @@ const Map<String, List<String>> expectedIsChecksMap =
main() {
runTest() async {
CompilationResult result = await runCompiler(
memorySourceFiles: {'main.dart': code},
options: [Flags.disableRtiOptimization, Flags.disableInlining]);
CompilationResult result = await runCompiler(memorySourceFiles: {
'main.dart': code
}, options: [
Flags.noPreviewDart2,
Flags.disableRtiOptimization,
Flags.disableInlining
]);
Expect.isTrue(result.isSuccess);
Compiler compiler = result.compiler;
JClosedWorld closedWorld = compiler.backendClosedWorldForTesting;

View file

@ -67,7 +67,7 @@ main() {
''';
CompilationResult result = await runCompiler(
memorySourceFiles: {'main.dart': source},
options: strongMode ? [Flags.strongMode] : []);
options: strongMode ? [Flags.strongMode] : [Flags.noPreviewDart2]);
Expect.isTrue(result.isSuccess);
Compiler compiler = result.compiler;
JavaScriptBackend backend = compiler.backend;

View file

@ -131,7 +131,7 @@ bool parseArgument(String argument, Set<String> configurations,
}
const Map<String, List<String>> TEST_CONFIGURATIONS = const {
'kernel': const [],
'kernel': const [Flags.noPreviewDart2],
};
final Map<String, Uri> TEST_FILES = _computeTestFiles();

View file

@ -1259,6 +1259,13 @@ class StandardTestSuite extends TestSuite {
if (options != null) args.addAll(options);
options = optionsFromFile['dart2jsOptions'] as List<String>;
if (options != null) args.addAll(options);
if (configuration.compiler == Compiler.dart2js) {
if (configuration.noPreviewDart2) {
args.add("--no-preview-dart-2");
} else {
args.add("--preview-dart-2");
}
}
return Command.compilation(Compiler.dart2js.name, outputFile,
dart2JsBootstrapDependencies, compilerPath, args, environmentOverrides,
@ -1301,6 +1308,14 @@ class StandardTestSuite extends TestSuite {
}
}
if (configuration.compiler == Compiler.dart2js) {
if (configuration.noPreviewDart2) {
args.add("--no-preview-dart-2");
} else {
args.add("--preview-dart-2");
}
}
var isMultitest = optionsFromFile["isMultitest"] as bool;
var dartOptions = optionsFromFile["dartOptions"] as List<String>;