Skip to content

[4.2] SIL: Profile the witnessMethodConformance as part of the SILFun… #19464

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
6 changes: 4 additions & 2 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -4034,7 +4034,8 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
void Profile(llvm::FoldingSetNodeID &ID) {
Profile(ID, getGenericSignature(), getExtInfo(), getCoroutineKind(),
getCalleeConvention(), getParameters(), getYields(),
getResults(), getOptionalErrorResult());
getResults(), getOptionalErrorResult(),
getWitnessMethodConformanceOrNone());
}
static void Profile(llvm::FoldingSetNodeID &ID,
GenericSignature *genericSig,
Expand All @@ -4044,7 +4045,8 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
ArrayRef<SILParameterInfo> params,
ArrayRef<SILYieldInfo> yields,
ArrayRef<SILResultInfo> results,
Optional<SILResultInfo> errorResult);
Optional<SILResultInfo> errorResult,
Optional<ProtocolConformanceRef> conformance);

// Implement isa/cast/dyncast/etc.
static bool classof(const TypeBase *T) {
Expand Down
10 changes: 7 additions & 3 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3863,7 +3863,8 @@ void SILFunctionType::Profile(llvm::FoldingSetNodeID &id,
ArrayRef<SILParameterInfo> params,
ArrayRef<SILYieldInfo> yields,
ArrayRef<SILResultInfo> results,
Optional<SILResultInfo> errorResult) {
Optional<SILResultInfo> errorResult,
Optional<ProtocolConformanceRef> conformance) {
id.AddPointer(genericParams);
id.AddInteger(info.getFuncAttrKey());
id.AddInteger(unsigned(coroutineKind));
Expand All @@ -3881,6 +3882,8 @@ void SILFunctionType::Profile(llvm::FoldingSetNodeID &id,
// Just allow the profile length to implicitly distinguish the
// presence of an error result.
if (errorResult) errorResult->profile(id);
if (conformance)
id.AddPointer(conformance->getRequirement());
}

SILFunctionType::SILFunctionType(GenericSignature *genericSig, ExtInfo ext,
Expand Down Expand Up @@ -4016,8 +4019,9 @@ CanSILFunctionType SILFunctionType::get(GenericSignature *genericSig,
assert(coroutineKind != SILCoroutineKind::None || yields.empty());

llvm::FoldingSetNodeID id;
SILFunctionType::Profile(id, genericSig, ext, coroutineKind, callee,
params, yields, normalResults, errorResult);
SILFunctionType::Profile(id, genericSig, ext, coroutineKind, callee, params,
yields, normalResults, errorResult,
witnessMethodConformance);

// Do we already have this generic function type?
void *insertPos;
Expand Down
23 changes: 21 additions & 2 deletions test/SILGen/witnesses.swift
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ protocol IUOFailableRequirement {
struct NonFailableModel: FailableRequirement, NonFailableRefinement, IUOFailableRequirement {
// CHECK-LABEL: sil private [transparent] [thunk] @$S9witnesses16NonFailableModelVAA0C11Requirement{{[_0-9a-zA-Z]*}}fCTW : $@convention(witness_method: FailableRequirement) (Int, @thick NonFailableModel.Type) -> @out Optional<NonFailableModel>
// CHECK-LABEL: sil private [transparent] [thunk] @$S9witnesses16NonFailableModelVAA0bC10Refinement{{[_0-9a-zA-Z]*}}fCTW : $@convention(witness_method: NonFailableRefinement) (Int, @thick NonFailableModel.Type) -> @out NonFailableModel
// CHECK-LABEL: sil private [transparent] [thunk] @$S9witnesses16NonFailableModelVAA22IUOFailableRequirement{{[_0-9a-zA-Z]*}}fCTW : $@convention(witness_method: FailableRequirement) (Int, @thick NonFailableModel.Type) -> @out Optional<NonFailableModel>
// CHECK-LABEL: sil private [transparent] [thunk] @$S9witnesses16NonFailableModelVAA22IUOFailableRequirement{{[_0-9a-zA-Z]*}}fCTW : $@convention(witness_method: IUOFailableRequirement) (Int, @thick NonFailableModel.Type) -> @out Optional<NonFailableModel>
init(foo: Int) {}
}

Expand Down Expand Up @@ -380,7 +380,7 @@ protocol IUOFailableClassRequirement: class {
final class NonFailableClassModel: FailableClassRequirement, NonFailableClassRefinement, IUOFailableClassRequirement {
// CHECK-LABEL: sil private [transparent] [thunk] @$S9witnesses21NonFailableClassModelCAA0cD11Requirement{{[_0-9a-zA-Z]*}}fCTW : $@convention(witness_method: FailableClassRequirement) (Int, @thick NonFailableClassModel.Type) -> @owned Optional<NonFailableClassModel>
// CHECK-LABEL: sil private [transparent] [thunk] @$S9witnesses21NonFailableClassModelCAA0bcD10Refinement{{[_0-9a-zA-Z]*}}fCTW : $@convention(witness_method: NonFailableClassRefinement) (Int, @thick NonFailableClassModel.Type) -> @owned NonFailableClassModel
// CHECK-LABEL: sil private [transparent] [thunk] @$S9witnesses21NonFailableClassModelCAA011IUOFailableD11Requirement{{[_0-9a-zA-Z]*}}fCTW : $@convention(witness_method: FailableClassRequirement) (Int, @thick NonFailableClassModel.Type) -> @owned Optional<NonFailableClassModel>
// CHECK-LABEL: sil private [transparent] [thunk] @$S9witnesses21NonFailableClassModelCAA011IUOFailableD11Requirement{{[_0-9a-zA-Z]*}}fCTW : $@convention(witness_method: IUOFailableClassRequirement) (Int, @thick NonFailableClassModel.Type) -> @owned Optional<NonFailableClassModel>
init(foo: Int) {}
}

Expand Down Expand Up @@ -525,3 +525,22 @@ protocol EscapingReq {
struct EscapingCovariance: EscapingReq {
func f(_: (Int) -> Int) { }
}


protocol Base {
func foo()
}

protocol Sub : Base {
func bar()
}

struct MyImpl :Sub {
func bar() {}
func foo() {}
}

// protocol witness for witnesses.Sub.bar() -> () in conformance witnesses.MyImpl : witnesses.Sub in witnesses
// CHECK: sil private [transparent] [thunk] @$S9witnesses6MyImplVAA3SubA2aDP3baryyFTW : $@convention(witness_method: Sub) (@in_guaranteed MyImpl) -> ()
// protocol witness for witnesses.Base.foo() -> () in conformance witnesses.MyImpl : witnesses.Base in witnesses
// CHECK: sil private [transparent] [thunk] @$S9witnesses6MyImplVAA4BaseA2aDP3fooyyFTW : $@convention(witness_method: Base) (@in_guaranteed MyImpl) -> ()