Skip to content

Commit c9a68d1

Browse files
committed
Add a new bit to ExtInfo to represent inout results
Move NumParams from ExtInfo to AnyFunctionType to make room in ExtInfo
1 parent 1bc0056 commit c9a68d1

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

include/swift/AST/ExtInfo.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,8 @@ class ASTExtInfoBuilder {
537537
DifferentiabilityMaskOffset = 11,
538538
DifferentiabilityMask = 0x7 << DifferentiabilityMaskOffset,
539539
SendingResultMask = 1 << 14,
540-
NumMaskBits = 15
540+
InOutResultMask = 1 << 15,
541+
NumMaskBits = 16
541542
};
542543

543544
static_assert(FunctionTypeIsolation::Mask == 0x7, "update mask manually");
@@ -660,6 +661,8 @@ class ASTExtInfoBuilder {
660661
globalActor);
661662
}
662663

664+
constexpr bool hasInOutResult() const { return bits & InOutResultMask; }
665+
663666
constexpr bool hasSelfParam() const {
664667
switch (getSILRepresentation()) {
665668
case SILFunctionTypeRepresentation::Thick:
@@ -782,6 +785,11 @@ class ASTExtInfoBuilder {
782785
lifetimeDependencies);
783786
}
784787

788+
[[nodiscard]] ASTExtInfoBuilder withHasInOutResult() const {
789+
return ASTExtInfoBuilder((bits | InOutResultMask), clangTypeInfo,
790+
globalActor, thrownError, lifetimeDependencies);
791+
}
792+
785793
void Profile(llvm::FoldingSetNodeID &ID) const {
786794
ID.AddInteger(bits);
787795
ID.AddPointer(clangTypeInfo.getType());
@@ -877,6 +885,8 @@ class ASTExtInfo {
877885

878886
FunctionTypeIsolation getIsolation() const { return builder.getIsolation(); }
879887

888+
constexpr bool hasInOutResult() const { return builder.hasInOutResult(); }
889+
880890
/// Helper method for changing the representation.
881891
///
882892
/// Prefer using \c ASTExtInfoBuilder::withRepresentation for chaining.

include/swift/AST/Types.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ class alignas(1 << TypeAlignInBits) TypeBase
407407
}
408408

409409
protected:
410-
enum { NumAFTExtInfoBits = 15 };
410+
enum { NumAFTExtInfoBits = 16 };
411411
enum { NumSILExtInfoBits = 14 };
412412

413413
// clang-format off
@@ -444,8 +444,7 @@ class alignas(1 << TypeAlignInBits) TypeBase
444444
HasExtInfo : 1,
445445
HasClangTypeInfo : 1,
446446
HasThrownError : 1,
447-
HasLifetimeDependencies : 1,
448-
NumParams : 15
447+
HasLifetimeDependencies : 1
449448
);
450449

451450
SWIFT_INLINE_BITFIELD_FULL(ArchetypeType, TypeBase, 1+1+16,
@@ -3350,7 +3349,8 @@ END_CAN_TYPE_WRAPPER(DynamicSelfType, Type)
33503349
/// represented at the binary level as a single function pointer.
33513350
class AnyFunctionType : public TypeBase {
33523351
const Type Output;
3353-
3352+
uint16_t NumParams;
3353+
33543354
public:
33553355
using Representation = FunctionTypeRepresentation;
33563356

@@ -3611,8 +3611,8 @@ class AnyFunctionType : public TypeBase {
36113611
Bits.AnyFunctionType.HasThrownError = false;
36123612
Bits.AnyFunctionType.HasLifetimeDependencies = false;
36133613
}
3614-
Bits.AnyFunctionType.NumParams = NumParams;
3615-
assert(Bits.AnyFunctionType.NumParams == NumParams && "Params dropped!");
3614+
this->NumParams = NumParams;
3615+
assert(this->NumParams == NumParams && "Params dropped!");
36163616

36173617
if (Info && CONDITIONAL_ASSERT_enabled()) {
36183618
unsigned maxLifetimeTarget = NumParams + 1;
@@ -3650,7 +3650,7 @@ class AnyFunctionType : public TypeBase {
36503650

36513651
Type getResult() const { return Output; }
36523652
ArrayRef<Param> getParams() const;
3653-
unsigned getNumParams() const { return Bits.AnyFunctionType.NumParams; }
3653+
unsigned getNumParams() const { return NumParams; }
36543654

36553655
GenericSignature getOptGenericSignature() const;
36563656

lib/Sema/TypeCheckDecl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,6 +2572,11 @@ InterfaceTypeRequest::evaluate(Evaluator &eval, ValueDecl *D) const {
25722572
infoBuilder.withLifetimeDependencies(*lifetimeDependenceInfo);
25732573
}
25742574

2575+
auto *accessor = dyn_cast<AccessorDecl>(AFD);
2576+
if (accessor && accessor->isMutateAccessor()) {
2577+
infoBuilder = infoBuilder.withHasInOutResult();
2578+
}
2579+
25752580
auto info = infoBuilder.build();
25762581

25772582
if (sig && !hasSelf) {

0 commit comments

Comments
 (0)