Skip to content

Commit 73e8193

Browse files
committed
Revert "SILGen: Cast the materializeForSet callback to the correct type when applying it"
This reverts commit 194c170.
1 parent 5ca1c72 commit 73e8193

File tree

5 files changed

+6
-56
lines changed

5 files changed

+6
-56
lines changed

lib/SILGen/SILGenLValue.cpp

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,6 @@ namespace {
905905
// warnings if we manage to devirtualize materializeForSet.
906906
loc.markAutoGenerated();
907907

908-
SILModule &M = gen.SGM.M;
909908
ASTContext &ctx = gen.getASTContext();
910909

911910
SILBasicBlock *contBB = gen.createBasicBlock();
@@ -920,7 +919,6 @@ namespace {
920919

921920
auto emptyTupleTy =
922921
SILType::getPrimitiveObjectType(TupleType::getEmpty(ctx));
923-
auto rawPointerTy = SILType::getRawPointerType(ctx);
924922

925923
SILType callbackSILType = gen.getLoweredType(
926924
materialized.callback->getType().getSwiftRValueType()
@@ -930,15 +928,8 @@ namespace {
930928
SILValue callback =
931929
writebackBB->createBBArg(callbackSILType);
932930

933-
// Cast the callback to the correct polymorphic function type.
934-
auto origCallbackFnType = gen.SGM.Types.getMaterializeForSetCallbackType(
935-
decl, materialized.genericSig, materialized.origSelfType);
936-
auto origCallbackType = SILType::getPrimitiveObjectType(origCallbackFnType);
937-
auto substCallbackFnType = origCallbackFnType->substGenericArgs(
938-
M, M.getSwiftModule(), substitutions);
939-
auto substCallbackType = SILType::getPrimitiveObjectType(substCallbackFnType);
940-
941-
auto metatypeType = substCallbackFnType->getParameters().back().getSILType();
931+
auto callbackType = callbackSILType.castTo<SILFunctionType>();
932+
SILType metatypeType = callbackType->getParameters().back().getSILType();
942933

943934
// We need to borrow the base here. We can't just consume it
944935
// because we're in conditionally-executed code (and because
@@ -958,21 +949,17 @@ namespace {
958949
// Otherwise, we have to pass something; use an empty tuple
959950
// and an undef metatype.
960951
} else {
961-
baseAddress = SILUndef::get(emptyTupleTy.getAddressType(), M);
962-
baseMetatype = SILUndef::get(metatypeType, M);
952+
baseAddress = SILUndef::get(emptyTupleTy.getAddressType(), gen.SGM.M);
953+
baseMetatype = SILUndef::get(metatypeType, gen.SGM.M);
963954
}
964955

965956
SILValue temporaryPointer =
966957
gen.B.createAddressToPointer(loc,
967958
materialized.temporary.getValue(),
968-
rawPointerTy);
969-
970-
callback = gen.B.createThinFunctionToPointer(loc, callback, rawPointerTy);
971-
callback = gen.B.createPointerToThinFunction(loc, callback, origCallbackType);
959+
SILType::getRawPointerType(ctx));
972960

973961
// Apply the callback.
974-
gen.B.createApply(loc, callback, substCallbackType,
975-
emptyTupleTy, substitutions, {
962+
gen.B.createApply(loc, callback, {
976963
temporaryPointer,
977964
materialized.callbackStorage,
978965
baseAddress,

test/SILGen/accessors.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ func test0(ref: A) {
6262
// CHECK-NEXT: store %0 to [[TEMP2]] : $*A
6363
// CHECK-NEXT: [[T0:%.*]] = metatype $@thick A.Type
6464
// CHECK-NEXT: [[T1:%.*]] = address_to_pointer [[ADDR]] : $*OrdinarySub to $Builtin.RawPointer
65-
// CHECK-NEXT: [[CALLBACK_ADDR:%.*]] = thin_function_to_pointer [[CALLBACK]] : $@convention(thin) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout A, @thick A.Type) -> () to $Builtin.RawPointer
66-
// CHECK-NEXT: [[CALLBACK:%.*]] = pointer_to_thin_function [[CALLBACK_ADDR]] : $Builtin.RawPointer to $@convention(thin) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout A, @thick A.Type) -> ()
6765
// CHECK-NEXT: apply [[CALLBACK]]([[T1]], [[STORAGE]], [[TEMP2]], [[T0]])
6866
// CHECK-NEXT: dealloc_stack [[TEMP2]]
6967
// CHECK-NEXT: br [[CONT]]
@@ -119,8 +117,6 @@ func test1(ref: B) {
119117
// CHECK-NEXT: store %0 to [[TEMP2]] : $*B
120118
// CHECK-NEXT: [[T0:%.*]] = metatype $@thick B.Type
121119
// CHECK-NEXT: [[T1:%.*]] = address_to_pointer [[ADDR]] : $*MutatingSub to $Builtin.RawPointer
122-
// CHECK-NEXT: [[CALLBACK_ADDR:%.*]] = thin_function_to_pointer [[CALLBACK]] : $@convention(thin) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout B, @thick B.Type) -> () to $Builtin.RawPointer
123-
// CHECK-NEXT: [[CALLBACK:%.*]] = pointer_to_thin_function [[CALLBACK_ADDR]] : $Builtin.RawPointer to $@convention(thin) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout B, @thick B.Type) -> ()
124120
// CHECK-NEXT: apply [[CALLBACK]]([[T1]], [[STORAGE]], [[TEMP2]], [[T0]])
125121
// CHECK-NEXT: dealloc_stack [[TEMP2]]
126122
// CHECK-NEXT: br [[CONT]]
@@ -144,8 +140,6 @@ func test1(ref: B) {
144140
// CHECK-NEXT: store %0 to [[TEMP2]] : $*B
145141
// CHECK-NEXT: [[T0:%.*]] = metatype $@thick B.Type
146142
// CHECK-NEXT: [[T1:%.*]] = address_to_pointer [[ADDR]] : $*MutatingSub to $Builtin.RawPointer
147-
// CHECK-NEXT: [[CALLBACK_ADDR:%.*]] = thin_function_to_pointer [[CALLBACK]] : $@convention(thin) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout B, @thick B.Type) -> () to $Builtin.RawPointer
148-
// CHECK-NEXT: [[CALLBACK:%.*]] = pointer_to_thin_function [[CALLBACK_ADDR]] : $Builtin.RawPointer to $@convention(thin) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout B, @thick B.Type) -> ()
149143
// CHECK-NEXT: apply [[CALLBACK]]([[T1]], [[STORAGE2]], [[TEMP2]], [[T0]])
150144
// CHECK-NEXT: dealloc_stack [[TEMP2]]
151145
// CHECK-NEXT: br [[CONT]]

test/SILGen/lifetime.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,6 @@ func logical_lvalue_lifetime(r: RefWithProp, _ i: Int, _ v: Val) {
384384
// CHECK: {{.*}}([[CALLBACK:%.*]] :
385385
// CHECK: [[TEMP:%.*]] = alloc_stack $RefWithProp
386386
// CHECK: store [[R2]] to [[TEMP]]
387-
// CHECK: [[CALLBACK_ADDR:%.*]] = thin_function_to_pointer [[CALLBACK]] : $@convention(thin) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout RefWithProp, @thick RefWithProp.Type) -> () to $Builtin.RawPointer
388-
// CHECK: [[CALLBACK:%.*]] = pointer_to_thin_function [[CALLBACK_ADDR]] : $Builtin.RawPointer to $@convention(thin) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout RefWithProp, @thick RefWithProp.Type) -> ()
389387
// CHECK: apply [[CALLBACK]]({{.*}}, [[STORAGE]], [[TEMP]], {{%.*}})
390388
}
391389

test/SILGen/properties.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,6 @@ func logical_struct_in_reftype_set(value: inout Val, z1: Int) {
232232
// CHECK: store [[VAL_REF]] to [[REF_MAT]]
233233
// CHECK: [[T0:%.*]] = metatype $@thick Ref.Type
234234
// CHECK: [[T1:%.*]] = address_to_pointer [[VAL_REF_VAL_PROP_MAT]]
235-
// CHECK: [[CALLBACK_ADDR:%.*]] = thin_function_to_pointer [[CALLBACK]] : $@convention(thin) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout Ref, @thick Ref.Type) -> () to $Builtin.RawPointer
236-
// CHECK: [[CALLBACK:%.*]] = pointer_to_thin_function [[CALLBACK_ADDR]] : $Builtin.RawPointer to $@convention(thin) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout Ref, @thick Ref.Type) -> ()
237235
// CHECK: apply [[CALLBACK]]([[T1]], [[STORAGE]], [[REF_MAT]], [[T0]])
238236
// CHECK: br [[CONT]]
239237
// CHECK: [[CONT]]:

test/SILGen/protocols.swift

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -401,33 +401,6 @@ func testExistentialPropertyRead<T: ExistentialProperty>(t: inout T) {
401401
// CHECK-NOT: witness_method
402402
// CHECK: return
403403

404-
func modify(x: inout Int) {}
405-
406-
// Make sure we call the materializeForSet callback with the correct
407-
// generic signature.
408-
409-
func modifyProperty<T : PropertyWithGetterSetter>(x: inout T) {
410-
modify(&x.b)
411-
}
412-
// CHECK-LABEL: sil hidden @_TF9protocols14modifyPropertyuRxS_24PropertyWithGetterSetterrFRxT_
413-
// CHECK: [[SELF_BOX:%.*]] = alloc_box $T
414-
// CHECK: [[SELF:%.*]] = project_box %1 : $@box T
415-
// CHECK: [[MODIFY_FN:%.*]] = function_ref @_TF9protocols6modifyFRSiT_
416-
// CHECK: [[WITNESS_FN:%.*]] = witness_method $T, #PropertyWithGetterSetter.b!materializeForSet.1
417-
// CHECK: [[RESULT:%.*]] = apply [[WITNESS_FN]]<T>
418-
// CHECK: [[TEMPORARY:%.*]] = tuple_extract [[RESULT]]
419-
// CHECK: [[CALLBACK:%.*]] = tuple_extract [[RESULT]]
420-
// CHECK: [[TEMPORARY_ADDR_TMP:%.*]] = pointer_to_address [[TEMPORARY]] : $Builtin.RawPointer to $*Int
421-
// CHECK: [[TEMPORARY_ADDR:%.*]] = mark_dependence [[TEMPORARY_ADDR_TMP]] : $*Int on [[SELF]] : $*T
422-
// CHECK: apply [[MODIFY_FN]]([[TEMPORARY_ADDR]])
423-
// CHECK: switch_enum [[CALLBACK]] : $Optional<@convention(thin) (Builtin.RawPointer, inout Builtin.UnsafeValueBuffer, inout T, @thick T.Type) -> ()>, case #Optional.some!enumelt.1: bb1, case #Optional.none!enumelt: bb2
424-
// CHECK: bb1([[CALLBACK:%.*]] : $@convention(thin) (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout T, @thick T.Type) -> ()):
425-
// CHECK: [[METATYPE:%.*]] = metatype $@thick T.Type
426-
// CHECK: [[TEMPORARY:%.*]] = address_to_pointer [[TEMPORARY_ADDR]] : $*Int to $Builtin.RawPointer
427-
// CHECK: [[CALLBACK_ADDR:%.*]] = thin_function_to_pointer [[CALLBACK]]
428-
// CHECK: [[CALLBACK:%.*]] = pointer_to_thin_function [[CALLBACK_ADDR]]
429-
// CHECK: apply [[CALLBACK]]<T>
430-
431404
// CHECK-LABEL: sil_witness_table hidden ClassWithGetter: PropertyWithGetter module protocols {
432405
// CHECK-NEXT: method #PropertyWithGetter.a!getter.1: @_TTWC9protocols15ClassWithGetterS_18PropertyWithGetterS_FS1_g1aSi
433406
// CHECK-NEXT: }

0 commit comments

Comments
 (0)