Skip to content

Commit 670f9ab

Browse files
committed
Merge commit '65401da92251a7318e3264b816ce0c4e14701751' into analyzer
2 parents 6905e57 + 65401da commit 670f9ab

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+508
-1034
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,21 @@
2525

2626
#### Linter
2727

28-
The linter was bumped to `0.1.73` which introduces the following new lints to the SDK:
28+
The linter was bumped to `0.1.75` which introduces the following new lints to the SDK:
2929

3030
* `unnecessary_await_in_return`
3131
* `use_function_type_syntax_for_parameters`
3232
* `avoid_returning_null_for_future`
3333
* `avoid_shadowing_type_parameters`
3434

35+
and:
36+
37+
* `unnecessary_parenthesis` lint has been improved to handle function expressions.
38+
3539
In addition, `prefer_bool_in_asserts` has been deprecated as its semantics are
36-
redundant with Dart 2 checks.
40+
redundant with Dart 2 checks and experimental lints `avoid_positional_boolean_parameters`,
41+
`literal_only_boolean_expressions`, `prefer_foreach`, `prefer_void_to_null` have all been
42+
promoted to stable.
3743

3844
#### Other Tools
3945

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ vars = {
9797
"intl_tag": "0.15.7",
9898
"jinja2_rev": "2222b31554f03e62600cd7e383376a7c187967a1",
9999
"json_rpc_2_tag": "2.0.9",
100-
"linter_tag": "0.1.73",
100+
"linter_tag": "0.1.75",
101101
"logging_tag": "0.11.3+2",
102102
"markdown_tag": "2.0.2",
103103
"matcher_tag": "0.12.3",

pkg/analyzer/lib/error/error.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ const List<ErrorCode> errorCodeValues = const [
413413
ParserErrorCode.FACTORY_WITHOUT_BODY,
414414
ParserErrorCode.FACTORY_WITH_INITIALIZERS,
415415
ParserErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR,
416+
ParserErrorCode.FIELD_INITIALIZED_OUTSIDE_DECLARING_CLASS,
416417
ParserErrorCode.FINAL_AND_COVARIANT,
417418
ParserErrorCode.FINAL_AND_VAR,
418419
ParserErrorCode.FINAL_CLASS,

pkg/analyzer/lib/src/dart/error/syntactic_errors.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ class ParserErrorCode extends ErrorCode {
256256
static const ParserErrorCode FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR =
257257
_FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR;
258258

259+
static const ParserErrorCode FIELD_INITIALIZED_OUTSIDE_DECLARING_CLASS =
260+
_FIELD_INITIALIZED_OUTSIDE_DECLARING_CLASS;
261+
259262
static const ParserErrorCode FINAL_AND_COVARIANT = _FINAL_AND_COVARIANT;
260263

261264
static const ParserErrorCode FINAL_AND_VAR = _FINAL_AND_VAR;

pkg/analyzer/lib/src/dart/error/syntactic_errors.g.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ final fastaAnalyzerErrorCodes = <ErrorCode>[
9595
_EXTERNAL_FACTORY_REDIRECTION,
9696
_EXTERNAL_FACTORY_WITH_BODY,
9797
_EXTERNAL_CONSTRUCTOR_WITH_BODY,
98+
_FIELD_INITIALIZED_OUTSIDE_DECLARING_CLASS,
9899
];
99100

100101
const ParserErrorCode _ABSTRACT_CLASS_MEMBER = const ParserErrorCode(
@@ -301,6 +302,12 @@ const ParserErrorCode _FACTORY_TOP_LEVEL_DECLARATION = const ParserErrorCode(
301302
r"Top-level declarations can't be declared to be 'factory'.",
302303
correction: "Try removing the keyword 'factory'.");
303304

305+
const ParserErrorCode _FIELD_INITIALIZED_OUTSIDE_DECLARING_CLASS =
306+
const ParserErrorCode('FIELD_INITIALIZED_OUTSIDE_DECLARING_CLASS',
307+
r"A field can only be initialized in it's declaring class",
308+
correction:
309+
"Try moving the field initialization into the constructor body.");
310+
304311
const ParserErrorCode _FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR =
305312
const ParserErrorCode('FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR',
306313
r"Field formal parameters can only be used in a constructor.",

pkg/analyzer/lib/src/fasta/ast_builder.dart

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,12 +625,23 @@ class AstBuilder extends StackListener {
625625
SimpleIdentifier fieldName;
626626
Expression left = initializerObject.leftHandSide;
627627
if (left is PropertyAccess) {
628-
var thisExpression = left.target as ThisExpression;
629-
thisKeyword = thisExpression.thisKeyword;
630-
period = left.operator;
628+
Expression target = left.target;
629+
if (target is ThisExpression) {
630+
thisKeyword = target.thisKeyword;
631+
period = left.operator;
632+
} else {
633+
assert(target is SuperExpression);
634+
// Recovery:
635+
// Parser has reported FieldInitializedOutsideDeclaringClass.
636+
}
631637
fieldName = left.propertyName;
638+
} else if (left is SimpleIdentifier) {
639+
fieldName = left;
632640
} else {
633-
fieldName = left as SimpleIdentifier;
641+
// Recovery:
642+
// Parser has reported invalid assignment.
643+
SuperExpression superExpression = left;
644+
fieldName = ast.simpleIdentifier(superExpression.superKeyword);
634645
}
635646
initializers.add(ast.constructorFieldInitializer(
636647
thisKeyword,

pkg/analyzer/test/generated/parser_test.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3890,6 +3890,41 @@ class Wrong<T> {
38903890
]);
38913891
}
38923892

3893+
void test_invalidConstructorSuperAssignment() {
3894+
createParser("C() : super = 42;");
3895+
ClassMember member = parser.parseClassMember('C');
3896+
expectNotNullIfNoErrors(member);
3897+
listener.assertErrors(usingFastaParser
3898+
? [expectedError(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, 6, 5)]
3899+
: [
3900+
expectedError(ParserErrorCode.EXPECTED_TOKEN, 14, 1),
3901+
expectedError(ParserErrorCode.EXPECTED_TYPE_NAME, 16, 2),
3902+
expectedError(ParserErrorCode.UNEXPECTED_TOKEN, 16, 2),
3903+
expectedError(
3904+
ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR, 16, 0),
3905+
]);
3906+
}
3907+
3908+
void test_invalidConstructorSuperFieldAssignment() {
3909+
createParser("C() : super.a = 42;");
3910+
ClassMember member = parser.parseClassMember('C');
3911+
expectNotNullIfNoErrors(member);
3912+
listener.assertErrors(usingFastaParser
3913+
? [
3914+
expectedError(
3915+
ParserErrorCode.FIELD_INITIALIZED_OUTSIDE_DECLARING_CLASS,
3916+
12,
3917+
1)
3918+
]
3919+
: [
3920+
expectedError(ParserErrorCode.EXPECTED_TOKEN, 14, 1),
3921+
expectedError(ParserErrorCode.EXPECTED_TYPE_NAME, 16, 2),
3922+
expectedError(ParserErrorCode.UNEXPECTED_TOKEN, 16, 2),
3923+
expectedError(
3924+
ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR, 16, 0),
3925+
]);
3926+
}
3927+
38933928
void test_invalidHexEscape_invalidDigit() {
38943929
StringLiteral literal = parseExpression("'not \\x0 a'",
38953930
errors: [expectedError(ParserErrorCode.INVALID_HEX_ESCAPE, 5, 3)]);

pkg/compiler/lib/src/commandline_options.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class Flags {
7474

7575
static const String readData = '--read-data';
7676
static const String writeData = '--write-data';
77+
static const String cfeOnly = '--cfe-only';
7778

7879
static const String serverMode = '--server-mode';
7980

pkg/compiler/lib/src/compiler.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ abstract class Compiler {
168168
enqueuer = backend.makeEnqueuer();
169169

170170
tasks = [
171-
kernelLoader =
172-
new KernelLoaderTask(options, provider, reporter, measurer),
171+
kernelLoader = new KernelLoaderTask(
172+
options, provider, _outputProvider, reporter, measurer),
173173
kernelFrontEndTask,
174174
globalInference = new GlobalTypeInferenceTask(this),
175175
constants = backend.constantCompilerTask,
@@ -255,6 +255,7 @@ abstract class Compiler {
255255
if (compilationFailed && !options.generateCodeWithCompileTimeErrors) {
256256
return;
257257
}
258+
if (options.cfeOnly) return;
258259
_mainLibraryUri = result.rootLibraryUri;
259260

260261
frontendStrategy.registerLoadedLibraries(result);

pkg/compiler/lib/src/dart2js.dart

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ Future<api.CompilationResult> compile(List<String> argv,
263263
compilationStrategy = CompilationStrategy.fromData;
264264
}
265265

266+
void setCfeOnly(String argument) {
267+
compilationStrategy = CompilationStrategy.toKernel;
268+
}
269+
266270
void setWriteData(String argument) {
267271
if (compilationStrategy == CompilationStrategy.fromData) {
268272
fail("Cannot read and write serialized simultaneously.");
@@ -333,6 +337,7 @@ Future<api.CompilationResult> compile(List<String> argv,
333337
new OptionHandler('--libraries-spec=.+', setLibrarySpecificationUri),
334338
new OptionHandler('${Flags.readData}|${Flags.readData}=.+', setReadData),
335339
new OptionHandler('${Flags.writeData}|${Flags.writeData}=.+', setWriteData),
340+
new OptionHandler(Flags.cfeOnly, setCfeOnly),
336341
new OptionHandler('--out=.+|-o.*', setOutput, multipleArguments: true),
337342
new OptionHandler('-O.*', setOptimizationLevel),
338343
new OptionHandler(Flags.allowMockCompilation, ignoreOption),
@@ -492,6 +497,10 @@ Future<api.CompilationResult> compile(List<String> argv,
492497
case CompilationStrategy.direct:
493498
out ??= currentDirectory.resolve('out.js');
494499
break;
500+
case CompilationStrategy.toKernel:
501+
out ??= currentDirectory.resolve('out.dill');
502+
options.add(Flags.cfeOnly);
503+
break;
495504
case CompilationStrategy.toData:
496505
out ??= currentDirectory.resolve('out.dill');
497506
writeDataUri ??= currentDirectory.resolve('$out.data');
@@ -544,6 +553,18 @@ Future<api.CompilationResult> compile(List<String> argv,
544553
}
545554
}
546555
break;
556+
case CompilationStrategy.toKernel:
557+
int dartCharactersRead = inputProvider.dartCharactersRead;
558+
int dataBytesWritten = outputProvider.totalDataWritten;
559+
print('Compiled '
560+
'${_formatCharacterCount(dartCharactersRead)} characters Dart to '
561+
'${_formatCharacterCount(dataBytesWritten)} kernel bytes in '
562+
'${_formatDurationAsSeconds(wallclock.elapsed)} seconds');
563+
String input = uriPathToNative(scriptName);
564+
String dillOutput =
565+
relativize(currentDirectory, out, Platform.isWindows);
566+
print('Dart file ($input) compiled to ${dillOutput}.');
567+
break;
547568
case CompilationStrategy.toData:
548569
int dartCharactersRead = inputProvider.dartCharactersRead;
549570
int dataBytesWritten = outputProvider.totalDataWritten;
@@ -1007,4 +1028,4 @@ void batchMain(List<String> batchArguments) {
10071028
});
10081029
}
10091030

1010-
enum CompilationStrategy { direct, toData, fromData }
1031+
enum CompilationStrategy { direct, toKernel, toData, fromData }

pkg/compiler/lib/src/kernel/loader.dart

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'dart:async';
99
import 'package:front_end/src/fasta/kernel/utils.dart';
1010
import 'package:kernel/ast.dart' as ir;
1111
import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder;
12+
import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter;
1213

1314
import 'package:front_end/src/api_unstable/dart2js.dart' as fe;
1415
import 'package:kernel/kernel.dart' hide LibraryDependency, Combinator;
@@ -18,6 +19,7 @@ import '../../compiler_new.dart' as api;
1819
import '../common/tasks.dart' show CompilerTask, Measurer;
1920
import '../common.dart';
2021
import '../options.dart';
22+
import '../util/sink_adapter.dart';
2123

2224
import 'front_end_adapter.dart';
2325
import 'dart2js_target.dart' show Dart2jsTarget;
@@ -31,6 +33,7 @@ class KernelLoaderTask extends CompilerTask {
3133
final DiagnosticReporter _reporter;
3234

3335
final api.CompilerInput _compilerInput;
36+
final api.CompilerOutput _compilerOutput;
3437

3538
final CompilerOptions _options;
3639

@@ -43,8 +46,8 @@ class KernelLoaderTask extends CompilerTask {
4346
/// This is used for testing.
4447
bool forceSerialization = false;
4548

46-
KernelLoaderTask(
47-
this._options, this._compilerInput, this._reporter, Measurer measurer)
49+
KernelLoaderTask(this._options, this._compilerInput, this._compilerOutput,
50+
this._reporter, Measurer measurer)
4851
: initializedCompilerState = _options.kernelInitializedCompilerState,
4952
super(measurer);
5053

@@ -78,6 +81,20 @@ class KernelLoaderTask extends CompilerTask {
7881
resolvedUri);
7982
}
8083
if (component == null) return null;
84+
85+
if (_options.cfeOnly) {
86+
measureSubtask('serialize dill', () {
87+
_reporter.log('Writing dill to ${_options.outputUri}');
88+
api.BinaryOutputSink dillOutput =
89+
_compilerOutput.createBinarySink(_options.outputUri);
90+
BinaryOutputSinkAdapter irSink =
91+
new BinaryOutputSinkAdapter(dillOutput);
92+
BinaryPrinter printer = new BinaryPrinter(irSink);
93+
printer.writeComponentFile(component);
94+
irSink.close();
95+
});
96+
}
97+
8198
if (forceSerialization) {
8299
// TODO(johnniwinther): Remove this when #34942 is fixed.
83100
List<int> data = serializeComponent(component);

pkg/compiler/lib/src/options.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ class CompilerOptions implements DiagnosticOptions {
6262
/// If this is set, the compilation stops after type inference.
6363
Uri writeDataUri;
6464

65+
/// Whether to run only the CFE and emit the generated kernel file in
66+
/// [outputUri].
67+
bool cfeOnly = false;
68+
6569
/// Resolved constant "environment" values passed to the compiler via the `-D`
6670
/// flags.
6771
Map<String, String> environment = const <String, String>{};
@@ -332,7 +336,8 @@ class CompilerOptions implements DiagnosticOptions {
332336
..verbose = _hasOption(options, Flags.verbose)
333337
..showInternalProgress = _hasOption(options, Flags.progress)
334338
..readDataUri = _extractUriOption(options, '${Flags.readData}=')
335-
..writeDataUri = _extractUriOption(options, '${Flags.writeData}=');
339+
..writeDataUri = _extractUriOption(options, '${Flags.writeData}=')
340+
..cfeOnly = _hasOption(options, Flags.cfeOnly);
336341
}
337342

338343
void validate() {

pkg/compiler/lib/src/serialization/strategies.dart

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import 'package:front_end/src/fasta/kernel/utils.dart';
1010
import 'package:kernel/ast.dart' as ir;
1111
import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder;
1212

13-
import '../../compiler_new.dart' as api;
1413
import '../diagnostics/diagnostic_listener.dart';
1514
import '../environment.dart';
1615
import '../js_model/js_world.dart';
1716
import '../options.dart';
1817
import '../source_file_provider.dart';
1918
import '../types/abstract_value_domain.dart';
2019
import '../types/types.dart';
20+
import '../util/sink_adapter.dart';
2121
import 'serialization.dart';
2222
import 'task.dart';
2323

@@ -130,19 +130,3 @@ class ObjectsInMemorySerializationStrategy
130130
abstractValueStrategy, component, source);
131131
}
132132
}
133-
134-
class BinaryOutputSinkAdapter implements Sink<List<int>> {
135-
api.BinaryOutputSink output;
136-
137-
BinaryOutputSinkAdapter(this.output);
138-
139-
@override
140-
void add(List<int> data) {
141-
output.write(data);
142-
}
143-
144-
@override
145-
void close() {
146-
output.close();
147-
}
148-
}

pkg/compiler/lib/src/serialization/task.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import '../js_model/js_world.dart';
1616
import '../options.dart';
1717
import '../types/abstract_value_domain.dart';
1818
import '../types/types.dart';
19-
import 'strategies.dart';
19+
import '../util/sink_adapter.dart';
2020
import 'serialization.dart';
2121

2222
void serializeGlobalTypeInferenceResults(
@@ -53,6 +53,9 @@ class SerializationTask extends CompilerTask {
5353

5454
void serialize(GlobalTypeInferenceResults results) {
5555
measureSubtask('serialize dill', () {
56+
// TODO(sigmund): remove entirely: we will do this immediately as soon as
57+
// we get the component in the kernel/loader.dart task once we refactor
58+
// how we apply our modular kernel transformation for super mixin calls.
5659
compiler.reporter.log('Writing dill to ${compiler.options.outputUri}');
5760
api.BinaryOutputSink dillOutput =
5861
compiler.outputProvider.createBinarySink(compiler.options.outputUri);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import '../../compiler_new.dart' as api;
2+
3+
class BinaryOutputSinkAdapter implements Sink<List<int>> {
4+
api.BinaryOutputSink output;
5+
6+
BinaryOutputSinkAdapter(this.output);
7+
8+
@override
9+
void add(List<int> data) {
10+
output.write(data);
11+
}
12+
13+
@override
14+
void close() {
15+
output.close();
16+
}
17+
}

0 commit comments

Comments
 (0)