@@ -162,6 +162,21 @@ struct SILDeclRef {
162162 AsyncEntryPoint,
163163 };
164164
165+ // / Represents the variants of a back deployable function.
166+ enum class BackDeploymentKind : unsigned {
167+ // / Default value. If a SILDecRef references a function that has been back
168+ // / deployed and has this back deployment kind, then it references the
169+ // / original ABI stable function.
170+ None,
171+ // / The thunk variant of a function that calls either the original function
172+ // / or the fallback variant if the original is unavailable. This thunk will
173+ // / be emitted with PublicNonABI linkage.
174+ Thunk,
175+ // / The fallback variant of the function. This function will be emitted with
176+ // / PublicNonABI linkage.
177+ Fallback,
178+ };
179+
165180 // / The AST node represented by this SILDeclRef.
166181 Loc loc;
167182 // / The Kind of this SILDeclRef.
@@ -170,8 +185,8 @@ struct SILDeclRef {
170185 unsigned isForeign : 1 ;
171186 // / True if this references a distributed function.
172187 unsigned isDistributed : 1 ;
173- // / True if this references a back deployed entry point for the referenced decl .
174- unsigned isBackDeployed : 1 ;
188+ // / The BackDeploymentKind of this SILDeclRef .
189+ BackDeploymentKind backDeploymentKind : 2 ;
175190 // / The default argument index for a default argument getter.
176191 unsigned defaultArgIndex : 10 ;
177192
@@ -207,14 +222,14 @@ struct SILDeclRef {
207222 // / Produces a null SILDeclRef.
208223 SILDeclRef ()
209224 : loc(), kind(Kind::Func), isForeign(0 ), isDistributed(0 ),
210- isBackDeployed ( 0 ), defaultArgIndex(0 ) {}
225+ backDeploymentKind (BackDeploymentKind::None ), defaultArgIndex(0 ) {}
211226
212227 // / Produces a SILDeclRef of the given kind for the given decl.
213228 explicit SILDeclRef (
214229 ValueDecl *decl, Kind kind,
215230 bool isForeign = false ,
216231 bool isDistributed = false ,
217- bool isBackDeployed = false ,
232+ BackDeploymentKind backDeploymentKind = BackDeploymentKind::None ,
218233 AutoDiffDerivativeFunctionIdentifier *derivativeId = nullptr );
219234
220235 // / Produces a SILDeclRef for the given ValueDecl or
@@ -231,8 +246,7 @@ struct SILDeclRef {
231246 explicit SILDeclRef (
232247 Loc loc,
233248 bool isForeign = false ,
234- bool isDistributed = false ,
235- bool isBackDeployed = false );
249+ bool isDistributed = false );
236250
237251 // / See above put produces a prespecialization according to the signature.
238252 explicit SILDeclRef (Loc loc, GenericSignature prespecializationSig);
@@ -368,7 +382,7 @@ struct SILDeclRef {
368382 return loc.getOpaqueValue () == rhs.loc .getOpaqueValue () &&
369383 kind == rhs.kind && isForeign == rhs.isForeign &&
370384 isDistributed == rhs.isDistributed &&
371- isBackDeployed == rhs.isBackDeployed &&
385+ backDeploymentKind == rhs.backDeploymentKind &&
372386 defaultArgIndex == rhs.defaultArgIndex &&
373387 pointer == rhs.pointer ;
374388 }
@@ -387,7 +401,7 @@ struct SILDeclRef {
387401 return SILDeclRef (loc.getOpaqueValue (), kind,
388402 /* foreign=*/ foreign,
389403 /* distributed=*/ false ,
390- /* backDeployed= */ false ,
404+ backDeploymentKind ,
391405 defaultArgIndex,
392406 pointer.get <AutoDiffDerivativeFunctionIdentifier *>());
393407 }
@@ -397,17 +411,16 @@ struct SILDeclRef {
397411 return SILDeclRef (loc.getOpaqueValue (), kind,
398412 /* foreign=*/ false ,
399413 /* distributed=*/ distributed,
400- /* backDeployed= */ false ,
414+ backDeploymentKind ,
401415 defaultArgIndex,
402416 pointer.get <AutoDiffDerivativeFunctionIdentifier *>());
403417 }
404- // / Returns the back deployment entry point corresponding to the same
405- // / decl.
406- SILDeclRef asBackDeployed (bool backDeployed = true ) const {
418+ // / Returns a copy of the decl with the given back deployment kind.
419+ SILDeclRef asBackDeploymentKind (BackDeploymentKind backDeploymentKind) const {
407420 return SILDeclRef (loc.getOpaqueValue (), kind,
408- /* foreign= */ false ,
409- /* distributed= */ false ,
410- /* backDeployed= */ backDeployed ,
421+ isForeign ,
422+ isDistributed ,
423+ backDeploymentKind ,
411424 defaultArgIndex,
412425 pointer.get <AutoDiffDerivativeFunctionIdentifier *>());
413426 }
@@ -452,9 +465,13 @@ struct SILDeclRef {
452465 // / True if the decl ref references a thunk handling potentially distributed actor functions
453466 bool isDistributedThunk () const ;
454467
455- // / True if the decl ref references a thunk handling a call to a back deployed
456- // / function.
457- bool isBackDeployedThunk () const ;
468+ // / True if the decl ref references a thunk handling a call to a function that
469+ // / supports back deployment.
470+ bool isBackDeploymentThunk () const ;
471+
472+ // / True if the decl ref references a function that is the back deployment
473+ // / fallback for an original function which may be unavailable at runtime.
474+ bool isBackDeploymentFallback () const ;
458475
459476 // / True if the decl ref references a method which introduces a new vtable
460477 // / entry.
@@ -533,12 +550,13 @@ struct SILDeclRef {
533550 explicit SILDeclRef (void *opaqueLoc, Kind kind,
534551 bool isForeign,
535552 bool isDistributed,
536- bool isBackDeployed ,
553+ BackDeploymentKind backDeploymentKind ,
537554 unsigned defaultArgIndex,
538555 AutoDiffDerivativeFunctionIdentifier *derivativeId)
539556 : loc(Loc::getFromOpaqueValue(opaqueLoc)), kind(kind),
540557 isForeign(isForeign), isDistributed(isDistributed),
541- isBackDeployed(isBackDeployed), defaultArgIndex(defaultArgIndex),
558+ backDeploymentKind(backDeploymentKind),
559+ defaultArgIndex(defaultArgIndex),
542560 pointer(derivativeId) {}
543561};
544562
@@ -555,17 +573,18 @@ namespace llvm {
555573template <> struct DenseMapInfo <swift::SILDeclRef> {
556574 using SILDeclRef = swift::SILDeclRef;
557575 using Kind = SILDeclRef::Kind;
576+ using BackDeploymentKind = SILDeclRef::BackDeploymentKind;
558577 using Loc = SILDeclRef::Loc;
559578 using PointerInfo = DenseMapInfo<void *>;
560579 using UnsignedInfo = DenseMapInfo<unsigned >;
561580
562581 static SILDeclRef getEmptyKey () {
563582 return SILDeclRef (PointerInfo::getEmptyKey (), Kind::Func, false , false ,
564- false , 0 , nullptr );
583+ BackDeploymentKind::None , 0 , nullptr );
565584 }
566585 static SILDeclRef getTombstoneKey () {
567586 return SILDeclRef (PointerInfo::getTombstoneKey (), Kind::Func, false , false ,
568- false , 0 , nullptr );
587+ BackDeploymentKind::None , 0 , nullptr );
569588 }
570589 static unsigned getHashValue (swift::SILDeclRef Val) {
571590 unsigned h1 = PointerInfo::getHashValue (Val.loc .getOpaqueValue ());
@@ -576,7 +595,7 @@ template<> struct DenseMapInfo<swift::SILDeclRef> {
576595 unsigned h4 = UnsignedInfo::getHashValue (Val.isForeign );
577596 unsigned h5 = PointerInfo::getHashValue (Val.pointer .getOpaqueValue ());
578597 unsigned h6 = UnsignedInfo::getHashValue (Val.isDistributed );
579- unsigned h7 = UnsignedInfo::getHashValue (Val.isBackDeployed );
598+ unsigned h7 = UnsignedInfo::getHashValue (unsigned ( Val.backDeploymentKind ) );
580599 return h1 ^ (h2 << 4 ) ^ (h3 << 9 ) ^ (h4 << 7 ) ^ (h5 << 11 ) ^ (h6 << 8 ) ^
581600 (h7 << 10 );
582601 }
0 commit comments