Skip to content

Commit f38f3ff

Browse files
authoredJul 5, 2022
Merge pull request #59791 from artemcm/GatherOpaqueAssociatedTypeConformanceReqs
Gather opaque type conformance requirements when scanning associated type infos from a binary
2 parents f13a521 + ea0899d commit f38f3ff

File tree

10 files changed

+558
-296
lines changed

10 files changed

+558
-296
lines changed
 

‎include/swift/ABI/GenericContext.h

+14-1
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

+5-1
Original file line numberDiff line numberDiff line change
@@ -3039,7 +3039,11 @@ struct TargetOpaqueTypeDescriptor final
30393039
return cd->getKind() == ContextDescriptorKind::OpaqueType;
30403040
}
30413041
};
3042-
3042+
3043+
template <template <typename Runtime> class ObjCInteropKind,
3044+
unsigned PointerSize>
3045+
using ExternalOpaqueTypeDescriptor = TargetOpaqueTypeDescriptor<
3046+
External<ObjCInteropKind<RuntimeTarget<PointerSize>>>>;
30433047
using OpaqueTypeDescriptor = TargetOpaqueTypeDescriptor<InProcess>;
30443048

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

‎include/swift/ABI/MetadataRef.h

+10
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

+10-7
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)