Skip to content

Commit 3c53e3e

Browse files
natebiggsCommit Queue
authored andcommitted
[dart2wasm] Remove extra noisy type check warnings from WASM dry run.
These were producing false positives that could mislead users. We will cherrypick this to beta and then reimplement these in a different way for the next Dart release. Change-Id: I495135bbed6ca0b194ea84aaef3ec8e571fc2e98 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442960 Reviewed-by: Srujan Gaddam <[email protected]> Commit-Queue: Nate Biggs <[email protected]>
1 parent df45313 commit 3c53e3e

File tree

2 files changed

+4
-124
lines changed

2 files changed

+4
-124
lines changed

pkg/dart2wasm/lib/dry_run.dart

Lines changed: 4 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import 'package:kernel/ast.dart';
1010
import 'package:kernel/class_hierarchy.dart';
1111
import 'package:kernel/core_types.dart';
1212
import 'package:kernel/target/targets.dart' show DiagnosticReporter;
13-
import 'package:kernel/type_environment.dart';
1413

1514
/// Used to record the type of error in Flutter telemetry.
1615
///
@@ -25,8 +24,11 @@ enum _DryRunErrorCode {
2524
noDartHtml(0),
2625
noDartJs(1),
2726
interopChecksError(2),
27+
// ignore: unused_field
2828
isTestValueError(3),
29+
// ignore: unused_field
2930
isTestTypeError(4),
31+
// ignore: unused_field
3032
isTestGenericTypeError(5);
3133

3234
const _DryRunErrorCode(this.code);
@@ -113,17 +115,11 @@ class DryRunSummarizer {
113115
return collector.errors;
114116
}
115117

116-
List<_DryRunError> _analyzeComponent() {
117-
final analyzer = _AnalysisVisitor(coreTypes, classHierarchy);
118-
component.accept(analyzer);
119-
return analyzer.errors;
120-
}
121-
122118
bool summarize() {
123119
final errors = [
124120
..._analyzeImports(),
125121
..._interopChecks(),
126-
..._analyzeComponent(),
122+
// TODO: Add additional checks here.
127123
];
128124

129125
if (errors.isNotEmpty) {
@@ -157,85 +153,3 @@ class _CollectingDiagnosticReporter
157153
errorSourceUri: libraryUri ?? fileUri, errorLocation: location));
158154
}
159155
}
160-
161-
class _AnalysisVisitor extends RecursiveVisitor {
162-
Library? _enclosingLibrary;
163-
late StaticTypeContext _context;
164-
final TypeEnvironment _typeEnvironment;
165-
final DartType _jsAnyType;
166-
final List<_DryRunError> errors = [];
167-
168-
_AnalysisVisitor(CoreTypes coreTypes, ClassHierarchy hierarchy)
169-
: _typeEnvironment = TypeEnvironment(coreTypes, hierarchy),
170-
_jsAnyType = ExtensionType(
171-
coreTypes.index.getExtensionType('dart:js_interop', 'JSAny'),
172-
Nullability.nonNullable);
173-
174-
@override
175-
void visitLibrary(Library node) {
176-
if (node.importUri.scheme == 'dart') return;
177-
_enclosingLibrary = node;
178-
_context = StaticTypeContext.forAnnotations(node, _typeEnvironment);
179-
super.visitLibrary(node);
180-
_enclosingLibrary = null;
181-
}
182-
183-
@override
184-
void visitProcedure(Procedure node) {
185-
_context = StaticTypeContext(node, _typeEnvironment);
186-
super.visitProcedure(node);
187-
}
188-
189-
@override
190-
void visitIsExpression(IsExpression node) {
191-
final operandStaticType = node.operand.getStaticType(_context);
192-
if (_typeEnvironment.isSubtypeOf(
193-
operandStaticType.withDeclaredNullability(Nullability.nonNullable),
194-
_jsAnyType)) {
195-
errors.add(_DryRunError(
196-
_DryRunErrorCode.isTestValueError,
197-
'Should not perform an `is` test on a JS value. Use `isA` with a JS '
198-
'value type instead.',
199-
errorSourceUri: _enclosingLibrary?.importUri,
200-
errorLocation: node.location));
201-
}
202-
if (_typeEnvironment.isSubtypeOf(
203-
node.type.withDeclaredNullability(Nullability.nonNullable),
204-
_jsAnyType)) {
205-
errors.add(_DryRunError(
206-
_DryRunErrorCode.isTestTypeError,
207-
'Should not perform an `is` test against a JS value type. '
208-
'Use `isA` instead.',
209-
errorSourceUri: _enclosingLibrary?.importUri,
210-
errorLocation: node.location));
211-
} else if (_hasJsTypeArguments(node.type)) {
212-
errors.add(_DryRunError(
213-
_DryRunErrorCode.isTestGenericTypeError,
214-
'Should not perform an `is` test against a generic DartType with JS '
215-
'type arguments.',
216-
errorSourceUri: _enclosingLibrary?.importUri,
217-
errorLocation: node.location));
218-
}
219-
super.visitIsExpression(node);
220-
}
221-
222-
bool _hasJsTypeArguments(DartType type) {
223-
// Check InterfaceType and ExtensionType
224-
if (type is TypeDeclarationType) {
225-
final arguments = type.typeArguments;
226-
if (arguments.any((e) => _typeEnvironment.isSubtypeOf(
227-
e.withDeclaredNullability(Nullability.nonNullable), _jsAnyType))) {
228-
return true;
229-
}
230-
return arguments.any(_hasJsTypeArguments);
231-
} else if (type is RecordType) {
232-
final fields = type.positional.followedBy(type.named.map((t) => t.type));
233-
if (fields.any((e) => _typeEnvironment.isSubtypeOf(
234-
e.withDeclaredNullability(Nullability.nonNullable), _jsAnyType))) {
235-
return true;
236-
}
237-
return fields.any(_hasJsTypeArguments);
238-
}
239-
return false;
240-
}
241-
}

pkg/dart2wasm/test/dry_run/testcases/malformed_is.dart

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)