Skip to content

Allow @_preInverseGenerics on extensions #72142

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 2 commits into from
Mar 7, 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
3 changes: 3 additions & 0 deletions include/swift/AST/ASTMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ class ASTMangler : public Mangler {
BaseEntitySignature(const Decl *decl);
};

static bool inversesAllowed(const Decl *decl);
static bool inversesAllowedIn(const DeclContext *ctx);

void appendContextOf(const ValueDecl *decl, BaseEntitySignature &base);
void appendContextualInverses(const GenericTypeDecl *contextDecl,
BaseEntitySignature &base,
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/DeclAttr.def
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ DECL_ATTR(_allowFeatureSuppression, AllowFeatureSuppression,
OnAnyDecl | UserInaccessible | NotSerialized | ABIStableToAdd | APIStableToAdd | ABIStableToRemove | APIStableToRemove,
157)
SIMPLE_DECL_ATTR(_preInverseGenerics, PreInverseGenerics,
OnAbstractFunction | OnSubscript | OnVar | UserInaccessible | ABIBreakingToAdd | ABIBreakingToRemove | APIStableToAdd | APIStableToRemove,
OnAbstractFunction | OnSubscript | OnVar | OnExtension | UserInaccessible | ABIBreakingToAdd | ABIBreakingToRemove | APIStableToAdd | APIStableToRemove,
158)
LAST_DECL_ATTR(PreInverseGenerics)

Expand Down
10 changes: 8 additions & 2 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
using namespace swift;
using namespace swift::Mangle;

static bool inversesAllowed(const Decl *decl) {
bool ASTMangler::inversesAllowed(const Decl *decl) {
if (!decl)
return true;

Expand All @@ -73,7 +73,7 @@ static bool inversesAllowed(const Decl *decl) {
return !decl->getParsedAttrs().hasAttribute<PreInverseGenericsAttr>();
}

static bool inversesAllowedIn(const DeclContext *ctx) {
bool ASTMangler::inversesAllowedIn(const DeclContext *ctx) {
assert(ctx);
return inversesAllowed(ctx->getInnermostDeclarationDeclContext());
}
Expand Down Expand Up @@ -242,6 +242,9 @@ std::string ASTMangler::mangleConstructorVTableThunk(
}

std::string ASTMangler::mangleWitnessTable(const RootProtocolConformance *C) {
llvm::SaveAndRestore X(AllowInverses,
inversesAllowedIn(C->getDeclContext()));

beginMangling();
if (isa<NormalProtocolConformance>(C)) {
appendProtocolConformance(C);
Expand Down Expand Up @@ -450,6 +453,9 @@ std::string ASTMangler::mangleReabstractionThunkHelper(
assert(ThunkType->getPatternSubstitutions().empty() && "not implemented");
GenericSignature GenSig = ThunkType->getInvocationGenericSignature();

// Reabstraction thunks never reference inverse conformances.
llvm::SaveAndRestore X(AllowInverses, false);

beginMangling();
appendType(FromType, GenSig);
appendType(ToType, GenSig);
Expand Down
6 changes: 5 additions & 1 deletion lib/IRGen/IRGenMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ IRGenMangler::mangleTypeForFlatUniqueTypeRef(CanGenericSignature sig,

std::string IRGenMangler::mangleProtocolConformanceDescriptor(
const RootProtocolConformance *conformance) {
llvm::SaveAndRestore X(AllowInverses,
inversesAllowedIn(conformance->getDeclContext()));

beginMangling();
if (isa<NormalProtocolConformance>(conformance)) {
appendProtocolConformance(conformance);
Expand Down Expand Up @@ -496,8 +499,9 @@ IRGenMangler::appendExtendedExistentialTypeShape(CanGenericSignature genSig,
CanType shapeType) {
// Append the generalization signature.
if (genSig) {
// Generalization signature never reference inverses.
// Generalization signature never references inverses.
llvm::SaveAndRestore X(AllowInverses, false);

appendGenericSignature(genSig);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// RUN: %target-swift-frontend -emit-silgen %s | %FileCheck %s

// XFAIL: noncopyable_generics

protocol P {
associatedtype A

Expand Down
2 changes: 0 additions & 2 deletions test/SILGen/tuple_attribute_reabstraction.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// RUN: %target-swift-emit-silgen %s | %FileCheck %s

// XFAIL: noncopyable_generics

public struct G<T> {
var t: T

Expand Down
2 changes: 0 additions & 2 deletions test/SILGen/variadic-generic-reabstract-tuple-result.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// RUN: %target-swift-emit-silgen -disable-availability-checking %s | %FileCheck %s

// XFAIL: noncopyable_generics

// rdar://110391963

struct Use<each T> {}
Expand Down