Skip to content

Commit ebd7389

Browse files
committed
[NFC] Add RuntimeGenericSignature
This encapsulates the ABI representation of a generic signature, which can be used in multiple places in the system.
1 parent cffe105 commit ebd7389

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

include/swift/ABI/GenericContext.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,33 @@ class TargetGenericRequirementDescriptor {
184184
using GenericRequirementDescriptor =
185185
TargetGenericRequirementDescriptor<InProcess>;
186186

187+
/// A runtime description of a generic signature.
188+
class RuntimeGenericSignature {
189+
GenericContextDescriptorHeader Header;
190+
const GenericParamDescriptor *Params;
191+
const GenericRequirementDescriptor *Requirements;
192+
public:
193+
RuntimeGenericSignature()
194+
: Header{0, 0, 0, 0}, Params(nullptr), Requirements(nullptr) {}
195+
196+
RuntimeGenericSignature(const GenericContextDescriptorHeader &header,
197+
const GenericParamDescriptor *params,
198+
const GenericRequirementDescriptor *requirements)
199+
: Header(header), Params(params), Requirements(requirements) {}
200+
201+
llvm::ArrayRef<GenericParamDescriptor> getParams() const {
202+
return llvm::makeArrayRef(Params, Header.NumParams);
203+
}
204+
205+
llvm::ArrayRef<GenericRequirementDescriptor> getRequirements() const {
206+
return llvm::makeArrayRef(Requirements, Header.NumRequirements);
207+
}
208+
209+
size_t getArgumentLayoutSizeInWords() const {
210+
return Header.getArgumentLayoutSizeInWords();
211+
}
212+
};
213+
187214
template<typename Runtime>
188215
class TargetGenericEnvironment
189216
: public swift::ABI::TrailingObjects<TargetGenericEnvironment<Runtime>,
@@ -341,6 +368,13 @@ class TrailingGenericContextObjects<TargetSelf<Runtime>,
341368
* sizeof(StoredPointer);
342369
}
343370

371+
RuntimeGenericSignature getGenericSignature() const {
372+
if (!asSelf()->isGeneric()) return RuntimeGenericSignature();
373+
return {getGenericContextHeader(),
374+
getGenericParams().data(),
375+
getGenericRequirements().data()};
376+
}
377+
344378
protected:
345379
size_t numTrailingObjects(OverloadToken<GenericContextHeaderType>) const {
346380
return asSelf()->isGeneric() ? 1 : 0;

0 commit comments

Comments
 (0)