[Macros] Ignore the @TaskLocal macro attached to vars with projected values.

VarDecls with `@_projectedValueProperty` have already had the property
wrapper transform applied. This only impacts swiftinterfaces, and if
a swiftinterface was produced against a Concurrency library that does
not declare `TaskLocal` as a macro, we need to ignore the macro to avoid
producing duplicate declarations. This is only needed temporarily until
all swiftinterfaces have been built against the Concurrency library
containing the new macro declaration.
This commit is contained in:
Holly Borla
2024-05-22 17:59:42 -07:00
parent 31337dd004
commit 7ded57b162
2 changed files with 36 additions and 0 deletions

View File

@@ -1369,6 +1369,22 @@ static SourceFile *evaluateAttachedMacro(MacroDecl *macro, Decl *attachedTo,
dc = attachedTo->getInnermostDeclContext();
}
// FIXME: compatibility hack for the transition from property wrapper
// to macro for TaskLocal.
//
// VarDecls with `@_projectedValueProperty` have already had the property
// wrapper transform applied. This only impacts swiftinterfaces, and if
// a swiftinterface was produced against a Concurrency library that does
// not declare TaskLocal as a macro, we need to ignore the macro to avoid
// producing duplicate declarations. This is only needed temporarily until
// all swiftinterfaces have been built against the Concurrency library
// containing the new macro declaration.
if (auto *var = dyn_cast<VarDecl>(attachedTo)) {
if (var->getAttrs().getAttribute<ProjectedValuePropertyAttr>()) {
return nullptr;
}
}
ASTContext &ctx = dc->getASTContext();
auto moduleDecl = dc->getParentModule();

View File

@@ -0,0 +1,20 @@
// swift-interface-format-version: 1.0
// swift-compiler-version: Swift version 6.0
// swift-module-flags: -swift-version 5 -disable-availability-checking
// RUN: %empty-directory(%t)
// RUN: %target-swift-typecheck-module-from-interface(%s)
import Swift
import _Concurrency
@_hasMissingDesignatedInitializers final public class C {
@_Concurrency.TaskLocal @_projectedValueProperty($x) public static var x: Swift.Int? {
get
}
public static var $x: _Concurrency.TaskLocal<Swift.Int?> {
get
@available(*, unavailable, message: "use '$myTaskLocal.withValue(_:do:)' instead")
set
}
}