Skip to content

Commit bce1ba5

Browse files
committed
[AST] Remove @autoclosure flag from function type ExtInfo
1 parent d113b4a commit bce1ba5

File tree

12 files changed

+10
-94
lines changed

12 files changed

+10
-94
lines changed

include/swift/AST/Types.h

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ class alignas(1 << TypeAlignInBits) TypeBase {
276276
}
277277

278278
protected:
279-
enum { NumAFTExtInfoBits = 7 };
279+
enum { NumAFTExtInfoBits = 6 };
280280
enum { NumSILExtInfoBits = 6 };
281281
union { uint64_t OpaqueBits;
282282

@@ -2836,15 +2836,14 @@ class AnyFunctionType : public TypeBase {
28362836
// If bits are added or removed, then TypeBase::AnyFunctionTypeBits
28372837
// and NumMaskBits must be updated, and they must match.
28382838
//
2839-
// |representation|isAutoClosure|noEscape|throws|
2840-
// | 0 .. 3 | 4 | 5 | 6 |
2839+
// |representation|noEscape|throws|
2840+
// | 0 .. 3 | 4 | 5 |
28412841
//
28422842
enum : unsigned {
28432843
RepresentationMask = 0xF << 0,
2844-
AutoClosureMask = 1 << 4,
2845-
NoEscapeMask = 1 << 5,
2846-
ThrowsMask = 1 << 6,
2847-
NumMaskBits = 7
2844+
NoEscapeMask = 1 << 4,
2845+
ThrowsMask = 1 << 5,
2846+
NumMaskBits = 6
28482847
};
28492848

28502849
unsigned Bits; // Naturally sized for speed.
@@ -2866,14 +2865,12 @@ class AnyFunctionType : public TypeBase {
28662865

28672866
// Constructor with no defaults.
28682867
ExtInfo(Representation Rep,
2869-
bool IsAutoClosure, bool IsNoEscape,
2868+
bool IsNoEscape,
28702869
bool Throws)
28712870
: ExtInfo(Rep, Throws) {
2872-
Bits |= (IsAutoClosure ? AutoClosureMask : 0);
28732871
Bits |= (IsNoEscape ? NoEscapeMask : 0);
28742872
}
28752873

2876-
bool isAutoClosure() const { return Bits & AutoClosureMask; }
28772874
bool isNoEscape() const { return Bits & NoEscapeMask; }
28782875
bool throws() const { return Bits & ThrowsMask; }
28792876
Representation getRepresentation() const {
@@ -2926,13 +2923,6 @@ class AnyFunctionType : public TypeBase {
29262923
| (unsigned)Rep);
29272924
}
29282925
LLVM_NODISCARD
2929-
ExtInfo withIsAutoClosure(bool IsAutoClosure = true) const {
2930-
if (IsAutoClosure)
2931-
return ExtInfo(Bits | AutoClosureMask);
2932-
else
2933-
return ExtInfo(Bits & ~AutoClosureMask);
2934-
}
2935-
LLVM_NODISCARD
29362926
ExtInfo withNoEscape(bool NoEscape = true) const {
29372927
if (NoEscape)
29382928
return ExtInfo(Bits | NoEscapeMask);
@@ -3029,12 +3019,6 @@ class AnyFunctionType : public TypeBase {
30293019
Representation getRepresentation() const {
30303020
return getExtInfo().getRepresentation();
30313021
}
3032-
3033-
/// \brief True if this type allows an implicit conversion from a function
3034-
/// argument expression of type T to a function of type () -> T.
3035-
bool isAutoClosure() const {
3036-
return getExtInfo().isAutoClosure();
3037-
}
30383022

30393023
/// \brief True if the parameter declaration it is attached to is guaranteed
30403024
/// to not persist the closure for longer than the duration of the call.

include/swift/Serialization/ModuleFormat.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,6 @@ namespace decls_block {
737737
FUNCTION_TYPE,
738738
TypeIDField, // output
739739
FunctionTypeRepresentationField, // representation
740-
BCFixed<1>, // auto-closure?
741740
BCFixed<1>, // noescape?
742741
BCFixed<1> // throws?
743742

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3439,7 +3439,6 @@ namespace {
34393439
printField("representation",
34403440
getSILFunctionTypeRepresentationString(representation));
34413441

3442-
printFlag(T->isAutoClosure(), "autoclosure");
34433442
printFlag(!T->isNoEscape(), "escaping");
34443443
printFlag(T->throws(), "throws");
34453444

lib/AST/Decl.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2040,7 +2040,6 @@ mapSignatureExtInfo(AnyFunctionType::ExtInfo info,
20402040
return AnyFunctionType::ExtInfo();
20412041
return AnyFunctionType::ExtInfo()
20422042
.withRepresentation(info.getRepresentation())
2043-
.withIsAutoClosure(info.isAutoClosure())
20442043
.withThrows(info.throws());
20452044
}
20462045

lib/SIL/SILFunctionType.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2645,7 +2645,6 @@ TypeConverter::getLoweredFormalTypes(SILDeclRef constant,
26452645
}
26462646

26472647
SILFunctionTypeRepresentation rep = extInfo.getSILRepresentation();
2648-
assert(!extInfo.isAutoClosure() && "autoclosures cannot be curried");
26492648
assert(rep != SILFunctionType::Representation::Block
26502649
&& "objc blocks cannot be curried");
26512650

lib/Sema/CSBindings.cpp

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -132,49 +132,6 @@ findInferableTypeVars(Type type,
132132
type.walk(Walker(typeVars));
133133
}
134134

135-
/// \brief Return whether a relational constraint between a type variable and a
136-
/// trivial wrapper type (autoclosure, unary tuple) should result in the type
137-
/// variable being potentially bound to the value type, as opposed to the
138-
/// wrapper type.
139-
static bool shouldBindToValueType(Constraint *constraint) {
140-
switch (constraint->getKind()) {
141-
case ConstraintKind::OperatorArgumentConversion:
142-
case ConstraintKind::ArgumentConversion:
143-
case ConstraintKind::Conversion:
144-
case ConstraintKind::BridgingConversion:
145-
case ConstraintKind::Subtype:
146-
return true;
147-
case ConstraintKind::Bind:
148-
case ConstraintKind::Equal:
149-
case ConstraintKind::BindParam:
150-
case ConstraintKind::BindToPointerType:
151-
case ConstraintKind::ConformsTo:
152-
case ConstraintKind::LiteralConformsTo:
153-
case ConstraintKind::CheckedCast:
154-
case ConstraintKind::SelfObjectOfProtocol:
155-
case ConstraintKind::ApplicableFunction:
156-
case ConstraintKind::DynamicCallableApplicableFunction:
157-
case ConstraintKind::BindOverload:
158-
case ConstraintKind::OptionalObject:
159-
return false;
160-
case ConstraintKind::DynamicTypeOf:
161-
case ConstraintKind::EscapableFunctionOf:
162-
case ConstraintKind::OpenedExistentialOf:
163-
case ConstraintKind::KeyPath:
164-
case ConstraintKind::KeyPathApplication:
165-
case ConstraintKind::ValueMember:
166-
case ConstraintKind::UnresolvedValueMember:
167-
case ConstraintKind::Defaultable:
168-
case ConstraintKind::Disjunction:
169-
case ConstraintKind::FunctionInput:
170-
case ConstraintKind::FunctionResult:
171-
llvm_unreachable("shouldBindToValueType() may only be called on "
172-
"relational constraints");
173-
}
174-
175-
llvm_unreachable("Unhandled ConstraintKind in switch.");
176-
}
177-
178135
void ConstraintSystem::PotentialBindings::addPotentialBinding(
179136
PotentialBinding binding, bool allowJoinMeet) {
180137
assert(!binding.BindingType->is<ErrorType>());
@@ -297,13 +254,6 @@ ConstraintSystem::getPotentialBindingForRelationalConstraint(
297254
if (type->hasError())
298255
return None;
299256

300-
#ifndef NDEBUG
301-
if (shouldBindToValueType(constraint)) {
302-
if (auto funcTy = type->getAs<FunctionType>())
303-
assert(!funcTy->isAutoClosure());
304-
}
305-
#endif
306-
307257
// If the source of the binding is 'OptionalObject' constraint
308258
// and type variable is on the left-hand side, that means
309259
// that it _has_ to be of optional type, since the right-hand

lib/Sema/CSRanking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
10631063
auto param2 = params[1].getOldType()->castTo<AnyFunctionType>();
10641064

10651065
assert(param1->getOptionalObjectType());
1066-
assert(param2->isAutoClosure());
1066+
assert(params[1].isAutoClosure());
10671067
assert(param2->getResult()->getOptionalObjectType());
10681068

10691069
(void) param1;

lib/Sema/ConstraintSystem.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,7 +1560,6 @@ resolveOverloadForDeclWithSpecialTypeCheckingSemantics(ConstraintSystem &CS,
15601560
FunctionType::Param arg(escapeClosure);
15611561
auto bodyClosure = FunctionType::get(arg, result,
15621562
FunctionType::ExtInfo(FunctionType::Representation::Swift,
1563-
/*autoclosure*/ false,
15641563
/*noescape*/ true,
15651564
/*throws*/ true));
15661565
FunctionType::Param args[] = {
@@ -1570,7 +1569,6 @@ resolveOverloadForDeclWithSpecialTypeCheckingSemantics(ConstraintSystem &CS,
15701569

15711570
refType = FunctionType::get(args, result,
15721571
FunctionType::ExtInfo(FunctionType::Representation::Swift,
1573-
/*autoclosure*/ false,
15741572
/*noescape*/ false,
15751573
/*throws*/ true));
15761574
openedFullType = refType;
@@ -1591,7 +1589,6 @@ resolveOverloadForDeclWithSpecialTypeCheckingSemantics(ConstraintSystem &CS,
15911589
FunctionType::Param bodyArgs[] = {FunctionType::Param(openedTy)};
15921590
auto bodyClosure = FunctionType::get(bodyArgs, result,
15931591
FunctionType::ExtInfo(FunctionType::Representation::Swift,
1594-
/*autoclosure*/ false,
15951592
/*noescape*/ true,
15961593
/*throws*/ true));
15971594
FunctionType::Param args[] = {
@@ -1600,7 +1597,6 @@ resolveOverloadForDeclWithSpecialTypeCheckingSemantics(ConstraintSystem &CS,
16001597
};
16011598
refType = FunctionType::get(args, result,
16021599
FunctionType::ExtInfo(FunctionType::Representation::Swift,
1603-
/*autoclosure*/ false,
16041600
/*noescape*/ false,
16051601
/*throws*/ true));
16061602
openedFullType = refType;

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,11 +1975,6 @@ Type TypeChecker::typeCheckExpression(Expr *&expr, DeclContext *dc,
19751975

19761976
// Take a look at the conversion type to check to make sure it is sensible.
19771977
if (auto type = convertType.getType()) {
1978-
#ifndef NDEBUG
1979-
if (auto *fnType = type->getAs<AnyFunctionType>())
1980-
assert(!fnType->isAutoClosure());
1981-
#endif
1982-
19831978
// If we're asked to convert to an UnresolvedType, then ignore the request.
19841979
// This happens when CSDiags nukes a type.
19851980
if (type->is<UnresolvedType>() ||

lib/Sema/TypeCheckType.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2093,7 +2093,6 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs,
20932093

20942094
// Resolve the function type directly with these attributes.
20952095
FunctionType::ExtInfo extInfo(rep,
2096-
attrs.has(TAK_autoclosure),
20972096
attrs.has(TAK_noescape),
20982097
fnRepr->throws());
20992098

lib/Serialization/Deserialization.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4407,13 +4407,12 @@ Expected<Type> ModuleFile::getTypeChecked(TypeID TID) {
44074407
case decls_block::GENERIC_FUNCTION_TYPE: {
44084408
TypeID resultID;
44094409
uint8_t rawRepresentation;
4410-
bool autoClosure = false, noescape = false, throws;
4410+
bool noescape = false, throws;
44114411
GenericSignature *genericSig = nullptr;
44124412

44134413
if (recordID == decls_block::FUNCTION_TYPE) {
44144414
decls_block::FunctionTypeLayout::readRecord(scratch, resultID,
44154415
rawRepresentation,
4416-
autoClosure,
44174416
noescape,
44184417
throws);
44194418
} else {
@@ -4432,8 +4431,7 @@ Expected<Type> ModuleFile::getTypeChecked(TypeID TID) {
44324431
return nullptr;
44334432
}
44344433

4435-
auto info = FunctionType::ExtInfo(*representation, autoClosure, noescape,
4436-
throws);
4434+
auto info = FunctionType::ExtInfo(*representation, noescape, throws);
44374435

44384436
auto resultTy = getTypeChecked(resultID);
44394437
if (!resultTy)

lib/Serialization/Serialization.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3843,11 +3843,9 @@ void Serializer::writeType(Type ty) {
38433843
FunctionTypeLayout::emitRecord(Out, ScratchRecord, abbrCode,
38443844
addTypeRef(fnTy->getResult()),
38453845
getRawStableFunctionTypeRepresentation(fnTy->getRepresentation()),
3846-
fnTy->isAutoClosure(),
38473846
fnTy->isNoEscape(),
38483847
fnTy->throws());
38493848
} else {
3850-
assert(!fnTy->isAutoClosure());
38513849
assert(!fnTy->isNoEscape());
38523850

38533851
auto *genericSig = cast<GenericFunctionType>(fnTy)->getGenericSignature();

0 commit comments

Comments
 (0)