Skip to content

Commit

Permalink
Version 2.11.0-164.0.dev
Browse files Browse the repository at this point in the history
Merge commit '02923c6f83a03ca729e5418e7c0e3369912ed5cd' into 'dev'
  • Loading branch information
Dart CI committed Sep 25, 2020
2 parents 45e4923 + 02923c6 commit 13b3f2d
Show file tree
Hide file tree
Showing 65 changed files with 2,881 additions and 736 deletions.
79 changes: 55 additions & 24 deletions pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,26 @@ abstract class FlowAnalysis<Node, Statement extends Node, Expression, Variable,
/// collection element. See [forEach_bodyBegin] for details.
void forEach_end();

/// Call this method to forward information on [oldExpression] to
/// [newExpression].
///
/// This can be used to preserve promotions through a replacement from
/// [oldExpression] to [newExpression]. For instance when rewriting
///
/// method(int i) {
/// if (i is int) { ... } else { ... }
/// }
///
/// to
///
/// method(int i) {
/// if (i is int || throw ...) { ... } else { ... }
/// }
///
/// the promotion `i is int` can be forwarded to `i is int || throw ...` and
/// there preserved in the surrounding if statement.
void forwardExpression(Expression newExpression, Expression oldExpression);

/// Call this method just before visiting the body of a function expression or
/// local function.
///
Expand Down Expand Up @@ -915,6 +935,12 @@ class FlowAnalysisDebug<Node, Statement extends Node, Expression, Variable,
return _wrap('forEach_end()', () => _wrapped.forEach_end());
}

@override
void forwardExpression(Expression newExpression, Expression oldExpression) {
return _wrap('forwardExpression($newExpression, $oldExpression)',
() => _wrapped.forwardExpression(newExpression, oldExpression));
}

@override
void functionExpression_begin(Node node) {
_wrap('functionExpression_begin($node)',
Expand Down Expand Up @@ -1561,9 +1587,17 @@ class FlowModel<Variable, Type> {
}

Type factoredType = typeOperations.factor(previousType, type);
Type typeIfFailed = typeOperations.isSameType(factoredType, previousType)
? null
: factoredType;
Type typeIfFailed;
if (typeOperations.isNever(factoredType)) {
// Promoting to `Never` would mark the code as unreachable. But it might
// be reachable due to mixed mode unsoundness. So don't promote.
typeIfFailed = null;
} else if (typeOperations.isSameType(factoredType, previousType)) {
// No change to the type, so don't promote.
typeIfFailed = null;
} else {
typeIfFailed = factoredType;
}
FlowModel<Variable, Type> modelIfFailed =
_finishTypeTest(typeOperations, variable, info, type, typeIfFailed);

Expand Down Expand Up @@ -2564,8 +2598,11 @@ class _FlowAnalysisImpl<Node, Statement extends Node, Expression, Variable,
(rightOperandTypeClassification ==
TypeClassification.nullOrEquivalent &&
leftOperandTypeClassification == TypeClassification.nonNullable)) {
booleanLiteral(wholeExpression, notEqual);
return false;
// In strong mode the test is guaranteed to produce a "not equal" result,
// but weak mode it might produce an "equal" result. We don't want flow
// analysis behavior to depend on mode, so we conservatively assume that
// either result is possible.
return true;
} else if (lhsInfo is _NullInfo<Variable, Type> &&
rhsInfo is _VariableReadInfo<Variable, Type>) {
assert(
Expand All @@ -2581,7 +2618,7 @@ class _FlowAnalysisImpl<Node, Statement extends Node, Expression, Variable,
}
_storeExpressionInfo(wholeExpression,
notEqual ? equalityInfo : ExpressionInfo.invert(equalityInfo));
return equalityInfo.ifFalse.reachable;
return true;
}

@override
Expand Down Expand Up @@ -2655,6 +2692,13 @@ class _FlowAnalysisImpl<Node, Statement extends Node, Expression, Variable,
_current = _join(_current, context._previous);
}

@override
void forwardExpression(Expression newExpression, Expression oldExpression) {
if (identical(_expressionWithInfo, oldExpression)) {
_expressionWithInfo = newExpression;
}
}

@override
void functionExpression_begin(Node node) {
AssignedVariablesNodeInfo<Variable> info =
Expand Down Expand Up @@ -2720,12 +2764,8 @@ class _FlowAnalysisImpl<Node, Statement extends Node, Expression, Variable,
} else {
promoted = _current;
}
if (typeOperations.classifyType(leftHandSideType) ==
TypeClassification.nonNullable) {
_current = _current.setReachable(false);
}
_stack.add(new _SimpleContext<Variable, Type>(promoted));
return _current.reachable;
return true;
}

@override
Expand Down Expand Up @@ -2779,7 +2819,7 @@ class _FlowAnalysisImpl<Node, Statement extends Node, Expression, Variable,
_current.tryPromoteForTypeCheck(typeOperations, variable, type);
_storeExpressionInfo(isExpression,
isNot ? ExpressionInfo.invert(expressionInfo) : expressionInfo);
return expressionInfo.ifFalse.reachable;
return true;
}

@override
Expand Down Expand Up @@ -2858,14 +2898,7 @@ class _FlowAnalysisImpl<Node, Statement extends Node, Expression, Variable,
@override
bool nullAwareAccess_rightBegin(Expression target, Type targetType) {
assert(targetType != null);
bool shortingIsReachable = true;
FlowModel<Variable, Type> shortingModel = _current;
if (typeOperations.classifyType(targetType) ==
TypeClassification.nonNullable) {
shortingModel = shortingModel.setReachable(false);
shortingIsReachable = false;
}
_stack.add(new _SimpleContext<Variable, Type>(shortingModel));
_stack.add(new _SimpleContext<Variable, Type>(_current));
if (target != null) {
ExpressionInfo<Variable, Type> targetInfo = _getExpressionInfo(target);
if (targetInfo is _VariableReadInfo<Variable, Type>) {
Expand All @@ -2874,7 +2907,7 @@ class _FlowAnalysisImpl<Node, Statement extends Node, Expression, Variable,
.ifTrue;
}
}
return shortingIsReachable;
return true;
}

@override
Expand All @@ -2885,9 +2918,7 @@ class _FlowAnalysisImpl<Node, Statement extends Node, Expression, Variable,
@override
void parenthesizedExpression(
Expression outerExpression, Expression innerExpression) {
if (identical(_expressionWithInfo, innerExpression)) {
_expressionWithInfo = outerExpression;
}
forwardExpression(outerExpression, innerExpression);
}

@override
Expand Down
39 changes: 39 additions & 0 deletions pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6367,6 +6367,45 @@ const MessageCode messageNativeClauseShouldBeAnnotation = const MessageCode(
tip:
r"""Try removing this native clause and adding @native() or @native('native-name') before the declaration.""");

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeNeverReachableSwitchDefaultError =
messageNeverReachableSwitchDefaultError;

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageNeverReachableSwitchDefaultError = const MessageCode(
"NeverReachableSwitchDefaultError",
message:
r"""`null` encountered as case in a switch expression with a non-nullable enum type.""");

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeNeverReachableSwitchDefaultWarning =
messageNeverReachableSwitchDefaultWarning;

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageNeverReachableSwitchDefaultWarning = const MessageCode(
"NeverReachableSwitchDefaultWarning",
severity: Severity.warning,
message:
r"""The default case is not reachable with sound null safety because the switch expression is non-nullable.""");

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeNeverValueError = messageNeverValueError;

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageNeverValueError = const MessageCode("NeverValueError",
message:
r"""`null` encountered as the result from expression with type `Never`.""");

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Null> codeNeverValueWarning = messageNeverValueWarning;

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const MessageCode messageNeverValueWarning = const MessageCode(
"NeverValueWarning",
severity: Severity.warning,
message:
r"""The expression can not result in a value with sound null safety because the expression type is `Never`.""");

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Template<
Message Function(Token token)> templateNoFormals = const Template<
Expand Down
Loading

0 comments on commit 13b3f2d

Please sign in to comment.