Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4a4f34a

Browse files
author
Dart CI
committed
Version 2.17.0-18.0.dev
Merge commit '9bea02b9763e01f8871b7652096be9e10985197d' into 'dev'
2 parents 590635a + 9bea02b commit 4a4f34a

File tree

8 files changed

+134
-12
lines changed

8 files changed

+134
-12
lines changed

pkg/analysis_server/lib/src/lsp/mapping.dart

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,36 @@ List<lsp.DiagnosticTag>? getDiagnosticTags(
683683
bool isDartDocument(lsp.TextDocumentIdentifier? doc) =>
684684
doc?.uri.endsWith('.dart') ?? false;
685685

686+
/// Converts a [server.Location] to an [lsp.Range] by translating the
687+
/// offset/length using a `LineInfo`.
688+
///
689+
/// This function ignores any line/column info on the
690+
/// [server.Location] assuming it is either not available not unreliable.
691+
lsp.Range locationOffsetLenToRange(
692+
server.LineInfo lineInfo, server.Location location) =>
693+
toRange(lineInfo, location.offset, location.length);
694+
695+
/// Converts a [server.Location] to an [lsp.Range] if all line and column
696+
/// values are available.
697+
///
698+
/// Returns null if any values are -1 or null.
699+
lsp.Range? locationToRange(server.Location location) {
700+
final startLine = location.startLine;
701+
final startColumn = location.startColumn;
702+
final endLine = location.endLine ?? -1;
703+
final endColumn = location.endColumn ?? -1;
704+
if (startLine == -1 ||
705+
startColumn == -1 ||
706+
endLine == -1 ||
707+
endColumn == -1) {
708+
return null;
709+
}
710+
// LSP positions are 0-based but Location is 1-based.
711+
return Range(
712+
start: Position(line: startLine - 1, character: startColumn - 1),
713+
end: Position(line: endLine - 1, character: endColumn - 1));
714+
}
715+
686716
/// Merges two [WorkspaceEdit]s into a single one.
687717
///
688718
/// Will throw if given [WorkspaceEdit]s that do not use documentChanges.
@@ -800,10 +830,12 @@ lsp.Diagnostic pluginToDiagnostic(
800830
message = '$message\n${error.correction}';
801831
}
802832

803-
var lineInfo = getLineInfo(error.location.file);
833+
final range = locationToRange(error.location) ??
834+
locationOffsetLenToRange(
835+
getLineInfo(error.location.file), error.location);
804836
var documentationUrl = error.url;
805837
return lsp.Diagnostic(
806-
range: toRange(lineInfo, error.location.offset, error.location.length),
838+
range: range,
807839
severity: pluginToDiagnosticSeverity(error.severity),
808840
code: error.code,
809841
source: languageSourceName,
@@ -831,6 +863,9 @@ lsp.DiagnosticRelatedInformation? pluginToDiagnosticRelatedInformation(
831863
return lsp.DiagnosticRelatedInformation(
832864
location: lsp.Location(
833865
uri: Uri.file(file).toString(),
866+
// TODO(dantup): Switch to using line/col information from the context
867+
// message once confirmed that AnalyzerConverter is not using the wrong
868+
// LineInfo.
834869
range: toRange(
835870
lineInfo,
836871
message.location.offset,

pkg/analysis_server/test/lsp/diagnostic_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ String b = "Test";
3030
final pluginError = plugin.AnalysisError(
3131
plugin.AnalysisErrorSeverity.ERROR,
3232
plugin.AnalysisErrorType.STATIC_TYPE_WARNING,
33-
plugin.Location(pluginAnalyzedFilePath, 0, 6, 0, 0,
34-
endLine: 0, endColumn: 6),
33+
plugin.Location(pluginAnalyzedFilePath, 0, 6, 1, 1,
34+
endLine: 1, endColumn: 7),
3535
'Test error from plugin',
3636
'ERR1',
3737
contextMessages: [
3838
plugin.DiagnosticMessage(
3939
'Related error',
40-
plugin.Location(pluginAnalyzedFilePath, 31, 4, 1, 12,
41-
endLine: 1, endColumn: 16))
40+
plugin.Location(pluginAnalyzedFilePath, 31, 4, 2, 13,
41+
endLine: 2, endColumn: 17))
4242
],
4343
);
4444
final pluginResult =

pkg/analyzer/lib/src/summary2/top_level_inference.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ class _InferenceDependenciesCollector extends RecursiveAstVisitor<void> {
290290

291291
@override
292292
void visitSimpleIdentifier(SimpleIdentifier node) {
293-
var element = node.staticElement;
293+
var element = node.staticElement?.declaration;
294294
if (element is PropertyAccessorElement && element.isGetter) {
295295
_set.add(element.variable);
296296
}

pkg/analyzer/test/src/summary/resynthesize_common.dart

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31540,6 +31540,32 @@ library
3154031540
''');
3154131541
}
3154231542

31543+
test_type_inference_classField_fromNullSafe_toLegacy() async {
31544+
testFile = convertPath('/home/test/lib/test.dart');
31545+
addLibrarySource('/home/test/lib/a.dart', '''
31546+
class E {
31547+
static final a = 0;
31548+
}
31549+
''');
31550+
var library = await checkLibrary('''
31551+
// @dart = 2.9
31552+
import 'a.dart';
31553+
final v = E.a;
31554+
''');
31555+
checkElementText(library, r'''
31556+
library
31557+
imports
31558+
package:test/a.dart
31559+
definingUnit
31560+
topLevelVariables
31561+
static final v @38
31562+
type: int*
31563+
accessors
31564+
synthetic static get v @-1
31565+
returnType: int*
31566+
''');
31567+
}
31568+
3154331569
test_type_inference_closure_with_function_typed_parameter() async {
3154431570
var library = await checkLibrary('''
3154531571
var x = (int f(String x)) => 0;

pkg/vm/testcases/transformations/type_flow/transformer/enum_from_lib_used_as_type.dart.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ class Class extends core::Object {
2222
synthetic constructor •() → self::Class
2323
: super core::Object::•()
2424
;
25-
[@vm.procedure-attributes.metadata=methodOrSetterCalledDynamically:false,getterCalledDynamically:false,hasThisUses:false,hasTearOffUses:false,methodOrSetterSelectorId:3380,getterSelectorId:3381] method method([@vm.inferred-type.metadata=dart.core::Null? (value: null)] self::Enum e) → core::int
25+
[@vm.procedure-attributes.metadata=methodOrSetterCalledDynamically:false,getterCalledDynamically:false,hasThisUses:false,hasTearOffUses:false,methodOrSetterSelectorId:3384,getterSelectorId:3385] method method([@vm.inferred-type.metadata=dart.core::Null? (value: null)] self::Enum e) → core::int
2626
return [@vm.inferred-type.metadata=!] e.{core::_Enum::index}{core::int};
2727
}

pkg/vm/testcases/transformations/type_flow/transformer/tree_shake_enum_from_lib.dart.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ class ConstClass extends core::Object {
5151
synthetic constructor •() → self::ConstClass
5252
: super core::Object::•()
5353
;
54-
[@vm.procedure-attributes.metadata=methodOrSetterCalledDynamically:false,getterCalledDynamically:false,hasThisUses:false,hasTearOffUses:false,methodOrSetterSelectorId:3384,getterSelectorId:3385] method method([@vm.inferred-type.metadata=dart.core::Null? (value: null)] self::ConstEnum e) → core::int
54+
[@vm.procedure-attributes.metadata=methodOrSetterCalledDynamically:false,getterCalledDynamically:false,hasThisUses:false,hasTearOffUses:false,methodOrSetterSelectorId:3388,getterSelectorId:3389] method method([@vm.inferred-type.metadata=dart.core::Null? (value: null)] self::ConstEnum e) → core::int
5555
return [@vm.inferred-type.metadata=!] e.{core::_Enum::index}{core::int};
5656
}

sdk/lib/_internal/vm/lib/compact_hash.dart

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,27 @@ abstract class _HashBase implements _HashVMBase {
185185
!identical(_data, oldData) || (_checkSum != oldCheckSum);
186186

187187
int get length;
188+
189+
// If this collection has never had an insertion, and [other] is the same
190+
// representation and has had no deletions, then adding the entries of [other]
191+
// will end up building the same [_data] and [_index]. We can do this more
192+
// efficiently by copying the Lists directly.
193+
//
194+
// Precondition: [this] and [other] must use the same hashcode and equality.
195+
bool _quickCopy(_HashBase other) {
196+
if (!identical(_index, _uninitializedIndex)) return false;
197+
if (other._usedData == 0) return true; // [other] is empty, nothing to copy.
198+
if (other._deletedKeys != 0) return false;
199+
200+
assert(!identical(other._index, _uninitializedIndex));
201+
assert(!identical(other._data, _uninitializedData));
202+
_index = Uint32List.fromList(other._index);
203+
_hashMask = other._hashMask;
204+
_data = List.of(other._data, growable: false);
205+
_usedData = other._usedData;
206+
_deletedKeys = other._deletedKeys;
207+
return true;
208+
}
188209
}
189210

190211
class _OperatorEqualsAndHashCode {
@@ -233,6 +254,16 @@ class _InternalLinkedHashMap<K, V> extends _HashVMBase
233254
_usedData = 0;
234255
_deletedKeys = 0;
235256
}
257+
258+
void addAll(Map<K, V> other) {
259+
if (other is _InternalLinkedHashMap) {
260+
final otherBase = other as _InternalLinkedHashMap; // manual promotion.
261+
// If this map is empty we might be able to block-copy from [other].
262+
if (isEmpty && _quickCopy(otherBase)) return;
263+
// TODO(48143): Pre-grow capacity if it will reduce rehashing.
264+
}
265+
super.addAll(other);
266+
}
236267
}
237268

238269
// This is essentially the same class as _InternalLinkedHashMap, but it does
@@ -531,7 +562,7 @@ abstract class _LinkedHashMapMixin<K, V> implements _HashBase {
531562
return false;
532563
}
533564

534-
void forEach(void f(K key, V value)) {
565+
void forEach(void action(K key, V value)) {
535566
final data = _data;
536567
final checkSum = _checkSum;
537568
final len = _usedData;
@@ -540,7 +571,7 @@ abstract class _LinkedHashMapMixin<K, V> implements _HashBase {
540571
if (_HashBase._isDeleted(data, current)) continue;
541572
final key = internal.unsafeCast<K>(current);
542573
final value = internal.unsafeCast<V>(data[offset + 1]);
543-
f(key, value);
574+
action(key, value);
544575
if (_isModifiedSince(data, checkSum)) {
545576
throw ConcurrentModificationError(this);
546577
}
@@ -561,6 +592,16 @@ class _CompactLinkedIdentityHashMap<K, V> extends _HashFieldBase
561592
_IdenticalAndIdentityHashCode
562593
implements LinkedHashMap<K, V> {
563594
_CompactLinkedIdentityHashMap() : super(_HashBase._INITIAL_INDEX_SIZE);
595+
596+
void addAll(Map<K, V> other) {
597+
if (other is _CompactLinkedIdentityHashMap) {
598+
final otherBase = other as _CompactLinkedIdentityHashMap;
599+
// If this map is empty we might be able to block-copy from [other].
600+
if (isEmpty && _quickCopy(otherBase)) return;
601+
// TODO(48143): Pre-grow capacity if it will reduce rehashing.
602+
}
603+
super.addAll(other);
604+
}
564605
}
565606

566607
class _CompactLinkedCustomHashMap<K, V> extends _HashFieldBase
@@ -832,6 +873,16 @@ class _CompactLinkedHashSet<E> extends _HashVMBase
832873
// is not required by the spec. (For instance, always using an identity set
833874
// would be technically correct, albeit surprising.)
834875
Set<E> toSet() => new _CompactLinkedHashSet<E>()..addAll(this);
876+
877+
void addAll(Iterable<E> other) {
878+
if (other is _CompactLinkedHashSet) {
879+
final otherBase = other as _CompactLinkedHashSet;
880+
// If this set is empty we might be able to block-copy from [other].
881+
if (isEmpty && _quickCopy(otherBase)) return;
882+
// TODO(48143): Pre-grow capacity if it will reduce rehashing.
883+
}
884+
super.addAll(other);
885+
}
835886
}
836887

837888
@pragma("vm:entry-point")
@@ -924,6 +975,16 @@ class _CompactLinkedIdentityHashSet<E> extends _HashFieldBase
924975
static Set<R> _newEmpty<R>() => new _CompactLinkedIdentityHashSet<R>();
925976

926977
Set<R> cast<R>() => Set.castFrom<E, R>(this, newSet: _newEmpty);
978+
979+
void addAll(Iterable<E> other) {
980+
if (other is _CompactLinkedIdentityHashSet) {
981+
final otherBase = other as _CompactLinkedIdentityHashSet;
982+
// If this set is empty we might be able to block-copy from [other].
983+
if (isEmpty && _quickCopy(otherBase)) return;
984+
// TODO(48143): Pre-grow capacity if it will reduce rehashing.
985+
}
986+
super.addAll(other);
987+
}
927988
}
928989

929990
class _CompactLinkedCustomHashSet<E> extends _HashFieldBase

tools/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ CHANNEL dev
2727
MAJOR 2
2828
MINOR 17
2929
PATCH 0
30-
PRERELEASE 17
30+
PRERELEASE 18
3131
PRERELEASE_PATCH 0

0 commit comments

Comments
 (0)