Version 2.14.0-108.0.dev
Merge commit '3a3b3e480baf3750ec22e5a482ee5930ad55fb9b' into 'dev'
diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json
index ac72d20..35641bf 100644
--- a/.dart_tool/package_config.json
+++ b/.dart_tool/package_config.json
@@ -11,7 +11,7 @@
"constraint, update this by running tools/generate_package_config.dart."
],
"configVersion": 2,
- "generated": "2021-05-10T19:21:13.245788",
+ "generated": "2021-05-11T11:47:02.674706",
"generator": "tools/generate_package_config.dart",
"packages": [
{
@@ -635,7 +635,7 @@
"name": "sse",
"rootUri": "../third_party/pkg/sse",
"packageUri": "lib/",
- "languageVersion": "2.2"
+ "languageVersion": "2.12"
},
{
"name": "stack_trace",
diff --git a/DEPS b/DEPS
index 1505b2a..65c748d 100644
--- a/DEPS
+++ b/DEPS
@@ -155,7 +155,7 @@
"source_maps-0.9.4_rev": "38524",
"source_maps_rev": "53eb92ccfe6e64924054f83038a534b959b12b3e",
"source_span_rev": "1be3c44045a06dff840d2ed3a13e6082d7a03a23",
- "sse_tag": "5da8fedcdc56f306933d202e2d204753eecefd36",
+ "sse_tag": "adc3ac8027784ed9783d066dccadad44458788e4",
"stack_trace_tag": "6788afc61875079b71b3d1c3e65aeaa6a25cbc2f",
"stream_channel_tag": "d7251e61253ec389ee6e045ee1042311bced8f1d",
"string_scanner_rev": "1b63e6e5db5933d7be0a45da6e1129fe00262734",
diff --git a/pkg/analysis_server/lib/src/services/correction/fix/analysis_options/fix_generator.dart b/pkg/analysis_server/lib/src/services/correction/fix/analysis_options/fix_generator.dart
index 5b5d7cf..f6bbbc1 100644
--- a/pkg/analysis_server/lib/src/services/correction/fix/analysis_options/fix_generator.dart
+++ b/pkg/analysis_server/lib/src/services/correction/fix/analysis_options/fix_generator.dart
@@ -10,7 +10,6 @@
import 'package:analysis_server/src/utilities/yaml_node_locator.dart';
import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer/error/error.dart';
-import 'package:analyzer/source/line_info.dart';
import 'package:analyzer/src/analysis_options/error/option_codes.dart';
import 'package:analyzer/src/generated/java_core.dart';
import 'package:analyzer/src/generated/source.dart';
diff --git a/pkg/analysis_server/lib/src/services/correction/util.dart b/pkg/analysis_server/lib/src/services/correction/util.dart
index c77cc97..c170b01 100644
--- a/pkg/analysis_server/lib/src/services/correction/util.dart
+++ b/pkg/analysis_server/lib/src/services/correction/util.dart
@@ -14,7 +14,6 @@
import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/precedence.dart';
-import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
diff --git a/pkg/analyzer/lib/src/context/builder.dart b/pkg/analyzer/lib/src/context/builder.dart
index 7df7c16..8887ae4 100644
--- a/pkg/analyzer/lib/src/context/builder.dart
+++ b/pkg/analyzer/lib/src/context/builder.dart
@@ -57,10 +57,6 @@
/// they can be shared across contexts.
final DartSdkManager sdkManager;
- /// The cache containing the contents of overlaid files. If this builder will
- /// be used to build analysis drivers, set the [fileContentOverlay] instead.
- final ContentCache? contentCache;
-
/// The options used by the context builder.
final ContextBuilderOptions builderOptions;
@@ -77,10 +73,6 @@
/// The byte store used by any analysis drivers created through this interface.
late final ByteStore byteStore;
- /// The file content overlay used by analysis drivers. If this builder will be
- /// used to build analysis contexts, set the [contentCache] instead.
- FileContentOverlay? fileContentOverlay;
-
/// Whether any analysis driver created through this interface should support
/// indexing and search.
bool enableIndex = false;
@@ -92,7 +84,7 @@
/// Initialize a newly created builder to be ready to build a context rooted in
/// the directory with the given [rootDirectoryPath].
- ContextBuilder(this.resourceProvider, this.sdkManager, this.contentCache,
+ ContextBuilder(this.resourceProvider, this.sdkManager,
{ContextBuilderOptions? options})
: builderOptions = options ?? ContextBuilderOptions();
@@ -123,7 +115,7 @@
performanceLog,
resourceProvider,
byteStore,
- fileContentOverlay,
+ FileContentOverlay(),
contextRoot,
sf,
options,
diff --git a/pkg/analyzer/lib/src/dart/analysis/analysis_context_collection.dart b/pkg/analyzer/lib/src/dart/analysis/analysis_context_collection.dart
index dbe5024..a2f9ed7 100644
--- a/pkg/analyzer/lib/src/dart/analysis/analysis_context_collection.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/analysis_context_collection.dart
@@ -11,7 +11,6 @@
import 'package:analyzer/src/dart/analysis/context_builder.dart';
import 'package:analyzer/src/dart/analysis/driver.dart';
import 'package:analyzer/src/dart/analysis/driver_based_analysis_context.dart';
-import 'package:analyzer/src/dart/analysis/file_state.dart';
import 'package:analyzer/src/dart/analysis/performance_logger.dart';
import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl;
import 'package:cli_util/cli_util.dart';
@@ -57,7 +56,6 @@
optionsFile: optionsFile,
packagesFile: packagesFile,
);
- var fileContentOverlay = FileContentOverlay();
for (var root in roots) {
var contextBuilder = ContextBuilderImpl(
resourceProvider: this.resourceProvider,
@@ -68,7 +66,6 @@
declaredVariables: DeclaredVariables.fromMap(declaredVariables ?? {}),
drainStreams: drainStreams,
enableIndex: enableIndex,
- fileContentOverlay: fileContentOverlay,
performanceLog: performanceLog,
retainDataForTesting: retainDataForTesting,
sdkPath: sdkPath,
diff --git a/pkg/analyzer/lib/src/dart/analysis/context_builder.dart b/pkg/analyzer/lib/src/dart/analysis/context_builder.dart
index 531689b..a6313ef 100644
--- a/pkg/analyzer/lib/src/dart/analysis/context_builder.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/context_builder.dart
@@ -15,13 +15,10 @@
import 'package:analyzer/src/dart/analysis/driver.dart'
show AnalysisDriver, AnalysisDriverScheduler;
import 'package:analyzer/src/dart/analysis/driver_based_analysis_context.dart';
-import 'package:analyzer/src/dart/analysis/file_state.dart'
- show FileContentOverlay;
import 'package:analyzer/src/dart/analysis/performance_logger.dart'
show PerformanceLog;
import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl;
import 'package:analyzer/src/generated/sdk.dart' show DartSdkManager;
-import 'package:analyzer/src/generated/source.dart' show ContentCache;
import 'package:cli_util/cli_util.dart';
/// An implementation of a context builder.
@@ -43,7 +40,6 @@
DeclaredVariables? declaredVariables,
bool drainStreams = true,
bool enableIndex = false,
- FileContentOverlay? fileContentOverlay,
List<String>? librarySummaryPaths,
PerformanceLog? performanceLog,
bool retainDataForTesting = false,
@@ -57,7 +53,6 @@
ArgumentError.checkNotNull(sdkPath, 'sdkPath');
byteStore ??= MemoryByteStore();
- fileContentOverlay ??= FileContentOverlay();
performanceLog ??= PerformanceLog(StringBuffer());
DartSdkManager sdkManager = DartSdkManager(sdkPath);
@@ -82,12 +77,10 @@
options.defaultAnalysisOptionsFilePath = contextRoot.optionsFile?.path;
options.defaultPackageFilePath = contextRoot.packagesFile?.path;
- old.ContextBuilder builder = old.ContextBuilder(
- resourceProvider, sdkManager, ContentCache(),
- options: options);
+ old.ContextBuilder builder =
+ old.ContextBuilder(resourceProvider, sdkManager, options: options);
builder.analysisDriverScheduler = scheduler;
builder.byteStore = byteStore;
- builder.fileContentOverlay = fileContentOverlay;
builder.enableIndex = enableIndex;
builder.performanceLog = performanceLog;
builder.retainDataForTesting = retainDataForTesting;
diff --git a/pkg/analyzer/lib/src/dart/ast/ast.dart b/pkg/analyzer/lib/src/dart/ast/ast.dart
index 08e9662..4cc9c8a 100644
--- a/pkg/analyzer/lib/src/dart/ast/ast.dart
+++ b/pkg/analyzer/lib/src/dart/ast/ast.dart
@@ -2308,6 +2308,19 @@
}
}
+/// This class is used as a marker of constant context for initializers
+/// of constant fields and top-level variables read from summaries.
+class ConstantContextForExpressionImpl extends AstNodeImpl {
+ final ExpressionImpl expression;
+
+ ConstantContextForExpressionImpl(this.expression) {
+ _becomeParentOf(expression);
+ }
+
+ @override
+ noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
+}
+
/// A constructor declaration.
///
/// constructorDeclaration ::=
@@ -3446,13 +3459,6 @@
/// | [ThrowExpression]
abstract class ExpressionImpl extends AstNodeImpl
implements CollectionElementImpl, Expression {
- /// To support [inConstantContext] we need to know if an expression is
- /// an initializer of a constant variable. But when the initializer is
- /// a part of the element model, there is no parent AST node.
- ///
- /// TODO(scheglov) Consider alternative solutions.
- static final inConstContextWithoutParent = Expando<bool>();
-
/// The static type of this expression, or `null` if the AST structure has not
/// been resolved.
@override
@@ -3468,8 +3474,8 @@
child is IfElement ||
child is ForElement) {
var parent = child.parent;
- if (parent == null) {
- return inConstContextWithoutParent[child] ?? false;
+ if (parent is ConstantContextForExpressionImpl) {
+ return true;
} else if (parent is TypedLiteralImpl && parent.constKeyword != null) {
// Inside an explicitly `const` list or map literal.
return true;
@@ -3488,6 +3494,8 @@
} else if (parent is SwitchCase) {
// Inside a switch case.
return true;
+ } else if (parent == null) {
+ break;
}
child = parent;
}
diff --git a/pkg/analyzer/lib/src/generated/source.dart b/pkg/analyzer/lib/src/generated/source.dart
index 1d59f76..e08044c 100644
--- a/pkg/analyzer/lib/src/generated/source.dart
+++ b/pkg/analyzer/lib/src/generated/source.dart
@@ -43,78 +43,6 @@
bool operator ==(Object object) => object is Source && object.uri == uri;
}
-/// A cache used to override the default content of a [Source].
-///
-/// TODO(scheglov) Remove it.
-class ContentCache {
- /// A table mapping the full path of sources to the contents of those sources.
- /// This is used to override the default contents of a source.
- final Map<String, String> _contentMap = {};
-
- /// A table mapping the full path of sources to the modification stamps of
- /// those sources. This is used when the default contents of a source has been
- /// overridden.
- final Map<String, int> _stampMap = {};
-
- int _nextStamp = 0;
-
- /// Visit all entries of this cache.
- void accept(ContentCacheVisitor visitor) {
- _contentMap.forEach((String fullPath, String contents) {
- int stamp = _stampMap[fullPath]!;
- visitor(fullPath, stamp, contents);
- });
- }
-
- /// Return the contents of the given [source], or `null` if this cache does not
- /// override the contents of the source.
- ///
- /// <b>Note:</b> This method is not intended to be used except by
- /// [AnalysisContext.getContents].
- String? getContents(Source source) => _contentMap[source.fullName];
-
- /// Return `true` if the given [source] exists, `false` if it does not exist,
- /// or `null` if this cache does not override existence of the source.
- ///
- /// <b>Note:</b> This method is not intended to be used except by
- /// [AnalysisContext.exists].
- bool? getExists(Source source) {
- return _contentMap.containsKey(source.fullName) ? true : null;
- }
-
- /// Return the modification stamp of the given [source], or `null` if this
- /// cache does not override the contents of the source.
- ///
- /// <b>Note:</b> This method is not intended to be used except by
- /// [AnalysisContext.getModificationStamp].
- int? getModificationStamp(Source source) => _stampMap[source.fullName];
-
- /// Set the contents of the given [source] to the given [contents]. This has
- /// the effect of overriding the default contents of the source. If the
- /// contents are `null` the override is removed so that the default contents
- /// will be returned.
- String? setContents(Source source, String? contents) {
- String fullName = source.fullName;
- if (contents == null) {
- _stampMap.remove(fullName);
- return _contentMap.remove(fullName);
- } else {
- int newStamp = _nextStamp++;
- var oldStamp = _stampMap[fullName];
- _stampMap[fullName] = newStamp;
- // Occasionally, if this method is called in rapid succession, the
- // timestamps are equal. Guard against this by artificially incrementing
- // the new timestamp.
- if (newStamp == oldStamp) {
- _stampMap[fullName] = newStamp + 1;
- }
- var oldContent = _contentMap[fullName];
- _contentMap[fullName] = contents;
- return oldContent;
- }
- }
-}
-
/// Instances of the class `DartUriResolver` resolve `dart` URI's.
class DartUriResolver extends UriResolver {
/// The name of the `dart` scheme.
diff --git a/pkg/analyzer/lib/src/summary2/ast_binary_reader.dart b/pkg/analyzer/lib/src/summary2/ast_binary_reader.dart
index a9db47d..09c4891 100644
--- a/pkg/analyzer/lib/src/summary2/ast_binary_reader.dart
+++ b/pkg/analyzer/lib/src/summary2/ast_binary_reader.dart
@@ -51,8 +51,6 @@
return _readCascadeExpression();
case Tag.ConditionalExpression:
return _readConditionalExpression();
- case Tag.Configuration:
- return _readConfiguration();
case Tag.ConstructorFieldInitializer:
return _readConstructorFieldInitializer();
case Tag.ConstructorName:
@@ -89,8 +87,6 @@
return _readGenericFunctionType();
case Tag.IfElement:
return _readIfElement();
- case Tag.ImplementsClause:
- return _readImplementsClause();
case Tag.IndexExpression:
return _readIndexExpression();
case Tag.IntegerLiteralNegative1:
@@ -109,8 +105,6 @@
return _readInterpolationString();
case Tag.IsExpression:
return _readIsExpression();
- case Tag.Label:
- return _readLabel();
case Tag.ListLiteral:
return _readListLiteral();
case Tag.MapLiteralEntry:
@@ -121,12 +115,8 @@
return _readMethodInvocation();
case Tag.NamedExpression:
return _readNamedExpression();
- case Tag.NativeClause:
- return _readNativeClause();
case Tag.NullLiteral:
return _readNullLiteral();
- case Tag.OnClause:
- return _readOnClause();
case Tag.InstanceCreationExpression:
return _readInstanceCreationExpression();
case Tag.ParenthesizedExpression:
@@ -175,8 +165,6 @@
return _readVariableDeclaration();
case Tag.VariableDeclarationList:
return _readVariableDeclarationList();
- case Tag.WithClause:
- return _readWithClause();
default:
throw UnimplementedError('Unexpected tag: $tag');
}
@@ -334,22 +322,6 @@
return node;
}
- Configuration _readConfiguration() {
- var flags = _readByte();
- var name = readNode() as DottedName;
- var value = _readOptionalNode() as StringLiteral?;
- var uri = readNode() as StringLiteral;
- return astFactory.configuration(
- Tokens.IF,
- Tokens.OPEN_PAREN,
- name,
- AstBinaryFlags.hasEqual(flags) ? Tokens.EQ : null,
- value,
- Tokens.CLOSE_PAREN,
- uri,
- );
- }
-
ConstructorFieldInitializer _readConstructorFieldInitializer() {
var flags = _readByte();
var fieldName = readNode() as SimpleIdentifier;
@@ -647,11 +619,6 @@
);
}
- ImplementsClause _readImplementsClause() {
- var interfaces = _readNodeList<TypeName>();
- return astFactory.implementsClause(Tokens.IMPLEMENTS, interfaces);
- }
-
IndexExpression _readIndexExpression() {
var flags = _readByte();
var target = _readOptionalNode() as Expression?;
@@ -776,11 +743,6 @@
return node;
}
- Label _readLabel() {
- var label = readNode() as SimpleIdentifier;
- return astFactory.label(label, Tokens.COLON);
- }
-
ListLiteral _readListLiteral() {
var flags = _readByte();
var typeArguments = _readOptionalNode() as TypeArgumentList?;
@@ -863,11 +825,6 @@
return node;
}
- NativeClause _readNativeClause() {
- var name = _readOptionalNode() as StringLiteral?;
- return astFactory.nativeClause(Tokens.NATIVE, name);
- }
-
List<T> _readNodeList<T>() {
var length = _reader.readUInt30();
return List.generate(length, (_) => readNode() as T);
@@ -879,11 +836,6 @@
);
}
- OnClause _readOnClause() {
- var superclassConstraints = _readNodeList<TypeName>();
- return astFactory.onClause(Tokens.ON, superclassConstraints);
- }
-
AstNode? _readOptionalNode() {
if (_readOptionTag()) {
return readNode();
@@ -1222,11 +1174,6 @@
);
}
- WithClause _readWithClause() {
- var mixins = _readNodeList<TypeName>();
- return astFactory.withClause(Tokens.WITH, mixins);
- }
-
void _resolveNamedExpressions(
Element? executable,
ArgumentList argumentList,
diff --git a/pkg/analyzer/lib/src/summary2/ast_binary_tag.dart b/pkg/analyzer/lib/src/summary2/ast_binary_tag.dart
index 98809ef..b4e509c 100644
--- a/pkg/analyzer/lib/src/summary2/ast_binary_tag.dart
+++ b/pkg/analyzer/lib/src/summary2/ast_binary_tag.dart
@@ -32,7 +32,6 @@
static const int BooleanLiteral = 4;
static const int CascadeExpression = 95;
static const int ConditionalExpression = 51;
- static const int Configuration = 46;
static const int ConstructorFieldInitializer = 50;
static const int ConstructorName = 7;
static const int DeclaredIdentifier = 90;
@@ -54,7 +53,6 @@
static const int GenericFunctionType = 21;
static const int HideCombinator = 48;
static const int IfElement = 63;
- static const int ImplementsClause = 23;
static const int IndexExpression = 98;
static const int InstanceCreationExpression = 25;
static const int IntegerLiteralNegative = 73;
@@ -65,7 +63,6 @@
static const int InterpolationExpression = 77;
static const int InterpolationString = 78;
static const int IsExpression = 83;
- static const int Label = 61;
static const int ListLiteral = 56;
static const int MapLiteralEntry = 66;
static const int MethodDeclaration_getter = 85;
@@ -73,8 +70,6 @@
static const int MethodInvocation = 59;
static const int MixinDeclaration = 67;
static const int NamedExpression = 60;
- static const int NativeClause = 92;
- static const int OnClause = 68;
static const int NullLiteral = 49;
static const int ParenthesizedExpression = 53;
static const int PostfixExpression = 94;
@@ -100,7 +95,6 @@
static const int TypeParameterList = 41;
static const int VariableDeclaration = 42;
static const int VariableDeclarationList = 43;
- static const int WithClause = 45;
static const int RawElement = 0;
static const int MemberLegacyWithoutTypeArguments = 1;
diff --git a/pkg/analyzer/lib/src/summary2/ast_binary_writer.dart b/pkg/analyzer/lib/src/summary2/ast_binary_writer.dart
index c2573f6..998c88d 100644
--- a/pkg/analyzer/lib/src/summary2/ast_binary_writer.dart
+++ b/pkg/analyzer/lib/src/summary2/ast_binary_writer.dart
@@ -141,21 +141,6 @@
}
@override
- void visitConfiguration(Configuration node) {
- _writeByte(Tag.Configuration);
-
- _writeByte(
- AstBinaryFlags.encode(
- hasEqual: node.equalToken != null,
- ),
- );
-
- _writeNode(node.name);
- _writeOptionalNode(node.value);
- _writeNode(node.uri);
- }
-
- @override
void visitConstructorFieldInitializer(ConstructorFieldInitializer node) {
_writeByte(Tag.ConstructorFieldInitializer);
@@ -360,12 +345,6 @@
}
@override
- void visitImplementsClause(ImplementsClause node) {
- _writeByte(Tag.ImplementsClause);
- _writeNodeList(node.interfaces);
- }
-
- @override
void visitIndexExpression(IndexExpression node) {
_writeByte(Tag.IndexExpression);
_writeByte(
@@ -463,12 +442,6 @@
}
@override
- void visitLabel(Label node) {
- _writeByte(Tag.Label);
- _writeNode(node.label);
- }
-
- @override
void visitListLiteral(ListLiteral node) {
_writeByte(Tag.ListLiteral);
@@ -517,23 +490,11 @@
}
@override
- void visitNativeClause(NativeClause node) {
- _writeByte(Tag.NativeClause);
- _writeOptionalNode(node.name);
- }
-
- @override
void visitNullLiteral(NullLiteral node) {
_writeByte(Tag.NullLiteral);
}
@override
- void visitOnClause(OnClause node) {
- _writeByte(Tag.OnClause);
- _writeNodeList(node.superclassConstraints);
- }
-
- @override
void visitParenthesizedExpression(ParenthesizedExpression node) {
_writeByte(Tag.ParenthesizedExpression);
_writeNode(node.expression);
@@ -784,12 +745,6 @@
_storeAnnotatedNode(node);
}
- @override
- void visitWithClause(WithClause node) {
- _writeByte(Tag.WithClause);
- _writeNodeList(node.mixinTypes);
- }
-
void _pushScopeTypeParameters(TypeParameterList? node) {
_sink.localElements.pushScope();
diff --git a/pkg/analyzer/lib/src/summary2/bundle_reader.dart b/pkg/analyzer/lib/src/summary2/bundle_reader.dart
index 761f314..089f216 100644
--- a/pkg/analyzer/lib/src/summary2/bundle_reader.dart
+++ b/pkg/analyzer/lib/src/summary2/bundle_reader.dart
@@ -232,7 +232,6 @@
var initializer = reader._readOptionalExpression();
if (initializer != null) {
defaultParameter.constantInitializer = initializer;
- ExpressionImpl.inConstContextWithoutParent[initializer] = true;
}
}
if (parameter is FieldFormalParameterElementImpl) {
@@ -326,7 +325,7 @@
var initializer = reader._readOptionalExpression();
if (initializer != null) {
element.constantInitializer = initializer;
- ExpressionImpl.inConstContextWithoutParent[initializer] = true;
+ ConstantContextForExpressionImpl(initializer);
}
}
}
@@ -1672,9 +1671,9 @@
return NullabilitySuffix.values[index];
}
- Expression? _readOptionalExpression() {
+ ExpressionImpl? _readOptionalExpression() {
if (_reader.readBool()) {
- return _readRequiredNode() as Expression;
+ return _readRequiredNode() as ExpressionImpl;
}
}
@@ -1762,7 +1761,7 @@
var initializer = reader._readOptionalExpression();
if (initializer != null) {
element.constantInitializer = initializer;
- ExpressionImpl.inConstContextWithoutParent[initializer] = true;
+ ConstantContextForExpressionImpl(initializer);
}
}
}
diff --git a/pkg/analyzer/test/generated/all_the_rest_test.dart b/pkg/analyzer/test/generated/all_the_rest_test.dart
index e3a6c6a..2fd5fff 100644
--- a/pkg/analyzer/test/generated/all_the_rest_test.dart
+++ b/pkg/analyzer/test/generated/all_the_rest_test.dart
@@ -14,11 +14,8 @@
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
-import 'test_support.dart';
-
main() {
defineReflectiveSuite(() {
- defineReflectiveTests(ContentCacheTest);
defineReflectiveTests(DartUriResolverTest);
defineReflectiveTests(ErrorSeverityTest);
defineReflectiveTests(FileBasedSourceTest);
@@ -28,25 +25,6 @@
}
@reflectiveTest
-class ContentCacheTest {
- test_setContents() async {
- Source source = TestSource();
- ContentCache cache = ContentCache();
- expect(cache.getContents(source), isNull);
- expect(cache.getModificationStamp(source), isNull);
- String contents = "library lib;";
- expect(cache.setContents(source, contents), isNull);
- expect(cache.getContents(source), contents);
- expect(cache.getModificationStamp(source), isNotNull);
- expect(cache.setContents(source, contents), contents);
- expect(cache.setContents(source, null), contents);
- expect(cache.getContents(source), isNull);
- expect(cache.getModificationStamp(source), isNull);
- expect(cache.setContents(source, null), isNull);
- }
-}
-
-@reflectiveTest
class DartUriResolverTest extends _SimpleDartSdkTest {
late final DartUriResolver resolver;
diff --git a/pkg/analyzer/test/src/context/builder_test.dart b/pkg/analyzer/test/src/context/builder_test.dart
index bd4a9fe..727364a 100644
--- a/pkg/analyzer/test/src/context/builder_test.dart
+++ b/pkg/analyzer/test/src/context/builder_test.dart
@@ -37,9 +37,6 @@
/// The SDK manager used by the tests;
late final DartSdkManager sdkManager;
- /// The content cache used by the tests.
- late final ContentCache contentCache;
-
/// The options passed to the context builder.
ContextBuilderOptions builderOptions = ContextBuilderOptions();
@@ -63,11 +60,9 @@
void setUp() {
MockSdk(resourceProvider: resourceProvider);
sdkManager = DartSdkManager(convertPath('/sdk'));
- contentCache = ContentCache();
builder = ContextBuilder(
resourceProvider,
sdkManager,
- contentCache,
options: builderOptions,
);
}
@@ -372,8 +367,8 @@
newFile('/workspace/out/debug/gen/dart.sources/foo_pkg',
content: convertPath('/workspace/foo_pkg/lib'));
newFolder(projectPath);
- builder = ContextBuilder(resourceProvider, sdkManager, contentCache,
- options: builderOptions);
+ builder =
+ ContextBuilder(resourceProvider, sdkManager, options: builderOptions);
AnalysisOptionsImpl expected = AnalysisOptionsImpl();
var options = _getAnalysisOptions(builder, projectPath);
_expectEqualOptions(options, expected);
diff --git a/pkg/analyzer/test/src/lint/linter/linter_context_impl_test.dart b/pkg/analyzer/test/src/lint/linter/linter_context_impl_test.dart
index 99cce62..399d2e4 100644
--- a/pkg/analyzer/test/src/lint/linter/linter_context_impl_test.dart
+++ b/pkg/analyzer/test/src/lint/linter/linter_context_impl_test.dart
@@ -2,7 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-import 'package:analyzer/src/context/builder.dart';
import 'package:analyzer/src/dart/ast/ast.dart';
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
import 'package:analyzer/src/dart/element/type_system.dart';
@@ -31,13 +30,10 @@
await resolveTestCode(content);
var contextUnit = LinterContextUnit(result.content!, result.unit!);
- final libraryPath = result.libraryElement.source.fullName;
- // todo (pq): get workspace from analysis context
- final workspace = ContextBuilder.createWorkspace(
- resourceProvider: resourceProvider,
- options: ContextBuilderOptions(),
- rootPath: libraryPath,
- );
+ final libraryElement = result.libraryElement;
+ final analysisContext = libraryElement.session.analysisContext;
+ final libraryPath = libraryElement.source.fullName;
+ final workspace = analysisContext.contextRoot.workspace;
final workspacePackage = workspace.findPackageFor(libraryPath);
context = LinterContextImpl(
diff --git a/pkg/front_end/test/crashing_test_case_minimizer_impl.dart b/pkg/front_end/test/crashing_test_case_minimizer_impl.dart
index db1d9dcc..a9cb6ad 100644
--- a/pkg/front_end/test/crashing_test_case_minimizer_impl.dart
+++ b/pkg/front_end/test/crashing_test_case_minimizer_impl.dart
@@ -23,8 +23,6 @@
import 'package:_fe_analyzer_shared/src/scanner/scanner.dart'
show ErrorToken, ScannerConfiguration, Token;
-import 'package:_fe_analyzer_shared/src/scanner/token.dart' show Token;
-
import 'package:compiler/src/kernel/dart2js_target.dart' show Dart2jsTarget;
import 'package:dev_compiler/src/kernel/target.dart' show DevCompilerTarget;
diff --git a/pkg/front_end/test/fasta/parser/literal_entry_info_test.dart b/pkg/front_end/test/fasta/parser/literal_entry_info_test.dart
index 791ecbe..3dd5da0 100644
--- a/pkg/front_end/test/fasta/parser/literal_entry_info_test.dart
+++ b/pkg/front_end/test/fasta/parser/literal_entry_info_test.dart
@@ -7,7 +7,6 @@
import 'package:_fe_analyzer_shared/src/parser/parser.dart';
import 'package:_fe_analyzer_shared/src/parser/async_modifier.dart';
import 'package:_fe_analyzer_shared/src/scanner/scanner.dart';
-import 'package:_fe_analyzer_shared/src/scanner/token.dart';
import 'package:front_end/src/fasta/messages.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
diff --git a/pkg/front_end/test/fasta/testing/suite.dart b/pkg/front_end/test/fasta/testing/suite.dart
index 0da4649..198db8a 100644
--- a/pkg/front_end/test/fasta/testing/suite.dart
+++ b/pkg/front_end/test/fasta/testing/suite.dart
@@ -26,9 +26,6 @@
parseExperimentalArguments,
parseExperimentalFlags;
-import 'package:front_end/src/api_prototype/compiler_options.dart'
- show CompilerOptions, DiagnosticMessage;
-
import 'package:front_end/src/api_prototype/constant_evaluator.dart'
show ConstantEvaluator, ErrorReporter, EvaluationMode;
diff --git a/pkg/front_end/test/fasta/type_inference/type_schema_test.dart b/pkg/front_end/test/fasta/type_inference/type_schema_test.dart
index 141bcf0..5aa934b 100644
--- a/pkg/front_end/test/fasta/type_inference/type_schema_test.dart
+++ b/pkg/front_end/test/fasta/type_inference/type_schema_test.dart
@@ -6,7 +6,6 @@
import 'package:front_end/src/fasta/type_inference/type_schema.dart';
import 'package:kernel/ast.dart';
-import 'package:kernel/visitor.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
diff --git a/pkg/front_end/test/id_tests/constant_test.dart b/pkg/front_end/test/id_tests/constant_test.dart
index 3091acf..d01fd1e 100644
--- a/pkg/front_end/test/id_tests/constant_test.dart
+++ b/pkg/front_end/test/id_tests/constant_test.dart
@@ -21,7 +21,6 @@
onFailure,
runTestFor;
import 'package:front_end/src/testing/id_testing_utils.dart';
-import 'package:kernel/ast.dart' show Class, Member, TreeNode;
import 'package:kernel/ast.dart';
main(List<String> args) async {
diff --git a/pkg/front_end/test/incremental_load_from_invalid_dill_test.dart b/pkg/front_end/test/incremental_load_from_invalid_dill_test.dart
index 552cb48..2da47c7f 100644
--- a/pkg/front_end/test/incremental_load_from_invalid_dill_test.dart
+++ b/pkg/front_end/test/incremental_load_from_invalid_dill_test.dart
@@ -9,13 +9,10 @@
import 'package:_fe_analyzer_shared/src/messages/diagnostic_message.dart'
show DiagnosticMessage, getMessageCodeObject;
-import 'package:_fe_analyzer_shared/src/messages/severity.dart' show Severity;
-
import 'package:expect/expect.dart' show Expect;
import 'package:front_end/src/api_prototype/compiler_options.dart'
show CompilerOptions;
-import 'package:front_end/src/api_prototype/experimental_flags.dart';
import "package:front_end/src/api_prototype/memory_file_system.dart"
show MemoryFileSystem;
@@ -40,8 +37,6 @@
import 'package:front_end/src/fasta/incremental_compiler.dart'
show IncrementalCompiler;
-import 'package:front_end/src/fasta/kernel/utils.dart' show serializeComponent;
-
import 'package:kernel/kernel.dart'
show Component, Library, NonNullableByDefaultCompiledMode;
diff --git a/pkg/front_end/test/incremental_suite.dart b/pkg/front_end/test/incremental_suite.dart
index 9792678..b623b65 100644
--- a/pkg/front_end/test/incremental_suite.dart
+++ b/pkg/front_end/test/incremental_suite.dart
@@ -56,21 +56,6 @@
import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter;
import 'package:kernel/class_hierarchy.dart';
-import 'package:kernel/kernel.dart'
- show
- Class,
- Component,
- EmptyStatement,
- Field,
- Library,
- LibraryDependency,
- Member,
- Name,
- Procedure,
- Supertype,
- TreeNode,
- Version;
-
import 'package:kernel/target/targets.dart'
show NoneTarget, LateLowering, Target, TargetFlags;
diff --git a/pkg/front_end/test/language_versioning/language_versioning_test.dart b/pkg/front_end/test/language_versioning/language_versioning_test.dart
index 912905c..72dc28e 100644
--- a/pkg/front_end/test/language_versioning/language_versioning_test.dart
+++ b/pkg/front_end/test/language_versioning/language_versioning_test.dart
@@ -7,8 +7,6 @@
import 'dart:io' show Directory, File, Platform;
import 'package:_fe_analyzer_shared/src/testing/id.dart' show ActualData, Id;
import 'package:_fe_analyzer_shared/src/testing/features.dart';
-import 'package:_fe_analyzer_shared/src/testing/id_testing.dart'
- show DataInterpreter, runTests;
import 'package:_fe_analyzer_shared/src/testing/id_testing.dart';
import 'package:front_end/src/api_prototype/compiler_options.dart';
import 'package:front_end/src/api_prototype/language_version.dart' as lv;
diff --git a/pkg/front_end/test/parser_suite.dart b/pkg/front_end/test/parser_suite.dart
index 4b6015b..86e3f94 100644
--- a/pkg/front_end/test/parser_suite.dart
+++ b/pkg/front_end/test/parser_suite.dart
@@ -23,11 +23,6 @@
import 'package:_fe_analyzer_shared/src/scanner/scanner.dart'
show ErrorToken, ScannerConfiguration, Token, Utf8BytesScanner;
-import 'package:_fe_analyzer_shared/src/scanner/utf8_bytes_scanner.dart'
- show Utf8BytesScanner;
-
-import 'package:_fe_analyzer_shared/src/scanner/token.dart' show Token;
-
import 'package:front_end/src/fasta/source/stack_listener_impl.dart'
show offsetForToken;
diff --git a/pkg/front_end/test/parser_test_listener_creator.dart b/pkg/front_end/test/parser_test_listener_creator.dart
index 787e7f6..64edd83 100644
--- a/pkg/front_end/test/parser_test_listener_creator.dart
+++ b/pkg/front_end/test/parser_test_listener_creator.dart
@@ -8,9 +8,6 @@
import 'dart:typed_data';
import 'package:_fe_analyzer_shared/src/parser/parser.dart';
-import 'package:_fe_analyzer_shared/src/parser/formal_parameter_kind.dart';
-import 'package:_fe_analyzer_shared/src/parser/listener.dart';
-import 'package:_fe_analyzer_shared/src/parser/member_kind.dart';
import 'package:_fe_analyzer_shared/src/scanner/utf8_bytes_scanner.dart';
import 'package:_fe_analyzer_shared/src/scanner/token.dart';
import 'package:dart_style/dart_style.dart' show DartFormatter;
diff --git a/pkg/front_end/test/parser_test_parser.dart b/pkg/front_end/test/parser_test_parser.dart
index fd3ed9b..8aa6d40 100644
--- a/pkg/front_end/test/parser_test_parser.dart
+++ b/pkg/front_end/test/parser_test_parser.dart
@@ -15,7 +15,6 @@
import 'package:_fe_analyzer_shared/src/parser/parser.dart' show Parser;
import 'package:_fe_analyzer_shared/src/parser/token_stream_rewriter.dart';
import 'package:_fe_analyzer_shared/src/parser/type_info.dart';
-import 'package:_fe_analyzer_shared/src/scanner/scanner.dart';
import 'package:_fe_analyzer_shared/src/scanner/token.dart';
import 'package:front_end/src/fasta/fasta_codes.dart';
diff --git a/pkg/front_end/test/spelling_test_base.dart b/pkg/front_end/test/spelling_test_base.dart
index f63a61c..1c3a3ff 100644
--- a/pkg/front_end/test/spelling_test_base.dart
+++ b/pkg/front_end/test/spelling_test_base.dart
@@ -10,9 +10,6 @@
import 'package:_fe_analyzer_shared/src/scanner/scanner.dart' show ErrorToken;
-import 'package:_fe_analyzer_shared/src/scanner/token.dart'
- show Token, KeywordToken, BeginToken;
-
import 'package:_fe_analyzer_shared/src/scanner/token.dart';
import 'package:_fe_analyzer_shared/src/scanner/utf8_bytes_scanner.dart'
diff --git a/pkg/front_end/test/static_types/analysis_helper.dart b/pkg/front_end/test/static_types/analysis_helper.dart
index fcd3b9f..2c50697 100644
--- a/pkg/front_end/test/static_types/analysis_helper.dart
+++ b/pkg/front_end/test/static_types/analysis_helper.dart
@@ -10,8 +10,6 @@
import 'package:_fe_analyzer_shared/src/messages/diagnostic_message.dart';
import 'package:expect/expect.dart';
import 'package:front_end/src/api_prototype/front_end.dart';
-import 'package:front_end/src/api_prototype/kernel_generator.dart';
-import 'package:front_end/src/api_prototype/terminal_color_support.dart';
import 'package:front_end/src/api_unstable/ddc.dart';
import 'package:front_end/src/compute_platform_binaries_location.dart';
import 'package:front_end/src/fasta/command_line_reporting.dart';
diff --git a/pkg/front_end/test/static_types/static_type_test.dart b/pkg/front_end/test/static_types/static_type_test.dart
index 53a9ee2..9e35c25 100644
--- a/pkg/front_end/test/static_types/static_type_test.dart
+++ b/pkg/front_end/test/static_types/static_type_test.dart
@@ -6,10 +6,7 @@
import 'dart:io' show Directory, Platform;
import 'package:_fe_analyzer_shared/src/testing/id.dart';
-import 'package:_fe_analyzer_shared/src/testing/id_testing.dart'
- show DataInterpreter, runTests;
import 'package:_fe_analyzer_shared/src/testing/id_testing.dart';
-import 'package:front_end/src/fasta/kernel/kernel_api.dart';
import 'package:front_end/src/testing/id_testing_helper.dart';
import 'package:front_end/src/testing/id_testing_utils.dart';
import 'package:kernel/ast.dart';
diff --git a/pkg/front_end/tool/_fasta/command_line.dart b/pkg/front_end/tool/_fasta/command_line.dart
index e38ab78..2dc1077 100644
--- a/pkg/front_end/tool/_fasta/command_line.dart
+++ b/pkg/front_end/tool/_fasta/command_line.dart
@@ -13,8 +13,6 @@
import 'package:build_integration/file_system/single_root.dart'
show SingleRootFileSystem;
-import 'package:front_end/src/api_prototype/compiler_options.dart'
- show CompilerOptions, parseExperimentalFlags;
import 'package:front_end/src/api_prototype/compiler_options.dart';
import 'package:front_end/src/api_prototype/experimental_flags.dart'
diff --git a/pkg/front_end/tool/_fasta/direct_parser_ast_helper_creator.dart b/pkg/front_end/tool/_fasta/direct_parser_ast_helper_creator.dart
index 3fde7d0..e7cdb79 100644
--- a/pkg/front_end/tool/_fasta/direct_parser_ast_helper_creator.dart
+++ b/pkg/front_end/tool/_fasta/direct_parser_ast_helper_creator.dart
@@ -8,9 +8,6 @@
import 'dart:typed_data';
import 'package:_fe_analyzer_shared/src/parser/parser.dart';
-import 'package:_fe_analyzer_shared/src/parser/formal_parameter_kind.dart';
-import 'package:_fe_analyzer_shared/src/parser/listener.dart';
-import 'package:_fe_analyzer_shared/src/parser/member_kind.dart';
import 'package:_fe_analyzer_shared/src/scanner/utf8_bytes_scanner.dart';
import 'package:_fe_analyzer_shared/src/scanner/token.dart';
import 'package:dart_style/dart_style.dart' show DartFormatter;
diff --git a/pkg/front_end/tool/incremental_perf.dart b/pkg/front_end/tool/incremental_perf.dart
index cb00f51..81956ff 100644
--- a/pkg/front_end/tool/incremental_perf.dart
+++ b/pkg/front_end/tool/incremental_perf.dart
@@ -48,8 +48,6 @@
import 'dart:io' hide FileSystemEntity;
import 'package:args/args.dart';
-import 'package:front_end/src/api_prototype/file_system.dart'
- show FileSystemEntity;
import 'package:front_end/src/api_prototype/front_end.dart';
import 'package:front_end/src/api_prototype/incremental_kernel_generator.dart';
import 'package:front_end/src/api_prototype/memory_file_system.dart';
diff --git a/pkg/front_end/tool/kernel_ast_file_rewriter.dart b/pkg/front_end/tool/kernel_ast_file_rewriter.dart
index 64bd396..eaa6bcc 100644
--- a/pkg/front_end/tool/kernel_ast_file_rewriter.dart
+++ b/pkg/front_end/tool/kernel_ast_file_rewriter.dart
@@ -8,10 +8,7 @@
import "dart:typed_data" show Uint8List;
import 'package:_fe_analyzer_shared/src/scanner/token.dart';
-import 'package:analyzer/dart/ast/token.dart';
import "package:front_end/src/fasta/util/direct_parser_ast.dart";
-import "package:front_end/src/fasta/util/direct_parser_ast_helper.dart"
- show DirectParserASTContent;
import 'package:_fe_analyzer_shared/src/parser/parser.dart'
show IdentifierContext;
import 'package:front_end/src/fasta/util/direct_parser_ast_helper.dart';
diff --git a/pkg/front_end/tool/perf.dart b/pkg/front_end/tool/perf.dart
index 61ee9d3..0917caf 100644
--- a/pkg/front_end/tool/perf.dart
+++ b/pkg/front_end/tool/perf.dart
@@ -20,7 +20,6 @@
import 'dart:io' show Directory, File, Platform, exit;
import 'package:_fe_analyzer_shared/src/scanner/scanner.dart';
-import 'package:_fe_analyzer_shared/src/scanner/token.dart';
import 'package:analyzer/dart/analysis/features.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/error/listener.dart';
diff --git a/pkg/vm/lib/transformations/type_flow/protobuf_handler.dart b/pkg/vm/lib/transformations/type_flow/protobuf_handler.dart
index 865f56d..c1f616d 100644
--- a/pkg/vm/lib/transformations/type_flow/protobuf_handler.dart
+++ b/pkg/vm/lib/transformations/type_flow/protobuf_handler.dart
@@ -68,6 +68,8 @@
_builderInfoAddMethod =
libraryIndex.getMember(protobufLibraryUri, 'BuilderInfo', 'add');
+ bool usesAnnotationClass(Class cls) => cls == _tagNumberClass;
+
/// This method is called from summary collector when analysis discovered
/// that [member] is called and needs to construct a summary for its body.
///
diff --git a/pkg/vm/lib/transformations/type_flow/summary_collector.dart b/pkg/vm/lib/transformations/type_flow/summary_collector.dart
index a20c840..9e73f76 100644
--- a/pkg/vm/lib/transformations/type_flow/summary_collector.dart
+++ b/pkg/vm/lib/transformations/type_flow/summary_collector.dart
@@ -774,6 +774,12 @@
_summary.result = _returnValue;
}
+ // Visit annotations on members, classes and libraries.
+ // Other nodes currently do not have annotations used by the VM.
+ member.annotations.forEach(_visit);
+ member.enclosingClass?.annotations?.forEach(_visit);
+ member.enclosingLibrary?.annotations?.forEach(_visit);
+
_staticTypeContext = null;
debugPrint("------------ SUMMARY ------------");
diff --git a/pkg/vm/lib/transformations/type_flow/transformer.dart b/pkg/vm/lib/transformations/type_flow/transformer.dart
index e7ac652..5dcdfe7 100644
--- a/pkg/vm/lib/transformations/type_flow/transformer.dart
+++ b/pkg/vm/lib/transformations/type_flow/transformer.dart
@@ -75,6 +75,9 @@
typeFlowAnalysis.addRawCall(mainSelector);
}
+ CleanupAnnotations(coreTypes, libraryIndex, protobufHandler)
+ .visitComponent(component);
+
typeFlowAnalysis.process();
analysisStopWatch.stop();
@@ -118,6 +121,56 @@
return component;
}
+// Pass which removes all annotations except @ExternalName and @pragma
+// on members, classes and libraries. May also keep @TagNumber which is used
+// by protobuf handler.
+class CleanupAnnotations extends RecursiveVisitor {
+ final Class externalNameClass;
+ final Class pragmaClass;
+ final ProtobufHandler protobufHandler;
+
+ CleanupAnnotations(
+ CoreTypes coreTypes, LibraryIndex index, this.protobufHandler)
+ : externalNameClass = index.getClass('dart:_internal', 'ExternalName'),
+ pragmaClass = coreTypes.pragmaClass;
+
+ @override
+ defaultNode(Node node) {
+ if (node is Annotatable && node.annotations.isNotEmpty) {
+ _cleanupAnnotations(node, node.annotations);
+ }
+ super.defaultNode(node);
+ }
+
+ @override
+ visitTypedef(Typedef node) {
+ super.visitTypedef(node);
+ // These sub-nodes can have annotations but are not visited by
+ // Typedef.visitChildren.
+ visitList(node.positionalParameters, this);
+ visitList(node.namedParameters, this);
+ }
+
+ void _cleanupAnnotations(Node node, List<Expression> annotations) {
+ if (node is Member || node is Class || node is Library) {
+ annotations.removeWhere((a) => !_keepAnnotation(a));
+ } else {
+ annotations.clear();
+ }
+ }
+
+ bool _keepAnnotation(Expression annotation) {
+ final constant = (annotation as ConstantExpression).constant;
+ if (constant is InstanceConstant) {
+ final cls = constant.classNode;
+ return (cls == externalNameClass) ||
+ (cls == pragmaClass) ||
+ (protobufHandler != null && protobufHandler.usesAnnotationClass(cls));
+ }
+ return false;
+ }
+}
+
/// Devirtualization based on results of type flow analysis.
class TFADevirtualization extends Devirtualization {
final TypeFlowAnalysis _typeFlowAnalysis;
@@ -731,6 +784,7 @@
void addUsedExtension(Extension node) {
if (_usedExtensions.add(node)) {
+ node.annotations = const <Expression>[];
_pass1.transformTypeParameterList(node.typeParameters, node);
node.onType?.accept(typeVisitor);
}
@@ -738,7 +792,7 @@
void addUsedTypedef(Typedef typedef) {
if (_usedTypedefs.add(typedef)) {
- _pass1.transformExpressionList(typedef.annotations, typedef);
+ typedef.annotations = const <Expression>[];
_pass1.transformTypeParameterList(typedef.typeParameters, typedef);
_pass1.transformTypeParameterList(
typedef.typeParametersOfFunctionType, typedef);
@@ -1719,7 +1773,10 @@
shaker.addClassUsedInType(constant.classNode);
visitList(constant.typeArguments, typeVisitor);
constant.fieldValues.forEach((Reference fieldRef, Constant value) {
- shaker.addUsedMember(fieldRef.asField);
+ if (!shaker.retainField(fieldRef.asField)) {
+ throw 'Constant $constant references field ${fieldRef.asField} '
+ 'which is not retained';
+ }
analyzeConstant(value);
});
}
diff --git a/pkg/vm/testcases/transformations/type_flow/transformer/annotation.dart.expect b/pkg/vm/testcases/transformations/type_flow/transformer/annotation.dart.expect
index 28378be..a1350da 100644
--- a/pkg/vm/testcases/transformations/type_flow/transformer/annotation.dart.expect
+++ b/pkg/vm/testcases/transformations/type_flow/transformer/annotation.dart.expect
@@ -2,37 +2,20 @@
import self as self;
import "dart:core" as core;
-@#C5
typedef SomeType<contravariant T extends core::Object* = dynamic> = (core::List<T*>*) →* void;
-abstract class ClassAnnotation2 extends core::Object /*hasConstConstructor*/ {
-}
-abstract class MethodAnnotation extends core::Object /*hasConstConstructor*/ {
-[@vm.unreachable.metadata=] [@vm.procedure-attributes.metadata=methodOrSetterCalledDynamically:false,getterCalledDynamically:false,hasThisUses:false,hasNonThisUses:false,hasTearOffUses:false,getterSelectorId:1] final field core::int* x;
-}
-abstract class TypedefAnnotation extends core::Object /*hasConstConstructor*/ {
-[@vm.unreachable.metadata=] [@vm.procedure-attributes.metadata=methodOrSetterCalledDynamically:false,getterCalledDynamically:false,hasThisUses:false,hasNonThisUses:false,hasTearOffUses:false,getterSelectorId:2] final field core::List<core::int*>* list;
-}
-abstract class VarAnnotation extends core::Object /*hasConstConstructor*/ {
-}
-abstract class ParametrizedAnnotation<T extends core::Object* = dynamic> extends core::Object /*hasConstConstructor*/ {
-[@vm.unreachable.metadata=] [@vm.procedure-attributes.metadata=methodOrSetterCalledDynamically:false,getterCalledDynamically:false,hasThisUses:false,hasNonThisUses:false,hasTearOffUses:false,getterSelectorId:3] final field self::ParametrizedAnnotation::T* foo;
-}
abstract class A extends core::Object {
static method staticMethod() → void {}
}
-@#C6
class B extends core::Object {
synthetic constructor •() → self::B*
: super core::Object::•()
;
-[@vm.procedure-attributes.metadata=methodOrSetterCalledDynamically:false,getterCalledDynamically:false,hasThisUses:false,hasTearOffUses:false,methodOrSetterSelectorId:4,getterSelectorId:5] @#C8
- method instanceMethod() → void {}
+[@vm.procedure-attributes.metadata=methodOrSetterCalledDynamically:false,getterCalledDynamically:false,hasThisUses:false,hasTearOffUses:false,methodOrSetterSelectorId:1,getterSelectorId:2] method instanceMethod() → void {}
}
[@vm.unboxing-info.metadata=()->i]static method foo() → core::int* {
- @#C9 core::int* x = 2;
+ core::int* x = 2;
return [@vm.direct-call.metadata=dart.core::_IntegerImplementation.+] [@vm.inferred-type.metadata=int (skip check)] x.{core::num::+}(2);
}
-@#C11
static method main(core::List<core::String*>* args) → dynamic {
self::A::staticMethod();
[@vm.direct-call.metadata=#lib::B.instanceMethod] [@vm.inferred-type.metadata=!? (skip check)] new self::B::•().{self::B::instanceMethod}();
diff --git a/runtime/tests/vm/dart/regress_45968_test.dart b/runtime/tests/vm/dart/regress_45968_test.dart
new file mode 100644
index 0000000..80cff1f
--- /dev/null
+++ b/runtime/tests/vm/dart/regress_45968_test.dart
@@ -0,0 +1,28 @@
+// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Regression test for https://github.com/dart-lang/sdk/issues/45968.
+// Verifies that compiler doesn't crash if annotation references field
+// which is replaced with a getter.
+
+class Qualifier {
+ final String name;
+ const Qualifier(this.name);
+}
+
+class Foo implements Qualifier {
+ String get name => 'a';
+}
+
+class Bar {
+ @Qualifier('b')
+ void bar() {}
+}
+
+Qualifier x = Foo();
+
+main() {
+ print(x.name);
+ Bar().bar();
+}
diff --git a/runtime/tests/vm/dart_2/regress_45968_test.dart b/runtime/tests/vm/dart_2/regress_45968_test.dart
new file mode 100644
index 0000000..80cff1f
--- /dev/null
+++ b/runtime/tests/vm/dart_2/regress_45968_test.dart
@@ -0,0 +1,28 @@
+// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Regression test for https://github.com/dart-lang/sdk/issues/45968.
+// Verifies that compiler doesn't crash if annotation references field
+// which is replaced with a getter.
+
+class Qualifier {
+ final String name;
+ const Qualifier(this.name);
+}
+
+class Foo implements Qualifier {
+ String get name => 'a';
+}
+
+class Bar {
+ @Qualifier('b')
+ void bar() {}
+}
+
+Qualifier x = Foo();
+
+main() {
+ print(x.name);
+ Bar().bar();
+}
diff --git a/runtime/vm/clustered_snapshot.cc b/runtime/vm/clustered_snapshot.cc
index 6802b92..dd57f81 100644
--- a/runtime/vm/clustered_snapshot.cc
+++ b/runtime/vm/clustered_snapshot.cc
@@ -1812,25 +1812,24 @@
void Trace(Serializer* s, ObjectPtr object) {
CodePtr code = Code::RawCast(object);
- if (s->InCurrentLoadingUnit(code, /*record*/ true)) {
+ const bool is_deferred = !s->InCurrentLoadingUnitOrRoot(code);
+ if (is_deferred) {
+ s->RecordDeferredCode(code);
+ } else {
objects_.Add(code);
}
+ // Even if this code object is itself deferred we still need to scan
+ // the pool for references to other code objects (which might reside
+ // in the current loading unit).
+ ObjectPoolPtr pool = code->untag()->object_pool_;
if (s->kind() == Snapshot::kFullAOT && FLAG_use_bare_instructions) {
- ObjectPoolPtr pool = code->untag()->object_pool_;
- if ((pool != ObjectPool::null()) && s->InCurrentLoadingUnit(code)) {
- const intptr_t length = pool->untag()->length_;
- uint8_t* entry_bits = pool->untag()->entry_bits();
- for (intptr_t i = 0; i < length; i++) {
- auto entry_type = ObjectPool::TypeBits::decode(entry_bits[i]);
- if (entry_type == ObjectPool::EntryType::kTaggedObject) {
- s->Push(pool->untag()->data()[i].raw_obj_);
- }
- }
- }
+ TracePool(s, pool, /*only_code=*/is_deferred);
} else {
- if (s->InCurrentLoadingUnit(code->untag()->object_pool_)) {
- s->Push(code->untag()->object_pool_);
+ if (s->InCurrentLoadingUnitOrRoot(pool)) {
+ s->Push(pool);
+ } else {
+ TracePool(s, pool, /*only_code=*/true);
}
}
@@ -1868,7 +1867,7 @@
#endif
}
- if (s->InCurrentLoadingUnit(code->untag()->compressed_stackmaps_)) {
+ if (s->InCurrentLoadingUnitOrRoot(code->untag()->compressed_stackmaps_)) {
s->Push(code->untag()->compressed_stackmaps_);
}
@@ -1886,7 +1885,7 @@
s->Push(code->untag()->catch_entry_);
if (!FLAG_precompiled_mode || !FLAG_dwarf_stack_traces_mode) {
s->Push(code->untag()->inlined_id_to_function_);
- if (s->InCurrentLoadingUnit(code->untag()->code_source_map_)) {
+ if (s->InCurrentLoadingUnitOrRoot(code->untag()->code_source_map_)) {
s->Push(code->untag()->code_source_map_);
}
}
@@ -1898,6 +1897,24 @@
#endif
}
+ void TracePool(Serializer* s, ObjectPoolPtr pool, bool only_code) {
+ if (pool == ObjectPool::null()) {
+ return;
+ }
+
+ const intptr_t length = pool->untag()->length_;
+ uint8_t* entry_bits = pool->untag()->entry_bits();
+ for (intptr_t i = 0; i < length; i++) {
+ auto entry_type = ObjectPool::TypeBits::decode(entry_bits[i]);
+ if (entry_type == ObjectPool::EntryType::kTaggedObject) {
+ const ObjectPtr target = pool->untag()->data()[i].raw_obj_;
+ if (!only_code || target->IsCode()) {
+ s->Push(target);
+ }
+ }
+ }
+ }
+
struct CodeOrderInfo {
CodePtr code;
intptr_t order;
@@ -2074,7 +2091,7 @@
// No need to write object pool out if we are producing full AOT
// snapshot with bare instructions.
if (!(kind == Snapshot::kFullAOT && FLAG_use_bare_instructions)) {
- if (s->InCurrentLoadingUnit(code->untag()->object_pool_)) {
+ if (s->InCurrentLoadingUnitOrRoot(code->untag()->object_pool_)) {
WriteField(code, object_pool_);
} else {
WriteFieldValue(object_pool_, ObjectPool::null());
@@ -2084,7 +2101,7 @@
WriteField(code, exception_handlers_);
WriteField(code, pc_descriptors_);
WriteField(code, catch_entry_);
- if (s->InCurrentLoadingUnit(code->untag()->compressed_stackmaps_)) {
+ if (s->InCurrentLoadingUnitOrRoot(code->untag()->compressed_stackmaps_)) {
WriteField(code, compressed_stackmaps_);
} else {
WriteFieldValue(compressed_stackmaps_, CompressedStackMaps::null());
@@ -2094,7 +2111,7 @@
WriteFieldValue(code_source_map_, CodeSourceMap::null());
} else {
WriteField(code, inlined_id_to_function_);
- if (s->InCurrentLoadingUnit(code->untag()->code_source_map_)) {
+ if (s->InCurrentLoadingUnitOrRoot(code->untag()->code_source_map_)) {
WriteField(code, code_source_map_);
} else {
WriteFieldValue(code_source_map_, CodeSourceMap::null());
@@ -6701,7 +6718,7 @@
#endif // !DART_PRECOMPILED_RUNTIME
}
-bool Serializer::InCurrentLoadingUnit(ObjectPtr obj, bool record) {
+bool Serializer::InCurrentLoadingUnitOrRoot(ObjectPtr obj) {
if (loading_units_ == nullptr) return true;
intptr_t unit_id = heap_->GetLoadingUnit(obj);
@@ -6709,17 +6726,15 @@
// Not found in early assignment. Conservatively choose the root.
// TODO(41974): Are these always type testing stubs?
unit_id = LoadingUnit::kRootId;
+ heap_->SetLoadingUnit(obj, unit_id);
}
- if (unit_id == LoadingUnit::kRootId) {
- return true;
- }
- if (unit_id != current_loading_unit_id_) {
- if (record) {
- (*loading_units_)[unit_id]->AddDeferredObject(static_cast<CodePtr>(obj));
- }
- return false;
- }
- return true;
+ return unit_id == LoadingUnit::kRootId || unit_id == current_loading_unit_id_;
+}
+
+void Serializer::RecordDeferredCode(CodePtr code) {
+ const intptr_t unit_id = heap_->GetLoadingUnit(code);
+ ASSERT(unit_id != WeakTable::kNoValue && unit_id != LoadingUnit::kRootId);
+ (*loading_units_)[unit_id]->AddDeferredObject(code);
}
#if !defined(DART_PRECOMPILED_RUNTIME)
@@ -6786,7 +6801,7 @@
bool deferred) {
ASSERT(code != Code::null());
- ASSERT(InCurrentLoadingUnit(code) != deferred);
+ ASSERT(InCurrentLoadingUnitOrRoot(code) != deferred);
if (deferred) {
return;
}
diff --git a/runtime/vm/clustered_snapshot.h b/runtime/vm/clustered_snapshot.h
index ac3e31b..a97d6bd 100644
--- a/runtime/vm/clustered_snapshot.h
+++ b/runtime/vm/clustered_snapshot.h
@@ -434,7 +434,8 @@
// Returns true if [obj] has an artificial profile node associated with it.
bool CreateArtificialNodeIfNeeded(ObjectPtr obj);
- bool InCurrentLoadingUnit(ObjectPtr obj, bool record = false);
+ bool InCurrentLoadingUnitOrRoot(ObjectPtr obj);
+ void RecordDeferredCode(CodePtr ptr);
GrowableArray<LoadingUnitSerializationData*>* loading_units() const {
return loading_units_;
}
diff --git a/runtime/vm/runtime_entry.cc b/runtime/vm/runtime_entry.cc
index 2b33298..e420a88 100644
--- a/runtime/vm/runtime_entry.cc
+++ b/runtime/vm/runtime_entry.cc
@@ -549,6 +549,33 @@
arguments.SetReturn(type_arguments);
}
+// Helper routine for tracing a subtype check.
+static void PrintSubtypeCheck(const AbstractType& subtype,
+ const AbstractType& supertype,
+ const bool result) {
+ DartFrameIterator iterator(Thread::Current(),
+ StackFrameIterator::kNoCrossThreadIteration);
+ StackFrame* caller_frame = iterator.NextFrame();
+ ASSERT(caller_frame != NULL);
+
+ OS::PrintErr("SubtypeCheck: '%s' %d %s '%s' %d (pc: %#" Px ").\n",
+ String::Handle(subtype.Name()).ToCString(),
+ subtype.type_class_id(), result ? "is" : "is !",
+ String::Handle(supertype.Name()).ToCString(),
+ supertype.type_class_id(), caller_frame->pc());
+
+ const Function& function =
+ Function::Handle(caller_frame->LookupDartFunction());
+ if (function.HasSavedArgumentsDescriptor()) {
+ const auto& args_desc_array = Array::Handle(function.saved_args_desc());
+ const ArgumentsDescriptor args_desc(args_desc_array);
+ OS::PrintErr(" -> Function %s [%s]\n", function.ToFullyQualifiedCString(),
+ args_desc.ToCString());
+ } else {
+ OS::PrintErr(" -> Function %s\n", function.ToFullyQualifiedCString());
+ }
+}
+
// Instantiate type.
// Arg0: instantiator type arguments
// Arg1: function type arguments
@@ -580,14 +607,19 @@
}
ASSERT(!subtype.IsNull() && !subtype.IsTypeRef());
- // TODO(regis): Support for FLAG_trace_type_checks is missing here. Is it
- // still useful or should we remove it everywhere?
-
// The supertype or subtype may not be instantiated.
if (AbstractType::InstantiateAndTestSubtype(
&subtype, &supertype, instantiator_type_args, function_type_args)) {
+ if (FLAG_trace_type_checks) {
+ // The supertype and subtype are now instantiated. Subtype check passed.
+ PrintSubtypeCheck(subtype, supertype, true);
+ }
return;
}
+ if (FLAG_trace_type_checks) {
+ // The supertype and subtype are now instantiated. Subtype check failed.
+ PrintSubtypeCheck(subtype, supertype, false);
+ }
// Throw a dynamic type error.
const TokenPosition location = GetCallerLocation();
diff --git a/sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart b/sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart
index d537160..07ed13e 100644
--- a/sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart
+++ b/sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart
@@ -128,43 +128,31 @@
}
}
-// TODO(jmesserly): switch to WeakMap
// Patch for Expando implementation.
@patch
class Expando<T extends Object> {
+ final Object _jsWeakMap = JS('=Object', 'new WeakMap()');
+
@patch
- Expando([String? name]) : this.name = name;
+ Expando([this.name]);
@patch
T? operator [](Object object) {
- var values = Primitives.getProperty(object, _EXPANDO_PROPERTY_NAME);
- return (values == null)
- ? null
- : Primitives.getProperty(values, _getKey()) as T?;
+ _checkType(object); // WeakMap doesn't check on reading, only writing.
+ return JS('', '#.get(#)', _jsWeakMap, object);
}
@patch
void operator []=(Object object, T? value) {
- var values = Primitives.getProperty(object, _EXPANDO_PROPERTY_NAME);
- if (values == null) {
- values = Object();
- Primitives.setProperty(object, _EXPANDO_PROPERTY_NAME, values);
- }
- Primitives.setProperty(values, _getKey(), value);
+ JS('void', '#.set(#, #)', _jsWeakMap, object, value);
}
- String _getKey() {
- var key = Primitives.getProperty(this, _KEY_PROPERTY_NAME) as String?;
- if (key == null) {
- key = "expando\$key\$${_keyCount++}";
- Primitives.setProperty(this, _KEY_PROPERTY_NAME, key);
+ static _checkType(object) {
+ if (object == null || object is bool || object is num || object is String) {
+ throw new ArgumentError.value(object,
+ "Expandos are not allowed on strings, numbers, booleans or null");
}
- return key;
}
-
- static const String _KEY_PROPERTY_NAME = 'expando\$key';
- static const String _EXPANDO_PROPERTY_NAME = 'expando\$values';
- static int _keyCount = 0;
}
@patch
diff --git a/sdk/lib/_internal/js_runtime/lib/core_patch.dart b/sdk/lib/_internal/js_runtime/lib/core_patch.dart
index b8ec87b..abd63e2 100644
--- a/sdk/lib/_internal/js_runtime/lib/core_patch.dart
+++ b/sdk/lib/_internal/js_runtime/lib/core_patch.dart
@@ -92,56 +92,23 @@
// Patch for Expando implementation.
@patch
-class Expando<T> {
- static const String _EXPANDO_PROPERTY_NAME = 'expando\$values';
-
- // Incremented to make unique keys.
- static int _keyCount = 0;
-
- // Stores either a JS WeakMap or a "unique" string key.
- final Object _jsWeakMapOrKey;
+class Expando<T extends Object> {
+ final Object _jsWeakMap = JS('=Object', 'new WeakMap()');
@patch
- Expando([String? name])
- : this.name = name,
- _jsWeakMapOrKey = JS('bool', 'typeof WeakMap == "function"')
- ? JS('=Object', 'new WeakMap()')
- : _createKey();
+ Expando([this.name]);
@patch
T? operator [](Object object) {
- if (_jsWeakMapOrKey is! String) {
- _checkType(object); // WeakMap doesn't check on reading, only writing.
- return JS('', '#.get(#)', _jsWeakMapOrKey, object);
- }
- return _getFromObject(_jsWeakMapOrKey as String, object) as T?;
+ _checkType(object); // WeakMap doesn't check on reading, only writing.
+ return JS('', '#.get(#)', _jsWeakMap, object);
}
@patch
void operator []=(Object object, T? value) {
- if (_jsWeakMapOrKey is! String) {
- JS('void', '#.set(#, #)', _jsWeakMapOrKey, object, value);
- } else {
- _setOnObject(_jsWeakMapOrKey as String, object, value);
- }
+ JS('void', '#.set(#, #)', _jsWeakMap, object, value);
}
- static Object _getFromObject(String key, Object object) {
- var values = Primitives.getProperty(object, _EXPANDO_PROPERTY_NAME);
- return (values == null) ? null : Primitives.getProperty(values, key);
- }
-
- static void _setOnObject(String key, Object object, Object? value) {
- var values = Primitives.getProperty(object, _EXPANDO_PROPERTY_NAME);
- if (values == null) {
- values = new Object();
- Primitives.setProperty(object, _EXPANDO_PROPERTY_NAME, values);
- }
- Primitives.setProperty(values, key, value);
- }
-
- static String _createKey() => "expando\$key\$${_keyCount++}";
-
static _checkType(object) {
if (object == null || object is bool || object is num || object is String) {
throw new ArgumentError.value(object,
diff --git a/tests/dartdevc/hot_restart_expando_test.dart b/tests/dartdevc/hot_restart_expando_test.dart
new file mode 100644
index 0000000..4802a52
--- /dev/null
+++ b/tests/dartdevc/hot_restart_expando_test.dart
@@ -0,0 +1,30 @@
+// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:_runtime' as dart;
+
+import 'package:expect/expect.dart';
+import 'package:js/js.dart';
+
+final e = Expando<int>();
+
+@JS()
+external void eval(String s);
+
+@JS()
+external Object get singleton;
+
+void main() {
+ eval('''
+ if (!self.singleton) {
+ self.singleton = {};
+ }
+ ''');
+ var o = singleton;
+ Expect.equals(null, e[o]);
+ e[o] = 1;
+
+ dart.hotRestart();
+ Expect.equals(null, e[o]);
+}
diff --git a/tests/dartdevc_2/hot_restart_expando_test.dart b/tests/dartdevc_2/hot_restart_expando_test.dart
new file mode 100644
index 0000000..4802a52
--- /dev/null
+++ b/tests/dartdevc_2/hot_restart_expando_test.dart
@@ -0,0 +1,30 @@
+// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:_runtime' as dart;
+
+import 'package:expect/expect.dart';
+import 'package:js/js.dart';
+
+final e = Expando<int>();
+
+@JS()
+external void eval(String s);
+
+@JS()
+external Object get singleton;
+
+void main() {
+ eval('''
+ if (!self.singleton) {
+ self.singleton = {};
+ }
+ ''');
+ var o = singleton;
+ Expect.equals(null, e[o]);
+ e[o] = 1;
+
+ dart.hotRestart();
+ Expect.equals(null, e[o]);
+}
diff --git a/tools/VERSION b/tools/VERSION
index 4dbaebf..acf070f 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
MAJOR 2
MINOR 14
PATCH 0
-PRERELEASE 107
+PRERELEASE 108
PRERELEASE_PATCH 0
\ No newline at end of file