Skip to content

Commit

Permalink
Revert "[kernel] Ensure that visitors don't implicitly returns null"
Browse files Browse the repository at this point in the history
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 <johnniwinther@google.com>
> Reviewed-by: Jens Johansen <jensj@google.com>

TBR=jensj@google.com,johnniwinther@google.com

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 <johnniwinther@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
  • Loading branch information
johnniwinther authored and commit-bot@chromium.org committed Feb 9, 2021
1 parent 5c4a916 commit b60e0aa
Show file tree
Hide file tree
Showing 44 changed files with 103 additions and 261 deletions.
2 changes: 1 addition & 1 deletion pkg/_js_interop_checks/lib/js_interop_checks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import 'package:_fe_analyzer_shared/src/messages/codes.dart'

import 'src/js_interop.dart';

class JsInteropChecks extends RecursiveVisitor {
class JsInteropChecks extends RecursiveVisitor<void> {
final CoreTypes _coreTypes;
final DiagnosticReporter<Message, LocatedMessage> _diagnosticsReporter;
final Map<String, Class> _nativeClasses;
Expand Down
3 changes: 1 addition & 2 deletions pkg/compiler/lib/src/inferrer/builder_kernel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ import 'type_system.dart';
/// Calling [run] will start the work of visiting the body of the code to
/// construct a set of inference-nodes that abstractly represent what the code
/// is doing.
class KernelTypeGraphBuilder extends ir.Visitor<TypeInformation>
with ir.VisitorNullMixin<TypeInformation> {
class KernelTypeGraphBuilder extends ir.Visitor<TypeInformation> {
final CompilerOptions _options;
final JsClosedWorld _closedWorld;
final InferrerEngine _inferrer;
Expand Down
3 changes: 1 addition & 2 deletions pkg/compiler/lib/src/ir/debug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import 'package:kernel/visitor.dart';

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

class DebugPrinter extends Visitor<void>
with Indentation, Tagging<Node>, VisitorVoidMixin {
class DebugPrinter extends Visitor with Indentation, Tagging<Node> {
@override
StringBuffer sb = new StringBuffer();

Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/ir/scope_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'scope.dart';
/// a [VariableScopeModel] that can respond to queries about how a particular
/// variable is being used at any point in the code.
class ScopeModelBuilder extends ir.Visitor<EvaluationComplexity>
with VariableCollectorMixin, ir.VisitorNullMixin<EvaluationComplexity> {
with VariableCollectorMixin {
final Dart2jsConstantEvaluator _constantEvaluator;
ir.StaticTypeContext _staticTypeContext;

Expand Down
3 changes: 1 addition & 2 deletions pkg/compiler/lib/src/ir/static_type_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ class ExactInterfaceType extends ir.InterfaceType {
/// expression kind. For instance method invocations whose static type depend
/// on the static types of the receiver and type arguments and the signature
/// of the targeted procedure.
abstract class StaticTypeBase extends ir.Visitor<ir.DartType>
with ir.VisitorNullMixin<ir.DartType> {
abstract class StaticTypeBase extends ir.Visitor<ir.DartType> {
final ir.TypeEnvironment _typeEnvironment;

StaticTypeBase(this._typeEnvironment);
Expand Down
8 changes: 0 additions & 8 deletions pkg/compiler/lib/src/ir/visitors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ class Stringifier extends ir.ExpressionVisitor<String> {
}
return null;
}

@override
String defaultExpression(ir.Expression node) => null;
}

/// Visitor that converts kernel dart types into [DartType].
Expand Down Expand Up @@ -185,11 +182,6 @@ class DartTypeConverter extends ir.DartTypeVisitor<DartType> {
DartType visitNullType(ir.NullType node) {
return elementMap.commonElements.nullType;
}

@override
DartType defaultDartType(ir.DartType node) {
throw UnsupportedError('Unsupported type $node (${node.runtimeType})');
}
}

class ConstantValuefier extends ir.ComputeOnceConstantVisitor<ConstantValue> {
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/js_model/locals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class KernelToLocalsMapImpl implements KernelToLocalsMap {
}
}

class JumpVisitor extends ir.Visitor<void> with ir.VisitorVoidMixin {
class JumpVisitor extends ir.Visitor {
int jumpIndex = 0;
int labelIndex = 0;
final MemberEntity member;
Expand Down
3 changes: 1 addition & 2 deletions pkg/compiler/lib/src/serialization/node_indexer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ part of 'serialization.dart';

/// Visitor that ascribes an index to all [ir.TreeNode]s that potentially
/// needed for serialization and deserialization.
class _TreeNodeIndexerVisitor extends ir.Visitor<void>
with ir.VisitorVoidMixin {
class _TreeNodeIndexerVisitor extends ir.Visitor<void> {
int _currentIndex = 0;
final Map<int, ir.TreeNode> _indexToNodeMap;
final Map<ir.TreeNode, int> _nodeToIndexMap;
Expand Down
12 changes: 5 additions & 7 deletions pkg/compiler/lib/src/ssa/builder_kernel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class StackFrame {
this.staticTypeProvider);
}

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

Expand Down Expand Up @@ -6560,8 +6560,7 @@ class KernelTypeBuilder extends TypeBuilder {
}
}

class _ErroneousInitializerVisitor extends ir.Visitor<bool>
with ir.VisitorDefaultValueMixin<bool> {
class _ErroneousInitializerVisitor extends ir.Visitor<bool> {
_ErroneousInitializerVisitor();

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

// Expressions: Does the expression always throw?
@override
bool get defaultValue => false;
bool defaultExpression(ir.Expression node) => false;

@override
bool visitThrow(ir.Throw node) => true;
Expand Down Expand Up @@ -6840,7 +6839,7 @@ class InlineDataCache {
}
}

class InlineWeeder extends ir.Visitor<void> with ir.VisitorVoidMixin {
class InlineWeeder extends ir.Visitor {
// Invariant: *INSIDE_LOOP* > *OUTSIDE_LOOP*
static const INLINING_NODES_OUTSIDE_LOOP = 15;
static const INLINING_NODES_OUTSIDE_LOOP_ARG_FACTOR = 3;
Expand Down Expand Up @@ -7398,8 +7397,7 @@ class InlineWeeder extends ir.Visitor<void> with ir.VisitorVoidMixin {

/// Visitor to detect environment-rewriting that prevents inlining
/// (e.g. closures).
class InlineWeederBodyClosure extends ir.Visitor<void>
with ir.VisitorVoidMixin {
class InlineWeederBodyClosure extends ir.Visitor<void> {
bool tooDifficult = false;

InlineWeederBodyClosure();
Expand Down
2 changes: 1 addition & 1 deletion pkg/compiler/lib/src/ssa/kernel_string_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'builder_kernel.dart';
import 'nodes.dart';

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

/// The string value generated so far.
Expand Down
5 changes: 2 additions & 3 deletions pkg/compiler/lib/src/ssa/loop_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,9 @@ class KernelLoopHandler extends LoopHandler {
int loopKind(ir.TreeNode node) => node.accept(new _KernelLoopTypeVisitor());
}

class _KernelLoopTypeVisitor extends ir.Visitor<int>
with ir.VisitorDefaultValueMixin<int> {
class _KernelLoopTypeVisitor extends ir.Visitor<int> {
@override
int get defaultValue => HLoopBlockInformation.NOT_A_LOOP;
int defaultNode(ir.Node node) => HLoopBlockInformation.NOT_A_LOOP;

@override
int visitWhileStatement(ir.WhileStatement node) =>
Expand Down
5 changes: 2 additions & 3 deletions pkg/compiler/lib/src/ssa/switch_continue_analysis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import 'package:kernel/ast.dart' as ir;
/// Helper class that traverses a kernel AST subtree to see if it has any
/// continue statements in the body of any switch cases (having continue
/// statements results in a more complex generated code).
class SwitchContinueAnalysis extends ir.Visitor<bool>
with ir.VisitorDefaultValueMixin<bool> {
class SwitchContinueAnalysis extends ir.Visitor<bool> {
SwitchContinueAnalysis._();

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

@override
bool get defaultValue => false;
bool defaultNode(ir.Node node) => false;
}
10 changes: 4 additions & 6 deletions pkg/dev_compiler/lib/src/kernel/expression_compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ import 'package:kernel/ast.dart'
TreeNode,
TypeParameter,
VariableDeclaration,
Visitor,
VisitorNullMixin,
VisitorVoidMixin;
Visitor;

DiagnosticMessage _createInternalError(Uri uri, int line, int col, String msg) {
return Message(Code<String>('Expression Compiler Internal error'),
Expand Down Expand Up @@ -86,7 +84,7 @@ class DartScope {
/// - locals
/// - formals
/// - captured variables (for closures)
class DartScopeBuilder extends Visitor<void> with VisitorVoidMixin {
class DartScopeBuilder extends Visitor<void> {
final Component _component;
final int _line;
final int _column;
Expand Down Expand Up @@ -198,7 +196,7 @@ class DartScopeBuilder extends Visitor<void> with VisitorVoidMixin {
/// that do not have .fileEndOffset field.
///
/// For example - [Block]
class FileEndOffsetCalculator extends Visitor<int> with VisitorNullMixin<int> {
class FileEndOffsetCalculator extends Visitor<int> {
static const int noOffset = -1;

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

@override
Expand Down
3 changes: 0 additions & 3 deletions pkg/dev_compiler/lib/src/kernel/kernel_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,6 @@ class LabelContinueFinder extends StatementVisitor<void> {
visit(node.body);
visit(node.finalizer);
}

@override
void defaultStatement(Statement node) {}
}

/// Ensures that all of the known DartType implementors are handled.
Expand Down
2 changes: 1 addition & 1 deletion pkg/dev_compiler/lib/src/kernel/nullable_inference.dart
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ class NullableInference extends ExpressionVisitor<bool> {
/// variables that have already been determined to be nullable.
///
// TODO(jmesserly): Introduce flow analysis.
class _NullableVariableInference extends RecursiveVisitor {
class _NullableVariableInference extends RecursiveVisitor<void> {
NullableInference _nullInference;

/// Variables that are currently believed to be not-null.
Expand Down
2 changes: 1 addition & 1 deletion pkg/dev_compiler/lib/src/kernel/target.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class DevCompilerTarget extends Target {
/// members can be eliminated, and adjusts the flags to remove those checks.
///
/// See [_CovarianceTransformer.transform].
class _CovarianceTransformer extends RecursiveVisitor {
class _CovarianceTransformer extends RecursiveVisitor<void> {
/// The set of private instance members in [_library] that (potentially) need
/// covariance checks.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void main(List<String> args) {
});
}

class ScopeOffsetValidator extends Visitor<void> with VisitorVoidMixin {
class ScopeOffsetValidator extends Visitor<void> {
int classCount = 0;
int memberCount = 0;
int blockCount = 0;
Expand Down
2 changes: 1 addition & 1 deletion pkg/dev_compiler/test/nullable_inference_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ Future expectAllNotNull(String code) async {
bool useAnnotations = false;
NullableInference inference;

class _TestRecursiveVisitor extends RecursiveVisitor {
class _TestRecursiveVisitor extends RecursiveVisitor<void> {
final Set<Library> librariesFromDill;
int _functionNesting = 0;
TypeEnvironment _typeEnvironment;
Expand Down
2 changes: 1 addition & 1 deletion pkg/front_end/lib/src/fasta/kernel/constant_evaluator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ class ConstantsTransformer extends Transformer {
}
}

class ConstantEvaluator extends RecursiveResultVisitor<Constant> {
class ConstantEvaluator extends RecursiveVisitor<Constant> {
final ConstantsBackend backend;
final NumberSemantics numberSemantics;
ConstantIntFolder intFolder;
Expand Down
3 changes: 1 addition & 2 deletions pkg/front_end/lib/src/testing/id_extractor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ TreeNode computeTreeNodeWithOffset(TreeNode node) {

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

Expand Down
2 changes: 1 addition & 1 deletion pkg/front_end/test/comments_on_certain_arguments_tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ api.CompilerOptions getOptions() {
return options;
}

class InvocationVisitor extends RecursiveVisitor {
class InvocationVisitor extends RecursiveVisitor<void> {
void visitProcedure(Procedure node) {
if (node.isNoSuchMethodForwarder) return;
super.visitProcedure(node);
Expand Down
2 changes: 1 addition & 1 deletion pkg/front_end/test/fasta/assert_locations_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void main() {}

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

/// Set of names of verified [Procedure]s.
Expand Down
9 changes: 4 additions & 5 deletions pkg/front_end/test/fasta/testing/suite.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,14 @@ import 'package:kernel/ast.dart'
TreeNode,
UnevaluatedConstant,
Version,
Visitor,
VisitorVoidMixin;
Visitor;

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

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

import 'package:kernel/kernel.dart'
show RecursiveResultVisitor, loadComponentFromBytes;
show RecursiveVisitor, loadComponentFromBytes;

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

Expand Down Expand Up @@ -863,7 +862,7 @@ class StressConstantEvaluatorStep
}
}

class StressConstantEvaluatorVisitor extends RecursiveResultVisitor<Node>
class StressConstantEvaluatorVisitor extends RecursiveVisitor<Node>
implements ErrorReporter {
ConstantEvaluator constantEvaluator;
ConstantEvaluator constantEvaluatorWithEmptyEnvironment;
Expand Down Expand Up @@ -1917,7 +1916,7 @@ class Verify extends Step<ComponentResult, ComponentResult, FastaContext> {
/// Visitor that checks that the component has been transformed properly.
// TODO(johnniwinther): Add checks for all nodes that are unsupported after
// transformation.
class VerifyTransformed extends Visitor<void> with VisitorVoidMixin {
class VerifyTransformed extends Visitor<void> {
final Target target;
List<String> errors = [];

Expand Down
4 changes: 2 additions & 2 deletions pkg/front_end/test/fasta/type_inference/type_schema_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class UnknownTypeTest {
}
}

class _OrdinaryVisitor<R> extends Visitor<R> with VisitorNullMixin<R> {
class _OrdinaryVisitor<R> extends Visitor<R> {
final _UnaryFunction<DartType, R> _defaultDartType;

_OrdinaryVisitor({_UnaryFunction<DartType, R> defaultDartType})
Expand All @@ -129,7 +129,7 @@ class _OrdinaryVisitor<R> extends Visitor<R> with VisitorNullMixin<R> {
}
}

class _TypeSchemaVisitor<R> extends Visitor<R> with VisitorNullMixin<R> {
class _TypeSchemaVisitor<R> extends Visitor<R> {
final _UnaryFunction<DartType, R> _defaultDartType;
final _UnaryFunction<UnknownType, R> _visitUnknownType;

Expand Down
2 changes: 1 addition & 1 deletion pkg/front_end/test/static_types/analysis_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ run(Uri entryPoint, String allowedListPath,
.run(verbose: verbose, generate: generate);
}

class StaticTypeVisitorBase extends RecursiveVisitor {
class StaticTypeVisitorBase extends RecursiveVisitor<void> {
final TypeEnvironment typeEnvironment;

StaticTypeContext staticTypeContext;
Expand Down
2 changes: 1 addition & 1 deletion pkg/frontend_server/lib/src/to_string_transformer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import '../frontend_server.dart';

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

Expand Down
2 changes: 1 addition & 1 deletion pkg/kernel/lib/binary/ast_to_binary.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2711,7 +2711,7 @@ class SwitchCaseIndexer {
int operator [](SwitchCase node) => index[node];
}

class ConstantIndexer extends RecursiveResultVisitor {
class ConstantIndexer extends RecursiveVisitor {
final StringIndexer stringIndexer;

final List<Constant> entries = <Constant>[];
Expand Down
Loading

0 comments on commit b60e0aa

Please sign in to comment.