Skip to content

Commit

Permalink
Reapply "[typed_data] Deprecate unmodifiable views"
Browse files Browse the repository at this point in the history
This change, for Dart 3.4, deprecates the unmodifiable typed data constructors. Users of these constructors can upgrade the use of the constructors to instance method `asUnmodifiableView()`, or pin to Dart 3.3.

See #53785 for context.

CoreLibraryReviewExempt: Reviewed in https://dart-review.googlesource.com/c/sdk/+/321922
Issue: #53785
Change-Id: Icd52f2b6cd05cf3a328c82c197ef44d0b340b171
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332581
Reviewed-by: Lasse Nielsen <[email protected]>
Commit-Queue: Stephen Adams <[email protected]>
  • Loading branch information
rakudrama authored and Commit Queue committed Feb 6, 2024
1 parent bdf4528 commit 7ef215a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@

[#54138]: https://github.com/dart-lang/sdk/issues/54138

#### `dart:typed_data`

- **BREAKING CHANGE** [#53218][] [#53785][]: The unmodifiable view classes for
typed data are deprecated.

To create an unmodifiable view of a typed-data object, use the
`asUnmodifiableView()` methods added in Dart 3.3:

```dart
Uint8List data = ...;
final readOnlyView = data.asUnmodifiableView();
// readOnlyView has type Uint8List, and throws if attempted modified.
```

The reason for this change is to allow more flexibility in the implementation
of typed data, so the native and web platforms can use different strategies
to ensure that typed data has good performance.

The deprecated types will be removed in Dart 3.5.

[#53218]: https://github.com/dart-lang/sdk/issues/53218
[#53785]: https://github.com/dart-lang/sdk/issues/53785

## 3.3.0

### Language
Expand Down
32 changes: 16 additions & 16 deletions sdk/lib/typed_data/unmodifiable_typed_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ part of dart.typed_data;
///
/// It is a compile-time error for a class to attempt to extend or implement
/// UnmodifiableByteBufferView.
// TODO(53785): @Deprecated('No replacement')
@Deprecated('No replacement')
abstract final class UnmodifiableByteBufferView implements ByteBuffer {
external factory UnmodifiableByteBufferView(ByteBuffer data);
}
Expand All @@ -17,7 +17,7 @@ abstract final class UnmodifiableByteBufferView implements ByteBuffer {
///
/// It is a compile-time error for a class to attempt to extend or implement
/// UnmodifiableByteDataView.
// TODO(53785): @Deprecated('Use ByteData.asUnmodifiableView() instead')
@Deprecated('Use ByteData.asUnmodifiableView() instead')
abstract final class UnmodifiableByteDataView implements ByteData {
external factory UnmodifiableByteDataView(ByteData data);
}
Expand All @@ -26,7 +26,7 @@ abstract final class UnmodifiableByteDataView implements ByteData {
///
/// It is a compile-time error for a class to attempt to extend or implement
/// UnmodifiableUint8ListView.
// TODO(53785): @Deprecated('Use Uint8List.asUnmodifiableView() instead')
@Deprecated('Use Uint8List.asUnmodifiableView() instead')
abstract final class UnmodifiableUint8ListView implements Uint8List {
external factory UnmodifiableUint8ListView(Uint8List list);
}
Expand All @@ -35,7 +35,7 @@ abstract final class UnmodifiableUint8ListView implements Uint8List {
///
/// It is a compile-time error for a class to attempt to extend or implement
/// UnmodifiableInt8ListView.
// TODO(53785): @Deprecated('Use Int8List.asUnmodifiableView() instead')
@Deprecated('Use Int8List.asUnmodifiableView() instead')
abstract final class UnmodifiableInt8ListView implements Int8List {
external factory UnmodifiableInt8ListView(Int8List list);
}
Expand All @@ -44,7 +44,7 @@ abstract final class UnmodifiableInt8ListView implements Int8List {
///
/// It is a compile-time error for a class to attempt to extend or implement
/// UnmodifiableUint8ClampedListView.
// TODO(53785): @Deprecated('Use Uint8ClampedList.asUnmodifiableView() instead')
@Deprecated('Use Uint8ClampedList.asUnmodifiableView() instead')
abstract final class UnmodifiableUint8ClampedListView
implements Uint8ClampedList {
external factory UnmodifiableUint8ClampedListView(Uint8ClampedList list);
Expand All @@ -54,7 +54,7 @@ abstract final class UnmodifiableUint8ClampedListView
///
/// It is a compile-time error for a class to attempt to extend or implement
/// UnmodifiableUint16ListView.
// TODO(53785): @Deprecated('Use Uint16List.asUnmodifiableView() instead')
@Deprecated('Use Uint16List.asUnmodifiableView() instead')
abstract final class UnmodifiableUint16ListView implements Uint16List {
external factory UnmodifiableUint16ListView(Uint16List list);
}
Expand All @@ -63,7 +63,7 @@ abstract final class UnmodifiableUint16ListView implements Uint16List {
///
/// It is a compile-time error for a class to attempt to extend or implement
/// UnmodifiableInt16ListView.
// TODO(53785): @Deprecated('Use Int16List.asUnmodifiableView() instead')
@Deprecated('Use Int16List.asUnmodifiableView() instead')
abstract final class UnmodifiableInt16ListView implements Int16List {
external factory UnmodifiableInt16ListView(Int16List list);
}
Expand All @@ -72,7 +72,7 @@ abstract final class UnmodifiableInt16ListView implements Int16List {
///
/// It is a compile-time error for a class to attempt to extend or implement
/// UnmodifiableUint32ListView.
// TODO(53785): @Deprecated('Use Uint32List.asUnmodifiableView() instead')
@Deprecated('Use Uint32List.asUnmodifiableView() instead')
abstract final class UnmodifiableUint32ListView implements Uint32List {
external factory UnmodifiableUint32ListView(Uint32List list);
}
Expand All @@ -81,7 +81,7 @@ abstract final class UnmodifiableUint32ListView implements Uint32List {
///
/// It is a compile-time error for a class to attempt to extend or implement
/// UnmodifiableInt32ListView.
// TODO(53785): @Deprecated('Use Int32List.asUnmodifiableView() instead')
@Deprecated('Use Int32List.asUnmodifiableView() instead')
abstract final class UnmodifiableInt32ListView implements Int32List {
external factory UnmodifiableInt32ListView(Int32List list);
}
Expand All @@ -90,7 +90,7 @@ abstract final class UnmodifiableInt32ListView implements Int32List {
///
/// It is a compile-time error for a class to attempt to extend or implement
/// UnmodifiableUint64ListView.
// TODO(53785): @Deprecated('Use Uint64List.asUnmodifiableView() instead')
@Deprecated('Use Uint64List.asUnmodifiableView() instead')
abstract final class UnmodifiableUint64ListView implements Uint64List {
external factory UnmodifiableUint64ListView(Uint64List list);
}
Expand All @@ -99,7 +99,7 @@ abstract final class UnmodifiableUint64ListView implements Uint64List {
///
/// It is a compile-time error for a class to attempt to extend or implement
/// UnmodifiableInt64ListView.
// TODO(53785): @Deprecated('Use Int64List.asUnmodifiableView() instead')
@Deprecated('Use Int64List.asUnmodifiableView() instead')
abstract final class UnmodifiableInt64ListView implements Int64List {
external factory UnmodifiableInt64ListView(Int64List list);
}
Expand All @@ -108,7 +108,7 @@ abstract final class UnmodifiableInt64ListView implements Int64List {
///
/// It is a compile-time error for a class to attempt to extend or implement
/// UnmodifiableInt32x4ListView.
// TODO(53785): @Deprecated('Use Int32x4List.asUnmodifiableView() instead')
@Deprecated('Use Int32x4List.asUnmodifiableView() instead')
abstract final class UnmodifiableInt32x4ListView implements Int32x4List {
external factory UnmodifiableInt32x4ListView(Int32x4List list);
}
Expand All @@ -117,7 +117,7 @@ abstract final class UnmodifiableInt32x4ListView implements Int32x4List {
///
/// It is a compile-time error for a class to attempt to extend or implement
/// UnmodifiableFloat32x4ListView.
// TODO(53785): @Deprecated('Use Float32x4List.asUnmodifiableView() instead')
@Deprecated('Use Float32x4List.asUnmodifiableView() instead')
abstract final class UnmodifiableFloat32x4ListView implements Float32x4List {
external factory UnmodifiableFloat32x4ListView(Float32x4List list);
}
Expand All @@ -126,7 +126,7 @@ abstract final class UnmodifiableFloat32x4ListView implements Float32x4List {
///
/// It is a compile-time error for a class to attempt to extend or implement
/// UnmodifiableFloat64x2ListView.
// TODO(53785): @Deprecated('Use Float64x2List.asUnmodifiableView() instead')
@Deprecated('Use Float64x2List.asUnmodifiableView() instead')
abstract final class UnmodifiableFloat64x2ListView implements Float64x2List {
external factory UnmodifiableFloat64x2ListView(Float64x2List list);
}
Expand All @@ -135,7 +135,7 @@ abstract final class UnmodifiableFloat64x2ListView implements Float64x2List {
///
/// It is a compile-time error for a class to attempt to extend or implement
/// UnmodifiableFloat32ListView.
// TODO(53785): @Deprecated('Use Float32List.asUnmodifiableView() instead')
@Deprecated('Use Float32List.asUnmodifiableView() instead')
abstract final class UnmodifiableFloat32ListView implements Float32List {
external factory UnmodifiableFloat32ListView(Float32List list);
}
Expand All @@ -144,7 +144,7 @@ abstract final class UnmodifiableFloat32ListView implements Float32List {
///
/// It is a compile-time error for a class to attempt to extend or implement
/// UnmodifiableFloat64ListView.
// TODO(53785): @Deprecated('Use Float64List.asUnmodifiableView() instead')
@Deprecated('Use Float64List.asUnmodifiableView() instead')
abstract final class UnmodifiableFloat64ListView implements Float64List {
external factory UnmodifiableFloat64ListView(Float64List list);
}

0 comments on commit 7ef215a

Please sign in to comment.