Skip to content

[Macros] Ignore the @TaskLocal macro attached to vars with projected value vars. #73832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/Sema/TypeCheckMacros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 20 additions & 0 deletions test/ModuleInterface/task_local_attr.swiftinterface
Original file line number Diff line number Diff line change
@@ -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
}
}