Skip to content

Commit 463b046

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-rebranch
2 parents be65fc9 + 38bde33 commit 463b046

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+798
-562
lines changed

include/swift/AST/Decl.h

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,6 +2947,8 @@ class OpaqueTypeDecl : public GenericTypeDecl {
29472947
/// TypeAliasDecl's always have 'MetatypeType' type.
29482948
///
29492949
class TypeAliasDecl : public GenericTypeDecl {
2950+
friend class UnderlyingTypeRequest;
2951+
29502952
/// The location of the 'typealias' keyword
29512953
SourceLoc TypeAliasLoc;
29522954

@@ -2974,20 +2976,28 @@ class TypeAliasDecl : public GenericTypeDecl {
29742976

29752977
void setTypeEndLoc(SourceLoc e) { TypeEndLoc = e; }
29762978

2977-
TypeLoc &getUnderlyingTypeLoc() {
2978-
return UnderlyingTy;
2979+
/// Retrieve the TypeRepr corresponding to the parsed underlying type.
2980+
TypeRepr *getUnderlyingTypeRepr() const {
2981+
return UnderlyingTy.getTypeRepr();
29792982
}
2980-
const TypeLoc &getUnderlyingTypeLoc() const {
2981-
return UnderlyingTy;
2983+
void setUnderlyingTypeRepr(TypeRepr *repr) {
2984+
UnderlyingTy = repr;
29822985
}
2983-
2986+
2987+
/// Retrieve the interface type of the underlying type.
2988+
Type getUnderlyingType() const;
29842989
void setUnderlyingType(Type type);
29852990

29862991
/// For generic typealiases, return the unbound generic type.
29872992
UnboundGenericType *getUnboundGenericType() const;
29882993

2994+
/// Retrieve a sugared interface type containing the structure of the interface
2995+
/// type before any semantic validation has occured.
29892996
Type getStructuralType() const;
29902997

2998+
/// Set the interface type of this typealias declaration from the underlying type.
2999+
void computeType();
3000+
29913001
bool isCompatibilityAlias() const {
29923002
return Bits.TypeAliasDecl.IsCompatibilityAlias;
29933003
}
@@ -5164,6 +5174,7 @@ class ParamDecl : public VarDecl {
51645174
PointerUnion<Expr *, VarDecl *> DefaultArg;
51655175
Initializer *InitContext = nullptr;
51665176
StringRef StringRepresentation;
5177+
CaptureInfo Captures;
51675178
};
51685179

51695180
enum class Flags : uint8_t {
@@ -5249,6 +5260,13 @@ class ParamDecl : public VarDecl {
52495260

52505261
void setDefaultArgumentInitContext(Initializer *initContext);
52515262

5263+
const CaptureInfo &getDefaultArgumentCaptureInfo() const {
5264+
assert(DefaultValueAndFlags.getPointer());
5265+
return DefaultValueAndFlags.getPointer()->Captures;
5266+
}
5267+
5268+
void setDefaultArgumentCaptureInfo(const CaptureInfo &captures);
5269+
52525270
/// Extracts the text of the default argument attached to the provided
52535271
/// ParamDecl, removing all inactive #if clauses and providing only the
52545272
/// text of active #if clauses.

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2655,6 +2655,8 @@ ERROR(dynamic_self_invalid_method,none,
26552655
"covariant 'Self' can only appear at the top level of method result type", ())
26562656
ERROR(dynamic_self_stored_property_init,none,
26572657
"covariant 'Self' type cannot be referenced from a stored property initializer", ())
2658+
ERROR(dynamic_self_default_arg,none,
2659+
"covariant 'Self' type cannot be referenced from a default argument expression", ())
26582660

26592661
//------------------------------------------------------------------------------
26602662
// MARK: Type Check Attributes

include/swift/AST/TypeCheckRequests.h

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,9 @@ class RequirementRequest :
434434
// Source location
435435
SourceLoc getNearestLoc() const;
436436

437+
// Cycle handling.
438+
void noteCycleStep(DiagnosticEngine &diags) const;
439+
437440
// Separate caching.
438441
bool isCached() const;
439442
Optional<Requirement> getCachedResult() const;
@@ -1120,6 +1123,9 @@ class InferredGenericSignatureRequest :
11201123
SourceLoc getNearestLoc() const {
11211124
return SourceLoc();
11221125
}
1126+
1127+
// Cycle handling.
1128+
void noteCycleStep(DiagnosticEngine &diags) const;
11231129
};
11241130

11251131
void simple_display(llvm::raw_ostream &out, const TypeLoc source);
@@ -1174,13 +1180,35 @@ class GenericSignatureRequest :
11741180
llvm::Expected<GenericSignature *>
11751181
evaluate(Evaluator &evaluator, GenericContext *value) const;
11761182

1177-
public:
1183+
public:
11781184
// Separate caching.
11791185
bool isCached() const { return true; }
11801186
Optional<GenericSignature *> getCachedResult() const;
11811187
void cacheResult(GenericSignature *value) const;
11821188
};
11831189

1190+
/// Compute the interface type of the underlying definition type of a typealias declaration.
1191+
class UnderlyingTypeRequest :
1192+
public SimpleRequest<UnderlyingTypeRequest,
1193+
Type(TypeAliasDecl *),
1194+
CacheKind::SeparatelyCached> {
1195+
public:
1196+
using SimpleRequest::SimpleRequest;
1197+
1198+
private:
1199+
friend SimpleRequest;
1200+
1201+
// Evaluation.
1202+
llvm::Expected<Type> evaluate(Evaluator &evaluator,
1203+
TypeAliasDecl *decl) const;
1204+
1205+
public:
1206+
// Caching.
1207+
bool isCached() const { return true; }
1208+
Optional<Type> getCachedResult() const;
1209+
void cacheResult(Type value) const;
1210+
};
1211+
11841212
// Allow AnyValue to compare two Type values, even though Type doesn't
11851213
// support ==.
11861214
template<>

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,5 +132,7 @@ SWIFT_REQUEST(TypeChecker, SynthesizeAccessorRequest,
132132
SeparatelyCached, NoLocationInfo)
133133
SWIFT_REQUEST(TypeChecker, TypeCheckFunctionBodyUntilRequest,
134134
bool(AbstractFunctionDecl *, SourceLoc), Cached, NoLocationInfo)
135+
SWIFT_REQUEST(TypeChecker, UnderlyingTypeRequest, Type(TypeAliasDecl *),
136+
SeparatelyCached, NoLocationInfo)
135137
SWIFT_REQUEST(TypeChecker, USRGenerationRequest, std::string(const ValueDecl *),
136138
Cached, NoLocationInfo)

include/swift/SIL/TypeLowering.h

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ class TypeConverter {
689689

690690
llvm::DenseMap<OverrideKey, SILConstantInfo *> ConstantOverrideTypes;
691691

692-
llvm::DenseMap<AnyFunctionRef, CaptureInfo> LoweredCaptures;
692+
llvm::DenseMap<SILDeclRef, CaptureInfo> LoweredCaptures;
693693

694694
/// Cache of loadable SILType to number of (estimated) fields
695695
///
@@ -844,10 +844,13 @@ class TypeConverter {
844844
/// Returns the formal type, lowered AST type, and SILFunctionType
845845
/// for a constant reference.
846846
const SILConstantInfo &getConstantInfo(SILDeclRef constant);
847-
847+
848+
/// Get the generic environment for a constant.
849+
GenericSignature *getConstantGenericSignature(SILDeclRef constant);
850+
848851
/// Get the generic environment for a constant.
849852
GenericEnvironment *getConstantGenericEnvironment(SILDeclRef constant);
850-
853+
851854
/// Returns the SIL type of a constant reference.
852855
SILType getConstantType(SILDeclRef constant) {
853856
return getConstantInfo(constant).getSILType();
@@ -893,11 +896,6 @@ class TypeConverter {
893896
SILType getEmptyTupleType() {
894897
return SILType::getPrimitiveObjectType(TupleType::getEmpty(Context));
895898
}
896-
897-
/// Get a function type curried with its capture context.
898-
CanAnyFunctionType getFunctionInterfaceTypeWithCaptures(
899-
CanAnyFunctionType funcType,
900-
AnyFunctionRef closure);
901899

902900
/// Describes what we're trying to compute a bridged type for.
903901
///
@@ -944,17 +942,6 @@ class TypeConverter {
944942
SILType getSubstitutedStorageType(AbstractStorageDecl *value,
945943
Type lvalueType);
946944

947-
/// Retrieve the set of archetypes closed over by the given function.
948-
GenericEnvironment *getEffectiveGenericEnvironment(AnyFunctionRef fn,
949-
CaptureInfo captureInfo);
950-
951-
/// Retrieve the set of generic parameters closed over by the given function.
952-
CanGenericSignature getEffectiveGenericSignature(AnyFunctionRef fn,
953-
CaptureInfo captureInfo);
954-
955-
/// Retrieve the set of generic parameters closed over by the context.
956-
CanGenericSignature getEffectiveGenericSignature(DeclContext *dc);
957-
958945
/// Push a generic function context. See GenericContextScope for an RAII
959946
/// interface to this function.
960947
///
@@ -980,10 +967,10 @@ class TypeConverter {
980967
CanType get##BridgedType##Type();
981968
#include "swift/SIL/BridgedTypes.def"
982969

983-
/// Get the capture list from a closure, with transitive function captures
984-
/// flattened.
985-
CaptureInfo getLoweredLocalCaptures(AnyFunctionRef fn);
986-
bool hasLoweredLocalCaptures(AnyFunctionRef fn);
970+
/// Get the capture list for a function or default argument, with transitive
971+
/// function captures flattened.
972+
CaptureInfo getLoweredLocalCaptures(SILDeclRef fn);
973+
bool hasLoweredLocalCaptures(SILDeclRef fn);
987974

988975
enum class ABIDifference : uint8_t {
989976
// No ABI differences, function can be trivially bitcast to result type.

lib/AST/ASTDumper.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -617,9 +617,9 @@ namespace {
617617
void visitTypeAliasDecl(TypeAliasDecl *TAD) {
618618
printCommon(TAD, "typealias");
619619
PrintWithColorRAII(OS, TypeColor) << " type='";
620-
if (TAD->getUnderlyingTypeLoc().getType()) {
620+
if (auto underlying = TAD->getUnderlyingType()) {
621621
PrintWithColorRAII(OS, TypeColor)
622-
<< TAD->getUnderlyingTypeLoc().getType().getString();
622+
<< underlying.getString();
623623
} else {
624624
PrintWithColorRAII(OS, TypeColor) << "<<<unresolved>>>";
625625
}
@@ -988,9 +988,17 @@ namespace {
988988
if (P->isAutoClosure())
989989
OS << " autoclosure";
990990

991-
if (P->getDefaultArgumentKind() != DefaultArgumentKind::None)
991+
if (P->getDefaultArgumentKind() != DefaultArgumentKind::None) {
992992
printField("default_arg",
993993
getDefaultArgumentKindString(P->getDefaultArgumentKind()));
994+
}
995+
996+
if (P->getDefaultValue() &&
997+
!P->getDefaultArgumentCaptureInfo().isTrivial()) {
998+
OS << " ";
999+
P->getDefaultArgumentCaptureInfo().print(
1000+
PrintWithColorRAII(OS, CapturesColor).getOS());
1001+
}
9941002

9951003
if (auto init = P->getDefaultValue()) {
9961004
OS << " expression=\n";
@@ -3379,6 +3387,12 @@ namespace {
33793387
void visitTypeAliasType(TypeAliasType *T, StringRef label) {
33803388
printCommon(label, "type_alias_type");
33813389
printField("decl", T->getDecl()->printRef());
3390+
PrintWithColorRAII(OS, TypeColor) << " underlying='";
3391+
if (auto underlying = T->getSinglyDesugaredType()) {
3392+
PrintWithColorRAII(OS, TypeColor) << underlying->getString();
3393+
} else {
3394+
PrintWithColorRAII(OS, TypeColor) << "<<<unresolved>>>";
3395+
}
33823396
if (T->getParent())
33833397
printRec("parent", T->getParent());
33843398

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,7 +2277,7 @@ void PrintAST::visitTypeAliasDecl(TypeAliasDecl *decl) {
22772277
printGenericDeclGenericParams(decl);
22782278
});
22792279
bool ShouldPrint = true;
2280-
Type Ty = decl->getUnderlyingTypeLoc().getType();
2280+
Type Ty = decl->getUnderlyingType();
22812281

22822282
// If the underlying type is private, don't print it.
22832283
if (Options.SkipPrivateStdlibDecls && Ty && Ty.isPrivateStdlibType())
@@ -2295,7 +2295,7 @@ void PrintAST::visitTypeAliasDecl(TypeAliasDecl *decl) {
22952295
// preserving sugar.
22962296
llvm::SaveAndRestore<GenericEnvironment*> setGenericEnv(Options.GenericEnv,
22972297
decl->getGenericEnvironment());
2298-
printTypeLoc(decl->getUnderlyingTypeLoc());
2298+
printTypeLoc(TypeLoc(decl->getUnderlyingTypeRepr(), Ty));
22992299
printGenericDeclGenericRequirements(decl);
23002300
}
23012301
}

lib/AST/ASTWalker.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,10 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
232232
return true;
233233
}
234234

235-
return doIt(TAD->getUnderlyingTypeLoc());
235+
if (auto typerepr = TAD->getUnderlyingTypeRepr())
236+
if (doIt(typerepr))
237+
return true;
238+
return false;
236239
}
237240

238241
bool visitOpaqueTypeDecl(OpaqueTypeDecl *OTD) {

lib/AST/Decl.cpp

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3528,34 +3528,42 @@ SourceRange TypeAliasDecl::getSourceRange() const {
35283528
return { TypeAliasLoc, getNameLoc() };
35293529
}
35303530

3531-
void TypeAliasDecl::setUnderlyingType(Type underlying) {
3532-
setValidationToChecked();
3531+
void TypeAliasDecl::computeType() {
3532+
assert(!hasInterfaceType());
3533+
3534+
// Set the interface type of this declaration.
3535+
ASTContext &ctx = getASTContext();
3536+
3537+
auto *genericSig = getGenericSignature();
3538+
SubstitutionMap subs;
3539+
if (genericSig)
3540+
subs = genericSig->getIdentitySubstitutionMap();
3541+
3542+
Type parent;
3543+
auto parentDC = getDeclContext();
3544+
if (parentDC->isTypeContext())
3545+
parent = parentDC->getDeclaredInterfaceType();
3546+
auto sugaredType = TypeAliasType::get(this, parent, subs, getUnderlyingType());
3547+
setInterfaceType(MetatypeType::get(sugaredType, ctx));
3548+
}
35333549

3550+
Type TypeAliasDecl::getUnderlyingType() const {
3551+
return evaluateOrDefault(getASTContext().evaluator,
3552+
UnderlyingTypeRequest{const_cast<TypeAliasDecl *>(this)},
3553+
Type());
3554+
}
3555+
3556+
void TypeAliasDecl::setUnderlyingType(Type underlying) {
35343557
// lldb creates global typealiases containing archetypes
35353558
// sometimes...
35363559
if (underlying->hasArchetype() && isGenericContext())
35373560
underlying = underlying->mapTypeOutOfContext();
3538-
UnderlyingTy.setType(underlying);
3539-
3540-
// FIXME -- if we already have an interface type, we're changing the
3541-
// underlying type. See the comment in the ProtocolDecl case of
3542-
// validateDecl().
3543-
if (!hasInterfaceType()) {
3544-
// Set the interface type of this declaration.
3545-
ASTContext &ctx = getASTContext();
3546-
3547-
auto *genericSig = getGenericSignature();
3548-
SubstitutionMap subs;
3549-
if (genericSig)
3550-
subs = genericSig->getIdentitySubstitutionMap();
3551-
3552-
Type parent;
3553-
auto parentDC = getDeclContext();
3554-
if (parentDC->isTypeContext())
3555-
parent = parentDC->getDeclaredInterfaceType();
3556-
auto sugaredType = TypeAliasType::get(this, parent, subs, underlying);
3557-
setInterfaceType(MetatypeType::get(sugaredType, ctx));
3558-
}
3561+
getASTContext().evaluator.cacheOutput(
3562+
StructuralTypeRequest{const_cast<TypeAliasDecl *>(this)},
3563+
std::move(underlying));
3564+
getASTContext().evaluator.cacheOutput(
3565+
UnderlyingTypeRequest{const_cast<TypeAliasDecl *>(this)},
3566+
std::move(underlying));
35593567
}
35603568

35613569
UnboundGenericType *TypeAliasDecl::getUnboundGenericType() const {
@@ -3572,12 +3580,10 @@ UnboundGenericType *TypeAliasDecl::getUnboundGenericType() const {
35723580
}
35733581

35743582
Type TypeAliasDecl::getStructuralType() const {
3575-
assert(!getGenericParams());
3576-
35773583
auto &context = getASTContext();
3578-
return evaluateOrDefault(context.evaluator,
3579-
StructuralTypeRequest { const_cast<TypeAliasDecl *>(this) },
3580-
Type());
3584+
return evaluateOrDefault(
3585+
context.evaluator,
3586+
StructuralTypeRequest{const_cast<TypeAliasDecl *>(this)}, Type());
35813587
}
35823588

35833589
Type AbstractTypeParamDecl::getSuperclass() const {
@@ -5866,6 +5872,11 @@ void ParamDecl::setDefaultArgumentInitContext(Initializer *initContext) {
58665872
DefaultValueAndFlags.getPointer()->InitContext = initContext;
58675873
}
58685874

5875+
void ParamDecl::setDefaultArgumentCaptureInfo(const CaptureInfo &captures) {
5876+
assert(DefaultValueAndFlags.getPointer());
5877+
DefaultValueAndFlags.getPointer()->Captures = captures;
5878+
}
5879+
58695880
/// Return nullptr if there is no property wrapper
58705881
Expr *swift::findOriginalPropertyWrapperInitialValue(VarDecl *var,
58715882
Expr *init) {

lib/AST/DiagnosticEngine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ static bool isInterestingTypealias(Type type) {
380380
// Compatibility aliases are only interesting insofar as their underlying
381381
// types are interesting.
382382
if (aliasDecl->isCompatibilityAlias()) {
383-
auto underlyingTy = aliasDecl->getUnderlyingTypeLoc().getType();
383+
auto underlyingTy = aliasDecl->getUnderlyingType();
384384
return isInterestingTypealias(underlyingTy);
385385
}
386386

0 commit comments

Comments
 (0)