Skip to content

IRGen: Conformance records for dependent conformances should referenc… #16084

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
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
37 changes: 18 additions & 19 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "GenMeta.h"
#include "GenObjC.h"
#include "GenOpaque.h"
#include "GenProto.h"
#include "GenType.h"
#include "IRGenDebugInfo.h"
#include "IRGenFunction.h"
Expand Down Expand Up @@ -2728,31 +2729,29 @@ namespace {
void addWitnessTable() {
using ConformanceKind = ConformanceFlags::ConformanceKind;

// Figure out what kind of witness table we have.
auto proto = Conformance->getProtocol();
// Figure out what kind of witness table we have.
llvm::Constant *witnessTableVar;
if (!IGM.isResilient(proto, ResilienceExpansion::Maximal) &&
Conformance->getConditionalRequirements().empty()) {
Flags = Flags.withConformanceKind(ConformanceKind::WitnessTable);

// If the conformance is in this object's table, then the witness table
// should also be in this object file, so we can always directly
// reference it.
witnessTableVar = IGM.getAddrOfWitnessTable(Conformance);
} else {
if (Conformance->getConditionalRequirements().empty()) {

if (Conformance->getConditionalRequirements().empty()) {
if (!isDependentConformance(IGM, Conformance,
ResilienceExpansion::Maximal)) {
Flags = Flags.withConformanceKind(ConformanceKind::WitnessTable);
witnessTableVar = IGM.getAddrOfWitnessTable(Conformance);
} else {
Flags = Flags.withConformanceKind(
ConformanceKind::WitnessTableAccessor);
} else {
Flags =
Flags.withConformanceKind(
ConformanceKind::ConditionalWitnessTableAccessor)
.withNumConditionalRequirements(
Conformance->getConditionalRequirements().size());
witnessTableVar = IGM.getAddrOfWitnessTableAccessFunction(
Conformance, ForDefinition);
}
} else {
Flags =
Flags.withConformanceKind(
ConformanceKind::ConditionalWitnessTableAccessor)
.withNumConditionalRequirements(
Conformance->getConditionalRequirements().size());

witnessTableVar = IGM.getAddrOfWitnessTableAccessFunction(
Conformance, ForDefinition);
Conformance, ForDefinition);
}

// Relative reference to the witness table.
Expand Down
5 changes: 4 additions & 1 deletion lib/IRGen/GenProto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ static bool isResilientConformance(const NormalProtocolConformance *conformance)

/// Is there anything about the given conformance that requires witness
/// tables to be dependently-generated?
static bool isDependentConformance(IRGenModule &IGM,
bool irgen::isDependentConformance(IRGenModule &IGM,
const NormalProtocolConformance *conformance,
ResilienceExpansion expansion) {
// If the conformance is resilient, this is always true.
Expand All @@ -950,6 +950,9 @@ static bool isDependentConformance(IRGenModule &IGM,

// Check whether any of the inherited conformances are dependent.
for (auto inherited : conformance->getProtocol()->getInheritedProtocols()) {
if (inherited->isObjC())
continue;

if (isDependentConformance(IGM,
conformance->getInheritedConformance(inherited)
->getRootNormalConformance(),
Expand Down
4 changes: 4 additions & 0 deletions lib/IRGen/GenProto.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ namespace irgen {
CanSILFunctionType fnType,
GenericParamFulfillmentCallback callback);

bool isDependentConformance(IRGenModule &IGM,
const NormalProtocolConformance *conformance,
ResilienceExpansion expansion);

} // end namespace irgen
} // end namespace swift

Expand Down
22 changes: 21 additions & 1 deletion test/IRGen/protocol_conformance_records.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@
import resilient_struct
import resilient_protocol

public protocol Associate {
associatedtype X
}

// Dependent conformance
// CHECK-LABEL: @"$S28protocol_conformance_records9DependentVyxGAA9AssociateAAMc" ={{ protected | }}constant
// -- protocol descriptor
// CHECK-SAME: @"$S28protocol_conformance_records9AssociateMp"
// -- nominal type descriptor
// CHECK-SAME: @"$S28protocol_conformance_records9DependentVMn"
// -- witness table accessor
// CHECK-SAME: @"$S28protocol_conformance_records9DependentVyxGAA9AssociateAAWa"
// -- flags
// CHECK-SAME: i32 1
// CHECK-SAME: }
public struct Dependent<T> {}

extension Dependent : Associate {
public typealias X = (T, T)
}

public protocol Runcible {
func runce()
}
Expand Down Expand Up @@ -85,7 +106,6 @@ extension Size: Runcible {
// CHECK-SAME: @"$S28protocol_conformance_records8RuncibleMp"
// CHECK-SAME: @"$S28protocol_conformance_records5SpoonMp"

// TODO: conformances that need lazy initialization
public protocol Spoon { }

// Conditional conformances
Expand Down