Skip to content

Commit 99919c6

Browse files
stereotype441Commit Bot
authored and
Commit Bot
committed
Flow analysis: Separate variable and type operations.
This change moves the `variableType` method from the class `TypeOperations` to a new class, `VariableOperations`, which in turn allows removing the type parameter `Variable` parameter from `TypeOperations`. A new class, `Operations`, is introduced to serve the role served previously by `TypeOperations` for flow analysis clients (i.e. it is the base class that clients should extend). This paves the way for a future CL that will remove the type parameter `Variable` from other classes inside flow analysis. Bug: dart-lang/language#2020 Change-Id: Ic45d07a0f873b692fda4b6f807c1130ac592b010 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/250108 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent ec9a660 commit 99919c6

File tree

6 files changed

+117
-122
lines changed

6 files changed

+117
-122
lines changed

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

Lines changed: 96 additions & 98 deletions
Large diffs are not rendered by default.

pkg/_fe_analyzer_shared/test/mini_ast.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ abstract class Expression extends Node {
247247
}
248248

249249
/// Test harness for creating flow analysis tests. This class implements all
250-
/// the [TypeOperations] needed by flow analysis, as well as other methods
251-
/// needed for testing.
252-
class Harness extends TypeOperations<Var, Type> {
250+
/// the [Operations] needed by flow analysis, as well as other methods needed
251+
/// for testing.
252+
class Harness extends Operations<Var, Type> {
253253
static const Map<String, bool> _coreSubtypes = const {
254254
'bool <: int': false,
255255
'bool <: Object': true,
@@ -1486,7 +1486,7 @@ class _MiniAstTypeAnalyzer {
14861486
var rightType = analyzeExpression(rhs);
14871487
flow.ifNullExpression_end();
14881488
return leastUpperBound(
1489-
flow.typeOperations.promoteToNonNull(leftType), rightType);
1489+
flow.operations.promoteToNonNull(leftType), rightType);
14901490
}
14911491

14921492
void analyzeIfStatement(Statement node, Expression condition,
@@ -1520,7 +1520,7 @@ class _MiniAstTypeAnalyzer {
15201520
Type analyzeNonNullAssert(Expression node, Expression expression) {
15211521
var type = analyzeExpression(expression);
15221522
flow.nonNullAssert_end(expression);
1523-
return flow.typeOperations.promoteToNonNull(type);
1523+
return flow.operations.promoteToNonNull(type);
15241524
}
15251525

15261526
Type analyzeNullLiteral(Expression node) {

pkg/analyzer/lib/src/dart/resolver/flow_analysis_visitor.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class FlowAnalysisDataForTesting {
5959
/// be extracted.
6060
class FlowAnalysisHelper {
6161
/// The reused instance for creating new [FlowAnalysis] instances.
62-
final TypeSystemTypeOperations _typeOperations;
62+
final TypeSystemOperations _typeOperations;
6363

6464
/// Precomputed sets of potentially assigned variables.
6565
AssignedVariables<AstNode, PromotableElement>? assignedVariables;
@@ -82,7 +82,7 @@ class FlowAnalysisHelper {
8282

8383
FlowAnalysisHelper(TypeSystemImpl typeSystem, bool retainDataForTesting,
8484
FeatureSet featureSet)
85-
: this._(TypeSystemTypeOperations(typeSystem),
85+
: this._(TypeSystemOperations(typeSystem),
8686
retainDataForTesting ? FlowAnalysisDataForTesting() : null,
8787
isNonNullableByDefault: featureSet.isEnabled(Feature.non_nullable),
8888
respectImplicitlyTypedVarInitializers:
@@ -375,11 +375,10 @@ class FlowAnalysisHelperForMigration extends FlowAnalysisHelper {
375375
}
376376
}
377377

378-
class TypeSystemTypeOperations
379-
extends TypeOperations<PromotableElement, DartType> {
378+
class TypeSystemOperations extends Operations<PromotableElement, DartType> {
380379
final TypeSystemImpl typeSystem;
381380

382-
TypeSystemTypeOperations(this.typeSystem);
381+
TypeSystemOperations(this.typeSystem);
383382

384383
@override
385384
TypeClassification classifyType(DartType type) {

pkg/front_end/lib/src/fasta/type_inference/type_inference_engine.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,10 @@ class FlowAnalysisResult {
260260
}
261261

262262
/// CFE-specific implementation of [TypeOperations].
263-
class TypeOperationsCfe extends TypeOperations<VariableDeclaration, DartType> {
263+
class OperationsCfe extends Operations<VariableDeclaration, DartType> {
264264
final TypeEnvironment typeEnvironment;
265265

266-
TypeOperationsCfe(this.typeEnvironment);
266+
OperationsCfe(this.typeEnvironment);
267267

268268
@override
269269
TypeClassification classifyType(DartType? type) {

pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,14 @@ class TypeInferrerImpl implements TypeInferrer {
228228

229229
@override
230230
late final FlowAnalysis<TreeNode, Statement, Expression, VariableDeclaration,
231-
DartType> flowAnalysis =
232-
libraryBuilder.isNonNullableByDefault
233-
? new FlowAnalysis(
234-
new TypeOperationsCfe(engine.typeSchemaEnvironment),
235-
assignedVariables,
236-
respectImplicitlyTypedVarInitializers:
237-
libraryBuilder.libraryFeatures.constructorTearoffs.isEnabled)
238-
: new FlowAnalysis.legacy(
239-
new TypeOperationsCfe(engine.typeSchemaEnvironment),
240-
assignedVariables);
231+
DartType> flowAnalysis = libraryBuilder
232+
.isNonNullableByDefault
233+
? new FlowAnalysis(
234+
new OperationsCfe(engine.typeSchemaEnvironment), assignedVariables,
235+
respectImplicitlyTypedVarInitializers:
236+
libraryBuilder.libraryFeatures.constructorTearoffs.isEnabled)
237+
: new FlowAnalysis.legacy(
238+
new OperationsCfe(engine.typeSchemaEnvironment), assignedVariables);
241239

242240
@override
243241
final AssignedVariables<TreeNode, VariableDeclaration> assignedVariables;

pkg/nnbd_migration/lib/src/decorated_type_operations.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import 'package:nnbd_migration/src/edge_origin.dart';
1111
import 'package:nnbd_migration/src/nullability_node.dart';
1212
import 'package:nnbd_migration/src/variables.dart';
1313

14-
/// [TypeOperations] that works with [DecoratedType]s.
14+
/// [Operations] that works with [DecoratedType]s.
1515
class DecoratedTypeOperations
16-
implements TypeOperations<PromotableElement, DecoratedType> {
16+
implements Operations<PromotableElement, DecoratedType> {
1717
final TypeSystem _typeSystem;
1818
final Variables? _variableRepository;
1919
final NullabilityGraph _graph;

0 commit comments

Comments
 (0)