Skip to content

Commit 52499bb

Browse files
authored
Merge pull request #59897 from artemcm/57_ssm_opaque_requirements
[5.7] Gather opaque type conformance requirements when scanning associated type infos from a binary
2 parents 1674f86 + ddd0521 commit 52499bb

File tree

14 files changed

+580
-297
lines changed

14 files changed

+580
-297
lines changed

include/swift-c/StaticMirror/BinaryScan.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/// SWIFTSTATICMIRROR_VERSION_MINOR should increase when there are API additions.
2626
/// SWIFTSTATICMIRROR_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
2727
#define SWIFTSTATICMIRROR_VERSION_MAJOR 0
28-
#define SWIFTSTATICMIRROR_VERSION_MINOR 3 // Added filed type info gather
28+
#define SWIFTSTATICMIRROR_VERSION_MINOR 4 // Added opaque associated type's protocol requirements
2929

3030
SWIFTSTATICMIRROR_BEGIN_DECLS
3131

@@ -115,6 +115,9 @@ SWIFTSTATICMIRROR_PUBLIC swift_static_mirror_string_ref_t
115115
SWIFTSTATICMIRROR_PUBLIC swift_static_mirror_string_ref_t
116116
swift_static_mirror_type_alias_get_substituted_type_mangled_name(
117117
swift_static_mirror_type_alias_t);
118+
SWIFTSTATICMIRROR_PUBLIC swiftscan_string_set_t *
119+
swift_static_mirror_type_alias_get_opaque_type_requirements(
120+
swift_static_mirror_type_alias_t);
118121

119122
// swift_static_mirror_associated_type_info query methods
120123
SWIFTSTATICMIRROR_PUBLIC swift_static_mirror_string_ref_t

include/swift/ABI/GenericContext.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,18 @@ class TargetGenericRequirementDescriptor {
145145
return Protocol;
146146
}
147147

148+
/// Retreive the raw value of the Protocol requirement pointer.
149+
int32_t getUnresolvedProtocolAddress() const {
150+
assert(getKind() == GenericRequirementKind::Protocol);
151+
return Protocol.getUnresolvedProtocolAddress();
152+
}
153+
154+
/// Retreive the offset to the Protocol field
155+
constexpr inline auto
156+
getProtocolOffset() const -> typename Runtime::StoredSize {
157+
return offsetof(typename std::remove_reference<decltype(*this)>::type, Protocol);
158+
}
159+
148160
/// Retrieve the right-hand type for a SameType or BaseClass requirement.
149161
llvm::StringRef getMangledTypeName() const {
150162
assert(getKind() == GenericRequirementKind::SameType ||
@@ -301,7 +313,8 @@ class TargetGenericEnvironment
301313
}
302314
};
303315

304-
using GenericEnvironmentDescriptor = TargetGenericEnvironment<InProcess>;
316+
using GenericEnvironmentDescriptor =
317+
TargetGenericEnvironment<InProcess>;
305318

306319
/// CRTP class for a context descriptor that includes trailing generic
307320
/// context description.

include/swift/ABI/Metadata.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2996,7 +2996,11 @@ struct TargetOpaqueTypeDescriptor final
29962996
return cd->getKind() == ContextDescriptorKind::OpaqueType;
29972997
}
29982998
};
2999-
2999+
3000+
template <template <typename Runtime> class ObjCInteropKind,
3001+
unsigned PointerSize>
3002+
using ExternalOpaqueTypeDescriptor = TargetOpaqueTypeDescriptor<
3003+
External<ObjCInteropKind<RuntimeTarget<PointerSize>>>>;
30003004
using OpaqueTypeDescriptor = TargetOpaqueTypeDescriptor<InProcess>;
30013005

30023006
/// The instantiation cache for generic metadata. This must be guaranteed

include/swift/ABI/MetadataRef.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,16 @@ class RelativeTargetProtocolDescriptorPointer {
308308
swiftPointer.getPointer()));
309309
}
310310

311+
/// Retrieve a reference to the protocol.
312+
int32_t getUnresolvedProtocolAddress() const {
313+
#if SWIFT_OBJC_INTEROP
314+
if (isObjC()) {
315+
return objcPointer.getUnresolvedOffset();
316+
}
317+
#endif
318+
return swiftPointer.getUnresolvedOffset();
319+
}
320+
311321
operator TargetProtocolDescriptorRef<Runtime>() const {
312322
return getProtocol();
313323
}

include/swift/Basic/RelativePointer.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -347,11 +347,7 @@ class RelativeIndirectablePointerIntPair {
347347

348348
public:
349349
const ValueTy *getPointer() const & {
350-
static_assert(alignof(ValueTy) >= 2 && alignof(Offset) >= 2,
351-
"alignment of value and offset must be at least 2 to "
352-
"make room for indirectable flag");
353-
354-
Offset offset = (RelativeOffsetPlusIndirectAndInt & ~getIntMask());
350+
Offset offset = getUnresolvedOffset();
355351

356352
// Check for null.
357353
if (Nullable && offset == 0)
@@ -370,10 +366,17 @@ class RelativeIndirectablePointerIntPair {
370366
}
371367
}
372368

369+
Offset getUnresolvedOffset() const & {
370+
static_assert(alignof(ValueTy) >= 2 && alignof(Offset) >= 2,
371+
"alignment of value and offset must be at least 2 to "
372+
"make room for indirectable flag");
373+
Offset offset = (RelativeOffsetPlusIndirectAndInt & ~getIntMask());
374+
return offset;
375+
}
376+
373377
/// A zero relative offset encodes a null reference.
374378
bool isNull() const & {
375-
Offset offset = (RelativeOffsetPlusIndirectAndInt & ~getIntMask());
376-
return offset == 0;
379+
return getUnresolvedOffset() == 0;
377380
}
378381

379382
IntTy getInt() const & {

0 commit comments

Comments
 (0)