Skip to content

Commit 50dcff4

Browse files
author
Dart CI
committed
Version 2.18.0-164.0.dev
Merge commit 'aa0d0c56cb36ee1b3df7dcfef819d7e37256fbb1' into 'dev'
2 parents 7621b91 + aa0d0c5 commit 50dcff4

File tree

63 files changed

+807
-236
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+807
-236
lines changed

DEPS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ vars = {
107107
"dart_style_rev": "d7b73536a8079331c888b7da539b80e6825270ea",
108108

109109
"dartdoc_rev": "8549817bb1b59808108e83ef0e513157cb572d2a",
110-
"devtools_rev": "3c16b8d73120e46958982d94215d499793b972eb",
110+
"devtools_rev": "51ac983d2db7eb19b3ce5956cb70b769d74fe784",
111111
"ffi_rev": "0c8364a728cfe4e4ba859c53b99d56b3dbe3add4",
112112
"file_rev": "0132eeedea2933513bf230513a766a8baeab0c4f",
113113
"fixnum_rev": "3bfc2ed1eea7e7acb79ad4f17392f92c816fc5ce",
@@ -116,7 +116,7 @@ vars = {
116116
"http_io_rev": "405fc79233b4a3d4bb079ebf438bb2caf2f49355",
117117
"http_multi_server_rev": "35a3b947256768426090e3b1f5132e4fc23c175d",
118118
"http_parser_rev": "9126ee04e77fd8e4e2e6435b503ee4dd708d7ddc",
119-
"http_rev": "2c9b418f5086f999c150d18172d2eec1f963de7b",
119+
"http_rev": "2993ea5dff5ffb066b4a35c707e7a2b8dcfa17c2",
120120
"icu_rev": "81d656878ec611cb0b42d52c82e9dae93920d9ba",
121121
"intl_rev": "9145f308f1458f37630a1ffce3b7d3b471ebbc56",
122122
"jinja2_rev": "2222b31554f03e62600cd7e383376a7c187967a1",

pkg/analyzer/lib/src/dart/analysis/byte_store.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,18 @@ class MemoryCachingByteStore implements ByteStore {
5050

5151
@override
5252
Uint8List? get(String key) {
53-
return _cache.get(key, () => _store.get(key));
53+
final cached = _cache.get(key);
54+
if (cached != null) {
55+
return cached;
56+
}
57+
58+
final fromStore = _store.get(key);
59+
if (fromStore != null) {
60+
_cache.put(key, fromStore);
61+
return fromStore;
62+
}
63+
64+
return null;
5465
}
5566

5667
@override

pkg/analyzer/lib/src/dart/analysis/cache.dart

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,49 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:meta/meta.dart';
6+
57
/// LRU cache of objects.
68
class Cache<K, V> {
79
final int _maxSizeBytes;
810
final int Function(V) _meter;
911

10-
final _map = <K, V>{};
12+
@visibleForTesting
13+
final map = <K, V>{};
1114
int _currentSizeBytes = 0;
1215

1316
Cache(this._maxSizeBytes, this._meter);
1417

15-
V? get(K key, V? Function() getNotCached) {
16-
V? value = _map.remove(key);
17-
if (value == null) {
18-
value = getNotCached();
19-
if (value != null) {
20-
_map[key] = value;
21-
_currentSizeBytes += _meter(value);
22-
_evict();
23-
}
24-
} else {
25-
_map[key] = value;
18+
V? get(K key) {
19+
final value = map.remove(key);
20+
if (value != null) {
21+
map[key] = value;
2622
}
2723
return value;
2824
}
2925

3026
void put(K key, V value) {
31-
V? oldValue = _map[key];
27+
V? oldValue = map[key];
3228
if (oldValue != null) {
3329
_currentSizeBytes -= _meter(oldValue);
3430
}
35-
_map[key] = value;
31+
map[key] = value;
3632
_currentSizeBytes += _meter(value);
3733
_evict();
3834
}
3935

4036
void _evict() {
4137
if (_currentSizeBytes > _maxSizeBytes) {
4238
var keysToRemove = <K>[];
43-
for (var entry in _map.entries) {
39+
for (var entry in map.entries) {
4440
keysToRemove.add(entry.key);
4541
_currentSizeBytes -= _meter(entry.value);
4642
if (_currentSizeBytes <= _maxSizeBytes) {
4743
break;
4844
}
4945
}
5046
for (var key in keysToRemove) {
51-
_map.remove(key);
47+
map.remove(key);
5248
}
5349
}
5450
}

pkg/analyzer/lib/src/dart/micro/cider_byte_store.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class CiderCachedByteStore implements CiderByteStore {
5454

5555
@override
5656
CacheData? get(String key, Uint8List signature) {
57-
var entry = _cache.get(key, () => null);
57+
final entry = _cache.get(key);
5858

5959
if (entry != null &&
6060
const ListEquality<int>().equals(entry.signature, signature)) {

pkg/analyzer/test/src/dart/analysis/cache_test.dart

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'dart:typed_data';
6+
57
import 'package:analyzer/src/dart/analysis/cache.dart';
8+
import 'package:analyzer_utilities/testing/map_entry_matcher.dart';
69
import 'package:test/test.dart';
710
import 'package:test_reflective_loader/test_reflective_loader.dart';
811

@@ -12,52 +15,47 @@ main() {
1215
});
1316
}
1417

15-
List<int> _b(int length) {
16-
return List<int>.filled(length, 0);
18+
Uint8List _b(int length) {
19+
return Uint8List(length);
1720
}
1821

1922
@reflectiveTest
2023
class CacheTest {
21-
test_get_notFound_evict() {
22-
var cache = _newBytesCache(100);
23-
24-
// Request '1'. Nothing found.
25-
expect(cache.get('1', _noBytes), isNull);
26-
27-
// Add enough data to the store to force an eviction.
28-
cache.put('2', _b(40));
29-
cache.put('3', _b(40));
30-
cache.put('4', _b(40));
31-
}
24+
test_get() {
25+
final cache = _newBytesCache(100);
3226

33-
test_get_notFound_retry() {
34-
var cache = _newBytesCache(100);
27+
expect(cache.get('1'), isNull);
28+
expect(cache.map.entries, isEmpty);
3529

36-
// Request '1'. Nothing found.
37-
expect(cache.get('1', _noBytes), isNull);
30+
cache.put('1', _b(10));
31+
expect(cache.map.entries, [
32+
isMapEntry('1', hasLength(10)),
33+
]);
3834

39-
// Request '1' again.
40-
// The previous `null` result should not have been cached.
41-
expect(cache.get('1', () => _b(40)), isNotNull);
35+
expect(cache.get('1'), hasLength(10));
4236
}
4337

44-
test_get_put_evict() {
45-
var cache = _newBytesCache(100);
46-
47-
// Keys: [1, 2].
48-
cache.put('1', _b(40));
49-
cache.put('2', _b(50));
50-
51-
// Request '1', so now it is the most recently used.
52-
// Keys: [2, 1].
53-
cache.get('1', _noBytes);
54-
55-
// 40 + 50 + 30 > 100
56-
// So, '2' is evicted.
57-
cache.put('3', _b(30));
58-
expect(cache.get('1', _noBytes), hasLength(40));
59-
expect(cache.get('2', _noBytes), isNull);
60-
expect(cache.get('3', _noBytes), hasLength(30));
38+
test_get_reorders() {
39+
final cache = _newBytesCache(100);
40+
41+
cache.put('1', _b(1));
42+
cache.put('2', _b(2));
43+
cache.put('3', _b(3));
44+
cache.put('4', _b(4));
45+
expect(cache.map.entries, [
46+
isMapEntry('1', hasLength(1)),
47+
isMapEntry('2', hasLength(2)),
48+
isMapEntry('3', hasLength(3)),
49+
isMapEntry('4', hasLength(4)),
50+
]);
51+
52+
expect(cache.get('2'), hasLength(2));
53+
expect(cache.map.entries, [
54+
isMapEntry('1', hasLength(1)),
55+
isMapEntry('3', hasLength(3)),
56+
isMapEntry('4', hasLength(4)),
57+
isMapEntry('2', hasLength(2)),
58+
]);
6159
}
6260

6361
test_put_evict_first() {
@@ -66,36 +64,39 @@ class CacheTest {
6664
// 40 + 50 < 100
6765
cache.put('1', _b(40));
6866
cache.put('2', _b(50));
69-
expect(cache.get('1', _noBytes), hasLength(40));
70-
expect(cache.get('2', _noBytes), hasLength(50));
67+
expect(cache.map.entries, [
68+
isMapEntry('1', hasLength(40)),
69+
isMapEntry('2', hasLength(50)),
70+
]);
7171

7272
// 40 + 50 + 30 > 100
7373
// So, '1' is evicted.
7474
cache.put('3', _b(30));
75-
expect(cache.get('1', _noBytes), isNull);
76-
expect(cache.get('2', _noBytes), hasLength(50));
77-
expect(cache.get('3', _noBytes), hasLength(30));
75+
expect(cache.map.entries, [
76+
isMapEntry('2', hasLength(50)),
77+
isMapEntry('3', hasLength(30)),
78+
]);
7879
}
7980

80-
test_put_evict_firstAndSecond() {
81+
test_put_evict_firstSecond() {
8182
var cache = _newBytesCache(100);
8283

8384
// 10 + 80 < 100
8485
cache.put('1', _b(10));
8586
cache.put('2', _b(80));
86-
expect(cache.get('1', _noBytes), hasLength(10));
87-
expect(cache.get('2', _noBytes), hasLength(80));
87+
expect(cache.map.entries, [
88+
isMapEntry('1', hasLength(10)),
89+
isMapEntry('2', hasLength(80)),
90+
]);
8891

8992
// 10 + 80 + 30 > 100
9093
// So, '1' and '2' are evicted.
9194
cache.put('3', _b(30));
92-
expect(cache.get('1', _noBytes), isNull);
93-
expect(cache.get('2', _noBytes), isNull);
94-
expect(cache.get('3', _noBytes), hasLength(30));
95+
expect(cache.map.entries, [
96+
isMapEntry('3', hasLength(30)),
97+
]);
9598
}
9699

97-
Cache<String, List<int>> _newBytesCache(int maxSizeBytes) =>
98-
Cache<String, List<int>>(maxSizeBytes, (bytes) => bytes.length);
99-
100-
static List<int>? _noBytes() => null;
100+
Cache<String, Uint8List> _newBytesCache(int maxSizeBytes) =>
101+
Cache<String, Uint8List>(maxSizeBytes, (bytes) => bytes.length);
101102
}

pkg/analyzer/test/src/dart/analysis/file_state_test.dart

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -642,8 +642,7 @@ export 'dart:math';
642642
],
643643
);
644644

645-
final bundleFile =
646-
resourceProvider.getFile('/home/summaries/packages.sum');
645+
final bundleFile = getFile('/home/summaries/packages.sum');
647646
bundleFile.writeAsBytesSync(bundleBytes);
648647

649648
librarySummaryFiles.add(bundleFile);
@@ -716,8 +715,7 @@ part of 'foo.dart';
716715
],
717716
);
718717

719-
final bundleFile =
720-
resourceProvider.getFile('/home/summaries/packages.sum');
718+
final bundleFile = getFile('/home/summaries/packages.sum');
721719
bundleFile.writeAsBytesSync(bundleBytes);
722720

723721
librarySummaryFiles.add(bundleFile);
@@ -895,8 +893,7 @@ import 'dart:math';
895893
],
896894
);
897895

898-
final bundleFile =
899-
resourceProvider.getFile('/home/summaries/packages.sum');
896+
final bundleFile = getFile('/home/summaries/packages.sum');
900897
bundleFile.writeAsBytesSync(bundleBytes);
901898

902899
librarySummaryFiles.add(bundleFile);
@@ -975,8 +972,7 @@ part of 'foo.dart';
975972
],
976973
);
977974

978-
final bundleFile =
979-
resourceProvider.getFile('/home/summaries/packages.sum');
975+
final bundleFile = getFile('/home/summaries/packages.sum');
980976
bundleFile.writeAsBytesSync(bundleBytes);
981977

982978
librarySummaryFiles.add(bundleFile);
@@ -2156,7 +2152,7 @@ class A2 {}
21562152
}
21572153

21582154
Future<File> _writeSdkSummary() async {
2159-
final file = resourceProvider.getFile('/home/summaries/sdk.sum');
2155+
final file = getFile('/home/summaries/sdk.sum');
21602156
final bytes = await buildSdkSummary2(
21612157
resourceProvider: resourceProvider,
21622158
sdkPath: sdkRoot.path,

pkg/analyzer/test/src/dart/analysis/session_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ library augment 'a.dart';
428428
''');
429429

430430
final session = contextFor(testFilePath).currentSession;
431-
final result = session.getParsedLibrary(testFilePath);
431+
final result = session.getParsedLibrary(testFile.path);
432432
expect(result, isA<NotLibraryButAugmentationResult>());
433433
}
434434

@@ -697,7 +697,7 @@ library augment of 'a.dart';
697697
''');
698698

699699
final session = contextFor(testFilePath).currentSession;
700-
final result = await session.getResolvedLibrary(testFilePath);
700+
final result = await session.getResolvedLibrary(testFile.path);
701701
expect(result, isA<NotLibraryButAugmentationResult>());
702702
}
703703

pkg/analyzer/test/src/workspace/package_build_test.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ class PackageBuildWorkspacePackageTest with ResourceProviderMixin {
268268
convertPath(myPackageRootPath),
269269
)!;
270270

271-
myPackage = myWorkspace.findPackageFor('$myPackageLibPath/fake.dart')!;
271+
final fakeFile = getFile('$myPackageLibPath/fake.dart');
272+
myPackage = myWorkspace.findPackageFor(fakeFile.path)!;
272273
}
273274

274275
test_contains_fileUri() {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:test/test.dart';
6+
7+
/// Matches a [MapEntry] with matching [MapEntry.key] and [MapEntry.value].
8+
MapEntryMatcher isMapEntry(key, value) => MapEntryMatcher(key, value);
9+
10+
class MapEntryMatcher extends Matcher {
11+
final Matcher keyMatcher;
12+
final Matcher valueMatcher;
13+
14+
MapEntryMatcher(key, value)
15+
: keyMatcher = wrapMatcher(key),
16+
valueMatcher = wrapMatcher(value);
17+
18+
@override
19+
Description describe(Description description) => description
20+
.add('MapEntry(key: ')
21+
.addDescriptionOf(keyMatcher)
22+
.add(', value: ')
23+
.addDescriptionOf(valueMatcher)
24+
.add(')');
25+
26+
@override
27+
bool matches(item, Map matchState) =>
28+
item is MapEntry &&
29+
keyMatcher.matches(item.key, {}) &&
30+
valueMatcher.matches(item.value, {});
31+
}

0 commit comments

Comments
 (0)