diff --git a/include/swift/AST/Attr.h b/include/swift/AST/Attr.h index fde3102843bd5..d6482297d272f 100644 --- a/include/swift/AST/Attr.h +++ b/include/swift/AST/Attr.h @@ -36,7 +36,6 @@ #include "swift/AST/PlatformKind.h" #include "swift/AST/Requirement.h" #include "swift/AST/TrailingCallArguments.h" -#include "swift/AST/TypeLoc.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/ErrorHandling.h" @@ -56,6 +55,7 @@ class LazyConformanceLoader; class LazyMemberLoader; class PatternBindingInitializer; class TrailingWhereClause; +class TypeExpr; /// TypeAttributes - These are attributes that may be applied to types. class TypeAttributes { @@ -1110,22 +1110,22 @@ class DynamicReplacementAttr final /// The \c @_typeEraser(TypeEraserType) attribute. class TypeEraserAttr final : public DeclAttribute { - TypeLoc TypeEraserLoc; + TypeExpr *TypeEraserExpr; LazyMemberLoader *Resolver; uint64_t ResolverContextData; friend class ResolveTypeEraserTypeRequest; - TypeEraserAttr(SourceLoc atLoc, SourceRange range, TypeLoc typeEraserLoc, + TypeEraserAttr(SourceLoc atLoc, SourceRange range, TypeExpr *typeEraserExpr, LazyMemberLoader *Resolver, uint64_t Data) : DeclAttribute(DAK_TypeEraser, atLoc, range, /*Implicit=*/false), - TypeEraserLoc(typeEraserLoc), + TypeEraserExpr(typeEraserExpr), Resolver(Resolver), ResolverContextData(Data) {} public: static TypeEraserAttr *create(ASTContext &ctx, SourceLoc atLoc, SourceRange range, - TypeLoc typeEraserLoc); + TypeExpr *typeEraserRepr); static TypeEraserAttr *create(ASTContext &ctx, LazyMemberLoader *Resolver, @@ -1133,14 +1133,10 @@ class TypeEraserAttr final : public DeclAttribute { /// Retrieve the parsed type repr for this attribute, if it /// was parsed. Else returns \c nullptr. - TypeRepr *getParsedTypeEraserTypeRepr() const { - return TypeEraserLoc.getTypeRepr(); - } + TypeRepr *getParsedTypeEraserTypeRepr() const; /// Retrieve the parsed location for this attribute, if it was parsed. - SourceLoc getLoc() const { - return TypeEraserLoc.getLoc(); - } + SourceLoc getLoc() const; /// Retrieve the resolved type of this attribute if it has been resolved by a /// successful call to \c getResolvedType(). Otherwise, @@ -1148,9 +1144,7 @@ class TypeEraserAttr final : public DeclAttribute { /// /// This entrypoint is only suitable for syntactic clients like the /// AST printer. Semantic clients should use \c getResolvedType() instead. - Type getTypeWithoutResolving() const { - return TypeEraserLoc.getType(); - } + Type getTypeWithoutResolving() const; /// Returns \c true if the type eraser type has a valid implementation of the /// erasing initializer for the given protocol. @@ -1464,25 +1458,26 @@ class SpecializeAttr : public DeclAttribute { /// The @_implements attribute, which treats a decl as the implementation for /// some named protocol requirement (but otherwise not-visible by that name). class ImplementsAttr : public DeclAttribute { - - TypeLoc ProtocolType; + TypeExpr *ProtocolType; DeclName MemberName; DeclNameLoc MemberNameLoc; public: ImplementsAttr(SourceLoc atLoc, SourceRange Range, - TypeLoc ProtocolType, + TypeExpr *ProtocolType, DeclName MemberName, DeclNameLoc MemberNameLoc); static ImplementsAttr *create(ASTContext &Ctx, SourceLoc atLoc, SourceRange Range, - TypeLoc ProtocolType, + TypeExpr *ProtocolType, DeclName MemberName, DeclNameLoc MemberNameLoc); - TypeLoc getProtocolType() const; - TypeLoc &getProtocolType(); + void setProtocolType(Type ty); + Type getProtocolType() const; + TypeRepr *getProtocolTypeRepr() const; + DeclName getMemberName() const { return MemberName; } DeclNameLoc getMemberNameLoc() const { return MemberNameLoc; } @@ -1595,7 +1590,7 @@ class ClangImporterSynthesizedTypeAttr : public DeclAttribute { /// Defines a custom attribute. class CustomAttr final : public DeclAttribute, public TrailingCallArguments { - TypeLoc type; + TypeExpr *typeExpr; Expr *arg; PatternBindingInitializer *initContext; Expr *semanticInit = nullptr; @@ -1603,19 +1598,19 @@ class CustomAttr final : public DeclAttribute, unsigned hasArgLabelLocs : 1; unsigned numArgLabels : 16; - CustomAttr(SourceLoc atLoc, SourceRange range, TypeLoc type, + CustomAttr(SourceLoc atLoc, SourceRange range, TypeExpr *type, PatternBindingInitializer *initContext, Expr *arg, ArrayRef argLabels, ArrayRef argLabelLocs, bool implicit); public: - static CustomAttr *create(ASTContext &ctx, SourceLoc atLoc, TypeLoc type, + static CustomAttr *create(ASTContext &ctx, SourceLoc atLoc, TypeExpr *type, bool implicit = false) { return create(ctx, atLoc, type, false, nullptr, SourceLoc(), { }, { }, { }, SourceLoc(), implicit); } - static CustomAttr *create(ASTContext &ctx, SourceLoc atLoc, TypeLoc type, + static CustomAttr *create(ASTContext &ctx, SourceLoc atLoc, TypeExpr *type, bool hasInitializer, PatternBindingInitializer *initContext, SourceLoc lParenLoc, @@ -1628,8 +1623,8 @@ class CustomAttr final : public DeclAttribute, unsigned getNumArguments() const { return numArgLabels; } bool hasArgumentLabelLocs() const { return hasArgLabelLocs; } - TypeLoc &getTypeLoc() { return type; } - const TypeLoc &getTypeLoc() const { return type; } + TypeRepr *getTypeRepr() const; + Type getType() const; Expr *getArg() const { return arg; } void setArg(Expr *newArg) { arg = newArg; } @@ -1642,6 +1637,14 @@ class CustomAttr final : public DeclAttribute, static bool classof(const DeclAttribute *DA) { return DA->getKind() == DAK_Custom; } + +private: + friend class CustomAttrNominalRequest; + void resetTypeInformation(TypeExpr *repr); + +private: + friend class CustomAttrTypeRequest; + void setType(Type ty); }; /// Relates a property to its projection value property, as described by a property wrapper. For diff --git a/include/swift/AST/LazyResolver.h b/include/swift/AST/LazyResolver.h index eb468f7cfe855..ee6e64ff25ac8 100644 --- a/include/swift/AST/LazyResolver.h +++ b/include/swift/AST/LazyResolver.h @@ -18,7 +18,6 @@ #define SWIFT_AST_LAZYRESOLVER_H #include "swift/AST/ProtocolConformanceRef.h" -#include "swift/AST/TypeLoc.h" #include "llvm/ADT/PointerEmbeddedInt.h" namespace swift { diff --git a/include/swift/AST/TypeCheckRequests.h b/include/swift/AST/TypeCheckRequests.h index cedeea5866a0c..75392765ce473 100644 --- a/include/swift/AST/TypeCheckRequests.h +++ b/include/swift/AST/TypeCheckRequests.h @@ -2513,6 +2513,41 @@ class CodeCompletionFileRequest bool isCached() const { return true; } }; +/// Kinds of types for CustomAttr. +enum class CustomAttrTypeKind { + /// The type is required to not be expressed in terms of + /// any contextual type parameters. + NonGeneric, + + /// Property delegates have some funky rules, like allowing + /// unbound generic types. + PropertyDelegate, +}; + +void simple_display(llvm::raw_ostream &out, CustomAttrTypeKind value); + +class CustomAttrTypeRequest + : public SimpleRequest { +public: + using SimpleRequest::SimpleRequest; + +private: + friend SimpleRequest; + + // Evaluation. + Type evaluate(Evaluator &evaluator, CustomAttr *, DeclContext *, + CustomAttrTypeKind) const; + +public: + // Separate caching. + bool isCached() const { return true; } + Optional getCachedResult() const; + void cacheResult(Type value) const; +}; + // Allow AnyValue to compare two Type values, even though Type doesn't // support ==. template<> diff --git a/include/swift/AST/TypeCheckerTypeIDZone.def b/include/swift/AST/TypeCheckerTypeIDZone.def index f1b71d2d25a83..4df761af7c2d2 100644 --- a/include/swift/AST/TypeCheckerTypeIDZone.def +++ b/include/swift/AST/TypeCheckerTypeIDZone.def @@ -41,6 +41,9 @@ SWIFT_REQUEST(TypeChecker, CodeCompletionFileRequest, SWIFT_REQUEST(TypeChecker, CompareDeclSpecializationRequest, bool (DeclContext *, ValueDecl *, ValueDecl *, bool), Cached, NoLocationInfo) +SWIFT_REQUEST(TypeChecker, CustomAttrTypeRequest, + Type(CustomAttr *, DeclContext *, CustomAttrTypeKind), + SeparatelyCached, NoLocationInfo) SWIFT_REQUEST(TypeChecker, DefaultArgumentExprRequest, Expr *(ParamDecl *), SeparatelyCached, NoLocationInfo) SWIFT_REQUEST(TypeChecker, DefaultArgumentInitContextRequest, diff --git a/include/swift/Basic/Statistics.def b/include/swift/Basic/Statistics.def index 6cc99e356934c..419567fc8bba5 100644 --- a/include/swift/Basic/Statistics.def +++ b/include/swift/Basic/Statistics.def @@ -247,9 +247,6 @@ FRONTEND_STATISTIC(Sema, NamedLazyMemberLoadSuccessCount) /// Number of types deserialized. FRONTEND_STATISTIC(Sema, NumTypesDeserialized) -/// Number of types validated. -FRONTEND_STATISTIC(Sema, NumTypesValidated) - /// Number of lazy iterable declaration contexts left unloaded. FRONTEND_STATISTIC(Sema, NumUnloadedLazyIterableDeclContexts) diff --git a/lib/AST/ASTScope.cpp b/lib/AST/ASTScope.cpp index 33cf89aa8e28b..019cc3ccfde42 100644 --- a/lib/AST/ASTScope.cpp +++ b/lib/AST/ASTScope.cpp @@ -99,9 +99,9 @@ AttachedPropertyWrapperScope::getSourceRangeOfVarDecl(const VarDecl *const vd) { SourceRange sr; for (auto *attr : vd->getAttrs().getAttributes()) { if (sr.isInvalid()) - sr = attr->getTypeLoc().getSourceRange(); + sr = attr->getTypeRepr()->getSourceRange(); else - sr.widen(attr->getTypeLoc().getSourceRange()); + sr.widen(attr->getTypeRepr()->getSourceRange()); } return sr; } diff --git a/lib/AST/Attr.cpp b/lib/AST/Attr.cpp index cf90377151b74..8173205f3d2cf 100644 --- a/lib/AST/Attr.cpp +++ b/lib/AST/Attr.cpp @@ -975,7 +975,7 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options, Printer.printAttrName("@_implements"); Printer << "("; auto *attr = cast(this); - attr->getProtocolType().getType().print(Printer, Options); + attr->getProtocolType().print(Printer, Options); Printer << ", " << attr->getMemberName() << ")"; break; } @@ -1022,11 +1022,11 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options, case DAK_Custom: { Printer.callPrintNamePre(PrintNameContext::Attribute); Printer << "@"; - const TypeLoc &typeLoc = cast(this)->getTypeLoc(); - if (auto type = typeLoc.getType()) - type->print(Printer, Options); + auto *attr = cast(this); + if (auto type = attr->getType()) + type.print(Printer, Options); else - typeLoc.getTypeRepr()->print(Printer, Options); + attr->getTypeRepr()->print(Printer, Options); Printer.printNamePost(PrintNameContext::Attribute); break; } @@ -1386,25 +1386,36 @@ SourceLoc DynamicReplacementAttr::getRParenLoc() const { TypeEraserAttr *TypeEraserAttr::create(ASTContext &ctx, SourceLoc atLoc, SourceRange range, - TypeLoc typeEraserLoc) { - return new (ctx) TypeEraserAttr(atLoc, range, typeEraserLoc, nullptr, 0); + TypeExpr *typeEraserExpr) { + return new (ctx) TypeEraserAttr(atLoc, range, typeEraserExpr, nullptr, 0); } TypeEraserAttr *TypeEraserAttr::create(ASTContext &ctx, LazyMemberLoader *Resolver, uint64_t Data) { return new (ctx) TypeEraserAttr(SourceLoc(), SourceRange(), - TypeLoc(), Resolver, Data); + nullptr, Resolver, Data); } -bool -TypeEraserAttr::hasViableTypeEraserInit(ProtocolDecl *protocol) const { +bool TypeEraserAttr::hasViableTypeEraserInit(ProtocolDecl *protocol) const { return evaluateOrDefault(protocol->getASTContext().evaluator, TypeEraserHasViableInitRequest{ const_cast(this), protocol}, false); } +TypeRepr *TypeEraserAttr::getParsedTypeEraserTypeRepr() const { + return TypeEraserExpr ? TypeEraserExpr->getTypeRepr() : nullptr; +} + +SourceLoc TypeEraserAttr::getLoc() const { + return TypeEraserExpr ? TypeEraserExpr->getLoc() : SourceLoc(); +} + +Type TypeEraserAttr::getTypeWithoutResolving() const { + return TypeEraserExpr ? TypeEraserExpr->getInstanceType() : Type(); +} + Type TypeEraserAttr::getResolvedType(const ProtocolDecl *PD) const { auto &ctx = PD->getASTContext(); return evaluateOrDefault(ctx.evaluator, @@ -1814,7 +1825,7 @@ TransposeAttr *TransposeAttr::create(ASTContext &context, bool implicit, } ImplementsAttr::ImplementsAttr(SourceLoc atLoc, SourceRange range, - TypeLoc ProtocolType, + TypeExpr *ProtocolType, DeclName MemberName, DeclNameLoc MemberNameLoc) : DeclAttribute(DAK_Implements, atLoc, range, /*Implicit=*/false), @@ -1826,7 +1837,7 @@ ImplementsAttr::ImplementsAttr(SourceLoc atLoc, SourceRange range, ImplementsAttr *ImplementsAttr::create(ASTContext &Ctx, SourceLoc atLoc, SourceRange range, - TypeLoc ProtocolType, + TypeExpr *ProtocolType, DeclName MemberName, DeclNameLoc MemberNameLoc) { void *mem = Ctx.Allocate(sizeof(ImplementsAttr), alignof(ImplementsAttr)); @@ -1834,28 +1845,34 @@ ImplementsAttr *ImplementsAttr::create(ASTContext &Ctx, SourceLoc atLoc, MemberName, MemberNameLoc); } -TypeLoc ImplementsAttr::getProtocolType() const { - return ProtocolType; +void ImplementsAttr::setProtocolType(Type ty) { + assert(ty); + ProtocolType->setType(MetatypeType::get(ty)); } -TypeLoc &ImplementsAttr::getProtocolType() { - return ProtocolType; +Type ImplementsAttr::getProtocolType() const { + return ProtocolType->getInstanceType(); } -CustomAttr::CustomAttr(SourceLoc atLoc, SourceRange range, TypeLoc type, +TypeRepr *ImplementsAttr::getProtocolTypeRepr() const { + return ProtocolType->getTypeRepr(); +} + +CustomAttr::CustomAttr(SourceLoc atLoc, SourceRange range, TypeExpr *type, PatternBindingInitializer *initContext, Expr *arg, ArrayRef argLabels, ArrayRef argLabelLocs, bool implicit) : DeclAttribute(DAK_Custom, atLoc, range, implicit), - type(type), + typeExpr(type), arg(arg), initContext(initContext) { + assert(type); hasArgLabelLocs = !argLabelLocs.empty(); numArgLabels = argLabels.size(); initializeCallArguments(argLabels, argLabelLocs); } -CustomAttr *CustomAttr::create(ASTContext &ctx, SourceLoc atLoc, TypeLoc type, +CustomAttr *CustomAttr::create(ASTContext &ctx, SourceLoc atLoc, TypeExpr *type, bool hasInitializer, PatternBindingInitializer *initContext, SourceLoc lParenLoc, @@ -1864,6 +1881,7 @@ CustomAttr *CustomAttr::create(ASTContext &ctx, SourceLoc atLoc, TypeLoc type, ArrayRef argLabelLocs, SourceLoc rParenLoc, bool implicit) { + assert(type); SmallVector argLabelsScratch; SmallVector argLabelLocsScratch; Expr *arg = nullptr; @@ -1873,7 +1891,7 @@ CustomAttr *CustomAttr::create(ASTContext &ctx, SourceLoc atLoc, TypeLoc type, argLabelsScratch, argLabelLocsScratch); } - SourceRange range(atLoc, type.getSourceRange().End); + SourceRange range(atLoc, type->getSourceRange().End); if (arg) range.End = arg->getEndLoc(); @@ -1883,6 +1901,16 @@ CustomAttr *CustomAttr::create(ASTContext &ctx, SourceLoc atLoc, TypeLoc type, argLabelLocs, implicit); } +TypeRepr *CustomAttr::getTypeRepr() const { return typeExpr->getTypeRepr(); } +Type CustomAttr::getType() const { return typeExpr->getInstanceType(); } + +void CustomAttr::resetTypeInformation(TypeExpr *info) { typeExpr = info; } + +void CustomAttr::setType(Type ty) { + assert(ty); + typeExpr->setType(MetatypeType::get(ty)); +} + void swift::simple_display(llvm::raw_ostream &out, const DeclAttribute *attr) { if (attr) attr->print(out); diff --git a/lib/AST/ConformanceLookupTable.h b/lib/AST/ConformanceLookupTable.h index a27c89f03e063..c6843b32dabe1 100644 --- a/lib/AST/ConformanceLookupTable.h +++ b/lib/AST/ConformanceLookupTable.h @@ -21,7 +21,6 @@ #define SWIFT_AST_CONFORMANCE_LOOKUP_TABLE_H #include "swift/AST/DeclContext.h" -#include "swift/AST/TypeLoc.h" #include "swift/Basic/Debug.h" #include "swift/Basic/LLVM.h" #include "swift/Basic/SourceLoc.h" diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 8f3a00ffafea2..81706cee2a48b 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -6515,7 +6515,7 @@ ParamDecl::getDefaultValueStringRepresentation( if (wrapperAttrs.size() > 0) { auto attr = wrapperAttrs.front(); if (auto arg = attr->getArg()) { - SourceRange fullRange(attr->getTypeLoc().getSourceRange().Start, + SourceRange fullRange(attr->getTypeRepr()->getSourceRange().Start, arg->getEndLoc()); auto charRange = Lexer::getCharSourceRangeFromSourceRange( getASTContext().SourceMgr, fullRange); diff --git a/lib/AST/NameLookup.cpp b/lib/AST/NameLookup.cpp index 5da65daf1d014..36311b7f85644 100644 --- a/lib/AST/NameLookup.cpp +++ b/lib/AST/NameLookup.cpp @@ -2296,12 +2296,11 @@ CustomAttrNominalRequest::evaluate(Evaluator &evaluator, CustomAttr *attr, DeclContext *dc) const { // Find the types referenced by the custom attribute. auto &ctx = dc->getASTContext(); - TypeLoc &typeLoc = attr->getTypeLoc(); DirectlyReferencedTypeDecls decls; - if (auto typeRepr = typeLoc.getTypeRepr()) { + if (auto *typeRepr = attr->getTypeRepr()) { decls = directReferencesForTypeRepr( evaluator, ctx, typeRepr, dc); - } else if (Type type = typeLoc.getType()) { + } else if (Type type = attr->getType()) { decls = directReferencesForType(type); } @@ -2316,7 +2315,7 @@ CustomAttrNominalRequest::evaluate(Evaluator &evaluator, // If we found declarations that are associated types, look outside of // the current context to see if we can recover. if (declsAreAssociatedTypes(decls)) { - if (auto typeRepr = typeLoc.getTypeRepr()) { + if (auto typeRepr = attr->getTypeRepr()) { if (auto identTypeRepr = dyn_cast(typeRepr)) { auto assocType = cast(decls.front()); @@ -2348,7 +2347,8 @@ CustomAttrNominalRequest::evaluate(Evaluator &evaluator, identTypeRepr }; - typeLoc = TypeLoc(IdentTypeRepr::create(ctx, components)); + auto *newTE = new (ctx) TypeExpr(IdentTypeRepr::create(ctx, components)); + attr->resetTypeInformation(newTE); return nominal; } } diff --git a/lib/AST/TypeCheckRequests.cpp b/lib/AST/TypeCheckRequests.cpp index f6313796e1fc4..6ecd7c87e2b50 100644 --- a/lib/AST/TypeCheckRequests.cpp +++ b/lib/AST/TypeCheckRequests.cpp @@ -1410,16 +1410,22 @@ void LookupAllConformancesInContextRequest::writeDependencySink( //----------------------------------------------------------------------------// Optional ResolveTypeEraserTypeRequest::getCachedResult() const { - auto ty = std::get<1>(getStorage())->TypeEraserLoc.getType(); - if (ty.isNull()) { + auto *TyExpr = std::get<1>(getStorage())->TypeEraserExpr; + if (!TyExpr || !TyExpr->getType()) { return None; } - return ty; + return TyExpr->getInstanceType(); } void ResolveTypeEraserTypeRequest::cacheResult(Type value) const { assert(value && "Resolved type erasure type to null type!"); - std::get<1>(getStorage())->TypeEraserLoc.setType(value); + auto *attr = std::get<1>(getStorage()); + if (attr->TypeEraserExpr) { + attr->TypeEraserExpr->setType(MetatypeType::get(value)); + } else { + attr->TypeEraserExpr = TypeExpr::createImplicit(value, + value->getASTContext()); + } } //----------------------------------------------------------------------------// @@ -1498,3 +1504,33 @@ SourceLoc swift::extractNearestSourceLoc(const TypeRepr *repr) { return SourceLoc(); return repr->getLoc(); } + +//----------------------------------------------------------------------------// +// CustomAttrTypeRequest computation. +//----------------------------------------------------------------------------// + +void swift::simple_display(llvm::raw_ostream &out, CustomAttrTypeKind value) { + switch (value) { + case CustomAttrTypeKind::NonGeneric: + out << "non-generic"; + return; + + case CustomAttrTypeKind::PropertyDelegate: + out << "property-delegate"; + return; + } + llvm_unreachable("bad kind"); +} + +Optional CustomAttrTypeRequest::getCachedResult() const { + auto *attr = std::get<0>(getStorage()); + if (auto ty = attr->getType()) { + return ty; + } + return None; +} + +void CustomAttrTypeRequest::cacheResult(Type value) const { + auto *attr = std::get<0>(getStorage()); + attr->setType(value); +} diff --git a/lib/IDE/Formatting.cpp b/lib/IDE/Formatting.cpp index cf601d5b7d5b2..102e0786ebfe9 100644 --- a/lib/IDE/Formatting.cpp +++ b/lib/IDE/Formatting.cpp @@ -446,7 +446,7 @@ class RangeWalker: protected ASTWalker { } } for (auto *customAttr : D->getAttrs().getAttributes()) { - if (auto *Repr = customAttr->getTypeLoc().getTypeRepr()) { + if (auto *Repr = customAttr->getTypeRepr()) { if (!Repr->walk(*this)) return false; } @@ -1260,7 +1260,7 @@ class FormatWalker : public ASTWalker { } } for (auto *customAttr : D->getAttrs().getAttributes()) { - if (auto *Repr = customAttr->getTypeLoc().getTypeRepr()) { + if (auto *Repr = customAttr->getTypeRepr()) { if (!Repr->walk(*this)) return false; } diff --git a/lib/IDE/SourceEntityWalker.cpp b/lib/IDE/SourceEntityWalker.cpp index f2dc3e165a072..d52e8c43fd368 100644 --- a/lib/IDE/SourceEntityWalker.cpp +++ b/lib/IDE/SourceEntityWalker.cpp @@ -598,7 +598,7 @@ bool SemaAnnotator::handleCustomAttributes(Decl *D) { } } for (auto *customAttr : D->getAttrs().getAttributes()) { - if (auto *Repr = customAttr->getTypeLoc().getTypeRepr()) { + if (auto *Repr = customAttr->getTypeRepr()) { if (!Repr->walk(*this)) return false; } diff --git a/lib/IDE/SwiftSourceDocInfo.cpp b/lib/IDE/SwiftSourceDocInfo.cpp index f8211c437795a..a08719d75af83 100644 --- a/lib/IDE/SwiftSourceDocInfo.cpp +++ b/lib/IDE/SwiftSourceDocInfo.cpp @@ -177,7 +177,7 @@ bool NameMatcher::handleCustomAttrs(Decl *D) { if (shouldSkip(customAttr->getRangeWithAt())) continue; auto *Arg = customAttr->getArg(); - if (auto *Repr = customAttr->getTypeLoc().getTypeRepr()) { + if (auto *Repr = customAttr->getTypeRepr()) { // Note the associated call arguments of the semantic initializer call // in case we're resolving an explicit initializer call within the // CustomAttr's type, e.g. on `Wrapper` in `@Wrapper(wrappedValue: 10)`. diff --git a/lib/IDE/SyntaxModel.cpp b/lib/IDE/SyntaxModel.cpp index aa97eb458e3b0..0d06879c184a7 100644 --- a/lib/IDE/SyntaxModel.cpp +++ b/lib/IDE/SyntaxModel.cpp @@ -1199,7 +1199,7 @@ bool ModelASTWalker::handleSpecialDeclAttribute(const DeclAttribute *D, ExcludeNodeAtLocation).shouldContinue) return false; if (auto *CA = dyn_cast(D)) { - if (auto *Repr = CA->getTypeLoc().getTypeRepr()) { + if (auto *Repr = CA->getTypeRepr()) { if (!Repr->walk(*this)) return false; } diff --git a/lib/Index/Index.cpp b/lib/Index/Index.cpp index 8153592ff4dae..487eeace69098 100644 --- a/lib/Index/Index.cpp +++ b/lib/Index/Index.cpp @@ -343,13 +343,13 @@ class IndexSwiftASTWalker : public SourceEntityWalker { if (customAttr->isImplicit()) continue; - auto &Loc = customAttr->getTypeLoc(); if (auto *semanticInit = dyn_cast_or_null(customAttr->getSemanticInit())) { if (auto *CD = semanticInit->getCalledValue()) { if (!shouldIndex(CD, /*IsRef*/true)) continue; IndexSymbol Info; - if (initIndexSymbol(CD, Loc.getLoc(), /*IsRef=*/true, Info)) + const auto reprLoc = customAttr->getTypeRepr()->getLoc(); + if (initIndexSymbol(CD, reprLoc, /*IsRef=*/true, Info)) continue; Info.roles |= (unsigned)SymbolRole::Call; if (semanticInit->isImplicit()) diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index b13b09ceea5d1..b69991bafd180 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -811,10 +811,10 @@ Parser::parseImplementsAttribute(SourceLoc AtLoc, SourceLoc Loc) { } // FIXME(ModQual): Reject module qualification on MemberName. - + auto *TE = new (Context) TypeExpr(ProtocolType.get()); return ParserResult( ImplementsAttr::create(Context, AtLoc, SourceRange(Loc, rParenLoc), - ProtocolType.get(), MemberName.getFullName(), + TE, MemberName.getFullName(), MemberNameLoc)); } @@ -2218,7 +2218,8 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc, if (invalid) return false; - Attributes.add(TypeEraserAttr::create(Context, AtLoc, {Loc, RParenLoc}, ErasedType.get())); + auto *TE = new (Context) TypeExpr(ErasedType.get()); + Attributes.add(TypeEraserAttr::create(Context, AtLoc, {Loc, RParenLoc}, TE)); break; } @@ -2591,7 +2592,8 @@ ParserStatus Parser::parseDeclAttribute(DeclAttributes &Attributes, SourceLoc At } // Form the attribute. - auto attr = CustomAttr::create(Context, AtLoc, type.get(), hasInitializer, + auto *TE = new (Context) TypeExpr(type.get()); + auto attr = CustomAttr::create(Context, AtLoc, TE, hasInitializer, initContext, lParenLoc, args, argLabels, argLabelLocs, rParenLoc); Attributes.add(attr); diff --git a/lib/Parse/ParseType.cpp b/lib/Parse/ParseType.cpp index 68c1b715be06c..d4d20c0e36d6a 100644 --- a/lib/Parse/ParseType.cpp +++ b/lib/Parse/ParseType.cpp @@ -17,7 +17,6 @@ #include "swift/Parse/Parser.h" #include "swift/AST/ASTWalker.h" #include "swift/AST/Attr.h" -#include "swift/AST/TypeLoc.h" #include "swift/AST/TypeRepr.h" #include "swift/Parse/Lexer.h" #include "swift/Parse/CodeCompletionCallbacks.h" diff --git a/lib/Sema/CSGen.cpp b/lib/Sema/CSGen.cpp index d77d99c7b48e9..15b1d5ee7a85a 100644 --- a/lib/Sema/CSGen.cpp +++ b/lib/Sema/CSGen.cpp @@ -1495,12 +1495,14 @@ namespace { Type resolveTypeReferenceInExpression(TypeRepr *repr, TypeResolverContext resCtx) { - TypeLoc loc(repr); TypeResolutionOptions options(resCtx); options |= TypeResolutionFlags::AllowUnboundGenerics; - bool hadError = TypeChecker::validateType( - loc, TypeResolution::forContextual(CS.DC, options)); - return hadError ? Type() : loc.getType(); + auto result = TypeResolution::forContextual(CS.DC, options) + .resolveType(repr); + if (!result || result->hasError()) { + return Type(); + } + return result; } Type visitTypeExpr(TypeExpr *E) { diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp index 4d1dff495fdff..2b579f51e7352 100644 --- a/lib/Sema/ConstraintSystem.cpp +++ b/lib/Sema/ConstraintSystem.cpp @@ -4389,9 +4389,12 @@ void SolutionApplicationTarget::maybeApplyPropertyWrapper() { isImplicit = true; } - auto typeExpr = TypeExpr::createImplicitHack( - outermostWrapperAttr->getTypeLoc().getLoc(), - outermostWrapperType, ctx); + SourceLoc typeLoc; + if (auto *repr = outermostWrapperAttr->getTypeRepr()) { + typeLoc = repr->getLoc(); + } + auto typeExpr = + TypeExpr::createImplicitHack(typeLoc, outermostWrapperType, ctx); backingInitializer = CallExpr::create( ctx, typeExpr, outermostArg, outermostWrapperAttr->getArgumentLabels(), @@ -4405,7 +4408,8 @@ void SolutionApplicationTarget::maybeApplyPropertyWrapper() { // the initializer type later. expression.wrappedVar = singleVar; expression.expression = backingInitializer; - expression.convertType = outermostWrapperAttr->getTypeLoc(); + expression.convertType = {outermostWrapperAttr->getTypeRepr(), + outermostWrapperAttr->getType()}; } SolutionApplicationTarget SolutionApplicationTarget::forInitialization( diff --git a/lib/Sema/DerivedConformanceComparable.cpp b/lib/Sema/DerivedConformanceComparable.cpp index d543ffb7314a6..216db050d320b 100644 --- a/lib/Sema/DerivedConformanceComparable.cpp +++ b/lib/Sema/DerivedConformanceComparable.cpp @@ -289,13 +289,13 @@ deriveComparable_lt( if (generatedIdentifier != C.Id_LessThanOperator) { auto comparable = C.getProtocol(KnownProtocolKind::Comparable); auto comparableType = comparable->getDeclaredType(); - auto comparableTypeLoc = TypeLoc::withoutLoc(comparableType); + auto comparableTypeExpr = TypeExpr::createImplicit(comparableType, C); SmallVector argumentLabels = { Identifier(), Identifier() }; auto comparableDeclName = DeclName(C, DeclBaseName(C.Id_LessThanOperator), argumentLabels); comparableDecl->getAttrs().add(new (C) ImplementsAttr(SourceLoc(), SourceRange(), - comparableTypeLoc, + comparableTypeExpr, comparableDeclName, DeclNameLoc())); } diff --git a/lib/Sema/DerivedConformanceEquatableHashable.cpp b/lib/Sema/DerivedConformanceEquatableHashable.cpp index dbd323d495fe0..589c61b447d6e 100644 --- a/lib/Sema/DerivedConformanceEquatableHashable.cpp +++ b/lib/Sema/DerivedConformanceEquatableHashable.cpp @@ -506,13 +506,13 @@ deriveEquatable_eq( if (generatedIdentifier != C.Id_EqualsOperator) { auto equatableProto = C.getProtocol(KnownProtocolKind::Equatable); auto equatableTy = equatableProto->getDeclaredType(); - auto equatableTypeLoc = TypeLoc::withoutLoc(equatableTy); + auto equatableTyExpr = TypeExpr::createImplicit(equatableTy, C); SmallVector argumentLabels = { Identifier(), Identifier() }; auto equalsDeclName = DeclName(C, DeclBaseName(C.Id_EqualsOperator), argumentLabels); eqDecl->getAttrs().add(new (C) ImplementsAttr(SourceLoc(), SourceRange(), - equatableTypeLoc, + equatableTyExpr, equalsDeclName, DeclNameLoc())); } diff --git a/lib/Sema/TypeCheckAccess.cpp b/lib/Sema/TypeCheckAccess.cpp index c67093cd5c843..a3720d157e27f 100644 --- a/lib/Sema/TypeCheckAccess.cpp +++ b/lib/Sema/TypeCheckAccess.cpp @@ -526,7 +526,7 @@ class AccessControlChecker : public AccessControlCheckerBase, // Check the property wrapper types. for (auto attr : anyVar->getAttachedPropertyWrappers()) { - checkTypeAccess(attr->getTypeLoc(), anyVar, + checkTypeAccess(attr->getType(), attr->getTypeRepr(), anyVar, /*mayBeInferred=*/false, [&](AccessScope typeAccessScope, const TypeRepr *complainRepr, @@ -1152,7 +1152,7 @@ class UsableFromInlineChecker : public AccessControlCheckerBase, }); for (auto attr : anyVar->getAttachedPropertyWrappers()) { - checkTypeAccess(attr->getTypeLoc(), + checkTypeAccess(attr->getType(), attr->getTypeRepr(), fixedLayoutStructContext ? fixedLayoutStructContext : anyVar, /*mayBeInferred*/false, @@ -1827,7 +1827,7 @@ class ExportabilityChecker : public DeclVisitor { // Check the property wrapper types. for (auto attr : anyVar->getAttachedPropertyWrappers()) - checkType(attr->getTypeLoc(), anyVar, + checkType(attr->getType(), attr->getTypeRepr(), anyVar, getDiagnoser(anyVar, Reason::PropertyWrapper)); } diff --git a/lib/Sema/TypeCheckAttr.cpp b/lib/Sema/TypeCheckAttr.cpp index abd39331ef685..505232f6748ad 100644 --- a/lib/Sema/TypeCheckAttr.cpp +++ b/lib/Sema/TypeCheckAttr.cpp @@ -2841,23 +2841,21 @@ void AttributeChecker::visitTypeEraserAttr(TypeEraserAttr *attr) { } void AttributeChecker::visitImplementsAttr(ImplementsAttr *attr) { - TypeLoc &ProtoTypeLoc = attr->getProtocolType(); - DeclContext *DC = D->getDeclContext(); - Type T = ProtoTypeLoc.getType(); - if (!T && ProtoTypeLoc.getTypeRepr()) { + Type T = attr->getProtocolType(); + if (!T && attr->getProtocolTypeRepr()) { TypeResolutionOptions options = None; options |= TypeResolutionFlags::AllowUnboundGenerics; - auto resolution = TypeResolution::forContextual(DC, options); - T = resolution.resolveType(ProtoTypeLoc.getTypeRepr()); - ProtoTypeLoc.setType(T); + T = TypeResolution::forContextual(DC, options) + .resolveType(attr->getProtocolTypeRepr()); } // Definite error-types were already diagnosed in resolveType. - if (T->hasError()) + if (!T || T->hasError()) return; + attr->setProtocolType(T); // Check that we got a ProtocolType. if (auto PT = T->getAs()) { @@ -2882,12 +2880,12 @@ void AttributeChecker::visitImplementsAttr(ImplementsAttr *attr) { diagnose(attr->getLocation(), diag::implements_attr_protocol_not_conformed_to, NTD->getName(), PD->getName()) - .highlight(ProtoTypeLoc.getTypeRepr()->getSourceRange()); + .highlight(attr->getProtocolTypeRepr()->getSourceRange()); } } else { diagnose(attr->getLocation(), diag::implements_attr_non_protocol_type) - .highlight(ProtoTypeLoc.getTypeRepr()->getSourceRange()); + .highlight(attr->getProtocolTypeRepr()->getSourceRange()); } } @@ -2925,11 +2923,11 @@ void AttributeChecker::visitCustomAttr(CustomAttr *attr) { // an unknown attribute. if (!nominal) { std::string typeName; - if (auto typeRepr = attr->getTypeLoc().getTypeRepr()) { + if (auto typeRepr = attr->getTypeRepr()) { llvm::raw_string_ostream out(typeName); typeRepr->print(out); } else { - typeName = attr->getTypeLoc().getType().getString(); + typeName = attr->getType().getString(); } diagnose(attr->getLocation(), diag::unknown_attribute, typeName); diff --git a/lib/Sema/TypeCheckPropertyWrapper.cpp b/lib/Sema/TypeCheckPropertyWrapper.cpp index ff7efa8af8ecb..5c1cdfc6f9987 100644 --- a/lib/Sema/TypeCheckPropertyWrapper.cpp +++ b/lib/Sema/TypeCheckPropertyWrapper.cpp @@ -556,16 +556,15 @@ Type AttachedPropertyWrapperTypeRequest::evaluate(Evaluator &evaluator, if (!customAttr) return Type(); - TypeResolutionOptions options(TypeResolverContext::PatternBindingDecl); - options |= TypeResolutionFlags::AllowUnboundGenerics; - - auto resolution = - TypeResolution::forContextual(var->getDeclContext(), options); - if (TypeChecker::validateType(customAttr->getTypeLoc(), resolution)) { + auto ty = evaluateOrDefault( + evaluator, + CustomAttrTypeRequest{customAttr, var->getDeclContext(), + CustomAttrTypeKind::PropertyDelegate}, + Type()); + if (!ty || ty->hasError()) { return ErrorType::get(var->getASTContext()); } - - return customAttr->getTypeLoc().getType(); + return ty; } Type @@ -720,12 +719,16 @@ Expr *swift::buildPropertyWrapperWrappedValueCall( : var->getAttachedPropertyWrapperType(i); if (!wrapperType) return nullptr; - - auto typeExpr = TypeExpr::createImplicitHack( - wrapperAttrs[i]->getTypeLoc().getLoc(), - wrapperType, ctx); - SourceLoc startLoc = wrapperAttrs[i]->getTypeLoc().getSourceRange().Start; + auto reprRange = SourceRange(); + if (auto *repr = wrapperAttrs[i]->getTypeRepr()) { + reprRange = repr->getSourceRange(); + } + + auto typeExpr = + TypeExpr::createImplicitHack(reprRange.Start, wrapperType, ctx); + + SourceLoc startLoc = reprRange.Start; // If there were no arguments provided for the attribute at this level, // call `init(wrappedValue:)` directly. @@ -745,7 +748,7 @@ Expr *swift::buildPropertyWrapperWrappedValueCall( auto endLoc = initializer->getEndLoc(); if (endLoc.isInvalid() && startLoc.isValid()) - endLoc = wrapperAttrs[i]->getTypeLoc().getSourceRange().End; + endLoc = reprRange.End; auto *init = CallExpr::create(ctx, typeExpr, startLoc, {initializer}, {argName}, @@ -781,7 +784,7 @@ Expr *swift::buildPropertyWrapperWrappedValueCall( auto endLoc = attr->getArg()->getEndLoc(); if (endLoc.isInvalid() && startLoc.isValid()) - endLoc = wrapperAttrs[i]->getTypeLoc().getSourceRange().End; + endLoc = reprRange.End; auto *init = CallExpr::create(ctx, typeExpr, startLoc, elements, elementNames, elementLocs, endLoc, diff --git a/lib/Sema/TypeCheckProtocol.cpp b/lib/Sema/TypeCheckProtocol.cpp index b3b7a9dc8a89c..b9cd51877744e 100644 --- a/lib/Sema/TypeCheckProtocol.cpp +++ b/lib/Sema/TypeCheckProtocol.cpp @@ -1039,7 +1039,7 @@ witnessHasImplementsAttrForExactRequirement(ValueDecl *witness, assert(requirement->isProtocolRequirement()); auto *PD = cast(requirement->getDeclContext()); if (auto A = witness->getAttrs().getAttribute()) { - if (Type T = A->getProtocolType().getType()) { + if (Type T = A->getProtocolType()) { if (auto ProtoTy = T->getAs()) { if (ProtoTy->getDecl() == PD) { return A->getMemberName() == requirement->getName(); diff --git a/lib/Sema/TypeCheckRequestFunctions.cpp b/lib/Sema/TypeCheckRequestFunctions.cpp index 7ab8c6511f595..cda70bdc3ee53 100644 --- a/lib/Sema/TypeCheckRequestFunctions.cpp +++ b/lib/Sema/TypeCheckRequestFunctions.cpp @@ -362,9 +362,11 @@ Type FunctionBuilderTypeRequest::evaluate(Evaluator &evaluator, auto mutableAttr = const_cast(attr); auto dc = decl->getDeclContext(); auto &ctx = dc->getASTContext(); - Type type = resolveCustomAttrType(mutableAttr, dc, - CustomAttrTypeKind::NonGeneric); - if (!type) return Type(); + Type type = evaluateOrDefault( + evaluator, + CustomAttrTypeRequest{mutableAttr, dc, CustomAttrTypeKind::NonGeneric}, + Type()); + if (!type || type->hasError()) return Type(); auto nominal = type->getAnyNominal(); if (!nominal) { diff --git a/lib/Sema/TypeCheckStorage.cpp b/lib/Sema/TypeCheckStorage.cpp index c43f4f52ea5fd..609c828010faa 100644 --- a/lib/Sema/TypeCheckStorage.cpp +++ b/lib/Sema/TypeCheckStorage.cpp @@ -2479,7 +2479,11 @@ PropertyWrapperMutabilityRequest::evaluate(Evaluator &, result.Getter = getGetterMutatingness(firstWrapper.*varMember); result.Setter = getSetterMutatingness(firstWrapper.*varMember, var->getInnermostDeclContext()); - + + auto getCustomAttrTypeLoc = [](const CustomAttr *CA) -> TypeLoc { + return { CA->getTypeRepr(), CA->getType() }; + }; + // Compose the traits of the following wrappers. for (unsigned i = 1; i < numWrappers && !isProjectedValue; ++i) { assert(var == originalVar); @@ -2496,8 +2500,8 @@ PropertyWrapperMutabilityRequest::evaluate(Evaluator &, auto &ctx = var->getASTContext(); ctx.Diags.diagnose(var->getAttachedPropertyWrappers()[i]->getLocation(), diag::property_wrapper_mutating_get_composed_to_get_only, - var->getAttachedPropertyWrappers()[i]->getTypeLoc(), - var->getAttachedPropertyWrappers()[i-1]->getTypeLoc()); + getCustomAttrTypeLoc(var->getAttachedPropertyWrappers()[i]), + getCustomAttrTypeLoc(var->getAttachedPropertyWrappers()[i-1])); return None; } diff --git a/lib/Sema/TypeCheckType.cpp b/lib/Sema/TypeCheckType.cpp index 7bb65199a882a..3f368011f8aa1 100644 --- a/lib/Sema/TypeCheckType.cpp +++ b/lib/Sema/TypeCheckType.cpp @@ -1688,20 +1688,6 @@ static bool validateAutoClosureAttributeUse(DiagnosticEngine &Diags, return !isValid; } -bool TypeChecker::validateType(TypeLoc &Loc, TypeResolution resolution) { - // If we've already validated this type, don't do so again. - if (Loc.wasValidated()) - return Loc.isError(); - - if (auto *Stats = resolution.getASTContext().Stats) - ++Stats->getFrontendCounters().NumTypesValidated; - - auto type = resolution.resolveType(Loc.getTypeRepr()); - Loc.setType(type); - - return type->hasError(); -} - namespace { const auto DefaultParameterConvention = ParameterConvention::Direct_Unowned; const auto DefaultResultConvention = ResultConvention::Unowned; @@ -3882,8 +3868,9 @@ void TypeChecker::checkUnsupportedProtocolType( visitor.visitRequirements(genericParams->getRequirements()); } -Type swift::resolveCustomAttrType(CustomAttr *attr, DeclContext *dc, - CustomAttrTypeKind typeKind) { +Type CustomAttrTypeRequest::evaluate(Evaluator &eval, CustomAttr *attr, + DeclContext *dc, + CustomAttrTypeKind typeKind) const { TypeResolutionOptions options(TypeResolverContext::PatternBindingDecl); // Property delegates allow their type to be an unbound generic. @@ -3891,15 +3878,13 @@ Type swift::resolveCustomAttrType(CustomAttr *attr, DeclContext *dc, options |= TypeResolutionFlags::AllowUnboundGenerics; ASTContext &ctx = dc->getASTContext(); - auto resolution = TypeResolution::forContextual(dc, options); - if (TypeChecker::validateType(attr->getTypeLoc(), resolution)) - return Type(); + auto type = TypeResolution::forContextual(dc, options) + .resolveType(attr->getTypeRepr()); // We always require the type to resolve to a nominal type. - Type type = attr->getTypeLoc().getType(); if (!type->getAnyNominal()) { assert(ctx.Diags.hadAnyError()); - return Type(); + return ErrorType::get(ctx); } return type; diff --git a/lib/Sema/TypeCheckType.h b/lib/Sema/TypeCheckType.h index 8613818fb17d3..b09e418464c2a 100644 --- a/lib/Sema/TypeCheckType.h +++ b/lib/Sema/TypeCheckType.h @@ -391,21 +391,6 @@ class TypeResolution { bool areSameType(Type type1, Type type2) const; }; -/// Kinds of types for CustomAttr. -enum class CustomAttrTypeKind { - /// The type is required to not be expressed in terms of - /// any contextual type parameters. - NonGeneric, - - /// Property delegates have some funky rules, like allowing - /// unbound generic types. - PropertyDelegate, -}; - -/// Attempt to resolve a concrete type for a custom attribute. -Type resolveCustomAttrType(CustomAttr *attr, DeclContext *dc, - CustomAttrTypeKind typeKind); - } // end namespace swift #endif /* SWIFT_SEMA_TYPE_CHECK_TYPE_H */ diff --git a/lib/Sema/TypeChecker.cpp b/lib/Sema/TypeChecker.cpp index 230adc8ca4e47..c8df3ebd2425a 100644 --- a/lib/Sema/TypeChecker.cpp +++ b/lib/Sema/TypeChecker.cpp @@ -424,7 +424,15 @@ bool swift::performTypeLocChecking(ASTContext &Ctx, TypeLoc &T, Optional suppression; if (!ProduceDiagnostics) suppression.emplace(Ctx.Diags); - return TypeChecker::validateType(T, resolution); + + // If we've already validated this type, don't do so again. + if (T.wasValidated()) { + return T.isError(); + } + + auto type = resolution.resolveType(T.getTypeRepr()); + T.setType(type); + return type->hasError(); } /// Expose TypeChecker's handling of GenericParamList to SIL parsing. diff --git a/lib/Serialization/Deserialization.cpp b/lib/Serialization/Deserialization.cpp index 3564ff780ae49..67b5d043a4242 100644 --- a/lib/Serialization/Deserialization.cpp +++ b/lib/Serialization/Deserialization.cpp @@ -4329,9 +4329,8 @@ llvm::Error DeclDeserializer::deserializeDeclAttributes() { } else return deserialized.takeError(); } else { - Attr = CustomAttr::create(ctx, SourceLoc(), - TypeLoc::withoutLoc(deserialized.get()), - isImplicit); + auto *TE = TypeExpr::createImplicit(deserialized.get(), ctx); + Attr = CustomAttr::create(ctx, SourceLoc(), TE, isImplicit); } break; } diff --git a/lib/Serialization/ModuleFile.h b/lib/Serialization/ModuleFile.h index 9f233aa1f89dc..fcbcda07ac089 100644 --- a/lib/Serialization/ModuleFile.h +++ b/lib/Serialization/ModuleFile.h @@ -20,7 +20,6 @@ #include "swift/AST/FileUnit.h" #include "swift/AST/Module.h" #include "swift/AST/RawComment.h" -#include "swift/AST/TypeLoc.h" #include "swift/Serialization/Validation.h" #include "swift/Basic/LLVM.h" #include "clang/AST/Type.h" diff --git a/lib/Serialization/Serialization.cpp b/lib/Serialization/Serialization.cpp index abe402eb7e470..2920b29971e44 100644 --- a/lib/Serialization/Serialization.cpp +++ b/lib/Serialization/Serialization.cpp @@ -2388,9 +2388,9 @@ class Serializer::DeclSerializer : public DeclVisitor { case DAK_Custom: { auto abbrCode = S.DeclTypeAbbrCodes[CustomDeclAttrLayout::Code]; auto theAttr = cast(DA); - CustomDeclAttrLayout::emitRecord( - S.Out, S.ScratchRecord, abbrCode, theAttr->isImplicit(), - S.addTypeRef(theAttr->getTypeLoc().getType())); + CustomDeclAttrLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode, + theAttr->isImplicit(), + S.addTypeRef(theAttr->getType())); return; }