Skip to content

Commit

Permalink
Version 3.6.0-77.0.dev
Browse files Browse the repository at this point in the history
Merge e02326f into dev
  • Loading branch information
Dart CI committed Jul 24, 2024
2 parents f4f9568 + e02326f commit 0b3c00f
Show file tree
Hide file tree
Showing 26 changed files with 522 additions and 7 deletions.
8 changes: 8 additions & 0 deletions pkg/analysis_server/lib/src/analysis_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ abstract class AnalysisServer {
/// The [SearchEngine] for this server.
late final SearchEngine searchEngine;

/// The optional [ByteStore] to use as [byteStore].
final ByteStore? providedByteStore;

late ByteStore byteStore;

late FileContentCache fileContentCache;
Expand Down Expand Up @@ -253,6 +256,7 @@ abstract class AnalysisServer {
this.requestStatistics,
bool enableBlazeWatcher = false,
DartFixPromptManager? dartFixPromptManager,
this.providedByteStore,
}) : resourceProvider = OverlayResourceProvider(baseResourceProvider),
pubApi = PubApi(instrumentationService, httpClient,
Platform.environment['PUB_HOSTED_URL']),
Expand Down Expand Up @@ -492,6 +496,10 @@ abstract class AnalysisServer {

const memoryCacheSize = 128 * M;

if (providedByteStore case var providedByteStore?) {
return providedByteStore;
}

if (resourceProvider is OverlayResourceProvider) {
resourceProvider = resourceProvider.baseProvider;
}
Expand Down
1 change: 1 addition & 0 deletions pkg/analysis_server/lib/src/legacy_analysis_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ class LegacyAnalysisServer extends AnalysisServer {
// Disable to avoid using this in unit tests.
bool enableBlazeWatcher = false,
DartFixPromptManager? dartFixPromptManager,
super.providedByteStore,
}) : lspClientConfiguration =
lsp.LspClientConfiguration(baseResourceProvider.pathContext),
super(
Expand Down
16 changes: 16 additions & 0 deletions pkg/analysis_server/test/analysis_server_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:analysis_server/src/utilities/mocks.dart';
import 'package:analyzer/dart/analysis/analysis_options.dart' as analysis;
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/instrumentation/service.dart';
import 'package:analyzer/src/dart/analysis/byte_store.dart';
import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/test_utilities/mock_sdk.dart';
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
Expand Down Expand Up @@ -84,6 +85,14 @@ class BlazeWorkspaceAnalysisServerTest extends ContextResolutionTest {
}

abstract class ContextResolutionTest with ResourceProviderMixin {
/// The byte store that is reused between tests. This allows reusing all
/// unlinked and linked summaries for SDK, so that tests run much faster.
/// However nothing is preserved between Dart VM runs, so changes to the
/// implementation are still fully verified.
static final MemoryByteStore _sharedByteStore = MemoryByteStore();

MemoryByteStore _byteStore = _sharedByteStore;

final TestPluginManager pluginManager = TestPluginManager();
late final MockServerChannel serverChannel;
late final LegacyAnalysisServer server;
Expand Down Expand Up @@ -184,6 +193,7 @@ abstract class ContextResolutionTest with ResourceProviderMixin {
CrashReportingAttachmentsBuilder.empty,
InstrumentationService.NULL_SERVICE,
dartFixPromptManager: dartFixPromptManager,
providedByteStore: _byteStore,
);

server.pluginManager = pluginManager;
Expand Down Expand Up @@ -301,6 +311,12 @@ class PubPackageAnalysisServerTest extends ContextResolutionTest
return offset;
}

/// Call this method if the test needs to use the empty byte store, without
/// any information cached.
void useEmptyByteStore() {
_byteStore = MemoryByteStore();
}

void writeTestPackageAnalysisOptionsFile(AnalysisOptionsFileConfig config) {
newAnalysisOptionsYamlFile(
testPackageRootPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ class DartTextDocumentContentProviderTest extends LspOverLegacyTest {
await handleRequest(request);
}

@override
Future<void> setUp() async {
useEmptyByteStore();
await super.setUp();
}

Future<void> test_valid_content() async {
addMacros([declareInTypeMacro()]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mixin DocumentationTestCases on AbstractCompletionDriverTest {

@override
Future<void> setUp() async {
useEmptyByteStore();
await super.setUp();
printerConfiguration.withDocumentation = true;
}
Expand Down
1 change: 1 addition & 0 deletions pkg/analyzer/lib/dart/ast/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export 'package:analyzer/src/dart/ast/ast.dart'
NodeList,
NormalFormalParameter,
NullAssertPattern,
NullAwareElement,
NullCheckPattern,
NullLiteral,
NullShortableExpression,
Expand Down
27 changes: 27 additions & 0 deletions pkg/analyzer/lib/dart/ast/visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,10 @@ class GeneralizingAstVisitor<R> implements AstVisitor<R> {
@override
R? visitNullAssertPattern(NullAssertPattern node) => visitDartPattern(node);

@override
R? visitNullAwareElement(NullAwareElement node) =>
visitCollectionElement(node);

@override
R? visitNullCheckPattern(NullCheckPattern node) => visitDartPattern(node);

Expand Down Expand Up @@ -1471,6 +1475,12 @@ class RecursiveAstVisitor<R> implements AstVisitor<R> {
return null;
}

@override
R? visitNullAwareElement(NullAwareElement node) {
node.visitChildren(this);
return null;
}

@override
R? visitNullCheckPattern(NullCheckPattern node) {
node.visitChildren(this);
Expand Down Expand Up @@ -2209,6 +2219,9 @@ class SimpleAstVisitor<R> implements AstVisitor<R> {
@override
R? visitNullAssertPattern(NullAssertPattern node) => null;

@override
R? visitNullAwareElement(NullAwareElement node) => null;

@override
R? visitNullCheckPattern(NullCheckPattern node) => null;

Expand Down Expand Up @@ -2770,6 +2783,9 @@ class ThrowingAstVisitor<R> implements AstVisitor<R> {
@override
R? visitNullAssertPattern(NullAssertPattern node) => _throw(node);

@override
R? visitNullAwareElement(NullAwareElement node) => _throw(node);

@override
R? visitNullCheckPattern(NullCheckPattern node) => _throw(node);

Expand Down Expand Up @@ -3880,6 +3896,14 @@ class TimedAstVisitor<T> implements AstVisitor<T> {
return result;
}

@override
T? visitNullAwareElement(NullAwareElement node) {
stopwatch.start();
T? result = _baseVisitor.visitNullAwareElement(node);
stopwatch.stop();
return result;
}

@override
T? visitNullCheckPattern(NullCheckPattern node) {
stopwatch.start();
Expand Down Expand Up @@ -4772,6 +4796,9 @@ class UnifyingAstVisitor<R> implements AstVisitor<R> {
@override
R? visitNullAssertPattern(NullAssertPattern node) => visitNode(node);

@override
R? visitNullAwareElement(NullAwareElement node) => visitNode(node);

@override
R? visitNullCheckPattern(NullCheckPattern node) => visitNode(node);

Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/analysis/driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ import 'package:meta/meta.dart';
// TODO(scheglov): Clean up the list of implicitly analyzed files.
class AnalysisDriver {
/// The version of data format, should be incremented on every format change.
static const int DATA_VERSION = 373;
static const int DATA_VERSION = 374;

/// The number of exception contexts allowed to write. Once this field is
/// zero, we stop writing any new exception contexts in this process.
Expand Down
84 changes: 82 additions & 2 deletions pkg/analyzer/lib/src/dart/ast/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,8 @@ abstract class AstVisitor<R> {

R? visitNullAssertPattern(NullAssertPattern node);

R? visitNullAwareElement(NullAwareElement node);

R? visitNullCheckPattern(NullCheckPattern node);

R? visitNullLiteral(NullLiteral node);
Expand Down Expand Up @@ -11268,31 +11270,47 @@ final class LogicalOrPatternImpl extends DartPatternImpl
/// A single key/value pair in a map literal.
///
/// mapLiteralEntry ::=
/// [Expression] ':' [Expression]
/// '?'? [Expression] ':' '?'? [Expression]
abstract final class MapLiteralEntry implements CollectionElement {
/// The expression computing the key with which the value is associated.
Expression get key;

/// The question prefix for the key that may present in null-aware map
/// entries.
Token? get keyQuestion;

/// The colon that separates the key from the value.
Token get separator;

/// The expression computing the value that is associated with the key.
Expression get value;

/// The question prefix for the value that may present in null-aware map
/// entries.
Token? get valueQuestion;
}

final class MapLiteralEntryImpl extends CollectionElementImpl
implements MapLiteralEntry {
@override
final Token? keyQuestion;

ExpressionImpl _key;

@override
final Token separator;

@override
final Token? valueQuestion;

ExpressionImpl _value;

/// Initializes a newly created map literal entry.
MapLiteralEntryImpl({
required this.keyQuestion,
required ExpressionImpl key,
required this.separator,
required this.valueQuestion,
required ExpressionImpl value,
}) : _key = key,
_value = value {
Expand All @@ -11301,7 +11319,7 @@ final class MapLiteralEntryImpl extends CollectionElementImpl
}

@override
Token get beginToken => _key.beginToken;
Token get beginToken => keyQuestion ?? _key.beginToken;

@override
Token get endToken => _value.endToken;
Expand All @@ -11322,8 +11340,10 @@ final class MapLiteralEntryImpl extends CollectionElementImpl

@override
ChildEntities get _childEntities => ChildEntities()
..addToken('keyQuestion', keyQuestion)
..addNode('key', key)
..addToken('separator', separator)
..addToken('valueQuestion', valueQuestion)
..addNode('value', value);

@override
Expand Down Expand Up @@ -12819,6 +12839,66 @@ final class NullAssertPatternImpl extends DartPatternImpl
}
}

/// A null-aware element in a list or set literal.
///
/// <nullAwareExpressionElement> ::= '?' <expression>
abstract final class NullAwareElement implements CollectionElement {
/// The question mark before the expression.
Token get question;

/// The expression computing the value that is associated with the element.
Expression get value;
}

final class NullAwareElementImpl extends CollectionElementImpl
implements NullAwareElement {
@override
final Token question;

ExpressionImpl _value;

/// Initializes a newly created null-aware element.
NullAwareElementImpl({
required this.question,
required ExpressionImpl value,
}) : _value = value {
_becomeParentOf(_value);
}

@override
Token get beginToken => question;

@override
Token get endToken => _value.endToken;

@override
ExpressionImpl get value => _value;

set value(ExpressionImpl expression) {
_value = _becomeParentOf(expression);
}

@override
ChildEntities get _childEntities => ChildEntities()
..addToken('question', question)
..addNode('value', value);

@override
E? accept<E>(AstVisitor<E> visitor) => visitor.visitNullAwareElement(this);

@override
void resolveElement(
ResolverVisitor resolver, CollectionLiteralContext? context) {
// resolver.visitNullAwareElement(this, context: context);
resolver.pushRewrite(null);
}

@override
void visitChildren(AstVisitor visitor) {
_value.accept(visitor);
}
}

/// A null-check pattern.
///
/// nullCheckPattern ::=
Expand Down
6 changes: 6 additions & 0 deletions pkg/analyzer/lib/src/dart/ast/to_source_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,12 @@ class ToSourceVisitor implements AstVisitor<void> {
sink.write(node.operator.lexeme);
}

@override
void visitNullAwareElement(NullAwareElement node) {
sink.write(node.question.lexeme);
_visitNode(node.value);
}

@override
void visitNullCheckPattern(NullCheckPattern node) {
_visitNode(node.pattern);
Expand Down
16 changes: 16 additions & 0 deletions pkg/analyzer/lib/src/dart/ast/utilities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,13 @@ class AstComparator implements AstVisitor<bool> {
isEqualTokens(node.operator, other.operator);
}

@override
bool visitNullAwareElement(NullAwareElement node) {
NullAwareElement other = _other as NullAwareElement;
return isEqualTokens(node.question, other.question) &&
isEqualNodes(node.value, other.value);
}

@override
bool visitNullCheckPattern(NullCheckPattern node) {
var other = _other as NullCheckPattern;
Expand Down Expand Up @@ -3042,6 +3049,15 @@ class NodeReplacer extends ThrowingAstVisitor<bool> {
return visitNode(node);
}

@override
bool visitNullAwareElement(NullAwareElement node) {
if (identical(node.value, _oldNode)) {
(node as NullAwareElementImpl).value = _newNode as ExpressionImpl;
return true;
}
return visitNode(node);
}

@override
bool visitNullLiteral(NullLiteral node) => visitNode(node);

Expand Down
Loading

0 comments on commit 0b3c00f

Please sign in to comment.