Skip to content

embedded: fix specialization of associated conformance entries in witness tables #79908

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 3 commits into from
Mar 11, 2025

Conversation

eeckstein
Copy link
Contributor

When creating a specialized witness table, we need to get the right specialized conformance.
In IRGen don't emit associated conformance witness table entries if the protocol is not a class protocol.
In this case the associated type can never be used to create an existential. Therefore such a witness table entry is never used at runtime in embedded swift.

Fixes a compiler crash

rdar://146448091

…ness tables

When creating a specialized witness table, we need to get the right specialized conformance.
In IRGen don't emit associated conformance witness table entries if the protocol is not a class protocol.
In this case the associated type can never be used to create an existential. Therefore such a witness table entry is never used at runtime in embedded swift.

Fixes a compiler crash

rdar://146448091
@eeckstein eeckstein requested review from kubamracek and removed request for xedin, rjmccall and hborla March 11, 2025 10:34
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test

@@ -959,6 +959,13 @@ namespace {
}

void addAssociatedConformance(const AssociatedConformance &req) {
if (req.getAssociation()->getASTContext().LangOpts.hasFeature(Feature::Embedded) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to push this check up to SILWitnessVisitor, which already includes this check for example:

        // ObjC protocols do not have witnesses.
        if (!Lowering::TypeConverter::protocolRequiresWitnessTable(requirement))
          continue;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work because the FragileWitnessTableBuilder needs to pull the witness table entry before returning.

@@ -1775,7 +1790,10 @@ class AccessorConformanceInfo : public ConformanceInfo {
if (IGM.Context.LangOpts.hasFeature(Feature::Embedded)) {
// In Embedded Swift associated-conformance entries simply point to the witness table
// of the associated conformance.
llvm::Constant *witnessEntry = IGM.getAddrOfWitnessTable(associatedConformance.getConcrete());
ProtocolConformanceRef assocConf =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for assocConf to differ from associatedConformance above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because ConformanceInContext is not the same as SILWT->getConformance().
(I tried that first and it didn't work).

@@ -3734,7 +3752,7 @@ llvm::Value *irgen::emitWitnessTableRef(IRGenFunction &IGF,

// In Embedded Swift, only class-bound wtables are allowed.
if (srcType->getASTContext().LangOpts.hasFeature(Feature::Embedded)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IGF.IGM.Context is cleaner IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed. I will change it next time I work on this code

@eeckstein eeckstein merged commit ca76efa into swiftlang:main Mar 11, 2025
3 checks passed
@eeckstein eeckstein deleted the fix-witness-table-specialization branch March 11, 2025 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants