Skip to content

Commit

Permalink
[macros] Fix _checkForKernelRuntime.
Browse files Browse the repository at this point in the history
The previous implementation always returns "true", making the PR a
no-op as it only does something for AOT runtimes. e2e test coverage
will land in
https://dart-review.googlesource.com/c/sdk/+/353100 to prevent such
mistakes in future.

R=johnniwinther@google.com

Change-Id: I8481187070a0af12a3f3bd77baa471f1a7d3256d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/355682
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Auto-Submit: Morgan :) <davidmorgan@google.com>
Commit-Queue: Morgan :) <davidmorgan@google.com>
  • Loading branch information
davidmorgan authored and Commit Queue committed Mar 5, 2024
1 parent 8235923 commit a4e1566
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions pkg/_fe_analyzer_shared/lib/src/util/runtimes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import 'dart:isolate';
import 'dart:typed_data';

/// Whether the current runtime can register kernel blobs and launch kernel
/// isolates.
Expand All @@ -11,10 +12,17 @@ bool get isKernelRuntime => _isKernelRuntime ??= _checkForKernelRuntime();
bool? _isKernelRuntime;

bool _checkForKernelRuntime() {
// `createUriForKernelBlob` throws `UnsupportedError` if kernel blobs are not
// supported at all. We don't actually want to register kernel so pass
// invalid kernel, an empty list, resulting in an `ArgumentError` if kernel
// blobs are supported.
try {
(Isolate.current as dynamic).createUriForKernelBlob;
return true;
} catch (_) {
(Isolate.current as dynamic)
.createUriForKernelBlob(new Uint8List.fromList(const []));
throw new StateError('Expected failure.');
} on UnsupportedError {
return false;
} on ArgumentError {
return true;
}
}
2 changes: 1 addition & 1 deletion pkg/front_end/test/static_types/cfe_allowed.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"Dynamic invocation of 'split'.": 1
},
"pkg/_fe_analyzer_shared/lib/src/util/runtimes.dart": {
"Dynamic access of 'createUriForKernelBlob'.": 1
"Dynamic invocation of 'createUriForKernelBlob'.": 1
},
"pkg/front_end/lib/src/macros/isolate_macro_serializer.dart": {
"Dynamic invocation of 'unregisterKernelBlobUri'.": 1,
Expand Down

0 comments on commit a4e1566

Please sign in to comment.