Skip to content

Commit b60e0aa

Browse files
johnniwinthercommit-bot@chromium.org
authored andcommitted
Revert "[kernel] Ensure that visitors don't implicitly returns null"
This reverts commit ce81216. Reason for revert: Flutter dependency Original change's description: > [kernel] Ensure that visitors don't implicitly returns `null` > > This is in preparation to migrate package:kernel to null safety. > For the visitor interfaces to support non-nullable return types, the > implementations must avoid using `null` as return value in its base case. > > TEST=Refactoring > > Change-Id: Ie5e4153f8d3779d94957bb13b3d2d2a942040ff2 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/179760 > Commit-Queue: Johnni Winther <[email protected]> > Reviewed-by: Jens Johansen <[email protected]> [email protected],[email protected] Change-Id: I61b838d3371e6b1de2427716d056324c120be499 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/183689 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent 5c4a916 commit b60e0aa

Some content is hidden

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

44 files changed

+103
-261
lines changed

pkg/_js_interop_checks/lib/js_interop_checks.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import 'package:_fe_analyzer_shared/src/messages/codes.dart'
2323

2424
import 'src/js_interop.dart';
2525

26-
class JsInteropChecks extends RecursiveVisitor {
26+
class JsInteropChecks extends RecursiveVisitor<void> {
2727
final CoreTypes _coreTypes;
2828
final DiagnosticReporter<Message, LocatedMessage> _diagnosticsReporter;
2929
final Map<String, Class> _nativeClasses;

pkg/compiler/lib/src/inferrer/builder_kernel.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ import 'type_system.dart';
3737
/// Calling [run] will start the work of visiting the body of the code to
3838
/// construct a set of inference-nodes that abstractly represent what the code
3939
/// is doing.
40-
class KernelTypeGraphBuilder extends ir.Visitor<TypeInformation>
41-
with ir.VisitorNullMixin<TypeInformation> {
40+
class KernelTypeGraphBuilder extends ir.Visitor<TypeInformation> {
4241
final CompilerOptions _options;
4342
final JsClosedWorld _closedWorld;
4443
final InferrerEngine _inferrer;

pkg/compiler/lib/src/ir/debug.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import 'package:kernel/visitor.dart';
1111

1212
import '../util/util.dart' show Indentation, Tagging;
1313

14-
class DebugPrinter extends Visitor<void>
15-
with Indentation, Tagging<Node>, VisitorVoidMixin {
14+
class DebugPrinter extends Visitor with Indentation, Tagging<Node> {
1615
@override
1716
StringBuffer sb = new StringBuffer();
1817

pkg/compiler/lib/src/ir/scope_visitor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import 'scope.dart';
1414
/// a [VariableScopeModel] that can respond to queries about how a particular
1515
/// variable is being used at any point in the code.
1616
class ScopeModelBuilder extends ir.Visitor<EvaluationComplexity>
17-
with VariableCollectorMixin, ir.VisitorNullMixin<EvaluationComplexity> {
17+
with VariableCollectorMixin {
1818
final Dart2jsConstantEvaluator _constantEvaluator;
1919
ir.StaticTypeContext _staticTypeContext;
2020

pkg/compiler/lib/src/ir/static_type_base.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ class ExactInterfaceType extends ir.InterfaceType {
5757
/// expression kind. For instance method invocations whose static type depend
5858
/// on the static types of the receiver and type arguments and the signature
5959
/// of the targeted procedure.
60-
abstract class StaticTypeBase extends ir.Visitor<ir.DartType>
61-
with ir.VisitorNullMixin<ir.DartType> {
60+
abstract class StaticTypeBase extends ir.Visitor<ir.DartType> {
6261
final ir.TypeEnvironment _typeEnvironment;
6362

6463
StaticTypeBase(this._typeEnvironment);

pkg/compiler/lib/src/ir/visitors.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ class Stringifier extends ir.ExpressionVisitor<String> {
3535
}
3636
return null;
3737
}
38-
39-
@override
40-
String defaultExpression(ir.Expression node) => null;
4138
}
4239

4340
/// Visitor that converts kernel dart types into [DartType].
@@ -185,11 +182,6 @@ class DartTypeConverter extends ir.DartTypeVisitor<DartType> {
185182
DartType visitNullType(ir.NullType node) {
186183
return elementMap.commonElements.nullType;
187184
}
188-
189-
@override
190-
DartType defaultDartType(ir.DartType node) {
191-
throw UnsupportedError('Unsupported type $node (${node.runtimeType})');
192-
}
193185
}
194186

195187
class ConstantValuefier extends ir.ComputeOnceConstantVisitor<ConstantValue> {

pkg/compiler/lib/src/js_model/locals.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class KernelToLocalsMapImpl implements KernelToLocalsMap {
292292
}
293293
}
294294

295-
class JumpVisitor extends ir.Visitor<void> with ir.VisitorVoidMixin {
295+
class JumpVisitor extends ir.Visitor {
296296
int jumpIndex = 0;
297297
int labelIndex = 0;
298298
final MemberEntity member;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ part of 'serialization.dart';
66

77
/// Visitor that ascribes an index to all [ir.TreeNode]s that potentially
88
/// needed for serialization and deserialization.
9-
class _TreeNodeIndexerVisitor extends ir.Visitor<void>
10-
with ir.VisitorVoidMixin {
9+
class _TreeNodeIndexerVisitor extends ir.Visitor<void> {
1110
int _currentIndex = 0;
1211
final Map<int, ir.TreeNode> _indexToNodeMap;
1312
final Map<ir.TreeNode, int> _nodeToIndexMap;

pkg/compiler/lib/src/ssa/builder_kernel.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class StackFrame {
8484
this.staticTypeProvider);
8585
}
8686

87-
class KernelSsaGraphBuilder extends ir.Visitor<void> with ir.VisitorVoidMixin {
87+
class KernelSsaGraphBuilder extends ir.Visitor {
8888
/// Holds the resulting SSA graph.
8989
final HGraph graph = new HGraph();
9090

@@ -6560,8 +6560,7 @@ class KernelTypeBuilder extends TypeBuilder {
65606560
}
65616561
}
65626562

6563-
class _ErroneousInitializerVisitor extends ir.Visitor<bool>
6564-
with ir.VisitorDefaultValueMixin<bool> {
6563+
class _ErroneousInitializerVisitor extends ir.Visitor<bool> {
65656564
_ErroneousInitializerVisitor();
65666565

65676566
// TODO(30809): Use const constructor.
@@ -6581,7 +6580,7 @@ class _ErroneousInitializerVisitor extends ir.Visitor<bool>
65816580

65826581
// Expressions: Does the expression always throw?
65836582
@override
6584-
bool get defaultValue => false;
6583+
bool defaultExpression(ir.Expression node) => false;
65856584

65866585
@override
65876586
bool visitThrow(ir.Throw node) => true;
@@ -6840,7 +6839,7 @@ class InlineDataCache {
68406839
}
68416840
}
68426841

6843-
class InlineWeeder extends ir.Visitor<void> with ir.VisitorVoidMixin {
6842+
class InlineWeeder extends ir.Visitor {
68446843
// Invariant: *INSIDE_LOOP* > *OUTSIDE_LOOP*
68456844
static const INLINING_NODES_OUTSIDE_LOOP = 15;
68466845
static const INLINING_NODES_OUTSIDE_LOOP_ARG_FACTOR = 3;
@@ -7398,8 +7397,7 @@ class InlineWeeder extends ir.Visitor<void> with ir.VisitorVoidMixin {
73987397

73997398
/// Visitor to detect environment-rewriting that prevents inlining
74007399
/// (e.g. closures).
7401-
class InlineWeederBodyClosure extends ir.Visitor<void>
7402-
with ir.VisitorVoidMixin {
7400+
class InlineWeederBodyClosure extends ir.Visitor<void> {
74037401
bool tooDifficult = false;
74047402

74057403
InlineWeederBodyClosure();

pkg/compiler/lib/src/ssa/kernel_string_builder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'builder_kernel.dart';
1010
import 'nodes.dart';
1111

1212
/// Visits and concatenates the expressions in a string concatenation.
13-
class KernelStringBuilder extends ir.Visitor<void> with ir.VisitorVoidMixin {
13+
class KernelStringBuilder extends ir.Visitor {
1414
final KernelSsaGraphBuilder builder;
1515

1616
/// The string value generated so far.

pkg/compiler/lib/src/ssa/loop_handler.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,9 @@ class KernelLoopHandler extends LoopHandler {
329329
int loopKind(ir.TreeNode node) => node.accept(new _KernelLoopTypeVisitor());
330330
}
331331

332-
class _KernelLoopTypeVisitor extends ir.Visitor<int>
333-
with ir.VisitorDefaultValueMixin<int> {
332+
class _KernelLoopTypeVisitor extends ir.Visitor<int> {
334333
@override
335-
int get defaultValue => HLoopBlockInformation.NOT_A_LOOP;
334+
int defaultNode(ir.Node node) => HLoopBlockInformation.NOT_A_LOOP;
336335

337336
@override
338337
int visitWhileStatement(ir.WhileStatement node) =>

pkg/compiler/lib/src/ssa/switch_continue_analysis.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import 'package:kernel/ast.dart' as ir;
77
/// Helper class that traverses a kernel AST subtree to see if it has any
88
/// continue statements in the body of any switch cases (having continue
99
/// statements results in a more complex generated code).
10-
class SwitchContinueAnalysis extends ir.Visitor<bool>
11-
with ir.VisitorDefaultValueMixin<bool> {
10+
class SwitchContinueAnalysis extends ir.Visitor<bool> {
1211
SwitchContinueAnalysis._();
1312

1413
static bool containsContinue(ir.Statement switchCaseBody) {
@@ -128,5 +127,5 @@ class SwitchContinueAnalysis extends ir.Visitor<bool>
128127
}
129128

130129
@override
131-
bool get defaultValue => false;
130+
bool defaultNode(ir.Node node) => false;
132131
}

pkg/dev_compiler/lib/src/kernel/expression_compiler.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ import 'package:kernel/ast.dart'
3636
TreeNode,
3737
TypeParameter,
3838
VariableDeclaration,
39-
Visitor,
40-
VisitorNullMixin,
41-
VisitorVoidMixin;
39+
Visitor;
4240

4341
DiagnosticMessage _createInternalError(Uri uri, int line, int col, String msg) {
4442
return Message(Code<String>('Expression Compiler Internal error'),
@@ -86,7 +84,7 @@ class DartScope {
8684
/// - locals
8785
/// - formals
8886
/// - captured variables (for closures)
89-
class DartScopeBuilder extends Visitor<void> with VisitorVoidMixin {
87+
class DartScopeBuilder extends Visitor<void> {
9088
final Component _component;
9189
final int _line;
9290
final int _column;
@@ -198,7 +196,7 @@ class DartScopeBuilder extends Visitor<void> with VisitorVoidMixin {
198196
/// that do not have .fileEndOffset field.
199197
///
200198
/// For example - [Block]
201-
class FileEndOffsetCalculator extends Visitor<int> with VisitorNullMixin<int> {
199+
class FileEndOffsetCalculator extends Visitor<int> {
202200
static const int noOffset = -1;
203201

204202
final int _startOffset;
@@ -268,7 +266,7 @@ class FileEndOffsetCalculator extends Visitor<int> with VisitorNullMixin<int> {
268266
/// in the JavaScript scope, so we need to redefine them.
269267
///
270268
/// See [_addSymbolDefinitions]
271-
class PrivateFieldsVisitor extends Visitor<void> with VisitorVoidMixin {
269+
class PrivateFieldsVisitor extends Visitor<void> {
272270
final Map<String, Library> privateFields = {};
273271

274272
@override

pkg/dev_compiler/lib/src/kernel/kernel_helpers.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,6 @@ class LabelContinueFinder extends StatementVisitor<void> {
332332
visit(node.body);
333333
visit(node.finalizer);
334334
}
335-
336-
@override
337-
void defaultStatement(Statement node) {}
338335
}
339336

340337
/// Ensures that all of the known DartType implementors are handled.

pkg/dev_compiler/lib/src/kernel/nullable_inference.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ class NullableInference extends ExpressionVisitor<bool> {
364364
/// variables that have already been determined to be nullable.
365365
///
366366
// TODO(jmesserly): Introduce flow analysis.
367-
class _NullableVariableInference extends RecursiveVisitor {
367+
class _NullableVariableInference extends RecursiveVisitor<void> {
368368
NullableInference _nullInference;
369369

370370
/// Variables that are currently believed to be not-null.

pkg/dev_compiler/lib/src/kernel/target.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class DevCompilerTarget extends Target {
245245
/// members can be eliminated, and adjusts the flags to remove those checks.
246246
///
247247
/// See [_CovarianceTransformer.transform].
248-
class _CovarianceTransformer extends RecursiveVisitor {
248+
class _CovarianceTransformer extends RecursiveVisitor<void> {
249249
/// The set of private instance members in [_library] that (potentially) need
250250
/// covariance checks.
251251
///

pkg/dev_compiler/test/expression_compiler/scope_offset_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void main(List<String> args) {
3434
});
3535
}
3636

37-
class ScopeOffsetValidator extends Visitor<void> with VisitorVoidMixin {
37+
class ScopeOffsetValidator extends Visitor<void> {
3838
int classCount = 0;
3939
int memberCount = 0;
4040
int blockCount = 0;

pkg/dev_compiler/test/nullable_inference_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ Future expectAllNotNull(String code) async {
536536
bool useAnnotations = false;
537537
NullableInference inference;
538538

539-
class _TestRecursiveVisitor extends RecursiveVisitor {
539+
class _TestRecursiveVisitor extends RecursiveVisitor<void> {
540540
final Set<Library> librariesFromDill;
541541
int _functionNesting = 0;
542542
TypeEnvironment _typeEnvironment;

pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ class ConstantsTransformer extends Transformer {
792792
}
793793
}
794794

795-
class ConstantEvaluator extends RecursiveResultVisitor<Constant> {
795+
class ConstantEvaluator extends RecursiveVisitor<Constant> {
796796
final ConstantsBackend backend;
797797
final NumberSemantics numberSemantics;
798798
ConstantIntFolder intFolder;

pkg/front_end/lib/src/testing/id_extractor.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ TreeNode computeTreeNodeWithOffset(TreeNode node) {
3333

3434
/// Abstract visitor for computing data corresponding to a node or element,
3535
/// and record it with a generic [Id]
36-
abstract class DataExtractor<T> extends Visitor<void>
37-
with VisitorVoidMixin, DataRegistry<T> {
36+
abstract class DataExtractor<T> extends Visitor with DataRegistry<T> {
3837
@override
3938
final Map<Id, ActualData<T>> actualMap;
4039

pkg/front_end/test/comments_on_certain_arguments_tool.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ api.CompilerOptions getOptions() {
159159
return options;
160160
}
161161

162-
class InvocationVisitor extends RecursiveVisitor {
162+
class InvocationVisitor extends RecursiveVisitor<void> {
163163
void visitProcedure(Procedure node) {
164164
if (node.isNoSuchMethodForwarder) return;
165165
super.visitProcedure(node);

pkg/front_end/test/fasta/assert_locations_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void main() {}
102102

103103
/// Visitor that verifies that all [AssertStatement]s in the Kernel AST
104104
/// have expected spans for their conditions.
105-
class VerifyingVisitor extends RecursiveVisitor {
105+
class VerifyingVisitor extends RecursiveVisitor<Null> {
106106
final Test test;
107107

108108
/// Set of names of verified [Procedure]s.

pkg/front_end/test/fasta/testing/suite.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,14 @@ import 'package:kernel/ast.dart'
109109
TreeNode,
110110
UnevaluatedConstant,
111111
Version,
112-
Visitor,
113-
VisitorVoidMixin;
112+
Visitor;
114113

115114
import 'package:kernel/class_hierarchy.dart' show ClassHierarchy;
116115

117116
import 'package:kernel/core_types.dart' show CoreTypes;
118117

119118
import 'package:kernel/kernel.dart'
120-
show RecursiveResultVisitor, loadComponentFromBytes;
119+
show RecursiveVisitor, loadComponentFromBytes;
121120

122121
import 'package:kernel/reference_from_index.dart' show ReferenceFromIndex;
123122

@@ -863,7 +862,7 @@ class StressConstantEvaluatorStep
863862
}
864863
}
865864

866-
class StressConstantEvaluatorVisitor extends RecursiveResultVisitor<Node>
865+
class StressConstantEvaluatorVisitor extends RecursiveVisitor<Node>
867866
implements ErrorReporter {
868867
ConstantEvaluator constantEvaluator;
869868
ConstantEvaluator constantEvaluatorWithEmptyEnvironment;
@@ -1917,7 +1916,7 @@ class Verify extends Step<ComponentResult, ComponentResult, FastaContext> {
19171916
/// Visitor that checks that the component has been transformed properly.
19181917
// TODO(johnniwinther): Add checks for all nodes that are unsupported after
19191918
// transformation.
1920-
class VerifyTransformed extends Visitor<void> with VisitorVoidMixin {
1919+
class VerifyTransformed extends Visitor<void> {
19211920
final Target target;
19221921
List<String> errors = [];
19231922

pkg/front_end/test/fasta/type_inference/type_schema_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class UnknownTypeTest {
113113
}
114114
}
115115

116-
class _OrdinaryVisitor<R> extends Visitor<R> with VisitorNullMixin<R> {
116+
class _OrdinaryVisitor<R> extends Visitor<R> {
117117
final _UnaryFunction<DartType, R> _defaultDartType;
118118

119119
_OrdinaryVisitor({_UnaryFunction<DartType, R> defaultDartType})
@@ -129,7 +129,7 @@ class _OrdinaryVisitor<R> extends Visitor<R> with VisitorNullMixin<R> {
129129
}
130130
}
131131

132-
class _TypeSchemaVisitor<R> extends Visitor<R> with VisitorNullMixin<R> {
132+
class _TypeSchemaVisitor<R> extends Visitor<R> {
133133
final _UnaryFunction<DartType, R> _defaultDartType;
134134
final _UnaryFunction<UnknownType, R> _visitUnknownType;
135135

pkg/front_end/test/static_types/analysis_helper.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ run(Uri entryPoint, String allowedListPath,
4242
.run(verbose: verbose, generate: generate);
4343
}
4444

45-
class StaticTypeVisitorBase extends RecursiveVisitor {
45+
class StaticTypeVisitorBase extends RecursiveVisitor<void> {
4646
final TypeEnvironment typeEnvironment;
4747

4848
StaticTypeContext staticTypeContext;

pkg/frontend_server/lib/src/to_string_transformer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import '../frontend_server.dart';
1111

1212
/// A [RecursiveVisitor] that replaces [Object.toString] overrides with
1313
/// `super.toString()`.
14-
class ToStringVisitor extends RecursiveVisitor {
14+
class ToStringVisitor extends RecursiveVisitor<void> {
1515
/// The [packageUris] must not be null.
1616
ToStringVisitor(this._packageUris) : assert(_packageUris != null);
1717

pkg/kernel/lib/binary/ast_to_binary.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2711,7 +2711,7 @@ class SwitchCaseIndexer {
27112711
int operator [](SwitchCase node) => index[node];
27122712
}
27132713

2714-
class ConstantIndexer extends RecursiveResultVisitor {
2714+
class ConstantIndexer extends RecursiveVisitor {
27152715
final StringIndexer stringIndexer;
27162716

27172717
final List<Constant> entries = <Constant>[];

0 commit comments

Comments
 (0)