Skip to content

[SIL] NFC: Moved flag to SILExtInfo. #33636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions include/swift/AST/ExtInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,16 +495,17 @@ class SILExtInfoBuilder {
// If bits are added or removed, then TypeBase::SILFunctionTypeBits
// and NumMaskBits must be updated, and they must match.

// |representation|pseudogeneric| noescape |differentiability|
// | 0 .. 3 | 4 | 5 | 6 .. 7 |
// |representation|pseudogeneric| noescape | async | differentiability|
// | 0 .. 3 | 4 | 5 | 6 | 7 .. 8 |
//
enum : unsigned {
RepresentationMask = 0xF << 0,
PseudogenericMask = 1 << 4,
NoEscapeMask = 1 << 5,
DifferentiabilityMaskOffset = 6,
AsyncMask = 1 << 6,
DifferentiabilityMaskOffset = 7,
DifferentiabilityMask = 0x3 << DifferentiabilityMaskOffset,
NumMaskBits = 8
NumMaskBits = 9
};

unsigned bits; // Naturally sized for speed.
Expand All @@ -523,10 +524,11 @@ class SILExtInfoBuilder {

// Constructor for polymorphic type.
SILExtInfoBuilder(Representation rep, bool isPseudogeneric, bool isNoEscape,
DifferentiabilityKind diffKind, const clang::Type *type)
bool isAsync, DifferentiabilityKind diffKind,
const clang::Type *type)
: SILExtInfoBuilder(
((unsigned)rep) | (isPseudogeneric ? PseudogenericMask : 0) |
(isNoEscape ? NoEscapeMask : 0) |
(isNoEscape ? NoEscapeMask : 0) | (isAsync ? AsyncMask : 0) |
(((unsigned)diffKind << DifferentiabilityMaskOffset) &
DifferentiabilityMask),
ClangTypeInfo(type)) {}
Expand All @@ -552,6 +554,8 @@ class SILExtInfoBuilder {
// Is this function guaranteed to be no-escape by the type system?
constexpr bool isNoEscape() const { return bits & NoEscapeMask; }

constexpr bool isAsync() const { return bits & AsyncMask; }

constexpr DifferentiabilityKind getDifferentiabilityKind() const {
return DifferentiabilityKind((bits & DifferentiabilityMask) >>
DifferentiabilityMaskOffset);
Expand Down Expand Up @@ -616,6 +620,10 @@ class SILExtInfoBuilder {
: (bits & ~NoEscapeMask),
clangTypeInfo);
}
SILExtInfoBuilder withAsync(bool isAsync = true) const {
return SILExtInfoBuilder(isAsync ? (bits | AsyncMask) : (bits & ~AsyncMask),
clangTypeInfo);
}
SILExtInfoBuilder
withDifferentiabilityKind(DifferentiabilityKind differentiability) const {
return SILExtInfoBuilder(
Expand Down Expand Up @@ -657,8 +665,8 @@ class SILExtInfo {

static SILExtInfo getThin() {
return SILExtInfoBuilder(SILExtInfoBuilder::Representation::Thin, false,
false, DifferentiabilityKind::NonDifferentiable,
nullptr)
false, false,
DifferentiabilityKind::NonDifferentiable, nullptr)
.build();
}

Expand All @@ -681,6 +689,8 @@ class SILExtInfo {

constexpr bool isNoEscape() const { return builder.isNoEscape(); }

constexpr bool isAsync() const { return builder.isAsync(); }

constexpr DifferentiabilityKind getDifferentiabilityKind() const {
return builder.getDifferentiabilityKind();
}
Expand Down
16 changes: 7 additions & 9 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class alignas(1 << TypeAlignInBits) TypeBase {

protected:
enum { NumAFTExtInfoBits = 9 };
enum { NumSILExtInfoBits = 8 };
enum { NumSILExtInfoBits = 9 };
union { uint64_t OpaqueBits;

SWIFT_INLINE_BITFIELD_BASE(TypeBase, bitmax(NumTypeKindBits,8) +
Expand Down Expand Up @@ -362,12 +362,11 @@ class alignas(1 << TypeAlignInBits) TypeBase {
ID : 32
);

SWIFT_INLINE_BITFIELD(SILFunctionType, TypeBase, NumSILExtInfoBits+1+3+1+1+2+1+1,
SWIFT_INLINE_BITFIELD(SILFunctionType, TypeBase, NumSILExtInfoBits+1+3+1+2+1+1,
ExtInfoBits : NumSILExtInfoBits,
HasClangTypeInfo : 1,
CalleeConvention : 3,
HasErrorResult : 1,
IsAsync : 1,
CoroutineKind : 2,
HasInvocationSubs : 1,
HasPatternSubs : 1
Expand Down Expand Up @@ -3980,7 +3979,7 @@ class SILFunctionType final
+ 1);
}

SILFunctionType(GenericSignature genericSig, ExtInfo ext, bool isAsync,
SILFunctionType(GenericSignature genericSig, ExtInfo ext,
SILCoroutineKind coroutineKind,
ParameterConvention calleeConvention,
ArrayRef<SILParameterInfo> params,
Expand All @@ -3994,8 +3993,7 @@ class SILFunctionType final

public:
static CanSILFunctionType
get(GenericSignature genericSig, ExtInfo ext, bool isAsync,
SILCoroutineKind coroutineKind,
get(GenericSignature genericSig, ExtInfo ext, SILCoroutineKind coroutineKind,
ParameterConvention calleeConvention,
ArrayRef<SILParameterInfo> interfaceParams,
ArrayRef<SILYieldInfo> interfaceYields,
Expand Down Expand Up @@ -4048,7 +4046,7 @@ class SILFunctionType final
return SILCoroutineKind(Bits.SILFunctionType.CoroutineKind);
}

bool isAsync() const { return Bits.SILFunctionType.IsAsync; }
bool isAsync() const { return getExtInfo().isAsync(); }

/// Return the array of all the yields.
ArrayRef<SILYieldInfo> getYields() const {
Expand Down Expand Up @@ -4577,14 +4575,14 @@ class SILFunctionType final

void Profile(llvm::FoldingSetNodeID &ID) {
Profile(ID, getInvocationGenericSignature(),
getExtInfo(), isAsync(), getCoroutineKind(), getCalleeConvention(),
getExtInfo(), getCoroutineKind(), getCalleeConvention(),
getParameters(), getYields(), getResults(),
getOptionalErrorResult(), getWitnessMethodConformanceOrInvalid(),
getPatternSubstitutions(), getInvocationSubstitutions());
}
static void
Profile(llvm::FoldingSetNodeID &ID, GenericSignature genericSig, ExtInfo info,
bool isAsync, SILCoroutineKind coroutineKind, ParameterConvention calleeConvention,
SILCoroutineKind coroutineKind, ParameterConvention calleeConvention,
ArrayRef<SILParameterInfo> params, ArrayRef<SILYieldInfo> yields,
ArrayRef<SILResultInfo> results, Optional<SILResultInfo> errorResult,
ProtocolConformanceRef conformance,
Expand Down
25 changes: 18 additions & 7 deletions include/swift/Demangling/TypeDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,49 +238,60 @@ class ImplFunctionTypeFlags {
unsigned Rep : 3;
unsigned Pseudogeneric : 1;
unsigned Escaping : 1;
unsigned Async : 1;
unsigned DifferentiabilityKind : 2;

public:
ImplFunctionTypeFlags()
: Rep(0), Pseudogeneric(0), Escaping(0), DifferentiabilityKind(0) {}
: Rep(0), Pseudogeneric(0), Escaping(0), Async(0),
DifferentiabilityKind(0) {}

ImplFunctionTypeFlags(ImplFunctionRepresentation rep, bool pseudogeneric,
bool noescape,
bool noescape, bool async,
ImplFunctionDifferentiabilityKind diffKind)
: Rep(unsigned(rep)), Pseudogeneric(pseudogeneric), Escaping(noescape),
DifferentiabilityKind(unsigned(diffKind)) {}
Async(async), DifferentiabilityKind(unsigned(diffKind)) {}

ImplFunctionTypeFlags
withRepresentation(ImplFunctionRepresentation rep) const {
return ImplFunctionTypeFlags(
rep, Pseudogeneric, Escaping,
rep, Pseudogeneric, Escaping, Async,
ImplFunctionDifferentiabilityKind(DifferentiabilityKind));
}

ImplFunctionTypeFlags
withAsync() const {
return ImplFunctionTypeFlags(
ImplFunctionRepresentation(Rep), Pseudogeneric, Escaping, true,
ImplFunctionDifferentiabilityKind(DifferentiabilityKind));
}

ImplFunctionTypeFlags
withEscaping() const {
return ImplFunctionTypeFlags(
ImplFunctionRepresentation(Rep), Pseudogeneric, true,
ImplFunctionRepresentation(Rep), Pseudogeneric, true, Async,
ImplFunctionDifferentiabilityKind(DifferentiabilityKind));
}

ImplFunctionTypeFlags
withPseudogeneric() const {
return ImplFunctionTypeFlags(
ImplFunctionRepresentation(Rep), true, Escaping,
ImplFunctionRepresentation(Rep), true, Escaping, Async,
ImplFunctionDifferentiabilityKind(DifferentiabilityKind));
}

ImplFunctionTypeFlags
withDifferentiabilityKind(ImplFunctionDifferentiabilityKind diffKind) const {
return ImplFunctionTypeFlags(ImplFunctionRepresentation(Rep), Pseudogeneric,
Escaping, diffKind);
Escaping, Async, diffKind);
}

ImplFunctionRepresentation getRepresentation() const {
return ImplFunctionRepresentation(Rep);
}

bool isAsync() const { return Async; }

bool isEscaping() const { return Escaping; }

bool isPseudogeneric() const { return Pseudogeneric; }
Expand Down
12 changes: 4 additions & 8 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3260,7 +3260,6 @@ void SILFunctionType::Profile(
llvm::FoldingSetNodeID &id,
GenericSignature genericParams,
ExtInfo info,
bool isAsync,
SILCoroutineKind coroutineKind,
ParameterConvention calleeConvention,
ArrayRef<SILParameterInfo> params,
Expand All @@ -3274,7 +3273,6 @@ void SILFunctionType::Profile(
auto infoKey = info.getFuncAttrKey();
id.AddInteger(infoKey.first);
id.AddPointer(infoKey.second);
id.AddBoolean(isAsync);
id.AddInteger(unsigned(coroutineKind));
id.AddInteger(unsigned(calleeConvention));
id.AddInteger(params.size());
Expand All @@ -3300,7 +3298,6 @@ void SILFunctionType::Profile(
SILFunctionType::SILFunctionType(
GenericSignature genericSig,
ExtInfo ext,
bool isAsync,
SILCoroutineKind coroutineKind,
ParameterConvention calleeConvention,
ArrayRef<SILParameterInfo> params,
Expand All @@ -3326,7 +3323,6 @@ SILFunctionType::SILFunctionType(
"Bits were dropped!");
static_assert(SILExtInfoBuilder::NumMaskBits == NumSILExtInfoBits,
"ExtInfo and SILFunctionTypeBitfields must agree on bit size");
Bits.SILFunctionType.IsAsync = isAsync;
Bits.SILFunctionType.CoroutineKind = unsigned(coroutineKind);
NumParameters = params.size();
if (coroutineKind == SILCoroutineKind::None) {
Expand Down Expand Up @@ -3470,7 +3466,7 @@ CanSILBlockStorageType SILBlockStorageType::get(CanType captureType) {

CanSILFunctionType SILFunctionType::get(
GenericSignature genericSig,
ExtInfo ext, bool isAsync, SILCoroutineKind coroutineKind,
ExtInfo ext, SILCoroutineKind coroutineKind,
ParameterConvention callee,
ArrayRef<SILParameterInfo> params,
ArrayRef<SILYieldInfo> yields,
Expand All @@ -3488,8 +3484,8 @@ CanSILFunctionType SILFunctionType::get(
invocationSubs = invocationSubs.getCanonical();

llvm::FoldingSetNodeID id;
SILFunctionType::Profile(id, genericSig, ext, isAsync, coroutineKind, callee,
params, yields, normalResults, errorResult,
SILFunctionType::Profile(id, genericSig, ext, coroutineKind, callee, params,
yields, normalResults, errorResult,
witnessMethodConformance,
patternSubs, invocationSubs);

Expand Down Expand Up @@ -3537,7 +3533,7 @@ CanSILFunctionType SILFunctionType::get(
}

auto fnType =
new (mem) SILFunctionType(genericSig, ext, isAsync, coroutineKind, callee,
new (mem) SILFunctionType(genericSig, ext, coroutineKind, callee,
params, yields, normalResults, errorResult,
patternSubs, invocationSubs,
ctx, properties, witnessMethodConformance);
Expand Down
5 changes: 2 additions & 3 deletions lib/AST/ASTDemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ Type ASTBuilder::createImplFunctionType(

// [TODO: Store-SIL-Clang-type]
auto einfo = SILExtInfoBuilder(representation, flags.isPseudogeneric(),
!flags.isEscaping(), diffKind,
!flags.isEscaping(), flags.isAsync(), diffKind,
/*clangFunctionType*/ nullptr)
.build();

Expand Down Expand Up @@ -558,8 +558,7 @@ Type ASTBuilder::createImplFunctionType(
auto conv = getResultConvention(errorResult->getConvention());
funcErrorResult.emplace(type, conv);
}
return SILFunctionType::get(genericSig, einfo,
/*isAsync*/ false, funcCoroutineKind,
return SILFunctionType::get(genericSig, einfo, funcCoroutineKind,
funcCalleeConvention, funcParams, funcYields,
funcResults, funcErrorResult,
SubstitutionMap(), SubstitutionMap(), Ctx);
Expand Down
4 changes: 3 additions & 1 deletion lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4133,6 +4133,9 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
if (info.isNoEscape()) {
Printer.printSimpleAttr("@noescape") << " ";
}
if (info.isAsync()) {
Printer.printSimpleAttr("@async") << " ";
}
}

void visitAnyFunctionTypeParams(ArrayRef<AnyFunctionType::Param> Params,
Expand Down Expand Up @@ -4277,7 +4280,6 @@ class TypePrinter : public TypeVisitor<TypePrinter> {

void visitSILFunctionType(SILFunctionType *T) {
printSILCoroutineKind(T->getCoroutineKind());
printSILAsyncAttr(T->isAsync());
printFunctionExtInfo(T->getASTContext(), T->getExtInfo(),
T->getWitnessMethodConformanceOrInvalid());
printCalleeConvention(T->getCalleeConvention());
Expand Down
7 changes: 3 additions & 4 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4378,7 +4378,6 @@ case TypeKind::Id:
return SILFunctionType::get(
fnTy->getInvocationGenericSignature(),
fnTy->getExtInfo(),
fnTy->isAsync(),
fnTy->getCoroutineKind(),
fnTy->getCalleeConvention(),
transInterfaceParams,
Expand Down Expand Up @@ -5372,7 +5371,7 @@ SILFunctionType::withInvocationSubstitutions(SubstitutionMap subs) const {
assert(!subs || CanGenericSignature(subs.getGenericSignature())
== getInvocationGenericSignature());
return SILFunctionType::get(getInvocationGenericSignature(),
getExtInfo(), isAsync(), getCoroutineKind(),
getExtInfo(), getCoroutineKind(),
getCalleeConvention(),
getParameters(), getYields(), getResults(),
getOptionalErrorResult(),
Expand All @@ -5390,7 +5389,7 @@ SILFunctionType::withPatternSubstitutions(SubstitutionMap subs) const {
assert(!subs || CanGenericSignature(subs.getGenericSignature())
== getPatternGenericSignature());
return SILFunctionType::get(getInvocationGenericSignature(),
getExtInfo(), isAsync(), getCoroutineKind(),
getExtInfo(), getCoroutineKind(),
getCalleeConvention(),
getParameters(), getYields(), getResults(),
getOptionalErrorResult(),
Expand All @@ -5409,7 +5408,7 @@ SILFunctionType::withPatternSpecialization(CanGenericSignature sig,
assert(!subs || CanGenericSignature(subs.getGenericSignature())
== getSubstGenericSignature());
return SILFunctionType::get(sig,
getExtInfo(), isAsync(), getCoroutineKind(),
getExtInfo(), getCoroutineKind(),
getCalleeConvention(),
getParameters(), getYields(), getResults(),
getOptionalErrorResult(),
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenProto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3056,7 +3056,7 @@ GenericTypeRequirements::GenericTypeRequirements(IRGenModule &IGM,
// Construct a representative function type.
auto generics = ncGenerics.getCanonicalSignature();
auto fnType = SILFunctionType::get(generics, SILFunctionType::ExtInfo(),
/*isAsync*/ false, SILCoroutineKind::None,
SILCoroutineKind::None,
/*callee*/ ParameterConvention::Direct_Unowned,
/*params*/ {}, /*yields*/ {},
/*results*/ {}, /*error*/ None,
Expand Down
2 changes: 0 additions & 2 deletions lib/IRGen/LoadableByAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ LargeSILTypeMapper::getNewSILFunctionType(GenericEnvironment *env,
auto newFnType = SILFunctionType::get(
fnType->getInvocationGenericSignature(),
fnType->getExtInfo(),
fnType->isAsync(),
fnType->getCoroutineKind(),
fnType->getCalleeConvention(),
newParams,
Expand Down Expand Up @@ -2362,7 +2361,6 @@ static bool rewriteFunctionReturn(StructLoweringState &pass) {
auto NewTy = SILFunctionType::get(
loweredTy->getSubstGenericSignature(),
loweredTy->getExtInfo(),
loweredTy->isAsync(),
loweredTy->getCoroutineKind(),
loweredTy->getCalleeConvention(),
loweredTy->getParameters(),
Expand Down
1 change: 0 additions & 1 deletion lib/SIL/IR/SILBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ SILType SILBuilder::getPartialApplyResultType(

auto appliedFnType = SILFunctionType::get(nullptr,
extInfo,
FTI->isAsync(),
FTI->getCoroutineKind(),
calleeConvention,
newParams,
Expand Down
Loading