Skip to content

Commit b11d6e3

Browse files
committed
---
yaml --- r: 346731 b: refs/heads/master c: c25e942 h: refs/heads/master i: 346729: 0594d22 346727: 01fb476
1 parent c964e5b commit b11d6e3

File tree

7 files changed

+38
-56
lines changed

7 files changed

+38
-56
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: a2df58e779d7c909b2e701e190ba483efae4cbbb
2+
refs/heads/master: c25e942fe7edace795894c71dd8fe42576e933d9
33
refs/heads/master-next: 203b3026584ecad859eb328b2e12490099409cd5
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea

trunk/include/swift/AST/Types.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4007,15 +4007,10 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
40074007

40084008
CanType getSelfInstanceType() const;
40094009

4010-
/// If this is a @convention(witness_method) function with a protocol
4011-
/// constrained self parameter, return the protocol constraint for
4012-
/// the Self type.
4013-
ProtocolDecl *getDefaultWitnessMethodProtocol() const;
4014-
40154010
/// If this is a @convention(witness_method) function with a class
40164011
/// constrained self parameter, return the class constraint for the
40174012
/// Self type.
4018-
ClassDecl *getWitnessMethodClass(ModuleDecl &M) const;
4013+
ClassDecl *getWitnessMethodClass() const;
40194014

40204015
/// If this is a @convention(witness_method) function, return the conformance
40214016
/// for which the method is a witness.

trunk/lib/IRGen/GenProto.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,7 @@ void PolymorphicConvention::considerWitnessSelf(CanSILFunctionType fnType) {
329329
MetadataSource::InvalidSourceIndex,
330330
selfTy);
331331

332-
if (fnType->getDefaultWitnessMethodProtocol() ||
333-
fnType->getWitnessMethodClass(M)) {
332+
if (fnType->getSelfInstanceType()->is<GenericTypeParamType>()) {
334333
// The Self type is abstract, so we can fulfill its metadata from
335334
// the Self metadata parameter.
336335
addSelfMetadataFulfillment(selfTy);

trunk/lib/SIL/SILFunctionType.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -98,25 +98,8 @@ CanType SILFunctionType::getSelfInstanceType() const {
9898
return selfTy;
9999
}
100100

101-
ProtocolDecl *
102-
SILFunctionType::getDefaultWitnessMethodProtocol() const {
103-
assert(getRepresentation() == SILFunctionTypeRepresentation::WitnessMethod);
104-
auto selfTy = getSelfInstanceType();
105-
if (auto paramTy = dyn_cast<GenericTypeParamType>(selfTy)) {
106-
assert(paramTy->getDepth() == 0 && paramTy->getIndex() == 0);
107-
auto superclass = GenericSig->getSuperclassBound(paramTy);
108-
if (superclass)
109-
return nullptr;
110-
auto protos = GenericSig->getConformsTo(paramTy);
111-
assert(protos.size() == 1);
112-
return protos[0];
113-
}
114-
115-
return nullptr;
116-
}
117-
118101
ClassDecl *
119-
SILFunctionType::getWitnessMethodClass(ModuleDecl &M) const {
102+
SILFunctionType::getWitnessMethodClass() const {
120103
auto selfTy = getSelfInstanceType();
121104
auto genericSig = getGenericSignature();
122105
if (auto paramTy = dyn_cast<GenericTypeParamType>(selfTy)) {

trunk/lib/SIL/SILVerifier.cpp

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2542,10 +2542,9 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
25422542
selfRequirement->getKind() == RequirementKind::Conformance,
25432543
"first non-same-typerequirement should be conformance requirement");
25442544
auto conformsTo = genericSig->getConformsTo(selfGenericParam);
2545-
require(conformsTo.size() == 1,
2546-
"requirement Self parameter must conform to exactly one protocol");
2547-
require(conformsTo[0] == protocol,
2548-
"requirement Self parameter should be constrained by protocol");
2545+
require(std::find(conformsTo.begin(), conformsTo.end(), protocol)
2546+
!= conformsTo.end(),
2547+
"requirement Self parameter must conform to called protocol");
25492548

25502549
auto lookupType = AMI->getLookupType();
25512550
if (getOpenedArchetypeOf(lookupType)) {
@@ -5028,8 +5027,6 @@ void SILWitnessTable::verify(const SILModule &M) const {
50285027
assert(getEntries().empty() &&
50295028
"A witness table declaration should not have any entries.");
50305029

5031-
auto *protocol = getConformance()->getProtocol();
5032-
50335030
for (const Entry &E : getEntries())
50345031
if (E.getKind() == SILWitnessTable::WitnessKind::Method) {
50355032
SILFunction *F = E.getMethodWitness().Witness;
@@ -5045,15 +5042,6 @@ void SILWitnessTable::verify(const SILModule &M) const {
50455042
assert(F->getLoweredFunctionType()->getRepresentation() ==
50465043
SILFunctionTypeRepresentation::WitnessMethod &&
50475044
"Witnesses must have witness_method representation.");
5048-
auto *witnessSelfProtocol = F->getLoweredFunctionType()
5049-
->getDefaultWitnessMethodProtocol();
5050-
assert((witnessSelfProtocol == nullptr ||
5051-
witnessSelfProtocol == protocol) &&
5052-
"Witnesses must either have a concrete Self, or an "
5053-
"an abstract Self that is constrained to their "
5054-
"protocol.");
5055-
(void)protocol;
5056-
(void)witnessSelfProtocol;
50575045
}
50585046
}
50595047
}
@@ -5078,12 +5066,6 @@ void SILDefaultWitnessTable::verify(const SILModule &M) const {
50785066
assert(F->getLoweredFunctionType()->getRepresentation() ==
50795067
SILFunctionTypeRepresentation::WitnessMethod &&
50805068
"Default witnesses must have witness_method representation.");
5081-
5082-
auto *witnessSelfProtocol = F->getLoweredFunctionType()
5083-
->getDefaultWitnessMethodProtocol();
5084-
assert(witnessSelfProtocol == getProtocol() &&
5085-
"Default witnesses must have an abstract Self parameter "
5086-
"constrained to their protocol.");
50875069
}
50885070
#endif
50895071
}

trunk/lib/SILOptimizer/Utils/Devirtualize.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,8 @@ swift::tryDevirtualizeClassMethod(FullApplySite AI, SILValue ClassInstance,
870870
/// \param requirementSig The generic signature of the requirement
871871
/// \param witnessThunkSig The generic signature of the witness method
872872
/// \param origSubMap The substitutions from the call instruction
873-
/// \param isDefaultWitness True if this is a default witness method
873+
/// \param isSelfAbstract True if the Self type of the witness method is
874+
/// still abstract (i.e., not a concrete type).
874875
/// \param classWitness The ClassDecl if this is a class witness method
875876
static SubstitutionMap
876877
getWitnessMethodSubstitutions(
@@ -879,13 +880,13 @@ getWitnessMethodSubstitutions(
879880
GenericSignature *requirementSig,
880881
GenericSignature *witnessThunkSig,
881882
SubstitutionMap origSubMap,
882-
bool isDefaultWitness,
883+
bool isSelfAbstract,
883884
ClassDecl *classWitness) {
884885

885886
if (witnessThunkSig == nullptr)
886887
return SubstitutionMap();
887888

888-
if (isDefaultWitness)
889+
if (isSelfAbstract && !classWitness)
889890
return origSubMap;
890891

891892
assert(!conformanceRef.isAbstract());
@@ -947,14 +948,13 @@ swift::getWitnessMethodSubstitutions(SILModule &Module, ApplySite AI,
947948
SubstitutionMap origSubs = AI.getSubstitutionMap();
948949

949950
auto *mod = Module.getSwiftModule();
950-
bool isDefaultWitness =
951-
(witnessFnTy->getDefaultWitnessMethodProtocol()
952-
== CRef.getRequirement());
953-
auto *classWitness = witnessFnTy->getWitnessMethodClass(*mod);
951+
bool isSelfAbstract =
952+
witnessFnTy->getSelfInstanceType()->is<GenericTypeParamType>();
953+
auto *classWitness = witnessFnTy->getWitnessMethodClass();
954954

955955
return ::getWitnessMethodSubstitutions(mod, CRef, requirementSig,
956956
witnessThunkSig, origSubs,
957-
isDefaultWitness, classWitness);
957+
isSelfAbstract, classWitness);
958958
}
959959

960960
/// Generate a new apply of a function_ref to replace an apply of a
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-swift-frontend %s -emit-ir | %FileCheck --check-prefix=CHECK %s -DINT=i%target-ptrsize
2+
3+
public protocol DummyProtocol { }
4+
5+
public protocol SIMDStorageStub {
6+
associatedtype Scalar : DummyProtocol
7+
}
8+
9+
public protocol SIMDScalarStub {
10+
associatedtype SIMD2Storage : SIMDStorageStub
11+
where SIMD2Storage.Scalar == Self
12+
13+
func abs() -> Self
14+
}
15+
16+
// CHECK: define {{.*}}swiftcc void @"$s22witness_method_default7callAbs1sxx_tAA14SIMDScalarStubRzlF
17+
public func callAbs<T: SIMDScalarStub>(s: T) -> T {
18+
// CHECK: [[ABS_PTR:%[0-9]+]] = getelementptr inbounds i8*, i8** %T.SIMDScalarStub, i32 3
19+
// CHECK-NEXT: [[ABS_VALUE:%[0-9]+]] = load i8*, i8** [[ABS_PTR]]
20+
// CHECK-NEXT: [[ABS:%[0-9]+]] = bitcast i8* [[ABS_VALUE]]
21+
// CHECK-NEXT: call swiftcc void [[ABS]]
22+
return s.abs()
23+
}

0 commit comments

Comments
 (0)