Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/swift/ABI/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,11 @@ struct TargetTupleTypeMetadata : public TargetMetadata<Runtime> {
ConstTargetMetadataPointer<Runtime, swift::TargetMetadata> Type;

/// The offset of the tuple element within the tuple.
#if __APPLE__
StoredSize Offset;
#else
uint32_t Offset;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! For ABI compatibility on Apple platforms, we'd want to conditionalize this, because existing binaries will try to load the full 64 bits, and we want to keep those zeroed:

#if __APPLE__
  StoredSize Offset;
#else
  uint32_t Offset;
#endif

I think the IRGen side is fine, though, because in practice nobody is going to have a 4GB tuple (they'll run into other practical limits first), and new binaries doing a 32-bit little-endian load of the 64-bit field should be safe, and would open the door to us possibly being able to drop this compatibility hack in time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jckarter Change made. Thanks.

#endif

OpaqueValue *findIn(OpaqueValue *tuple) const {
return (OpaqueValue*) (((char*) tuple) + Offset);
Expand All @@ -1506,6 +1510,9 @@ struct TargetTupleTypeMetadata : public TargetMetadata<Runtime> {
}
};

static_assert(sizeof(Element) == sizeof(StoredSize) * 2,
"element size should be two words");

Element *getElements() {
return reinterpret_cast<Element*>(this + 1);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/IRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
// A tuple type metadata record has a couple extra fields.
auto tupleElementTy = createStructType(*this, "swift.tuple_element_type", {
TypeMetadataPtrTy, // Metadata *Type;
SizeTy // size_t Offset;
Int32Ty // int32_t Offset;
});
TupleTypeMetadataPtrTy = createStructPointerType(*this, "swift.tuple_type", {
TypeMetadataStructTy, // (base)
Expand Down
2 changes: 1 addition & 1 deletion test/IRGen/generic_tuples.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// CHECK: [[TYPE:%swift.type]] = type {
// CHECK: [[OPAQUE:%swift.opaque]] = type opaque
// CHECK: [[TUPLE_TYPE:%swift.tuple_type]] = type { [[TYPE]], i64, i8*, [0 x %swift.tuple_element_type] }
// CHECK: %swift.tuple_element_type = type { [[TYPE]]*, i64 }
// CHECK: %swift.tuple_element_type = type { [[TYPE]]*, i32 }

func dup<T>(_ x: T) -> (T, T) { var x = x; return (x,x) }
// CHECK: define hidden swiftcc void @"$s14generic_tuples3dupyx_xtxlF"(%swift.opaque* noalias nocapture, %swift.opaque* noalias nocapture, %swift.opaque* noalias nocapture, %swift.type* %T)
Expand Down