Skip to content

Commit 18550b1

Browse files
committed
IRGen: witness_method function values no longer carry witness table
This was an unnecessary complication and didn't make a lot of logical sense, because we can recover the witness table from substitutions when we call a @convention(witness_method) anyway. Also, to fix materializeForSet for generic subscripts, I want the materializeForSet *callback* of a protocol witness to have @convention(witness_method), which requires representing such functions as a single function pointer in IRGen.
1 parent 412c71d commit 18550b1

File tree

9 files changed

+11
-36
lines changed

9 files changed

+11
-36
lines changed

lib/IRGen/GenFunc.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ const TypeInfo *TypeConverter::convertFunctionType(SILFunctionType *T) {
555555

556556
case SILFunctionType::Representation::Thin:
557557
case SILFunctionType::Representation::Method:
558+
case SILFunctionType::Representation::WitnessMethod:
558559
case SILFunctionType::Representation::ObjCMethod:
559560
case SILFunctionType::Representation::CFunctionPointer:
560561
case SILFunctionType::Representation::Closure:
@@ -576,19 +577,6 @@ const TypeInfo *TypeConverter::convertFunctionType(SILFunctionType *T) {
576577
std::move(spareBits),
577578
IsNotPOD);
578579
}
579-
// Witness method values carry a reference to their originating witness table
580-
// as context.
581-
case SILFunctionType::Representation::WitnessMethod: {
582-
SpareBitVector spareBits;
583-
spareBits.append(IGM.getFunctionPointerSpareBits());
584-
spareBits.append(IGM.getWitnessTablePtrSpareBits());
585-
return FuncTypeInfo::create(CanSILFunctionType(T),
586-
IGM.WitnessFunctionPairTy,
587-
IGM.getPointerSize() * 2,
588-
IGM.getPointerAlignment(),
589-
std::move(spareBits),
590-
IsPOD);
591-
}
592580
}
593581
llvm_unreachable("bad function type representation");
594582
}

lib/IRGen/GenProto.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2747,7 +2747,6 @@ irgen::emitWitnessMethodValue(IRGenFunction &IGF,
27472747

27482748
// Build the value.
27492749
out.add(witness);
2750-
out.add(wtable);
27512750
}
27522751

27532752
llvm::FunctionType *IRGenModule::getAssociatedTypeMetadataAccessFunctionTy() {

lib/IRGen/IRGenModule.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,6 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
273273
FunctionPtrTy,
274274
RefCountedPtrTy,
275275
});
276-
WitnessFunctionPairTy = createStructType(*this, "swift.function", {
277-
FunctionPtrTy,
278-
WitnessTablePtrTy,
279-
});
280276

281277
OpaquePtrTy = llvm::StructType::create(LLVMContext, "swift.opaque")
282278
->getPointerTo(DefaultAS);

lib/IRGen/IRGenModule.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ class IRGenModule {
430430
llvm::PointerType *UnownedReferencePtrTy;/// %swift.unowned_reference*
431431
llvm::Constant *RefCountedNull; /// %swift.refcounted* null
432432
llvm::StructType *FunctionPairTy; /// { i8*, %swift.refcounted* }
433-
llvm::StructType *WitnessFunctionPairTy; /// { i8*, %witness.table* }
434433
llvm::FunctionType *DeallocatingDtorTy; /// void (%swift.refcounted*)
435434
llvm::StructType *TypeMetadataStructTy; /// %swift.type = type { ... }
436435
llvm::PointerType *TypeMetadataPtrTy;/// %swift.type*

lib/IRGen/IRGenSIL.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,12 +1992,8 @@ static CallEmission getCallEmissionForLoweredValue(IRGenSILFunction &IGF,
19921992

19931993
if (origCalleeType->getRepresentation()
19941994
== SILFunctionType::Representation::WitnessMethod) {
1995-
// @convention(witness_method) callees are exploded as a
1996-
// triple consisting of the function, Self metadata, and
1997-
// the Self witness table.
1998-
witnessMetadata->SelfWitnessTable = calleeValues.claimNext();
1999-
assert(witnessMetadata->SelfWitnessTable->getType() ==
2000-
IGF.IGM.WitnessTablePtrTy);
1995+
witnessMetadata->SelfWitnessTable = emitWitnessTableForLoweredCallee(
1996+
IGF, origCalleeType, substitutions);
20011997
}
20021998

20031999
if (origCalleeType->getRepresentation()
@@ -2221,12 +2217,9 @@ getPartialApplicationFunction(IRGenSILFunction &IGF, SILValue v,
22212217
case SILFunctionType::Representation::Closure:
22222218
case SILFunctionType::Representation::ObjCMethod:
22232219
break;
2224-
case SILFunctionType::Representation::WitnessMethod: {
2225-
llvm::Value *wtable = ex.claimNext();
2226-
assert(wtable->getType() == IGF.IGM.WitnessTablePtrTy);
2227-
context = wtable;
2220+
case SILFunctionType::Representation::WitnessMethod:
2221+
context = emitWitnessTableForLoweredCallee(IGF, fnType, subs);
22282222
break;
2229-
}
22302223
case SILFunctionType::Representation::CFunctionPointer:
22312224
break;
22322225
case SILFunctionType::Representation::Thick:

test/IRGen/class_bounded_generics.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ func class_bounded_archetype_method<T : ClassBoundBinary>(_ x: T, y: T) {
8888
// CHECK: [[INHERITED:%.*]] = load i8*, i8** %T.ClassBoundBinary, align 8
8989
// CHECK: [[INHERITED_WTBL:%.*]] = bitcast i8* [[INHERITED]] to i8**
9090
// CHECK: [[WITNESS:%.*]] = load i8*, i8** [[INHERITED_WTBL]], align 8
91+
// FIXME: Redundant load of inherited conformance
92+
// CHECK: [[INHERITED:%.*]] = load i8*, i8** %T.ClassBoundBinary, align 8
93+
// CHECK: [[INHERITED_WTBL:%.*]] = bitcast i8* [[INHERITED]] to i8**
9194
// CHECK: [[WITNESS_FUNC:%.*]] = bitcast i8* [[WITNESS]] to void (%objc_object*, %swift.type*, i8**)
9295
// CHECK: call swiftcc void [[WITNESS_FUNC]](%objc_object* swiftself %0, %swift.type* {{.*}}, i8** [[INHERITED_WTBL]])
9396
x.classBoundBinaryMethod(y)

test/IRGen/function_types.sil

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ entry(%x : $() -> ()):
3636
return %x : $() -> ()
3737
}
3838

39-
// CHECK-LABEL: define{{( protected)?}} swiftcc { i8*, i8** } @thin_witness_value(i8*, i8**) {{.*}} {
39+
// CHECK-LABEL: define{{( protected)?}} swiftcc i8* @thin_witness_value(i8*) {{.*}} {
4040
// CHECK-NEXT: entry:
41-
// CHECK-NEXT: [[T0:%.*]] = insertvalue { i8*, i8** } undef, i8* %0, 0
42-
// CHECK-NEXT: [[T1:%.*]] = insertvalue { i8*, i8** } [[T0]], i8** %1, 1
43-
// CHECK-NEXT: ret { i8*, i8** } [[T1]]
41+
// CHECK-NEXT: ret i8* %0
4442
// CHECK-NEXT: }
4543
sil @thin_witness_value : $@convention(thin) (@convention(witness_method) () -> ()) -> @convention(witness_method) () -> () {
4644
entry(%x : $@convention(witness_method) () -> ()):

test/IRGen/sil_witness_methods.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ entry(%z : $*Z, %x : $*Foo):
8585
return %m : $@thick Foo.Type
8686
}
8787

88-
// CHECK-LABEL: define{{( protected)?}} swiftcc %swift.type* @generic_type_generic_method_witness(%swift.opaque* noalias nocapture, %swift.type* %Z, %T19sil_witness_methods3BarC{{(.1)?}}** noalias nocapture swiftself dereferenceable(8), %swift.type* %Self, i8** %SelfWitnessTable)
88+
// CHECK-LABEL: define{{( protected)?}} swiftcc %swift.type* @generic_type_generic_method_witness(%swift.opaque* noalias nocapture, %swift.type* %Z, %T19sil_witness_methods3BarC{{.*}}** noalias nocapture swiftself dereferenceable(8), %swift.type* %Self, i8** %SelfWitnessTable)
8989
sil @generic_type_generic_method_witness : $@convention(witness_method) <T, U, V, Z> (@in Z, @in Bar<T, U, V>) -> @thick Bar<T, U, V>.Type {
9090
entry(%z : $*Z, %x : $*Bar<T, U, V>):
9191
%t = metatype $@thick T.Type

test/IRGen/witness_method_phi.sil

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ entry:
1010
br bb1(%1 : $@convention(witness_method) <T: P> (@in P) -> ())
1111

1212
// CHECK: phi i8* [ %0, %entry ]
13-
// CHECK-NEXT: phi i8** [ %T.P, %entry ]
1413
bb1(%2 : $@convention(witness_method) <T: P> (@in P) -> ()):
1514
unreachable
1615
}

0 commit comments

Comments
 (0)