Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 616bc67

Browse files
author
Dart CI
committed
Version 2.11.0-157.0.dev
Merge commit 'd966206c6defa2b52be74642318c780283f24bfb' into 'dev'
2 parents 2b8d00a + d966206 commit 616bc67

File tree

358 files changed

+10295
-4326
lines changed

Some content is hidden

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

358 files changed

+10295
-4326
lines changed

.dart_tool/package_config.json

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"constraint, update this by running tools/generate_package_config.dart."
1212
],
1313
"configVersion": 2,
14-
"generated": "2020-08-18T15:38:52.410101",
14+
"generated": "2020-09-18T09:56:27.880444",
1515
"generator": "tools/generate_package_config.dart",
1616
"packages": [
1717
{
@@ -184,7 +184,7 @@
184184
"name": "dart2js_info",
185185
"rootUri": "../third_party/pkg/dart2js_info",
186186
"packageUri": "lib/",
187-
"languageVersion": "2.0"
187+
"languageVersion": "2.3"
188188
},
189189
{
190190
"name": "dart2js_tools",
@@ -207,8 +207,7 @@
207207
{
208208
"name": "dart_style",
209209
"rootUri": "../third_party/pkg_tested/dart_style",
210-
"packageUri": "lib/",
211-
"languageVersion": "2.7"
210+
"packageUri": "lib/"
212211
},
213212
{
214213
"name": "dartdev",
@@ -348,8 +347,7 @@
348347
{
349348
"name": "js_runtime",
350349
"rootUri": "../sdk/lib/_internal/js_runtime",
351-
"packageUri": "lib/",
352-
"languageVersion": "2.10"
350+
"packageUri": "lib/"
353351
},
354352
{
355353
"name": "json_rpc_2",
@@ -426,7 +424,7 @@
426424
"name": "native_stack_traces",
427425
"rootUri": "../pkg/native_stack_traces",
428426
"packageUri": "lib/",
429-
"languageVersion": "2.8"
427+
"languageVersion": "2.10"
430428
},
431429
{
432430
"name": "nnbd_migration",
@@ -484,8 +482,7 @@
484482
{
485483
"name": "pub",
486484
"rootUri": "../third_party/pkg/pub",
487-
"packageUri": "lib/",
488-
"languageVersion": "2.3"
485+
"packageUri": "lib/"
489486
},
490487
{
491488
"name": "pub_semver",
@@ -508,8 +505,7 @@
508505
{
509506
"name": "sdk_library_metadata",
510507
"rootUri": "../sdk/lib/_internal/sdk_library_metadata",
511-
"packageUri": "lib/",
512-
"languageVersion": "2.10"
508+
"packageUri": "lib/"
513509
},
514510
{
515511
"name": "shelf",

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
### Tools
1010

11+
#### Dartanalyzer
12+
13+
* Removed the `--use-fasta-parser`, `--preview-dart-2`, and
14+
`--enable-assert-initializers` command line options. These options haven't
15+
been supported in a while and were no-ops.
16+
1117
#### Linter
1218

1319
Updated the Linter to `0.1.119`, which includes:
@@ -55,7 +61,7 @@ Updated the Linter to `0.1.119`, which includes:
5561
deferred loading of types, pass `--no-defer-class-types`. See the original
5662
post on the [unsoundness in the deferred loading algorithm][].
5763
* Enables a new sound deferred splitting algorithm. To explicitly disable
58-
the new deferred splitting algorithm, pass `--no-new-deferred-split'.
64+
the new deferred splitting algorithm, pass `--no-new-deferred-split`.
5965
See the original post on the
6066
[unsoundness in the deferred loading algorithm][].
6167

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ vars = {
4444
# co19 is a cipd package. Use update.sh in tests/co19[_2] to update these
4545
# hashes. It requires access to the dart-build-access group, which EngProd
4646
# has.
47-
"co19_rev": "b7660861df12eb489243a591e45f251f8cf8c4a8",
47+
"co19_rev": "da33ec472443aa14d969bf54b9adc3af71cb6382",
4848
"co19_2_rev": "e48b3090826cf40b8037648f19d211e8eab1b4b6",
4949

5050
# The internal benchmarks to use. See go/dart-benchmarks-internal

pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,11 @@ abstract class FlowAnalysis<Node, Statement extends Node, Expression, Variable,
609609
void parenthesizedExpression(
610610
Expression outerExpression, Expression innerExpression);
611611

612+
/// Attempt to promote [variable] to [type]. The client may use this to
613+
/// ensure that a variable declaration of the form `var x = expr;` promotes
614+
/// `x` to type `X&T` in the circumstance where the type of `expr` is `X&T`.
615+
void promote(Variable variable, Type type);
616+
612617
/// Retrieves the type that the [variable] is promoted to, if the [variable]
613618
/// is currently promoted. Otherwise returns `null`.
614619
Type promotedType(Variable variable);
@@ -749,7 +754,12 @@ abstract class FlowAnalysis<Node, Statement extends Node, Expression, Variable,
749754

750755
/// Register write of the given [variable] in the current state.
751756
/// [writtenType] should be the type of the value that was written.
752-
void write(Variable variable, Type writtenType);
757+
///
758+
/// This should also be used for the implicit write to a non-final variable in
759+
/// its initializer, to ensure that the type is promoted to non-nullable if
760+
/// necessary; in this case, [viaInitializer] should be `true`.
761+
void write(Variable variable, Type writtenType,
762+
{bool viaInitializer = false});
753763
}
754764

755765
/// Alternate implementation of [FlowAnalysis] that prints out inputs and output
@@ -1054,6 +1064,11 @@ class FlowAnalysisDebug<Node, Statement extends Node, Expression, Variable,
10541064
_wrapped.parenthesizedExpression(outerExpression, innerExpression));
10551065
}
10561066

1067+
@override
1068+
void promote(Variable variable, Type type) {
1069+
_wrap('promote($variable, $type', () => _wrapped.promote(variable, type));
1070+
}
1071+
10571072
@override
10581073
Type promotedType(Variable variable) {
10591074
return _wrap(
@@ -1156,9 +1171,12 @@ class FlowAnalysisDebug<Node, Statement extends Node, Expression, Variable,
11561171
}
11571172

11581173
@override
1159-
void write(Variable variable, Type writtenType) {
1160-
_wrap('write($variable, $writtenType)',
1161-
() => _wrapped.write(variable, writtenType));
1174+
void write(Variable variable, Type writtenType,
1175+
{bool viaInitializer = false}) {
1176+
_wrap(
1177+
'write($variable, $writtenType, viaInitializer: $viaInitializer)',
1178+
() => _wrapped.write(variable, writtenType,
1179+
viaInitializer: viaInitializer));
11621180
}
11631181

11641182
T _wrap<T>(String description, T callback(),
@@ -1770,11 +1788,6 @@ abstract class TypeOperations<Variable, Type> {
17701788
List<Type> newPromotedTypes) =>
17711789
false;
17721790

1773-
/// Return `true` if the [variable] is a local variable (not a formal
1774-
/// parameter), and it has no declared type (no explicit type, and not
1775-
/// initializer).
1776-
bool isLocalVariableWithoutDeclaredType(Variable variable);
1777-
17781791
/// Determines whether the given [type] is equivalent to the `Never` type.
17791792
///
17801793
/// A type is equivalent to `Never` if it:
@@ -1985,11 +1998,6 @@ class VariableModel<Variable, Type> {
19851998
promotedTypes, tested, true, false, writeCaptured);
19861999
}
19872000

1988-
if (_isPromotableViaInitialization(typeOperations, variable)) {
1989-
return new VariableModel<Variable, Type>(
1990-
[writtenType], tested, true, false, writeCaptured);
1991-
}
1992-
19932001
List<Type> newPromotedTypes = _demoteViaAssignment(
19942002
writtenType,
19952003
typeOperations,
@@ -2041,26 +2049,6 @@ class VariableModel<Variable, Type> {
20412049
}
20422050
}
20432051

2044-
/// We say that a variable `x` is promotable via initialization given
2045-
/// variable model `VM` if `x` is a local variable (not a formal parameter)
2046-
/// and:
2047-
/// * VM = VariableModel(declared, promoted, tested,
2048-
/// assigned, unassigned, captured)
2049-
/// * and `captured` is false
2050-
/// * and `promoted` is empty
2051-
/// * and `x` is declared with no explicit type and no initializer
2052-
/// * and `assigned` is false and `unassigned` is true
2053-
bool _isPromotableViaInitialization<Variable>(
2054-
TypeOperations<Variable, Type> typeOperations,
2055-
Variable variable,
2056-
) {
2057-
return !writeCaptured &&
2058-
!assigned &&
2059-
unassigned &&
2060-
promotedTypes == null &&
2061-
typeOperations.isLocalVariableWithoutDeclaredType(variable);
2062-
}
2063-
20642052
/// Determines whether a variable with the given [promotedTypes] should be
20652053
/// promoted to [writtenType] based on types of interest. If it should,
20662054
/// returns an updated promotion chain; otherwise returns [promotedTypes]
@@ -2902,6 +2890,12 @@ class _FlowAnalysisImpl<Node, Statement extends Node, Expression, Variable,
29022890
}
29032891
}
29042892

2893+
@override
2894+
void promote(Variable variable, Type type) {
2895+
_current =
2896+
_current.tryPromoteForTypeCheck(typeOperations, variable, type).ifTrue;
2897+
}
2898+
29052899
@override
29062900
Type promotedType(Variable variable) {
29072901
return _current.infoFor(variable).promotedTypes?.last;
@@ -3055,11 +3049,14 @@ class _FlowAnalysisImpl<Node, Statement extends Node, Expression, Variable,
30553049
}
30563050

30573051
@override
3058-
void write(Variable variable, Type writtenType) {
3059-
assert(
3060-
_assignedVariables._anywhere._written.contains(variable),
3061-
"Variable is written to, but was not included in "
3062-
"_variablesWrittenAnywhere: $variable");
3052+
void write(Variable variable, Type writtenType,
3053+
{bool viaInitializer = false}) {
3054+
if (!viaInitializer) {
3055+
assert(
3056+
_assignedVariables._anywhere._written.contains(variable),
3057+
"Variable is written to, but was not included in "
3058+
"_variablesWrittenAnywhere: $variable");
3059+
}
30633060
_current = _current.write(variable, writtenType, typeOperations);
30643061
}
30653062

pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4012,6 +4012,32 @@ Message _withArgumentsFinalFieldWithoutInitializer(String name) {
40124012
arguments: {'name': name});
40134013
}
40144014

4015+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
4016+
const Template<
4017+
Message Function(
4018+
String
4019+
name)> templateFinalNotAssignedError = const Template<
4020+
Message Function(String name)>(
4021+
messageTemplate:
4022+
r"""Final variable '#name' must be assigned before it can be used.""",
4023+
withArguments: _withArgumentsFinalNotAssignedError);
4024+
4025+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
4026+
const Code<Message Function(String name)> codeFinalNotAssignedError =
4027+
const Code<Message Function(String name)>(
4028+
"FinalNotAssignedError", templateFinalNotAssignedError,
4029+
analyzerCodes: <String>["READ_POTENTIALLY_UNASSIGNED_FINAL"]);
4030+
4031+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
4032+
Message _withArgumentsFinalNotAssignedError(String name) {
4033+
if (name.isEmpty) throw 'No name provided';
4034+
name = demangleMixinApplicationName(name);
4035+
return new Message(codeFinalNotAssignedError,
4036+
message:
4037+
"""Final variable '${name}' must be assigned before it can be used.""",
4038+
arguments: {'name': name});
4039+
}
4040+
40154041
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
40164042
const Code<Null> codeForInLoopExactlyOneVariable =
40174043
messageForInLoopExactlyOneVariable;

pkg/_fe_analyzer_shared/test/flow_analysis/flow_analysis_test.dart

Lines changed: 49 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,54 @@ main() {
14431443
});
14441444
});
14451445

1446+
test('promote promotes to a subtype and sets type of interest', () {
1447+
var h = _Harness();
1448+
var x = h.addVar('x', 'num?');
1449+
h.assignedVariables((vars) {
1450+
vars.write(x);
1451+
});
1452+
h.run((flow) {
1453+
flow.declare(x, true);
1454+
expect(flow.promotedType(x), isNull);
1455+
flow.promote(x, _Type('num'));
1456+
expect(flow.promotedType(x).type, 'num');
1457+
// Check that it's a type of interest by promoting and de-promoting.
1458+
h.if_(h.isType(h.variableRead(x), 'int'), () {
1459+
expect(flow.promotedType(x).type, 'int');
1460+
flow.write(x, _Type('num'));
1461+
expect(flow.promotedType(x).type, 'num');
1462+
});
1463+
});
1464+
});
1465+
1466+
test('promote does not promote to a non-subtype', () {
1467+
var h = _Harness();
1468+
var x = h.addVar('x', 'num?');
1469+
h.run((flow) {
1470+
flow.declare(x, true);
1471+
expect(flow.promotedType(x), isNull);
1472+
flow.promote(x, _Type('String'));
1473+
expect(flow.promotedType(x), isNull);
1474+
});
1475+
});
1476+
1477+
test('promote does not promote if variable is write-captured', () {
1478+
var h = _Harness();
1479+
var x = h.addVar('x', 'num?');
1480+
var functionNode = _Node();
1481+
h.assignedVariables(
1482+
(vars) => vars.function(functionNode, () => vars.write(x)));
1483+
h.run((flow) {
1484+
flow.declare(x, true);
1485+
expect(flow.promotedType(x), isNull);
1486+
flow.functionExpression_begin(functionNode);
1487+
flow.write(x, _Type('num'));
1488+
flow.functionExpression_end();
1489+
flow.promote(x, _Type('num'));
1490+
expect(flow.promotedType(x), isNull);
1491+
});
1492+
});
1493+
14461494
test('promotedType handles not-yet-seen variables', () {
14471495
// Note: this is needed for error recovery in the analyzer.
14481496
var h = _Harness();
@@ -2658,21 +2706,6 @@ main() {
26582706
});
26592707
});
26602708
});
2661-
2662-
test('promote via initialization', () {
2663-
var h = _Harness();
2664-
var x = _Var('x', null, isLocalVariableWithoutDeclaredType: true);
2665-
2666-
var s1 = FlowModel<_Var, _Type>(true).declare(x, false);
2667-
expect(s1.variableInfo, {
2668-
x: _matchVariableModel(chain: null),
2669-
});
2670-
2671-
var s2 = s1.write(x, _Type('int'), h);
2672-
expect(s2.variableInfo, {
2673-
x: _matchVariableModel(chain: ['int']),
2674-
});
2675-
});
26762709
});
26772710

26782711
group('demotion, to NonNull', () {
@@ -3789,11 +3822,6 @@ class _Harness extends TypeOperations<_Var, _Type> {
37893822
if_(isNotType(variableRead(variable), type), ifTrue);
37903823
}
37913824

3792-
@override
3793-
bool isLocalVariableWithoutDeclaredType(_Var variable) {
3794-
return variable.isLocalVariableWithoutDeclaredType;
3795-
}
3796-
37973825
@override
37983826
bool isNever(_Type type) {
37993827
return type.type == 'Never';
@@ -3956,13 +3984,8 @@ class _Type {
39563984
class _Var {
39573985
final String name;
39583986
final _Type type;
3959-
final bool isLocalVariableWithoutDeclaredType;
39603987

3961-
_Var(
3962-
this.name,
3963-
this.type, {
3964-
this.isLocalVariableWithoutDeclaredType = false,
3965-
});
3988+
_Var(this.name, this.type);
39663989

39673990
@override
39683991
String toString() => '$type $name';

0 commit comments

Comments
 (0)