Skip to content

Commit 9f57a99

Browse files
committed
Link flutter#195202 in Dart 3.15 TODOs and expand bit-31/sliver cap tests
- Link flutter#195202 in the Dart 3.15 safe-integer TODO comments in `overlay.dart` and `sliver.dart`. - Move index 31 first in `persistent_hash_map_test.dart` and test `_FullNode` inflation while bit 31 is occupied. - Add `SliverMultiBoxAdaptorElement.childCount` widget test covering `2^53 - 1`, `2^53`, and `> 2^53` across JS web, Wasm, and VM.
1 parent dfb531f commit 9f57a99

4 files changed

Lines changed: 63 additions & 7 deletions

File tree

‎packages/flutter/lib/src/widgets/overlay.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,7 @@ class OverlayPortalController {
17041704
int? _zOrderIndex;
17051705
final String? _debugLabel;
17061706

1707-
// TODO(kevmoo): Use double.minSafeInteger - 1 when the minimum Dart SDK is 3.15.
1707+
// TODO(kevmoo): Use double.minSafeInteger - 1 when the minimum Dart SDK is 3.15, https://github.com/flutter/flutter/issues/195202.
17081708
static int _wallTime = kIsWeb && !kIsWasm
17091709
? -9007199254740992 // -2^53
17101710
: -1 << 63;

‎packages/flutter/lib/src/widgets/sliver.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ class SliverMultiBoxAdaptorElement extends RenderObjectElement
11861186
var lo = 0;
11871187
var hi = 1;
11881188
final adaptorWidget = widget as SliverMultiBoxAdaptorWidget;
1189-
// TODO(kevmoo): Use double.maxSafeInteger + 1 when the minimum Dart SDK is 3.15.
1189+
// TODO(kevmoo): Use double.maxSafeInteger + 1 when the minimum Dart SDK is 3.15, https://github.com/flutter/flutter/issues/195202.
11901190
const int max = kIsWeb && !kIsWasm
11911191
? 9007199254740992 // max safe integer on JS + 1 (2^53)
11921192
: ((1 << 63) - 1);

‎packages/flutter/test/foundation/persistent_hash_map_test.dart‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,24 @@ void main() {
7979
});
8080

8181
test('PersistentHashMap - bit 31 and compressed bitmap popcount', () {
82-
// Exercise 15 distinct level-0 indices including index 31 (1 << 31) while
83-
// staying below the 16-entry _FullNode inflation threshold.
84-
const indices = <int>[0, 1, 2, 5, 7, 11, 13, 15, 17, 19, 23, 25, 29, 30, 31];
82+
// Place index 31 (1 << 31) first so occupiedIndices has bit 31 set during
83+
// every subsequent _CompressedNode.put call while below the 16-entry
84+
// _FullNode inflation threshold, then cross inflation with bit 31 occupied.
85+
const compressedIndices = <int>[31, 0, 1, 2, 5, 7, 11, 13, 15, 17, 19, 23, 25, 29, 30];
8586
var map = const PersistentHashMap<_MockKey, int>.empty();
86-
for (final index in indices) {
87+
for (final index in compressedIndices) {
8788
map = map.put(_MockKey(hashCode: index, payload: 'k$index'), index * 10);
8889
}
89-
for (final index in indices) {
90+
for (final index in compressedIndices) {
91+
expect(map[_MockKey(hashCode: index, payload: 'k$index')], equals(index * 10));
92+
}
93+
expect(map[const _MockKey(hashCode: 28, payload: 'missing')], isNull);
94+
95+
const inflationIndices = <int>[3, 4];
96+
for (final index in inflationIndices) {
97+
map = map.put(_MockKey(hashCode: index, payload: 'k$index'), index * 10);
98+
}
99+
for (final index in <int>[...compressedIndices, ...inflationIndices]) {
90100
expect(map[_MockKey(hashCode: index, payload: 'k$index')], equals(index * 10));
91101
}
92102
expect(map[const _MockKey(hashCode: 28, payload: 'missing')], isNull);

‎packages/flutter/test/widgets/sliver_list_test.dart‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'package:flutter/foundation.dart';
56
import 'package:flutter/widgets.dart';
67
import 'package:flutter_test/flutter_test.dart';
78

@@ -381,6 +382,51 @@ void main() {
381382
expect(s1.index, 6);
382383
expect(s2.index, 7);
383384
});
385+
386+
testWidgets('SliverMultiBoxAdaptorElement.childCount scopes 53-bit cap to JS web', (
387+
WidgetTester tester,
388+
) async {
389+
const jsMaxSafeInteger = 9007199254740991; // 2^53 - 1
390+
const jsCap = 9007199254740992; // 2^53
391+
int? targetCount;
392+
393+
await tester.pumpWidget(
394+
Directionality(
395+
textDirection: TextDirection.ltr,
396+
child: CustomScrollView(
397+
slivers: <Widget>[
398+
SliverList.builder(
399+
itemBuilder: (BuildContext context, int index) {
400+
if (targetCount case final int count when index >= count) {
401+
return null;
402+
}
403+
return const SizedBox(height: 10);
404+
},
405+
),
406+
],
407+
),
408+
),
409+
);
410+
411+
final SliverMultiBoxAdaptorElement element = tester.element<SliverMultiBoxAdaptorElement>(
412+
find.byType(SliverList),
413+
);
414+
415+
targetCount = jsMaxSafeInteger;
416+
expect(element.childCount, jsMaxSafeInteger);
417+
418+
if (kIsWeb && !kIsWasm) {
419+
targetCount = jsCap;
420+
expect(() => element.childCount, throwsFlutterError);
421+
} else {
422+
targetCount = jsCap;
423+
expect(element.childCount, jsCap);
424+
425+
final int above53BitCount = int.parse('18014398509482021'); // 2^54 + 37
426+
targetCount = above53BitCount;
427+
expect(element.childCount, above53BitCount);
428+
}
429+
});
384430
}
385431

386432
Widget _buildSliverListRenderWidgetChild(List<String> items, ScrollController controller) {

0 commit comments

Comments
 (0)