Skip to content

Commit

Permalink
[macros] Add dart:_macros
Browse files Browse the repository at this point in the history
This adds the dart:_macros library to the SDK and adds support for accessing dart:_macros from package:macros. The library is not used yet.

This change is needed as a prestep to adding the package:macros and using it in the CFE and analyzer, and needs to be rolled in as the checked in sdk before package:macros can be supported.

TEST=ci

Change-Id: Ife3ffd48527e3a196048d2ddf7387b8b7818f3a3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/348680
Reviewed-by: Jake Macdonald <[email protected]>
Reviewed-by: William Hesse <[email protected]>
Reviewed-by: Chloe Stefantsova <[email protected]>
Reviewed-by: Alexander Markov <[email protected]>
Commit-Queue: Johnni Winther <[email protected]>
  • Loading branch information
johnniwinther authored and Commit Queue committed Feb 2, 2024
1 parent 1327a9a commit fe52b9b
Show file tree
Hide file tree
Showing 33 changed files with 1,790 additions and 112 deletions.
13 changes: 13 additions & 0 deletions pkg/analyzer/lib/src/test_utilities/mock_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,18 @@ class Isolate {
)
]);

final MockSdkLibrary _LIB_MACROS = MockSdkLibrary(
'_macros',
[
MockSdkLibraryUnit(
'_macros/_macros.dart',
'''
library dart._macros;
''',
)
],
);

final MockSdkLibrary _LIB_MATH = MockSdkLibrary(
'math',
[
Expand Down Expand Up @@ -1444,6 +1456,7 @@ final List<MockSdkLibrary> _LIBRARIES = [
_LIB_INTERNAL,
_LIB_IO,
_LIB_ISOLATE,
_LIB_MACROS,
_LIB_MATH,
_LIB_TYPED_DATA,
_LIB_WASM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ import 'dart:_internal';
]);
}

test_macros() async {
// Note, in these error cases we may generate an UNUSED_IMPORT hint, while
// we could prevent the hint from being generated by testing the import
// directive for the error, this is such a minor corner case that we don't
// think we should add the additional computation time to figure out such
// cases.
await assertErrorsInCode('''
import 'dart:_macros';
''', [
error(CompileTimeErrorCode.IMPORT_INTERNAL_LIBRARY, 7, 14),
error(WarningCode.UNUSED_IMPORT, 7, 14),
]);
}

test_wasm_fromJs() async {
final packageRootPath = _newPackage('js');
final file = newFile('$packageRootPath/lib/js.dart', '''
Expand Down
1 change: 1 addition & 0 deletions pkg/analyzer_cli/tool/perf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ Set<Source?> scanReachableFiles(Uri entryUri) {
'dart:core',
'dart:developer',
'dart:_internal',
'dart:_macros',
'dart:isolate',
'dart:math',
'dart:mirrors',
Expand Down
2 changes: 2 additions & 0 deletions pkg/compiler/lib/src/kernel/dart2js_target.dart
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ const requiredLibraries = <String, List<String>>{
'dart:_js_types',
'dart:_late_helper',
'dart:_load_library_priority',
'dart:_macros',
'dart:_metadata',
'dart:_native_typed_data',
'dart:_recipe_syntax',
Expand Down Expand Up @@ -315,6 +316,7 @@ const requiredLibraries = <String, List<String>>{
'dart:_js_types',
'dart:_late_helper',
'dart:_load_library_priority',
'dart:_macros',
'dart:_native_typed_data',
'dart:_recipe_syntax',
'dart:_rti',
Expand Down
1 change: 1 addition & 0 deletions pkg/dart2wasm/lib/target.dart
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class WasmTarget extends Target {
'dart:_internal',
'dart:_js_helper',
'dart:_js_types',
'dart:_macros',
'dart:_wasm',
'dart:async',
'dart:developer',
Expand Down
1 change: 1 addition & 0 deletions pkg/dev_compiler/lib/src/kernel/target.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class DevCompilerTarget extends Target {
'dart:_js_names',
'dart:_js_primitives',
'dart:_js_types',
'dart:_macros',
'dart:_metadata',
'dart:_native_typed_data',
'dart:async',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ library from "org-dartlang-test:///main.dart" as main {
static method foo() → dynamic {}
}

And 18 platform libraries:
And 19 platform libraries:
- dart:_http
- dart:_builtin
- dart:vmservice_io
- dart:_macros
- dart:async
- dart:cli
- dart:collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ library from "org-dartlang-test:///main.dart" as main {
static method foo() → dynamic {}
}

And 18 platform libraries:
And 19 platform libraries:
- dart:_http
- dart:_builtin
- dart:vmservice_io
- dart:_macros
- dart:async
- dart:cli
- dart:collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ library from "org-dartlang-test:///main.dart" as main {
}
}

And 17 platform libraries:
And 18 platform libraries:
- dart:_builtin
- dart:_internal
- dart:_macros
- dart:_vmservice
- dart:async
- dart:cli
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ library from "org-dartlang-test:///main.dart" as main {
}
}

And 18 platform libraries:
And 19 platform libraries:
- dart:_http
- dart:_builtin
- dart:vmservice_io
- dart:_macros
- dart:async
- dart:cli
- dart:collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ library from "org-dartlang-test:///main.dart" as main {
}
}

And 18 platform libraries:
And 19 platform libraries:
- dart:_http
- dart:_builtin
- dart:vmservice_io
- dart:_macros
- dart:async
- dart:cli
- dart:collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ library from "org-dartlang-test:///main.dart" as main {
}
}

And 18 platform libraries:
And 19 platform libraries:
- dart:_http
- dart:_builtin
- dart:vmservice_io
- dart:_macros
- dart:async
- dart:cli
- dart:collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ library from "org-dartlang-test:///main.dart" as main {
}
}

And 18 platform libraries:
And 19 platform libraries:
- dart:_http
- dart:_builtin
- dart:vmservice_io
- dart:_macros
- dart:async
- dart:cli
- dart:collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ library from "org-dartlang-test:///main.dart" as main {
}
}

And 18 platform libraries:
And 19 platform libraries:
- dart:_http
- dart:_builtin
- dart:vmservice_io
- dart:_macros
- dart:async
- dart:cli
- dart:collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ constants {
#C1 = 0
}

And 18 platform libraries:
And 19 platform libraries:
- dart:_http
- dart:_builtin
- dart:vmservice_io
- dart:_macros
- dart:async
- dart:cli
- dart:collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ constants {
#C1 = 0
}

And 18 platform libraries:
And 19 platform libraries:
- dart:_http
- dart:_builtin
- dart:vmservice_io
- dart:_macros
- dart:async
- dart:cli
- dart:collection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ constants {
#C1 = 0
}

And 18 platform libraries:
And 19 platform libraries:
- dart:_http
- dart:_builtin
- dart:vmservice_io
- dart:_macros
- dart:async
- dart:cli
- dart:collection
Expand Down
10 changes: 8 additions & 2 deletions pkg/kernel/lib/target/targets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,14 @@ abstract class Target {
/// testing purposes.
bool allowPlatformPrivateLibraryAccess(Uri importer, Uri imported) =>
importer.isScheme("dart") ||
(importer.isScheme("package") &&
importer.path.startsWith("dart_internal/"));
(imported.isScheme('dart') &&
imported.path == '_internal' &&
importer.isScheme("package") &&
importer.path.startsWith("dart_internal/")) ||
(imported.isScheme('dart') &&
imported.path == '_macros' &&
importer.isScheme("package") &&
importer.path.startsWith("macros/"));

/// Whether the `native` language extension is supported within the library
/// with the given import [uri].
Expand Down
1 change: 1 addition & 0 deletions pkg/vm/lib/target/dart_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class DartRunnerTarget extends VmTarget {
'dart:developer',
'dart:ffi',
'dart:_internal',
'dart:_macros',
'dart:isolate',
'dart:math',

Expand Down
1 change: 1 addition & 0 deletions pkg/vm/lib/target/flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class FlutterTarget extends VmTarget {
'dart:developer',
'dart:ffi',
'dart:_internal',
'dart:_macros',
'dart:isolate',
'dart:math',

Expand Down
1 change: 1 addition & 0 deletions pkg/vm/lib/target/flutter_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class FlutterRunnerTarget extends VmTarget {
'dart:developer',
'dart:ffi',
'dart:_internal',
'dart:_macros',
'dart:isolate',
'dart:math',

Expand Down
5 changes: 4 additions & 1 deletion pkg/vm/lib/target/vm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class VmTarget extends Target {
'dart:developer',
'dart:ffi',
'dart:_internal',
'dart:_macros',
'dart:isolate',
'dart:math',

Expand All @@ -96,7 +97,9 @@ class VmTarget extends Target {
];

@override
List<String> get extraRequiredLibrariesPlatform => const <String>[];
List<String> get extraRequiredLibrariesPlatform => const <String>[
'dart:_macros',
];

void _patchVmConstants(CoreTypes coreTypes) {
// Fix Endian.host to be a const field equal to Endian.little instead of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ LoadingUnit(id=1, parent=0,
dart:mirrors
dart:math
dart:isolate
dart:_macros
dart:_internal
dart:ffi
dart:developer
Expand Down
2 changes: 2 additions & 0 deletions sdk/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ _full_sdk_snapshots = _platform_sdk_snapshots + [
# Libraries that go under lib/
_full_sdk_libraries = [
"_internal",
"_macros",
"async",
"cli",
"collection",
Expand Down Expand Up @@ -193,6 +194,7 @@ _full_sdk_libraries = [
#
# _platform_sdk_libraries = [
# "_internal",
# "_macros",
# "async",
# "cli",
# "collection",
Expand Down
Loading

0 comments on commit fe52b9b

Please sign in to comment.