Update SDK to prepare for enabling interface-update-2.

Several locations in the core SDK contain `!` or `?.` operations that
will become unnecessary once the language feature `inference-update-2`
(which provides field promotion) is enabled.  For example, in this
method from the class `_IOOverridesScope`, `_previous` refers to a
private final field, so after field promotion is enabled, the test `if
(_previous != null)` will promote it, and the `!` in
`_previous!.createDirectory` will become unnecessary:

    Directory createDirectory(String path) {
      if (_createDirectory != null) return _createDirectory!(path);
      if (_previous != null) return _previous!.createDirectory(path);
      return super.createDirectory(path);
    }

Since the SDK is built in a mode where warnings like this result in
build failures, we need to temporarily change the logic into a form
where the same promotion effect is achieved through local variable
type promotion:

    Directory createDirectory(String path) {
      if (_createDirectory != null) return _createDirectory!(path);
      var previous = _previous;
      if (previous != null) return previous.createDirectory(path);
      return super.createDirectory(path);
    }

(Note that `_createDirectory` doesn't need to change, because it is a
non-final field, so it won't undergo promotion).

After `interface-update-2` has been enabled, I will make a follow-up
CL that removes the local variables and simply takes advantage of
field promotion, e.g.:

    Directory createDirectory(String path) {
      if (_createDirectory != null) return _createDirectory!(path);
      if (_previous != null) return _previous.createDirectory(path);
      return super.createDirectory(path);
    }

Note: in theory it would be possible to do all this in a single step,
by atomically enabling field promotion and changing the SDK in the
same CL. However, I prefer breaking it up into stages like this,
because the act of flipping a langauge flag on tends to have
wide-ranging consequences, so I want the CL that does the flip to be
as small as possible.

Change-Id: I421c7661348bf407093ee64ef7f9dbfc0c04a353
Bug: https://github.com/dart-lang/language/issues/2020
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/314500
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
This commit is contained in:
Paul Berry 2023-07-20 20:14:39 +00:00 committed by Commit Queue
parent 6fd249d379
commit fc387f0f7b
2 changed files with 11 additions and 5 deletions

View file

@ -703,10 +703,12 @@ class _HttpClientResponse extends _HttpInboundMessageListInt
.transform(gzip.decoder)
.transform(const _ToUint8List());
}
if (_profileData != null) {
// TODO(#52982): Make use of field promotion of `_profileData`.
var profileData = _profileData;
if (profileData != null) {
// If _timeline is not set up, don't add unnecessary map() to the stream.
stream = stream.map((data) {
_profileData?.appendResponseData(data);
profileData.appendResponseData(data);
return data;
});
}
@ -1150,11 +1152,13 @@ abstract class _HttpOutboundMessage<T> extends _IOSinkImpl {
}
Future addStream(Stream<List<int>> s) {
if (_profileData == null) {
// TODO(#52982): Make use of field promotion of `_profileData`.
var profileData = _profileData;
if (profileData == null) {
return super.addStream(s);
}
return super.addStream(s.map((data) {
_profileData?.appendRequestData(Uint8List.fromList(data));
profileData.appendRequestData(Uint8List.fromList(data));
return data;
}));
}

View file

@ -246,7 +246,9 @@ final class TimelineTask {
map[key] = arguments[key];
}
}
if (_parent != null) map['parentId'] = _parent!._taskId.toRadixString(16);
// TODO(#52982): Make use of field promotion of `_parent`.
var parent = _parent;
if (parent != null) map['parentId'] = parent._taskId.toRadixString(16);
if (_filterKey != null) map[_kFilterKey] = _filterKey;
block._start(map);
}