@@ -5868,6 +5868,78 @@ class ConvertFunctionInst final
58685868 bool onlyConvertsSendable () const ;
58695869};
58705870
5871+ class ThunkInst final
5872+ : public UnaryInstructionWithTypeDependentOperandsBase<
5873+ SILInstructionKind::ThunkInst, ThunkInst, SingleValueInstruction> {
5874+ public:
5875+ struct Kind {
5876+ enum InnerTy {
5877+ Invalid = 0 ,
5878+
5879+ // / A thunk that just calls the passed in function. Used for testing
5880+ // / purposes of the underlying thunking machinery.
5881+ Identity = 1 ,
5882+
5883+ MaxValue = Identity,
5884+ };
5885+
5886+ InnerTy innerTy;
5887+
5888+ Kind () : innerTy(InnerTy::Invalid) {}
5889+ Kind (InnerTy innerTy) : innerTy(innerTy) {}
5890+ Kind (unsigned inputInnerTy) : innerTy(InnerTy(inputInnerTy)) {
5891+ assert (inputInnerTy <= MaxValue && " Invalid value" );
5892+ }
5893+
5894+ operator InnerTy () const { return innerTy; }
5895+
5896+ // / Given the current enum state returned the derived output function from
5897+ // / \p inputFunction.
5898+ CanSILFunctionType getDerivedFunctionType (SILFunction *fn,
5899+ CanSILFunctionType inputFunction,
5900+ SubstitutionMap subMap) const ;
5901+
5902+ SILType getDerivedFunctionType (SILFunction *fn, SILType inputFunctionType,
5903+ SubstitutionMap subMap) const {
5904+ auto fType = inputFunctionType.castTo <SILFunctionType>();
5905+ return SILType::getPrimitiveType (
5906+ getDerivedFunctionType (fn, fType , subMap),
5907+ inputFunctionType.getCategory ());
5908+ }
5909+ };
5910+
5911+ // / The type of thunk we are supposed to produce.
5912+ Kind kind;
5913+
5914+ // / The substitutions being applied to the callee when we generate thunks for
5915+ // / it. E.x.: if we generate a partial_apply, this will be the substitution
5916+ // / map used to generate the partial_apply.
5917+ SubstitutionMap substitutions;
5918+
5919+ private:
5920+ friend SILBuilder;
5921+
5922+ ThunkInst (SILDebugLocation debugLoc, SILValue operand,
5923+ ArrayRef<SILValue> typeDependentOperands, SILType outputType,
5924+ Kind kind, SubstitutionMap subs)
5925+ : UnaryInstructionWithTypeDependentOperandsBase(
5926+ debugLoc, operand, typeDependentOperands, outputType),
5927+ kind (kind), substitutions(subs) {}
5928+
5929+ static ThunkInst *create (SILDebugLocation debugLoc, SILValue operand,
5930+ SILModule &mod, SILFunction *func, Kind kind,
5931+ SubstitutionMap subs);
5932+
5933+ public:
5934+ Kind getThunkKind () const { return kind; }
5935+
5936+ SubstitutionMap getSubstitutionMap () const { return substitutions; }
5937+
5938+ CanSILFunctionType getOrigCalleeType () const {
5939+ return getOperand ()->getType ().castTo <SILFunctionType>();
5940+ }
5941+ };
5942+
58715943// / ConvertEscapeToNoEscapeInst - Change the type of a escaping function value
58725944// / to a trivial function type (@noescape T -> U).
58735945class ConvertEscapeToNoEscapeInst final
0 commit comments