Skip to content

Commit 01644d5

Browse files
author
Jacob Mizraji
authored
Merge pull request #19464 from aschwaighofer/fix-sil-function-type-profile-4.2
[4.2] SIL: Profile the witnessMethodConformance as part of the SILFun…
2 parents ac7c511 + 9fe9191 commit 01644d5

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

include/swift/AST/Types.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4034,7 +4034,8 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
40344034
void Profile(llvm::FoldingSetNodeID &ID) {
40354035
Profile(ID, getGenericSignature(), getExtInfo(), getCoroutineKind(),
40364036
getCalleeConvention(), getParameters(), getYields(),
4037-
getResults(), getOptionalErrorResult());
4037+
getResults(), getOptionalErrorResult(),
4038+
getWitnessMethodConformanceOrNone());
40384039
}
40394040
static void Profile(llvm::FoldingSetNodeID &ID,
40404041
GenericSignature *genericSig,
@@ -4044,7 +4045,8 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
40444045
ArrayRef<SILParameterInfo> params,
40454046
ArrayRef<SILYieldInfo> yields,
40464047
ArrayRef<SILResultInfo> results,
4047-
Optional<SILResultInfo> errorResult);
4048+
Optional<SILResultInfo> errorResult,
4049+
Optional<ProtocolConformanceRef> conformance);
40484050

40494051
// Implement isa/cast/dyncast/etc.
40504052
static bool classof(const TypeBase *T) {

lib/AST/ASTContext.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3863,7 +3863,8 @@ void SILFunctionType::Profile(llvm::FoldingSetNodeID &id,
38633863
ArrayRef<SILParameterInfo> params,
38643864
ArrayRef<SILYieldInfo> yields,
38653865
ArrayRef<SILResultInfo> results,
3866-
Optional<SILResultInfo> errorResult) {
3866+
Optional<SILResultInfo> errorResult,
3867+
Optional<ProtocolConformanceRef> conformance) {
38673868
id.AddPointer(genericParams);
38683869
id.AddInteger(info.getFuncAttrKey());
38693870
id.AddInteger(unsigned(coroutineKind));
@@ -3881,6 +3882,8 @@ void SILFunctionType::Profile(llvm::FoldingSetNodeID &id,
38813882
// Just allow the profile length to implicitly distinguish the
38823883
// presence of an error result.
38833884
if (errorResult) errorResult->profile(id);
3885+
if (conformance)
3886+
id.AddPointer(conformance->getRequirement());
38843887
}
38853888

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

40184021
llvm::FoldingSetNodeID id;
4019-
SILFunctionType::Profile(id, genericSig, ext, coroutineKind, callee,
4020-
params, yields, normalResults, errorResult);
4022+
SILFunctionType::Profile(id, genericSig, ext, coroutineKind, callee, params,
4023+
yields, normalResults, errorResult,
4024+
witnessMethodConformance);
40214025

40224026
// Do we already have this generic function type?
40234027
void *insertPos;

test/SILGen/witnesses.swift

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ protocol IUOFailableRequirement {
337337
struct NonFailableModel: FailableRequirement, NonFailableRefinement, IUOFailableRequirement {
338338
// CHECK-LABEL: sil private [transparent] [thunk] @$S9witnesses16NonFailableModelVAA0C11Requirement{{[_0-9a-zA-Z]*}}fCTW : $@convention(witness_method: FailableRequirement) (Int, @thick NonFailableModel.Type) -> @out Optional<NonFailableModel>
339339
// CHECK-LABEL: sil private [transparent] [thunk] @$S9witnesses16NonFailableModelVAA0bC10Refinement{{[_0-9a-zA-Z]*}}fCTW : $@convention(witness_method: NonFailableRefinement) (Int, @thick NonFailableModel.Type) -> @out NonFailableModel
340-
// CHECK-LABEL: sil private [transparent] [thunk] @$S9witnesses16NonFailableModelVAA22IUOFailableRequirement{{[_0-9a-zA-Z]*}}fCTW : $@convention(witness_method: FailableRequirement) (Int, @thick NonFailableModel.Type) -> @out Optional<NonFailableModel>
340+
// CHECK-LABEL: sil private [transparent] [thunk] @$S9witnesses16NonFailableModelVAA22IUOFailableRequirement{{[_0-9a-zA-Z]*}}fCTW : $@convention(witness_method: IUOFailableRequirement) (Int, @thick NonFailableModel.Type) -> @out Optional<NonFailableModel>
341341
init(foo: Int) {}
342342
}
343343

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

@@ -525,3 +525,22 @@ protocol EscapingReq {
525525
struct EscapingCovariance: EscapingReq {
526526
func f(_: (Int) -> Int) { }
527527
}
528+
529+
530+
protocol Base {
531+
func foo()
532+
}
533+
534+
protocol Sub : Base {
535+
func bar()
536+
}
537+
538+
struct MyImpl :Sub {
539+
func bar() {}
540+
func foo() {}
541+
}
542+
543+
// protocol witness for witnesses.Sub.bar() -> () in conformance witnesses.MyImpl : witnesses.Sub in witnesses
544+
// CHECK: sil private [transparent] [thunk] @$S9witnesses6MyImplVAA3SubA2aDP3baryyFTW : $@convention(witness_method: Sub) (@in_guaranteed MyImpl) -> ()
545+
// protocol witness for witnesses.Base.foo() -> () in conformance witnesses.MyImpl : witnesses.Base in witnesses
546+
// CHECK: sil private [transparent] [thunk] @$S9witnesses6MyImplVAA4BaseA2aDP3fooyyFTW : $@convention(witness_method: Base) (@in_guaranteed MyImpl) -> ()

0 commit comments

Comments
 (0)