Skip to content

Commit 9ee10e7

Browse files
committed
IRGen: destructiveProjectEnumData() value witness doesn't need a return value
The rest of the runtime assumes the payload starts at the beginning of the enum, so simplify some code by removing the return value here.
1 parent e6d35f2 commit 9ee10e7

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
lines changed

include/swift/Runtime/Metadata.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,9 @@ typedef unsigned getEnumTag(const OpaqueValue *src,
542542
/// bits, leaving behind a value of the inhabited case payload type.
543543
/// If the case is indirect, the payload can then be projected from the box
544544
/// with swift_projectBox().
545-
typedef OpaqueValue *destructiveProjectEnumData(OpaqueValue *src,
546-
const Metadata *self);
545+
typedef void destructiveProjectEnumData(OpaqueValue *src,
546+
const Metadata *self);
547+
547548

548549
} // end namespace value_witness_types
549550

@@ -1066,8 +1067,8 @@ struct Metadata {
10661067
unsigned vw_getEnumTag(const OpaqueValue *value) const {
10671068
return getValueWitnesses()->_asEVWT()->getEnumTag(value, this);
10681069
}
1069-
OpaqueValue *vw_destructiveProjectEnumData(OpaqueValue *value) const {
1070-
return getValueWitnesses()->_asEVWT()->destructiveProjectEnumData(value, this);
1070+
void vw_destructiveProjectEnumData(OpaqueValue *value) const {
1071+
getValueWitnesses()->_asEVWT()->destructiveProjectEnumData(value, this);
10711072
}
10721073

10731074
/// Get the nominal type descriptor if this metadata describes a nominal type,

lib/IRGen/GenOpaque.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,15 @@ static llvm::Type *createWitnessType(IRGenModule &IGM, ValueWitness index) {
171171
->getPointerTo();
172172
}
173173

174-
/// U *(*destructiveProjectEnumData)(T *obj, M *self);
174+
/// void (*destructiveProjectEnumData)(T *obj, M *self);
175175
case ValueWitness::DestructiveProjectEnumData: {
176+
llvm::Type *voidTy = IGM.VoidTy;
176177
llvm::Type *ptrTy = IGM.OpaquePtrTy;
177178
llvm::Type *metaTy = IGM.TypeMetadataPtrTy;
178179

179180
llvm::Type *args[] = {ptrTy, metaTy};
180181

181-
return llvm::FunctionType::get(ptrTy, args, /*isVarArg*/ false)
182+
return llvm::FunctionType::get(voidTy, args, /*isVarArg*/ false)
182183
->getPointerTo();
183184
}
184185

lib/IRGen/GenProto.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@ static void buildValueWitnessFunction(IRGenModule &IGM,
11351135
Address(value, type.getBestKnownAlignment()));
11361136
}
11371137

1138-
IGF.Builder.CreateRet(value);
1138+
IGF.Builder.CreateRetVoid();
11391139
return;
11401140
}
11411141

lib/IRGen/ValueWitness.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,9 @@ enum class ValueWitness : unsigned {
286286
/// Given a valid object of this enum type, extracts the tag value indicating
287287
/// which case of the enum is inhabited.
288288
GetEnumTag = First_EnumValueWitness,
289-
/// U *(*destructiveProjectEnumData)(T *obj, unsigned tag, M *self);
289+
/// void (*destructiveProjectEnumData)(T *obj, M *self);
290290
/// Given a valid object of this enum type, destructively extracts the
291-
/// associated payload and returns a pointer to that payload.
291+
/// associated payload.
292292
DestructiveProjectEnumData,
293293
Last_EnumValueWitness = DestructiveProjectEnumData,
294294

stdlib/public/runtime/Reflection.mm

+2-1
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,8 @@ StringMirrorTuple swift_EnumMirror_subscript(intptr_t i,
544544

545545
owner = pair.first;
546546
type->vw_initializeWithTake(pair.second, const_cast<OpaqueValue *>(value));
547-
value = type->vw_destructiveProjectEnumData(pair.second);
547+
type->vw_destructiveProjectEnumData(pair.second);
548+
value = pair.second;
548549

549550
// If the payload is indirect, we need to jump through the box to get it.
550551
if (indirect) {

test/IRGen/enum_value_semantics.sil

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import Builtin
3232
// CHECK: i8* null,
3333
// CHECK: i8* null,
3434
// CHECK: i8* bitcast (i32 (%swift.opaque*, %swift.type*)* @_TwugO20enum_value_semantics20SinglePayloadTrivial to i8*),
35-
// CHECK: i8* bitcast (%swift.opaque* (%swift.opaque*, %swift.type*)* @_TwupO20enum_value_semantics20SinglePayloadTrivial to i8*)
35+
// CHECK: i8* bitcast (void (%swift.opaque*, %swift.type*)* @_TwupO20enum_value_semantics20SinglePayloadTrivial to i8*)
3636
// CHECK: ]
3737

3838
// CHECK: @_TMfO20enum_value_semantics20SinglePayloadTrivial = internal constant { {{.*}}* } {
@@ -68,7 +68,7 @@ import Builtin
6868
// CHECK: i8* bitcast (void (%swift.opaque*, i32, %swift.type*)* @_TwxsO20enum_value_semantics23SinglePayloadNontrivial to i8*)
6969
// CHECK: i8* bitcast (i32 (%swift.opaque*, %swift.type*)* @_TwxgO20enum_value_semantics23SinglePayloadNontrivial to i8*)
7070
// CHECK: i8* bitcast (i32 (%swift.opaque*, %swift.type*)* @_TwugO20enum_value_semantics23SinglePayloadNontrivial to i8*),
71-
// CHECK: i8* bitcast (%swift.opaque* (%swift.opaque*, %swift.type*)* @_TwupO20enum_value_semantics23SinglePayloadNontrivial to i8*)
71+
// CHECK: i8* bitcast (void (%swift.opaque*, %swift.type*)* @_TwupO20enum_value_semantics23SinglePayloadNontrivial to i8*)
7272
// CHECK: ]
7373

7474
// CHECK: @_TMfO20enum_value_semantics23SinglePayloadNontrivial = internal constant { {{.*}}* } {

0 commit comments

Comments
 (0)