Add a new bit to ExtInfo to represent inout results

Move NumParams from ExtInfo to AnyFunctionType to make room in ExtInfo
This commit is contained in:
Meghana Gupta
2025-10-01 15:28:47 -07:00
parent 1bc0056ea0
commit c9a68d1e18
3 changed files with 23 additions and 8 deletions

View File

@@ -537,7 +537,8 @@ class ASTExtInfoBuilder {
DifferentiabilityMaskOffset = 11,
DifferentiabilityMask = 0x7 << DifferentiabilityMaskOffset,
SendingResultMask = 1 << 14,
NumMaskBits = 15
InOutResultMask = 1 << 15,
NumMaskBits = 16
};
static_assert(FunctionTypeIsolation::Mask == 0x7, "update mask manually");
@@ -660,6 +661,8 @@ public:
globalActor);
}
constexpr bool hasInOutResult() const { return bits & InOutResultMask; }
constexpr bool hasSelfParam() const {
switch (getSILRepresentation()) {
case SILFunctionTypeRepresentation::Thick:
@@ -782,6 +785,11 @@ public:
lifetimeDependencies);
}
[[nodiscard]] ASTExtInfoBuilder withHasInOutResult() const {
return ASTExtInfoBuilder((bits | InOutResultMask), clangTypeInfo,
globalActor, thrownError, lifetimeDependencies);
}
void Profile(llvm::FoldingSetNodeID &ID) const {
ID.AddInteger(bits);
ID.AddPointer(clangTypeInfo.getType());
@@ -877,6 +885,8 @@ public:
FunctionTypeIsolation getIsolation() const { return builder.getIsolation(); }
constexpr bool hasInOutResult() const { return builder.hasInOutResult(); }
/// Helper method for changing the representation.
///
/// Prefer using \c ASTExtInfoBuilder::withRepresentation for chaining.

View File

@@ -407,7 +407,7 @@ class alignas(1 << TypeAlignInBits) TypeBase
}
protected:
enum { NumAFTExtInfoBits = 15 };
enum { NumAFTExtInfoBits = 16 };
enum { NumSILExtInfoBits = 14 };
// clang-format off
@@ -444,8 +444,7 @@ protected:
HasExtInfo : 1,
HasClangTypeInfo : 1,
HasThrownError : 1,
HasLifetimeDependencies : 1,
NumParams : 15
HasLifetimeDependencies : 1
);
SWIFT_INLINE_BITFIELD_FULL(ArchetypeType, TypeBase, 1+1+16,
@@ -3350,7 +3349,8 @@ END_CAN_TYPE_WRAPPER(DynamicSelfType, Type)
/// represented at the binary level as a single function pointer.
class AnyFunctionType : public TypeBase {
const Type Output;
uint16_t NumParams;
public:
using Representation = FunctionTypeRepresentation;
@@ -3611,8 +3611,8 @@ protected:
Bits.AnyFunctionType.HasThrownError = false;
Bits.AnyFunctionType.HasLifetimeDependencies = false;
}
Bits.AnyFunctionType.NumParams = NumParams;
assert(Bits.AnyFunctionType.NumParams == NumParams && "Params dropped!");
this->NumParams = NumParams;
assert(this->NumParams == NumParams && "Params dropped!");
if (Info && CONDITIONAL_ASSERT_enabled()) {
unsigned maxLifetimeTarget = NumParams + 1;
@@ -3650,7 +3650,7 @@ public:
Type getResult() const { return Output; }
ArrayRef<Param> getParams() const;
unsigned getNumParams() const { return Bits.AnyFunctionType.NumParams; }
unsigned getNumParams() const { return NumParams; }
GenericSignature getOptGenericSignature() const;

View File

@@ -2572,6 +2572,11 @@ InterfaceTypeRequest::evaluate(Evaluator &eval, ValueDecl *D) const {
infoBuilder.withLifetimeDependencies(*lifetimeDependenceInfo);
}
auto *accessor = dyn_cast<AccessorDecl>(AFD);
if (accessor && accessor->isMutateAccessor()) {
infoBuilder = infoBuilder.withHasInOutResult();
}
auto info = infoBuilder.build();
if (sig && !hasSelf) {