Skip to content

Commit 195896a

Browse files
committed
Print @_nonSendable extension in module interfaces
…instead of printing the attribute itself. This allows uses of @_nonSendable to back-deploy.
1 parent fa8436b commit 195896a

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

include/swift/AST/Decl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,8 @@ class ExtensionDecl final : public GenericContext, public Decl,
12841284
SourceLoc getStartLoc() const { return ExtensionLoc; }
12851285
SourceLoc getLocFromSource() const { return ExtensionLoc; }
12861286
SourceRange getSourceRange() const {
1287+
if (!Braces.isValid())
1288+
return SourceRange(ExtensionLoc);
12871289
return { ExtensionLoc, Braces.End };
12881290
}
12891291

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(ModuleDecl *ModuleToPrint,
263263
DAK_SetterAccess,
264264
DAK_Lazy,
265265
DAK_StaticInitializeObjCMetadata,
266-
DAK_RestatedObjCConformance
266+
DAK_RestatedObjCConformance,
267+
DAK_NonSendable,
267268
};
268269

269270
return result;

lib/AST/Attr.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,7 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
874874
case DAK_ReferenceOwnership:
875875
case DAK_Effects:
876876
case DAK_Optimize:
877+
case DAK_NonSendable:
877878
if (DeclAttribute::isDeclModifier(getKind())) {
878879
Printer.printKeyword(getAttrName(), Options);
879880
} else if (Options.IsForSwiftInterface && getKind() == DAK_ResultBuilder) {

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3943,8 +3943,7 @@ NormalProtocolConformance *GetImplicitSendableRequest::evaluate(
39433943
DeclContext *conformanceDC = nominal;
39443944
if (attrMakingUnavailable) {
39453945
llvm::VersionTuple NoVersion;
3946-
auto attr = new (ctx) AvailableAttr(attrMakingUnavailable->AtLoc,
3947-
attrMakingUnavailable->Range,
3946+
auto attr = new (ctx) AvailableAttr(SourceLoc(), SourceRange(),
39483947
PlatformKind::none, "", "", nullptr,
39493948
NoVersion, SourceRange(),
39503949
NoVersion, SourceRange(),
@@ -3954,8 +3953,11 @@ NormalProtocolConformance *GetImplicitSendableRequest::evaluate(
39543953

39553954
// Conformance availability is currently tied to the declaring extension.
39563955
// FIXME: This is a hack--we should give conformances real availability.
3956+
auto inherits = ctx.AllocateCopy(makeArrayRef(
3957+
InheritedEntry(TypeLoc::withoutLoc(proto->getDeclaredInterfaceType()),
3958+
/*isUnchecked*/true)));
39573959
auto extension = ExtensionDecl::create(ctx, attrMakingUnavailable->AtLoc,
3958-
nullptr, {},
3960+
nullptr, inherits,
39593961
nominal->getModuleScopeContext(),
39603962
nullptr);
39613963
extension->setImplicit();
@@ -3967,6 +3969,10 @@ NormalProtocolConformance *GetImplicitSendableRequest::evaluate(
39673969
std::move(nominal));
39683970
nominal->addExtension(extension);
39693971

3972+
// Make it accessible to getTopLevelDecls()
3973+
if (auto sf = dyn_cast<SourceFile>(nominal->getModuleScopeContext()))
3974+
sf->getOrCreateSynthesizedFile().addTopLevelDecl(extension);
3975+
39703976
conformanceDC = extension;
39713977
}
39723978

test/ModuleInterface/conformances.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,12 @@ public struct NestedAvailabilityOuter {
237237
public struct Inner: PrivateSubProto {}
238238
}
239239

240+
@_nonSendable public struct NonSendable {}
241+
// NEGATIVE-NOT: @_nonSendable
242+
// CHECK-LABEL: public struct NonSendable {
243+
// CHECK: @available(*, unavailable)
244+
// CHECK-NEXT: extension conformances.NonSendable : @unchecked Swift.Sendable {
245+
240246
// CHECK-END: @available(macOS 10.97, iOS 23, *)
241247
// CHECK-END: @available(tvOS, unavailable)
242248
// CHECK-END: extension conformances.NestedAvailabilityOuter.Inner : conformances.PublicBaseProto {}

0 commit comments

Comments
 (0)