Skip to content

Commit

Permalink
Version 3.5.0-11.0.dev
Browse files Browse the repository at this point in the history
Merge b2d31da into dev
  • Loading branch information
Dart CI committed Apr 2, 2024
2 parents 02776ce + b2d31da commit 091dd91
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 26 deletions.
50 changes: 31 additions & 19 deletions pkg/front_end/lib/src/fasta/kernel/macro/macro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:macros/macros.dart' as macro;
import 'package:macros/src/executor.dart' as macro;
import 'package:macros/src/executor/span.dart' as macro;
import 'package:_fe_analyzer_shared/src/macros/uri.dart';
import 'package:_fe_analyzer_shared/src/scanner/scanner.dart';
import 'package:front_end/src/fasta/uri_offset.dart';
import 'package:kernel/ast.dart';
import 'package:kernel/class_hierarchy.dart';
import 'package:macros/macros.dart' as macro;
import 'package:macros/src/executor.dart' as macro;
import 'package:macros/src/executor/span.dart' as macro;

import '../../../api_prototype/compiler_options.dart';
import '../../../base/common.dart';
Expand Down Expand Up @@ -551,22 +551,34 @@ class MacroApplications {
try {
benchmarker?.beginSubdivide(BenchmarkSubdivides
.macroApplications_macroExecutorInstantiateMacro);
macro.MacroInstanceIdentifier instance =
application.instanceIdentifier = instanceIdCache[
application] ??=
// TODO: Dispose of these instances using
// `macroExecutor.disposeMacro` once we are done with them.
await macroExecutor.instantiateMacro(
libraryUri,
macroClassName,
application.constructorName,
application.arguments);

application.phasesToExecute = macro.Phase.values.where((phase) {
return instance.shouldExecute(targetDeclarationKind, phase);
}).toSet();

if (!instance.supportsDeclarationKind(targetDeclarationKind)) {
macro.MacroInstanceIdentifier? instance;
try {
instance = application.instanceIdentifier = instanceIdCache[
application] ??=
// TODO: Dispose of these instances using
// `macroExecutor.disposeMacro` once we are done with them.
await macroExecutor.instantiateMacro(
libraryUri,
macroClassName,
application.constructorName,
application.arguments);
} catch (_) {
applicationData.libraryBuilder.addProblem(
messageUnsupportedMacroApplication,
application.uriOffset.fileOffset,
noLength,
application.uriOffset.uri);
}

application.phasesToExecute = instance == null
? {}
: macro.Phase.values.where((phase) {
return instance!
.shouldExecute(targetDeclarationKind, phase);
}).toSet();

if (instance != null &&
!instance.supportsDeclarationKind(targetDeclarationKind)) {
Iterable<macro.DeclarationKind> supportedKinds = macro
.DeclarationKind.values
.where(instance.supportsDeclarationKind);
Expand Down
15 changes: 13 additions & 2 deletions pkg/front_end/lib/src/kernel_generator_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ Future<Map<Uri, ExecutorFactoryToken>?> precompileMacros(
return null;
}

Future<Map<Uri, ExecutorFactoryToken>> _compileMacros(
Future<Map<Uri, ExecutorFactoryToken>?> _compileMacros(
NeededPrecompilations neededPrecompilations,
ProcessedOptions options) async {
CompilerOptions rawOptions = options.rawOptionsForTesting;
Expand Down Expand Up @@ -362,11 +362,22 @@ Future<Map<Uri, ExecutorFactoryToken>> _compileMacros(
MemoryFileSystem fs = new MemoryFileSystem(_defaultDir);
fs.entityForUri(uri).writeAsStringSync(
bootstrapMacroIsolate(macroDeclarations, SerializationMode.byteData));

precompilationOptions
..fileSystem = new HybridFileSystem(fs, options.fileSystem);

// Surface diagnostics in the outer compile, failing the build if the macro
// build fails.
bool failed = false;
precompilationOptions.onDiagnostic = (diagnostic) {
options.rawOptionsForTesting.onDiagnostic!(diagnostic);
if (diagnostic.severity == Severity.error) {
failed = true;
}
};

CompilerResult? compilerResult =
await kernelForProgramInternal(uri, precompilationOptions);
if (failed) return null;
Uri precompiledUri = await options.macroSerializer
.createUriForComponent(compilerResult!.component!);
Set<Uri> macroLibraries =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import "org-dartlang-test:///a/b/c/main_lib.dart";
static method method() → dynamic {}

library;
//
// Problems in library:
//
// org-dartlang-test:///a/b/c/main_lib.dart:15:2: Error: This macro application didn't apply correctly.
// @Macro() // Error
// ^
//
import self as self2;
import "dart:core" as core;
import "package:_macros/src/api.dart" as api;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

/*library:
Declarations Order:
method:Macro.new()*/

import 'dart:async';
import 'main_lib.dart';

Expand Down
2 changes: 1 addition & 1 deletion tools/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ CHANNEL dev
MAJOR 3
MINOR 5
PATCH 0
PRERELEASE 10
PRERELEASE 11
PRERELEASE_PATCH 0

0 comments on commit 091dd91

Please sign in to comment.