|
| 1 | +//===--- SILThunkKind.h ---------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | +/// |
| 13 | +/// \file This file contains a kind that defines the types of thunks that can be |
| 14 | +/// generated using a thunk inst. It provides an AST level interface that lets |
| 15 | +/// one generate the derived function kind and is also used to make adding such |
| 16 | +/// kinds to the mangler trivial. |
| 17 | +/// |
| 18 | +//===----------------------------------------------------------------------===// |
| 19 | + |
| 20 | +#ifndef SWIFT_AST_SILTHUNKKIND_H |
| 21 | +#define SWIFT_AST_SILTHUNKKIND_H |
| 22 | + |
| 23 | +#include "swift/AST/Types.h" |
| 24 | + |
| 25 | +namespace swift { |
| 26 | + |
| 27 | +class SILType; |
| 28 | + |
| 29 | +struct SILThunkKind { |
| 30 | + enum InnerTy { |
| 31 | + Invalid = 0, |
| 32 | + |
| 33 | + /// A thunk that just calls the passed in function. Used for testing |
| 34 | + /// purposes of the underlying thunking machinery. |
| 35 | + Identity = 1, |
| 36 | + |
| 37 | + /// A thunk that checks if a value is on the main actor and if it isn't |
| 38 | + /// jumps to the main actor. It expects that the passed in function does not |
| 39 | + /// have any arguments, results, is synchronous, and does not throw. |
| 40 | + HopToMainActorIfNeeded = 2, |
| 41 | + |
| 42 | + MaxValue = HopToMainActorIfNeeded, |
| 43 | + }; |
| 44 | + |
| 45 | + InnerTy innerTy; |
| 46 | + |
| 47 | + SILThunkKind() : innerTy(InnerTy::Invalid) {} |
| 48 | + SILThunkKind(InnerTy innerTy) : innerTy(innerTy) {} |
| 49 | + SILThunkKind(unsigned inputInnerTy) : innerTy(InnerTy(inputInnerTy)) { |
| 50 | + assert(inputInnerTy <= MaxValue && "Invalid value"); |
| 51 | + } |
| 52 | + |
| 53 | + operator InnerTy() const { return innerTy; } |
| 54 | + |
| 55 | + /// Given the current enum state returned the derived output function from |
| 56 | + /// \p inputFunction. |
| 57 | + /// |
| 58 | + /// Defined in Instructions.cpp |
| 59 | + CanSILFunctionType getDerivedFunctionType(SILFunction *fn, |
| 60 | + CanSILFunctionType inputFunction, |
| 61 | + SubstitutionMap subMap) const; |
| 62 | + |
| 63 | + /// Given the current enum state returned the derived output function from |
| 64 | + /// \p inputFunction. |
| 65 | + /// |
| 66 | + /// Defined in Instructions.cpp |
| 67 | + SILType getDerivedFunctionType(SILFunction *fn, SILType inputFunctionType, |
| 68 | + SubstitutionMap subMap) const; |
| 69 | + |
| 70 | + Demangle::MangledSILThunkKind getMangledKind() const { |
| 71 | + switch (innerTy) { |
| 72 | + case Invalid: |
| 73 | + return Demangle::MangledSILThunkKind::Invalid; |
| 74 | + case Identity: |
| 75 | + return Demangle::MangledSILThunkKind::Identity; |
| 76 | + case HopToMainActorIfNeeded: |
| 77 | + return Demangle::MangledSILThunkKind::HopToMainActorIfNeeded; |
| 78 | + } |
| 79 | + } |
| 80 | +}; |
| 81 | + |
| 82 | +} // namespace swift |
| 83 | + |
| 84 | +#endif |
0 commit comments