Skip to content

IRGen: Fix silly mistake in MetadataPath::followComponent() #80675

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
Apr 10, 2025
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
11 changes: 5 additions & 6 deletions lib/IRGen/GenProto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3390,16 +3390,15 @@ MetadataResponse MetadataPath::followComponent(IRGenFunction &IGF,
assert(entry.isOutOfLineBase());
auto inheritedProtocol = entry.getBase();

sourceKey.Kind =
LocalTypeDataKind::forAbstractProtocolWitnessTable(inheritedProtocol);
if (sourceKey.Kind.isConcreteProtocolConformance()) {
auto inheritedConformance =
sourceKey.Kind.getConcreteProtocolConformance()
->getInheritedConformance(inheritedProtocol);
if (inheritedConformance) {
sourceKey.Kind = LocalTypeDataKind::forConcreteProtocolWitnessTable(
inheritedConformance);
}
sourceKey.Kind = LocalTypeDataKind::forConcreteProtocolWitnessTable(
inheritedConformance);
} else {
sourceKey.Kind =
LocalTypeDataKind::forAbstractProtocolWitnessTable(inheritedProtocol);
}

if (!source) return MetadataResponse();
Expand Down
6 changes: 3 additions & 3 deletions lib/IRGen/LocalTypeDataKind.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,19 @@ class LocalTypeDataKind {
/// same function.
static LocalTypeDataKind
forAbstractProtocolWitnessTable(ProtocolDecl *protocol) {
assert(protocol && "protocol reference may not be null");
ASSERT(protocol && "protocol reference may not be null");
return LocalTypeDataKind(uintptr_t(protocol) | Kind_Decl);
}

/// A reference to a protocol witness table for a concrete type.
static LocalTypeDataKind
forConcreteProtocolWitnessTable(ProtocolConformance *conformance) {
assert(conformance && "conformance reference may not be null");
ASSERT(conformance && "conformance reference may not be null");
return LocalTypeDataKind(uintptr_t(conformance) | Kind_Conformance);
}

static LocalTypeDataKind forProtocolWitnessTablePack(PackConformance *pack) {
assert(pack && "pack conformance reference may not be null");
ASSERT(pack && "pack conformance reference may not be null");
return LocalTypeDataKind(uintptr_t(pack) | Kind_PackConformance);
}

Expand Down
29 changes: 29 additions & 0 deletions test/IRGen/conformance_path_with_concrete_steps.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// RUN: %target-swift-frontend -emit-ir %s

public protocol P1 {
associatedtype A: P3
}

public protocol P2: P1 where A.B == G<C> {
associatedtype C where C == A.B.C
}

public protocol P3 {
associatedtype B: P4
}

public protocol P4: P5 {}

public protocol P5 {
associatedtype C: P6
}

public protocol P6 {
func foo()
}

public struct G<C: P6>: P4 {}

public func f<T: P2>(_: T, c: T.C) {
return c.foo()
}