diff --git a/include/swift/AST/Attr.h b/include/swift/AST/Attr.h index 02106a667d6..fc428fbc1de 100644 --- a/include/swift/AST/Attr.h +++ b/include/swift/AST/Attr.h @@ -68,7 +68,7 @@ public: struct Convention { StringRef Name = {}; - StringRef WitnessMethodProtocol = {}; + DeclName WitnessMethodProtocol = {}; StringRef ClangType = {}; // Carry the source location for diagnostics. SourceLoc ClangTypeLoc = {}; @@ -78,7 +78,7 @@ public: /// Don't use this function if you are creating a C convention as you /// probably need a ClangType field as well. static Convention makeSwiftConvention(StringRef name) { - return {name, "", "", {}}; + return {name, DeclName(), "", {}}; } }; diff --git a/include/swift/AST/DiagnosticsParse.def b/include/swift/AST/DiagnosticsParse.def index 69a78ceea4d..c63421ad530 100644 --- a/include/swift/AST/DiagnosticsParse.def +++ b/include/swift/AST/DiagnosticsParse.def @@ -207,7 +207,7 @@ ERROR(lex_conflict_marker_in_file,none, //------------------------------------------------------------------------------ NOTE(note_in_decl_extension,none, - "in %select{declaration|extension}0 of %1", (bool, Identifier)) + "in %select{declaration|extension}0 of %1", (bool, DeclName)) ERROR(line_directive_style_deprecated,none, "#line directive was renamed to #sourceLocation", ()) diff --git a/include/swift/AST/DiagnosticsSema.def b/include/swift/AST/DiagnosticsSema.def index 18149a5e414..0ee160904c0 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -781,21 +781,21 @@ NOTE(invalid_redecl_prev,none, "%0 previously declared here", (DeclName)) ERROR(ambiguous_type_base,none, - "%0 is ambiguous for type lookup in this context", (Identifier)) + "%0 is ambiguous for type lookup in this context", (DeclName)) ERROR(invalid_member_type,none, - "%0 is not a member type of %1", (Identifier, Type)) + "%0 is not a member type of %1", (DeclName, Type)) ERROR(invalid_member_type_suggest,none, "%0 does not have a member type named %1; did you mean %2?", - (Type, Identifier, Identifier)) + (Type, DeclName, DeclName)) ERROR(invalid_member_reference,none, "%0 %1 is not a member type of %2", - (DescriptiveDeclKind, Identifier, Type)) + (DescriptiveDeclKind, DeclName, Type)) ERROR(ambiguous_member_type,none, - "ambiguous type name %0 in %1", (Identifier, Type)) + "ambiguous type name %0 in %1", (DeclName, Type)) ERROR(no_module_type,none, - "no type named %0 in module %1", (Identifier, Identifier)) + "no type named %0 in module %1", (DeclName, Identifier)) ERROR(ambiguous_module_type,none, - "ambiguous type name %0 in module %1", (Identifier, Identifier)) + "ambiguous type name %0 in module %1", (DeclName, Identifier)) ERROR(use_nonmatching_operator,none, "%0 is not a %select{binary|prefix unary|postfix unary}1 operator", (DeclName, unsigned)) @@ -828,9 +828,9 @@ NOTE(confusable_character,none, "did you mean to use '%2'?", (bool, StringRef, StringRef)) ERROR(use_undeclared_type,none, - "use of undeclared type %0", (Identifier)) + "use of undeclared type %0", (DeclName)) ERROR(use_undeclared_type_did_you_mean,none, - "use of undeclared type %0; did you mean to use '%1'?", (Identifier, StringRef)) + "use of undeclared type %0; did you mean to use '%1'?", (DeclName, StringRef)) NOTE(note_typo_candidate_implicit_member,none, "did you mean the implicitly-synthesized %1 '%0'?", (StringRef, StringRef)) NOTE(note_remapped_type,none, @@ -2178,10 +2178,10 @@ WARNING(append_interpolation_access_control,none, // Protocols and existentials ERROR(assoc_type_outside_of_protocol,none, "associated type %0 can only be used with a concrete type or " - "generic parameter base", (Identifier)) + "generic parameter base", (DeclName)) ERROR(typealias_outside_of_protocol,none, "type alias %0 can only be used with a concrete type or " - "generic parameter base", (Identifier)) + "generic parameter base", (DeclName)) ERROR(objc_protocol_inherits_non_objc_protocol,none, "@objc protocol %0 cannot refine non-@objc protocol %1", (Type, Type)) diff --git a/include/swift/AST/Expr.h b/include/swift/AST/Expr.h index 2d695a83094..f0a149ac7f9 100644 --- a/include/swift/AST/Expr.h +++ b/include/swift/AST/Expr.h @@ -1340,19 +1340,19 @@ public: /// Create a TypeExpr for a TypeDecl at the specified location. - static TypeExpr *createForDecl(SourceLoc Loc, TypeDecl *D, + static TypeExpr *createForDecl(DeclNameLoc Loc, TypeDecl *D, DeclContext *DC, bool isImplicit); /// Create a TypeExpr for a member TypeDecl of the given parent TypeDecl. - static TypeExpr *createForMemberDecl(SourceLoc ParentNameLoc, + static TypeExpr *createForMemberDecl(DeclNameLoc ParentNameLoc, TypeDecl *Parent, - SourceLoc NameLoc, + DeclNameLoc NameLoc, TypeDecl *Decl); /// Create a TypeExpr for a member TypeDecl of the given parent IdentTypeRepr. static TypeExpr *createForMemberDecl(IdentTypeRepr *ParentTR, - SourceLoc NameLoc, + DeclNameLoc NameLoc, TypeDecl *Decl); /// Create a TypeExpr from an IdentTypeRepr with the given arguments applied diff --git a/include/swift/AST/TypeRepr.h b/include/swift/AST/TypeRepr.h index 6979fb1ef9a..a1bd5e08068 100644 --- a/include/swift/AST/TypeRepr.h +++ b/include/swift/AST/TypeRepr.h @@ -256,30 +256,30 @@ public: }; class ComponentIdentTypeRepr : public IdentTypeRepr { - SourceLoc Loc; + DeclNameLoc Loc; /// Either the identifier or declaration that describes this /// component. /// /// The initial parsed representation is always an identifier, and /// name binding will resolve this to a specific declaration. - llvm::PointerUnion IdOrDecl; + llvm::PointerUnion IdOrDecl; /// The declaration context from which the bound declaration was /// found. only valid if IdOrDecl is a TypeDecl. DeclContext *DC; protected: - ComponentIdentTypeRepr(TypeReprKind K, SourceLoc Loc, Identifier Id) + ComponentIdentTypeRepr(TypeReprKind K, DeclNameLoc Loc, DeclName Id) : IdentTypeRepr(K), Loc(Loc), IdOrDecl(Id), DC(nullptr) {} public: - SourceLoc getIdLoc() const { return Loc; } - Identifier getIdentifier() const; + DeclNameLoc getNameLoc() const { return Loc; } + DeclName getNameRef() const; /// Replace the identifier with a new identifier, e.g., due to typo /// correction. - void overwriteIdentifier(Identifier newId) { IdOrDecl = newId; } + void overwriteNameRef(DeclName newId) { IdOrDecl = newId; } /// Return true if this has been name-bound already. bool isBound() const { return IdOrDecl.is(); } @@ -305,20 +305,20 @@ public: protected: void printImpl(ASTPrinter &Printer, const PrintOptions &Opts) const; - SourceLoc getLocImpl() const { return Loc; } + SourceLoc getLocImpl() const { return Loc.getBaseNameLoc(); } friend class TypeRepr; }; /// A simple identifier type like "Int". class SimpleIdentTypeRepr : public ComponentIdentTypeRepr { public: - SimpleIdentTypeRepr(SourceLoc Loc, Identifier Id) + SimpleIdentTypeRepr(DeclNameLoc Loc, DeclName Id) : ComponentIdentTypeRepr(TypeReprKind::SimpleIdent, Loc, Id) {} // SmallVector::emplace_back will never need to call this because // we reserve the right size, but it does try statically. SimpleIdentTypeRepr(const SimpleIdentTypeRepr &repr) - : SimpleIdentTypeRepr(repr.getLoc(), repr.getIdentifier()) { + : SimpleIdentTypeRepr(repr.getNameLoc(), repr.getNameRef()) { llvm_unreachable("should not be called dynamically"); } @@ -328,8 +328,8 @@ public: static bool classof(const SimpleIdentTypeRepr *T) { return true; } private: - SourceLoc getStartLocImpl() const { return getIdLoc(); } - SourceLoc getEndLocImpl() const { return getIdLoc(); } + SourceLoc getStartLocImpl() const { return getNameLoc().getStartLoc(); } + SourceLoc getEndLocImpl() const { return getNameLoc().getEndLoc(); } friend class TypeRepr; }; @@ -342,7 +342,7 @@ class GenericIdentTypeRepr final : public ComponentIdentTypeRepr, friend TrailingObjects; SourceRange AngleBrackets; - GenericIdentTypeRepr(SourceLoc Loc, Identifier Id, + GenericIdentTypeRepr(DeclNameLoc Loc, DeclName Id, ArrayRef GenericArgs, SourceRange AngleBrackets) : ComponentIdentTypeRepr(TypeReprKind::GenericIdent, Loc, Id), @@ -359,8 +359,8 @@ class GenericIdentTypeRepr final : public ComponentIdentTypeRepr, public: static GenericIdentTypeRepr *create(const ASTContext &C, - SourceLoc Loc, - Identifier Id, + DeclNameLoc Loc, + DeclName Id, ArrayRef GenericArgs, SourceRange AngleBrackets); @@ -380,7 +380,7 @@ public: static bool classof(const GenericIdentTypeRepr *T) { return true; } private: - SourceLoc getStartLocImpl() const { return getIdLoc(); } + SourceLoc getStartLocImpl() const { return getNameLoc().getStartLoc(); } SourceLoc getEndLocImpl() const { return AngleBrackets.End; } friend class TypeRepr; }; diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp index bec37a1a045..08e03ecfed5 100644 --- a/lib/AST/ASTDumper.cpp +++ b/lib/AST/ASTDumper.cpp @@ -2884,7 +2884,7 @@ public: OS << '\n'; printCommon("component"); PrintWithColorRAII(OS, IdentifierColor) - << " id='" << comp->getIdentifier() << '\''; + << " id='" << comp->getNameRef() << '\''; OS << " bind="; if (comp->isBound()) comp->getBoundDecl()->dumpRef(OS); @@ -3599,7 +3599,7 @@ namespace { if (auto assocType = T->getAssocType()) { printField("assoc_type", assocType->printRef()); } else { - printField("name", T->getName().str()); + printField("name", T->getName()); } printRec("base", T->getBase()); PrintWithColorRAII(OS, ParenthesisColor) << ')'; diff --git a/lib/AST/ASTPrinter.cpp b/lib/AST/ASTPrinter.cpp index fb6237e9dda..320ba9a5b47 100644 --- a/lib/AST/ASTPrinter.cpp +++ b/lib/AST/ASTPrinter.cpp @@ -2834,7 +2834,7 @@ void PrintAST::visitFuncDecl(FuncDecl *decl) { // TypeRepr is not getting 'typechecked'. See // \c resolveTopLevelIdentTypeComponent function in TypeCheckType.cpp. if (auto *simId = dyn_cast_or_null(ResultTyLoc.getTypeRepr())) { - if (simId->getIdentifier() == Ctx.Id_Self) + if (simId->getNameRef().isSimpleName(Ctx.Id_Self)) ResultTyLoc = TypeLoc::withoutLoc(ResultTy); } Printer << " -> "; diff --git a/lib/AST/Attr.cpp b/lib/AST/Attr.cpp index 74fbc4959d2..2a387e5cb1a 100644 --- a/lib/AST/Attr.cpp +++ b/lib/AST/Attr.cpp @@ -88,7 +88,7 @@ void TypeAttributes::getConventionArguments(SmallVectorImpl &buf) const { llvm::raw_svector_ostream stream(buf); auto &convention = ConventionArguments.getValue(); stream << convention.Name; - if (!convention.WitnessMethodProtocol.empty()) { + if (convention.WitnessMethodProtocol) { stream << ": " << convention.WitnessMethodProtocol; return; } diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 0ca9aa1bc53..0bbe74f098d 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -1741,12 +1741,12 @@ static bool isDefaultInitializable(const TypeRepr *typeRepr, ASTContext &ctx) { // Also support the desugared 'Optional' spelling. if (!ctx.isSwiftVersionAtLeast(5)) { if (auto *identRepr = dyn_cast(typeRepr)) { - if (identRepr->getIdentifier() == ctx.Id_Void) + if (identRepr->getNameRef().getBaseIdentifier() == ctx.Id_Void) return true; } if (auto *identRepr = dyn_cast(typeRepr)) { - if (identRepr->getIdentifier() == ctx.Id_Optional && + if (identRepr->getNameRef().getBaseIdentifier() == ctx.Id_Optional && identRepr->getNumGenericArgs() == 1) return true; } diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 12cc5f3e7ca..525a549c120 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1882,7 +1882,7 @@ Type TypeExpr::getInstanceType( } -TypeExpr *TypeExpr::createForDecl(SourceLoc Loc, TypeDecl *Decl, +TypeExpr *TypeExpr::createForDecl(DeclNameLoc Loc, TypeDecl *Decl, DeclContext *DC, bool isImplicit) { ASTContext &C = Decl->getASTContext(); @@ -1895,9 +1895,9 @@ TypeExpr *TypeExpr::createForDecl(SourceLoc Loc, TypeDecl *Decl, return result; } -TypeExpr *TypeExpr::createForMemberDecl(SourceLoc ParentNameLoc, +TypeExpr *TypeExpr::createForMemberDecl(DeclNameLoc ParentNameLoc, TypeDecl *Parent, - SourceLoc NameLoc, + DeclNameLoc NameLoc, TypeDecl *Decl) { ASTContext &C = Decl->getASTContext(); assert(ParentNameLoc.isValid()); @@ -1923,7 +1923,7 @@ TypeExpr *TypeExpr::createForMemberDecl(SourceLoc ParentNameLoc, } TypeExpr *TypeExpr::createForMemberDecl(IdentTypeRepr *ParentTR, - SourceLoc NameLoc, + DeclNameLoc NameLoc, TypeDecl *Decl) { ASTContext &C = Decl->getASTContext(); @@ -1983,7 +1983,7 @@ TypeExpr *TypeExpr::createForSpecializedDecl(IdentTypeRepr *ParentTR, } auto *genericComp = GenericIdentTypeRepr::create(C, - last->getIdLoc(), last->getIdentifier(), + last->getNameLoc(), last->getNameRef(), Args, AngleLocs); genericComp->setValue(last->getBoundDecl(), last->getDeclContext()); components.push_back(genericComp); diff --git a/lib/AST/NameLookup.cpp b/lib/AST/NameLookup.cpp index f8aa721065f..c4d83f80aac 100644 --- a/lib/AST/NameLookup.cpp +++ b/lib/AST/NameLookup.cpp @@ -775,7 +775,8 @@ SelfBoundsFromWhereClauseRequest::evaluate( bool isSelfLHS = false; if (auto typeRepr = req.getSubjectRepr()) { if (auto identTypeRepr = dyn_cast(typeRepr)) - isSelfLHS = (identTypeRepr->getIdentifier() == ctx.Id_Self); + isSelfLHS = (identTypeRepr->getNameRef().getBaseIdentifier() == + ctx.Id_Self); } else if (Type type = req.getSubject()) { isSelfLHS = type->isEqual(dc->getSelfInterfaceType()); } @@ -1889,8 +1890,8 @@ resolveTypeDeclsToNominal(Evaluator &evaluator, if (auto compound = dyn_cast(typeRepr)) { auto components = compound->getComponents(); if (components.size() == 2 && - components[0]->getIdentifier().is("Builtin") && - components[1]->getIdentifier().is("AnyObject")) { + components[0]->getNameRef().isSimpleName("Builtin") && + components[1]->getNameRef().isSimpleName("AnyObject")) { anyObject = true; } } @@ -2018,8 +2019,8 @@ directReferencesForIdentTypeRepr(Evaluator &evaluator, // For the first component, perform unqualified name lookup. if (current.empty()) { current = - directReferencesForUnqualifiedTypeLookup(component->getIdentifier(), - component->getIdLoc(), + directReferencesForUnqualifiedTypeLookup(component->getNameRef(), + component->getLoc(), dc, LookupOuterResults::Excluded); @@ -2034,7 +2035,7 @@ directReferencesForIdentTypeRepr(Evaluator &evaluator, // For subsequent components, perform qualified name lookup. current = directReferencesForQualifiedTypeLookup(evaluator, ctx, current, - component->getIdentifier(), dc); + component->getNameRef(), dc); if (current.empty()) return current; } @@ -2304,7 +2305,7 @@ CustomAttrNominalRequest::evaluate(Evaluator &evaluator, modulesFound.clear(); anyObject = false; decls = directReferencesForUnqualifiedTypeLookup( - identTypeRepr->getIdentifier(), identTypeRepr->getIdLoc(), dc, + identTypeRepr->getNameRef(), identTypeRepr->getLoc(), dc, LookupOuterResults::Included); nominals = resolveTypeDeclsToNominal(evaluator, ctx, decls, modulesFound, anyObject); @@ -2315,7 +2316,7 @@ CustomAttrNominalRequest::evaluate(Evaluator &evaluator, auto moduleName = nominal->getParentModule()->getName(); ctx.Diags.diagnose(typeRepr->getLoc(), diag::warn_property_wrapper_module_scope, - identTypeRepr->getIdentifier(), + identTypeRepr->getNameRef(), moduleName) .fixItInsert(typeRepr->getLoc(), moduleName.str().str() + "."); @@ -2324,7 +2325,8 @@ CustomAttrNominalRequest::evaluate(Evaluator &evaluator, assocType->getFullName()); ComponentIdentTypeRepr *components[2] = { - new (ctx) SimpleIdentTypeRepr(typeRepr->getLoc(), moduleName), + new (ctx) SimpleIdentTypeRepr(identTypeRepr->getNameLoc(), + moduleName), identTypeRepr }; diff --git a/lib/AST/TypeRepr.cpp b/lib/AST/TypeRepr.cpp index c6252349f4b..6077454bf96 100644 --- a/lib/AST/TypeRepr.cpp +++ b/lib/AST/TypeRepr.cpp @@ -79,11 +79,11 @@ void *TypeRepr::operator new(size_t Bytes, const ASTContext &C, return C.Allocate(Bytes, Alignment); } -Identifier ComponentIdentTypeRepr::getIdentifier() const { - if (IdOrDecl.is()) - return IdOrDecl.get(); +DeclName ComponentIdentTypeRepr::getNameRef() const { + if (IdOrDecl.is()) + return IdOrDecl.get(); - return IdOrDecl.get()->getName(); + return IdOrDecl.get()->getFullName(); } static void printTypeRepr(const TypeRepr *TyR, ASTPrinter &Printer, @@ -138,7 +138,7 @@ TypeRepr *CloneVisitor::visitAttributedTypeRepr(AttributedTypeRepr *T) { } TypeRepr *CloneVisitor::visitSimpleIdentTypeRepr(SimpleIdentTypeRepr *T) { - return new (Ctx) SimpleIdentTypeRepr(T->getIdLoc(), T->getIdentifier()); + return new (Ctx) SimpleIdentTypeRepr(T->getNameLoc(), T->getNameRef()); } TypeRepr *CloneVisitor::visitGenericIdentTypeRepr(GenericIdentTypeRepr *T) { @@ -148,7 +148,7 @@ TypeRepr *CloneVisitor::visitGenericIdentTypeRepr(GenericIdentTypeRepr *T) { for (auto &arg : T->getGenericArgs()) { genericArgs.push_back(visit(arg)); } - return GenericIdentTypeRepr::create(Ctx, T->getIdLoc(), T->getIdentifier(), + return GenericIdentTypeRepr::create(Ctx, T->getNameLoc(), T->getNameRef(), genericArgs, T->getAngleBrackets()); } @@ -347,11 +347,11 @@ void ComponentIdentTypeRepr::printImpl(ASTPrinter &Printer, const PrintOptions &Opts) const { if (auto *TD = dyn_cast_or_null(getBoundDecl())) { if (auto MD = dyn_cast(TD)) - Printer.printModuleRef(MD, getIdentifier()); + Printer.printModuleRef(MD, getNameRef().getBaseIdentifier()); else - Printer.printTypeRef(Type(), TD, getIdentifier()); + Printer.printTypeRef(Type(), TD, getNameRef().getBaseIdentifier()); } else { - Printer.printName(getIdentifier()); + Printer.printName(getNameRef().getBaseIdentifier()); } if (auto GenIdT = dyn_cast(this)) @@ -449,8 +449,8 @@ TupleTypeRepr *TupleTypeRepr::createEmpty(const ASTContext &C, } GenericIdentTypeRepr *GenericIdentTypeRepr::create(const ASTContext &C, - SourceLoc Loc, - Identifier Id, + DeclNameLoc Loc, + DeclName Id, ArrayRef GenericArgs, SourceRange AngleBrackets) { auto size = totalSizeToAlloc(GenericArgs.size()); diff --git a/lib/IDE/CodeCompletion.cpp b/lib/IDE/CodeCompletion.cpp index 96ea4f51900..f5b9b2e6584 100644 --- a/lib/IDE/CodeCompletion.cpp +++ b/lib/IDE/CodeCompletion.cpp @@ -1325,8 +1325,8 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks { if (auto *ITR = dyn_cast(ParsedTypeLoc.getTypeRepr())) { SmallVector AccessPath; for (auto Component : ITR->getComponentRange()) - AccessPath.push_back({ Component->getIdentifier(), - Component->getIdLoc() }); + AccessPath.push_back({ Component->getNameRef().getBaseIdentifier(), + Component->getLoc() }); if (auto Module = Context.getLoadedModule(AccessPath)) ParsedTypeLoc.setType(ModuleType::get(Module)); return true; diff --git a/lib/IDE/SourceEntityWalker.cpp b/lib/IDE/SourceEntityWalker.cpp index 364b3be704d..20131c6d5de 100644 --- a/lib/IDE/SourceEntityWalker.cpp +++ b/lib/IDE/SourceEntityWalker.cpp @@ -74,7 +74,7 @@ private: bool passReference(ValueDecl *D, Type Ty, SourceLoc Loc, SourceRange Range, ReferenceMetaData Data); bool passReference(ValueDecl *D, Type Ty, DeclNameLoc Loc, ReferenceMetaData Data); - bool passReference(ModuleEntity Mod, std::pair IdLoc); + bool passReference(ModuleEntity Mod, std::pair IdLoc); bool passSubscriptReference(ValueDecl *D, SourceLoc Loc, ReferenceMetaData Data, bool IsOpenBracket); @@ -490,10 +490,10 @@ bool SemaAnnotator::walkToTypeReprPre(TypeRepr *T) { if (auto IdT = dyn_cast(T)) { if (ValueDecl *VD = IdT->getBoundDecl()) { if (auto *ModD = dyn_cast(VD)) - return passReference(ModD, std::make_pair(IdT->getIdentifier(), - IdT->getIdLoc())); + return passReference(ModD, std::make_pair(IdT->getNameRef(), + IdT->getLoc())); - return passReference(VD, Type(), DeclNameLoc(IdT->getIdLoc()), + return passReference(VD, Type(), IdT->getNameLoc(), ReferenceMetaData(SemaReferenceKind::TypeRef, None)); } } @@ -668,10 +668,10 @@ passReference(ValueDecl *D, Type Ty, SourceLoc BaseNameLoc, SourceRange Range, } bool SemaAnnotator::passReference(ModuleEntity Mod, - std::pair IdLoc) { + std::pair IdLoc) { if (IdLoc.second.isInvalid()) return true; - unsigned NameLen = IdLoc.first.getLength(); + unsigned NameLen = IdLoc.first.getBaseIdentifier().getLength(); CharSourceRange Range{ IdLoc.second, NameLen }; bool Continue = SEWalker.visitModuleReference(Mod, Range); if (!Continue) diff --git a/lib/IDE/SyntaxModel.cpp b/lib/IDE/SyntaxModel.cpp index c3f7aad6a8a..af2e4e13d01 100644 --- a/lib/IDE/SyntaxModel.cpp +++ b/lib/IDE/SyntaxModel.cpp @@ -1108,11 +1108,11 @@ bool ModelASTWalker::walkToTypeReprPre(TypeRepr *T) { return false; } else if (auto IdT = dyn_cast(T)) { - if (!passTokenNodesUntil(IdT->getIdLoc(), + if (!passTokenNodesUntil(IdT->getStartLoc(), ExcludeNodeAtLocation).shouldContinue) return false; if (TokenNodes.empty() || - TokenNodes.front().Range.getStart() != IdT->getIdLoc()) + TokenNodes.front().Range.getStart() != IdT->getStartLoc()) return false; if (!passNode({SyntaxNodeKind::TypeId, TokenNodes.front().Range})) return false; diff --git a/lib/Index/Index.cpp b/lib/Index/Index.cpp index 6f4b2f4d63d..ca90d075fde 100644 --- a/lib/Index/Index.cpp +++ b/lib/Index/Index.cpp @@ -919,7 +919,7 @@ bool IndexSwiftASTWalker::reportRelatedTypeRef(const TypeLoc &Ty, SymbolRoleSet if (auto *T = dyn_cast_or_null(Ty.getTypeRepr())) { auto Comps = T->getComponentRange(); - SourceLoc IdLoc = Comps.back()->getIdLoc(); + SourceLoc IdLoc = Comps.back()->getLoc(); NominalTypeDecl *NTD = nullptr; bool isImplicit = false; if (auto *VD = Comps.back()->getBoundDecl()) { diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 501b48e368b..a1f3c2ce42e 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -2567,15 +2567,12 @@ bool Parser::parseConventionAttributeInternal( diag::convention_attribute_witness_method_expected_colon); return true; } - if (Tok.isNot(tok::identifier)) { - if (!justChecking) - diagnose(Tok, - diag::convention_attribute_witness_method_expected_protocol); - return true; - } - convention.WitnessMethodProtocol = Tok.getText(); - consumeToken(tok::identifier); + DeclNameLoc unusedWitnessMethodProtocolLoc; + convention.WitnessMethodProtocol = parseUnqualifiedDeclBaseName( + /*afterDot=*/false, unusedWitnessMethodProtocolLoc, + diag::convention_attribute_witness_method_expected_protocol + ); } // Parse the ')'. We can't use parseMatchingToken if we're in @@ -3660,7 +3657,7 @@ Parser::parseDecl(ParseDeclOptions Flags, if (auto repr = extension->getExtendedTypeRepr()) { if (auto idRepr = dyn_cast(repr)) { diagnose(extension->getLoc(), diag::note_in_decl_extension, true, - idRepr->getComponentRange().front()->getIdentifier()); + idRepr->getComponentRange().front()->getNameRef()); } } } @@ -4044,7 +4041,7 @@ ParserStatus Parser::parseInheritance(SmallVectorImpl &Inherited, // Add 'AnyObject' to the inherited list. Inherited.push_back( - new (Context) SimpleIdentTypeRepr(classLoc, + new (Context) SimpleIdentTypeRepr(DeclNameLoc(classLoc), Context.getIdentifier("AnyObject"))); continue; } diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index fde40e076e9..0b9866dbb01 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -2278,8 +2278,7 @@ Expr *Parser::parseExprIdentifier() { // global or local declarations here. assert(!TD->getDeclContext()->isTypeContext() || isa(TD)); - E = TypeExpr::createForDecl(loc.getBaseNameLoc(), TD, /*DC*/nullptr, - /*implicit*/false); + E = TypeExpr::createForDecl(loc, TD, /*DC*/nullptr, /*implicit*/false); } else { E = new (Context) DeclRefExpr(D, loc, /*Implicit=*/false); } diff --git a/lib/Parse/ParseType.cpp b/lib/Parse/ParseType.cpp index 19ff1dc0a34..80daf5ca87e 100644 --- a/lib/Parse/ParseType.cpp +++ b/lib/Parse/ParseType.cpp @@ -462,7 +462,7 @@ ParserResult Parser::parseType(Diag<> MessageID, } else { bool isVoid = false; if (const auto Void = dyn_cast(tyR)) { - if (Void->getIdentifier().str() == "Void") { + if (Void->getNameRef().isSimpleName(Context.Id_Void)) { isVoid = true; } } @@ -529,7 +529,7 @@ ParserResult Parser::parseType(Diag<> MessageID, if (auto ident = dyn_cast(T)) { if (auto decl = ident->getBoundDecl()) { if (auto genericParam = dyn_cast(decl)) - ident->overwriteIdentifier(genericParam->getName()); + ident->overwriteNameRef(genericParam->getName()); } } return true; @@ -666,17 +666,12 @@ ParserResult Parser::parseTypeIdentifier() { SmallVector ComponentsR; SourceLoc EndLoc; while (true) { - SourceLoc Loc; - Identifier Name; - if (Tok.is(tok::kw_Self)) { - Loc = consumeIdentifier(&Name); - } else { - // FIXME: specialize diagnostic for 'Type': type cannot start with - // 'metatype' - // FIXME: offer a fixit: 'self' -> 'Self' - if (parseIdentifier(Name, Loc, diag::expected_identifier_in_dotted_type)) - Status.setIsParseError(); - } + DeclNameLoc Loc; + DeclName Name = parseUnqualifiedDeclBaseName( + /*afterDot=*/false, Loc, + diag::expected_identifier_in_dotted_type); + if (!Name) + Status.setIsParseError(); if (Loc.isValid()) { SourceLoc LAngle, RAngle; @@ -686,7 +681,7 @@ ParserResult Parser::parseTypeIdentifier() { if (genericArgsStatus.isError()) return genericArgsStatus; } - EndLoc = Loc; + EndLoc = Loc.getEndLoc(); ComponentIdentTypeRepr *CompT; if (!GenericArgs.empty()) @@ -724,7 +719,7 @@ ParserResult Parser::parseTypeIdentifier() { if (!ComponentsR.empty()) { // Lookup element #0 through our current scope chains in case it is some // thing local (this returns null if nothing is found). - if (auto Entry = lookupInScope(ComponentsR[0]->getIdentifier())) + if (auto Entry = lookupInScope(ComponentsR[0]->getNameRef())) if (auto *TD = dyn_cast(Entry)) ComponentsR[0]->setValue(TD, nullptr); diff --git a/lib/ParseSIL/ParseSIL.cpp b/lib/ParseSIL/ParseSIL.cpp index 7d82905fea8..65d86dced3d 100644 --- a/lib/ParseSIL/ParseSIL.cpp +++ b/lib/ParseSIL/ParseSIL.cpp @@ -902,7 +902,7 @@ namespace { bool walkToTypeReprPre(TypeRepr *Ty) override { auto *T = dyn_cast_or_null(Ty); auto Comp = T->getComponentRange().front(); - if (auto Entry = P.lookupInScope(Comp->getIdentifier())) + if (auto Entry = P.lookupInScope(Comp->getNameRef())) if (auto *TD = dyn_cast(Entry)) { Comp->setValue(TD, nullptr); return false; @@ -1703,7 +1703,7 @@ static void bindProtocolSelfInTypeRepr(TypeLoc &TL, ProtocolDecl *proto) { virtual bool walkToTypeReprPre(TypeRepr *T) override { if (auto ident = dyn_cast(T)) { auto firstComponent = ident->getComponentRange().front(); - if (firstComponent->getIdentifier() == selfId) + if (firstComponent->getNameRef().isSimpleName(selfId)) firstComponent->setValue(selfParam, proto); } diff --git a/lib/Sema/DerivedConformanceCodable.cpp b/lib/Sema/DerivedConformanceCodable.cpp index 0f43af7018c..68d9577b2fd 100644 --- a/lib/Sema/DerivedConformanceCodable.cpp +++ b/lib/Sema/DerivedConformanceCodable.cpp @@ -421,7 +421,7 @@ static CallExpr *createContainerKeyedByCall(ASTContext &C, DeclContext *DC, paramList); // CodingKeys.self expr - auto *codingKeysExpr = TypeExpr::createForDecl(SourceLoc(), + auto *codingKeysExpr = TypeExpr::createForDecl(DeclNameLoc(), param, param->getDeclContext(), /*Implicit=*/true); diff --git a/lib/Sema/DerivedConformanceError.cpp b/lib/Sema/DerivedConformanceError.cpp index ecca344fee6..baf20f85e8f 100644 --- a/lib/Sema/DerivedConformanceError.cpp +++ b/lib/Sema/DerivedConformanceError.cpp @@ -42,7 +42,7 @@ deriveBodyBridgedNSError_enum_nsErrorDomain(AbstractFunctionDecl *domainDecl, auto self = domainDecl->getImplicitSelfDecl(); auto selfRef = new (C) DeclRefExpr(self, DeclNameLoc(), /*implicit*/ true); - auto stringType = TypeExpr::createForDecl(SourceLoc(), C.getStringDecl(), + auto stringType = TypeExpr::createForDecl(DeclNameLoc(), C.getStringDecl(), domainDecl, /*implicit*/ true); auto initReflectingCall = CallExpr::createImplicit(C, stringType, diff --git a/lib/Sema/TypeCheckConstraints.cpp b/lib/Sema/TypeCheckConstraints.cpp index 0076f97ab9c..eb9c508418a 100644 --- a/lib/Sema/TypeCheckConstraints.cpp +++ b/lib/Sema/TypeCheckConstraints.cpp @@ -458,7 +458,7 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, DeclContext *DC) { // Process UnresolvedDeclRefExpr by doing an unqualified lookup. DeclName Name = UDRE->getName(); - SourceLoc Loc = UDRE->getLoc(); + DeclNameLoc Loc = UDRE->getNameLoc(); // Perform standard value name lookup. NameLookupOptions lookupOptions = defaultUnqualifiedLookupOptions; @@ -467,7 +467,8 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, if (shouldConsiderOuterResultsFor(Name)) lookupOptions |= NameLookupFlags::IncludeOuterResults; - auto Lookup = TypeChecker::lookupUnqualified(DC, Name, Loc, lookupOptions); + auto Lookup = TypeChecker::lookupUnqualified(DC, Name, Loc.getBaseNameLoc(), + lookupOptions); auto &Context = DC->getASTContext(); if (!Lookup) { @@ -485,7 +486,8 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, relookupOptions |= NameLookupFlags::KnownPrivate; relookupOptions |= NameLookupFlags::IgnoreAccessControl; auto inaccessibleResults = - TypeChecker::lookupUnqualified(DC, Name, Loc, relookupOptions); + TypeChecker::lookupUnqualified(DC, Name, Loc.getBaseNameLoc(), + relookupOptions); if (inaccessibleResults) { // FIXME: What if the unviable candidates have different levels of access? const ValueDecl *first = inaccessibleResults.front().getValueDecl(); @@ -546,8 +548,9 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, if (typeContext->getSelfClassDecl()) SelfType = DynamicSelfType::get(SelfType, Context); SelfType = DC->mapTypeIntoContext(SelfType); - return new (Context) TypeExpr(TypeLoc(new (Context) - FixedTypeRepr(SelfType, Loc))); + return new (Context) TypeExpr( + TypeLoc(new (Context) FixedTypeRepr(SelfType, + Loc.getBaseNameLoc()))); } } @@ -573,7 +576,7 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, .diagnose(Loc, diag::confusable_character, UDRE->getName().isOperator(), simpleName.str(), expectedIdentifier) - .fixItReplace(Loc, expectedIdentifier); + .fixItReplace(Loc.getBaseNameLoc(), expectedIdentifier); } // TODO: consider recovering from here. We may want some way to suppress @@ -595,7 +598,7 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, if (Loc.isValid() && D->getLoc().isValid() && D->getDeclContext()->isLocalContext() && D->getDeclContext() == DC && - Context.SourceMgr.isBeforeInBuffer(Loc, D->getLoc()) && + Context.SourceMgr.isBeforeInBuffer(Loc.getBaseNameLoc(), D->getLoc()) && !isa(D)) { localDeclAfterUse = D; return false; @@ -615,7 +618,7 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, if (!lookupOptions.contains(NameLookupFlags::IncludeOuterResults)) { auto option = lookupOptions; option |= NameLookupFlags::IncludeOuterResults; - Lookup = lookupUnqualified(DC, Name, Loc, option); + Lookup = lookupUnqualified(DC, Name, Loc.getBaseNameLoc(), option); } while (localDeclAfterUse) { @@ -1397,7 +1400,7 @@ TypeExpr *PreCheckExpression::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) { return nullptr; auto Name = UDE->getName().getBaseIdentifier(); - auto NameLoc = UDE->getNameLoc().getBaseNameLoc(); + auto NameLoc = UDE->getNameLoc(); // Qualified type lookup with a module base is represented as a DeclRefExpr // and not a TypeExpr. @@ -1415,8 +1418,7 @@ TypeExpr *PreCheckExpression::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) { // If there is no nested type with this name, we have a lookup of // a non-type member, so leave the expression as-is. if (Result.size() == 1) { - return TypeExpr::createForMemberDecl(DRE->getNameLoc().getBaseNameLoc(), - TD, NameLoc, + return TypeExpr::createForMemberDecl(DRE->getNameLoc(), TD, NameLoc, Result.front().Member); } } @@ -1435,7 +1437,8 @@ TypeExpr *PreCheckExpression::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) { // Fold 'T.Protocol' into a protocol metatype. if (Name == getASTContext().Id_Protocol) { auto *NewTypeRepr = - new (getASTContext()) ProtocolTypeRepr(InnerTypeRepr, NameLoc); + new (getASTContext()) ProtocolTypeRepr(InnerTypeRepr, + NameLoc.getBaseNameLoc()); return new (getASTContext()) TypeExpr(TypeLoc(NewTypeRepr, Type())); } @@ -1443,7 +1446,8 @@ TypeExpr *PreCheckExpression::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) { // or an ordinary metatype otherwise. if (Name == getASTContext().Id_Type) { auto *NewTypeRepr = - new (getASTContext()) MetatypeTypeRepr(InnerTypeRepr, NameLoc); + new (getASTContext()) MetatypeTypeRepr(InnerTypeRepr, + NameLoc.getBaseNameLoc()); return new (getASTContext()) TypeExpr(TypeLoc(NewTypeRepr, Type())); } @@ -1671,7 +1675,7 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) { auto diagnoseMissingParens = [](ASTContext &ctx, TypeRepr *tyR) { bool isVoid = false; if (const auto Void = dyn_cast(tyR)) { - if (Void->getIdentifier() == ctx.Id_Void) { + if (Void->getNameRef().isSimpleName(ctx.Id_Void)) { isVoid = true; } } diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp index 8e32d9d7d83..8afee4886a9 100644 --- a/lib/Sema/TypeCheckDecl.cpp +++ b/lib/Sema/TypeCheckDecl.cpp @@ -1349,7 +1349,7 @@ PrecedenceGroupDecl *TypeChecker::lookupPrecedenceGroup(DeclContext *dc, static NominalTypeDecl *resolveSingleNominalTypeDecl( DeclContext *DC, SourceLoc loc, Identifier ident, ASTContext &Ctx, TypeResolutionFlags flags = TypeResolutionFlags(0)) { - auto *TyR = new (Ctx) SimpleIdentTypeRepr(loc, ident); + auto *TyR = new (Ctx) SimpleIdentTypeRepr(DeclNameLoc(loc), ident); TypeLoc typeLoc = TypeLoc(TyR); TypeResolutionOptions options = TypeResolverContext::TypeAliasDecl; diff --git a/lib/Sema/TypeCheckPattern.cpp b/lib/Sema/TypeCheckPattern.cpp index 00fdb45a141..521fe8c8ee5 100644 --- a/lib/Sema/TypeCheckPattern.cpp +++ b/lib/Sema/TypeCheckPattern.cpp @@ -174,7 +174,7 @@ struct ExprToIdentTypeRepr : public ASTVisitor // Get the declared type. if (auto *td = dyn_cast(dre->getDecl())) { components.push_back( - new (C) SimpleIdentTypeRepr(dre->getLoc(), td->getName())); + new (C) SimpleIdentTypeRepr(dre->getNameLoc(), td->getName())); components.back()->setValue(td, nullptr); return true; } @@ -185,8 +185,8 @@ struct ExprToIdentTypeRepr : public ASTVisitor assert(components.empty() && "decl ref should be root element of expr"); // Track the AST location of the component. components.push_back( - new (C) SimpleIdentTypeRepr(udre->getLoc(), - udre->getName().getBaseIdentifier())); + new (C) SimpleIdentTypeRepr(udre->getNameLoc(), + udre->getName())); return true; } @@ -198,8 +198,8 @@ struct ExprToIdentTypeRepr : public ASTVisitor // Track the AST location of the new component. components.push_back( - new (C) SimpleIdentTypeRepr(ude->getLoc(), - ude->getName().getBaseIdentifier())); + new (C) SimpleIdentTypeRepr(ude->getNameLoc(), + ude->getName())); return true; } @@ -215,8 +215,8 @@ struct ExprToIdentTypeRepr : public ASTVisitor argTypeReprs.push_back(arg.getTypeRepr()); auto origComponent = components.back(); components.back() = - GenericIdentTypeRepr::create(C, origComponent->getIdLoc(), - origComponent->getIdentifier(), argTypeReprs, + GenericIdentTypeRepr::create(C, origComponent->getNameLoc(), + origComponent->getNameRef(), argTypeReprs, SourceRange(use->getLAngleLoc(), use->getRAngleLoc())); @@ -547,8 +547,7 @@ public: if (components.empty()) { // Only one component. Try looking up an enum element in context. referencedElement - = lookupUnqualifiedEnumMemberElement(DC, - tailComponent->getIdentifier(), + = lookupUnqualifiedEnumMemberElement(DC, tailComponent->getNameRef(), tailComponent->getLoc()); if (!referencedElement) return nullptr; @@ -572,7 +571,7 @@ public: referencedElement = lookupEnumMemberElement(DC, enumTy, - tailComponent->getIdentifier(), + tailComponent->getNameRef(), tailComponent->getLoc()); if (!referencedElement) return nullptr; @@ -586,8 +585,8 @@ public: auto *subPattern = getSubExprPattern(ce->getArg()); return new (Context) EnumElementPattern( - loc, SourceLoc(), DeclNameLoc(tailComponent->getIdLoc()), - tailComponent->getIdentifier(), referencedElement, + loc, SourceLoc(), tailComponent->getNameLoc(), + tailComponent->getNameRef(), referencedElement, subPattern); } }; diff --git a/lib/Sema/TypeCheckType.cpp b/lib/Sema/TypeCheckType.cpp index db14dafa1b0..16606e77e02 100644 --- a/lib/Sema/TypeCheckType.cpp +++ b/lib/Sema/TypeCheckType.cpp @@ -140,9 +140,13 @@ Type TypeResolution::resolveDependentMemberType( Type baseTy, DeclContext *DC, SourceRange baseRange, ComponentIdentTypeRepr *ref) const { + // FIXME(ModQual): Reject qualified names immediately; they cannot be + // dependent member types. + Identifier refIdentifier = ref->getNameRef().getBaseIdentifier(); + switch (stage) { case TypeResolutionStage::Structural: - return DependentMemberType::get(baseTy, ref->getIdentifier()); + return DependentMemberType::get(baseTy, refIdentifier); case TypeResolutionStage::Contextual: llvm_unreachable("Dependent type after archetype substitution"); @@ -168,14 +172,13 @@ Type TypeResolution::resolveDependentMemberType( // Look for a nested type with the given name. if (auto nestedType = - baseEquivClass->lookupNestedType(*builder, ref->getIdentifier())) { + baseEquivClass->lookupNestedType(*builder, refIdentifier)) { // Record the type we found. ref->setValue(nestedType, nullptr); } else { // Resolve the base to a potential archetype. // Perform typo correction. - TypoCorrectionResults corrections(ref->getIdentifier(), - DeclNameLoc(ref->getIdLoc())); + TypoCorrectionResults corrections(ref->getNameRef(), ref->getNameLoc()); TypeChecker::performTypoCorrection(DC, DeclRefKind::Ordinary, MetatypeType::get(baseTy), NameLookupFlags::ProtocolMembers, @@ -189,8 +192,8 @@ Type TypeResolution::resolveDependentMemberType( // If we don't have a single result, complain and fail. if (!singleType) { - Identifier name = ref->getIdentifier(); - SourceLoc nameLoc = ref->getIdLoc(); + auto name = ref->getNameRef(); + auto nameLoc = ref->getNameLoc(); ctx.Diags.diagnose(nameLoc, diag::invalid_member_type, name, baseTy) .highlight(baseRange); corrections.noteAllCandidates(); @@ -199,14 +202,14 @@ Type TypeResolution::resolveDependentMemberType( } // We have a single type result. Suggest it. - ctx.Diags.diagnose(ref->getIdLoc(), diag::invalid_member_type_suggest, - baseTy, ref->getIdentifier(), - singleType->getBaseName().getIdentifier()) - .fixItReplace(ref->getIdLoc(), + ctx.Diags.diagnose(ref->getNameLoc(), diag::invalid_member_type_suggest, + baseTy, ref->getNameRef(), + singleType->getBaseName()) + .fixItReplace(ref->getNameLoc().getSourceRange(), singleType->getBaseName().userFacingName()); // Correct to the single type result. - ref->overwriteIdentifier(singleType->getBaseName().getIdentifier()); + ref->overwriteNameRef(singleType->getFullName()); ref->setValue(singleType, nullptr); } @@ -705,7 +708,7 @@ static Type applyGenericArguments(Type type, ComponentIdentTypeRepr *comp, TypeResolutionOptions options) { auto dc = resolution.getDeclContext(); - auto loc = comp->getIdLoc(); + auto loc = comp->getNameLoc().getBaseNameLoc(); auto *generic = dyn_cast(comp); if (!generic) { @@ -1012,7 +1015,8 @@ static Type resolveTypeDecl(TypeDecl *typeDecl, auto fromDC = resolution.getDeclContext(); assert(fromDC && "No declaration context for type resolution?"); maybeDiagnoseBadConformanceRef(fromDC, foundDC->getDeclaredInterfaceType(), - comp->getIdLoc(), typeDecl); + comp->getNameLoc().getBaseNameLoc(), + typeDecl); } return applyGenericArguments(type, resolution, comp, options); @@ -1067,7 +1071,7 @@ static Type diagnoseUnknownType(TypeResolution resolution, // Unqualified lookup case. if (parentType.isNull()) { - if (comp->getIdentifier() == ctx.Id_Self && + if (comp->getNameRef().isSimpleName(ctx.Id_Self) && !isa(comp)) { DeclContext *nominalDC = nullptr; NominalTypeDecl *nominal = nullptr; @@ -1079,18 +1083,18 @@ static Type diagnoseUnknownType(TypeResolution resolution, // Produce a Fix-It replacing 'Self' with the nominal type name. auto name = getDeclNameFromContext(dc, nominal); - diags.diagnose(comp->getIdLoc(), diag::dynamic_self_invalid, name) - .fixItReplace(comp->getIdLoc(), name); + diags.diagnose(comp->getNameLoc(), diag::dynamic_self_invalid, name) + .fixItReplace(comp->getNameLoc().getSourceRange(), name); auto type = resolution.mapTypeIntoContext( dc->getInnermostTypeContext()->getSelfInterfaceType()); - comp->overwriteIdentifier(nominal->getName()); + comp->overwriteNameRef(nominal->getName()); comp->setValue(nominal, nominalDC->getParent()); return type; } // Attempt to refer to 'Self' from a free function. - diags.diagnose(comp->getIdLoc(), diag::dynamic_self_non_method, + diags.diagnose(comp->getNameLoc(), diag::dynamic_self_non_method, dc->getParent()->isLocalContext()); return ErrorType::get(ctx); @@ -1101,13 +1105,13 @@ static Type diagnoseUnknownType(TypeResolution resolution, relookupOptions |= NameLookupFlags::KnownPrivate; relookupOptions |= NameLookupFlags::IgnoreAccessControl; auto inaccessibleResults = - TypeChecker::lookupUnqualifiedType(dc, comp->getIdentifier(), - comp->getIdLoc(), relookupOptions); + TypeChecker::lookupUnqualifiedType(dc, comp->getNameRef(), + comp->getLoc(), relookupOptions); if (!inaccessibleResults.empty()) { // FIXME: What if the unviable candidates have different levels of access? auto first = cast(inaccessibleResults.front().getValueDecl()); - diags.diagnose(comp->getIdLoc(), diag::candidate_inaccessible, - comp->getIdentifier(), first->getFormalAccess()); + diags.diagnose(comp->getNameLoc(), diag::candidate_inaccessible, + first->getBaseName(), first->getFormalAccess()); // FIXME: If any of the candidates (usually just one) are in the same // module we could offer a fix-it. @@ -1121,22 +1125,22 @@ static Type diagnoseUnknownType(TypeResolution resolution, } // Fallback. - SourceLoc L = comp->getIdLoc(); - SourceRange R = SourceRange(comp->getIdLoc()); + auto L = comp->getNameLoc(); + SourceRange R = comp->getNameLoc().getSourceRange(); // Check if the unknown type is in the type remappings. auto &Remapped = ctx.RemappedTypes; - auto TypeName = comp->getIdentifier().str(); + auto TypeName = comp->getNameRef().getBaseIdentifier().str(); auto I = Remapped.find(TypeName); if (I != Remapped.end()) { auto RemappedTy = I->second->getString(); diags.diagnose(L, diag::use_undeclared_type_did_you_mean, - comp->getIdentifier(), RemappedTy) + comp->getNameRef(), RemappedTy) .highlight(R) .fixItReplace(R, RemappedTy); // Replace the computed type with the suggested type. - comp->overwriteIdentifier(ctx.getIdentifier(RemappedTy)); + comp->overwriteNameRef(ctx.getIdentifier(RemappedTy)); // HACK: 'NSUInteger' suggests both 'UInt' and 'Int'. if (TypeName == ctx.getSwiftName(KnownFoundationEntity::NSUInteger)) { @@ -1148,7 +1152,7 @@ static Type diagnoseUnknownType(TypeResolution resolution, } diags.diagnose(L, diag::use_undeclared_type, - comp->getIdentifier()) + comp->getNameRef()) .highlight(R); return ErrorType::get(ctx); @@ -1156,8 +1160,8 @@ static Type diagnoseUnknownType(TypeResolution resolution, // Qualified lookup case. if (!parentType->mayHaveMembers()) { - diags.diagnose(comp->getIdLoc(), diag::invalid_member_type, - comp->getIdentifier(), parentType) + diags.diagnose(comp->getNameLoc(), diag::invalid_member_type, + comp->getNameRef(), parentType) .highlight(parentRange); return ErrorType::get(ctx); } @@ -1167,13 +1171,13 @@ static Type diagnoseUnknownType(TypeResolution resolution, relookupOptions |= NameLookupFlags::KnownPrivate; relookupOptions |= NameLookupFlags::IgnoreAccessControl; auto inaccessibleMembers = - TypeChecker::lookupMemberType(dc, parentType, comp->getIdentifier(), + TypeChecker::lookupMemberType(dc, parentType, comp->getNameRef(), relookupOptions); if (inaccessibleMembers) { // FIXME: What if the unviable candidates have different levels of access? const TypeDecl *first = inaccessibleMembers.front().Member; - diags.diagnose(comp->getIdLoc(), diag::candidate_inaccessible, - comp->getIdentifier(), first->getFormalAccess()); + diags.diagnose(comp->getNameLoc(), diag::candidate_inaccessible, + first->getBaseName(), first->getFormalAccess()); // FIXME: If any of the candidates (usually just one) are in the same module // we could offer a fix-it. @@ -1190,8 +1194,8 @@ static Type diagnoseUnknownType(TypeResolution resolution, // Lookup into a type. if (auto moduleType = parentType->getAs()) { - diags.diagnose(comp->getIdLoc(), diag::no_module_type, - comp->getIdentifier(), moduleType->getModule()->getName()); + diags.diagnose(comp->getNameLoc(), diag::no_module_type, + comp->getNameRef(), moduleType->getModule()->getName()); } else { LookupResult memberLookup; // Let's try to lookup given identifier as a member of the parent type, @@ -1202,19 +1206,19 @@ static Type diagnoseUnknownType(TypeResolution resolution, memberLookupOptions |= NameLookupFlags::KnownPrivate; memberLookup = TypeChecker::lookupMember(dc, parentType, - comp->getIdentifier(), + comp->getNameRef(), memberLookupOptions); // Looks like this is not a member type, but simply a member of parent type. if (!memberLookup.empty()) { auto member = memberLookup[0].getValueDecl(); - diags.diagnose(comp->getIdLoc(), diag::invalid_member_reference, - member->getDescriptiveKind(), comp->getIdentifier(), + diags.diagnose(comp->getNameLoc(), diag::invalid_member_reference, + member->getDescriptiveKind(), member->getFullName(), parentType) .highlight(parentRange); } else { - diags.diagnose(comp->getIdLoc(), diag::invalid_member_type, - comp->getIdentifier(), parentType) + diags.diagnose(comp->getNameLoc(), diag::invalid_member_type, + comp->getNameRef(), parentType) .highlight(parentRange); // Note where the type was defined, this can help diagnose if the user // expected name lookup to find a module when there's a conflicting type. @@ -1297,10 +1301,10 @@ resolveTopLevelIdentTypeComponent(TypeResolution resolution, // Resolve the first component, which is the only one that requires // unqualified name lookup. auto DC = resolution.getDeclContext(); - auto id = comp->getIdentifier(); + auto id = comp->getNameRef(); // Dynamic 'Self' in the result type of a function body. - if (id == ctx.Id_Self) { + if (id.isSimpleName(ctx.Id_Self)) { if (auto *typeDC = DC->getInnermostTypeContext()) { // FIXME: The passed-in TypeRepr should get 'typechecked' as well. // The issue is though that ComponentIdentTypeRepr only accepts a ValueDecl @@ -1323,9 +1327,7 @@ resolveTopLevelIdentTypeComponent(TypeResolution resolution, NameLookupOptions lookupOptions = defaultUnqualifiedLookupOptions; if (options.contains(TypeResolutionFlags::KnownNonCascadingDependency)) lookupOptions |= NameLookupFlags::KnownPrivate; - auto globals = TypeChecker::lookupUnqualifiedType(DC, - id, - comp->getIdLoc(), + auto globals = TypeChecker::lookupUnqualifiedType(DC, id, comp->getLoc(), lookupOptions); // Process the names we found. @@ -1364,9 +1366,9 @@ resolveTopLevelIdentTypeComponent(TypeResolution resolution, // FIXME: We could recover by looking at later components. if (isAmbiguous) { if (!options.contains(TypeResolutionFlags::SilenceErrors)) { - diags.diagnose(comp->getIdLoc(), diag::ambiguous_type_base, - comp->getIdentifier()) - .highlight(comp->getIdLoc()); + diags.diagnose(comp->getNameLoc(), diag::ambiguous_type_base, + comp->getNameRef()) + .highlight(comp->getNameLoc().getSourceRange()); for (auto entry : globals) { entry.getValueDecl()->diagnose(diag::found_candidate); } @@ -1392,7 +1394,7 @@ resolveTopLevelIdentTypeComponent(TypeResolution resolution, } static void diagnoseAmbiguousMemberType(Type baseTy, SourceRange baseRange, - Identifier name, SourceLoc nameLoc, + DeclName name, DeclNameLoc nameLoc, LookupTypeResult &lookup) { ASTContext &ctx = baseTy->getASTContext(); auto &diags = ctx.Diags; @@ -1431,12 +1433,12 @@ static Type resolveNestedIdentTypeComponent( diagnoseUnboundGenericType(parentTy, parentRange.End); else if (parentTy->isExistentialType() && isa(member)) { - diags.diagnose(comp->getIdLoc(), diag::assoc_type_outside_of_protocol, - comp->getIdentifier()); + diags.diagnose(comp->getNameLoc(), diag::assoc_type_outside_of_protocol, + comp->getNameRef()); } else if (parentTy->isExistentialType() && isa(member)) { - diags.diagnose(comp->getIdLoc(), diag::typealias_outside_of_protocol, - comp->getIdentifier()); + diags.diagnose(comp->getNameLoc(), diag::typealias_outside_of_protocol, + comp->getNameRef()); } } @@ -1515,7 +1517,7 @@ static Type resolveNestedIdentTypeComponent( LookupTypeResult memberTypes; if (parentTy->mayHaveMembers()) memberTypes = TypeChecker::lookupMemberType(DC, parentTy, - comp->getIdentifier(), + comp->getNameRef(), lookupOptions); // Name lookup was ambiguous. Complain. @@ -1523,8 +1525,8 @@ static Type resolveNestedIdentTypeComponent( // that resolves things. But do we really want that to succeed? if (memberTypes.size() > 1) { if (!options.contains(TypeResolutionFlags::SilenceErrors)) - diagnoseAmbiguousMemberType(parentTy, parentRange, comp->getIdentifier(), - comp->getIdLoc(), memberTypes); + diagnoseAmbiguousMemberType(parentTy, parentRange, comp->getNameRef(), + comp->getNameLoc(), memberTypes); return ErrorType::get(ctx); } @@ -1571,8 +1573,8 @@ static Type resolveIdentTypeComponent( Type parentTy = resolveIdentTypeComponent(resolution, parentComps, options); if (!parentTy || parentTy->hasError()) return parentTy; - SourceRange parentRange(parentComps.front()->getIdLoc(), - parentComps.back()->getSourceRange().End); + SourceRange parentRange(parentComps.front()->getStartLoc(), + parentComps.back()->getEndLoc()); // Resolve the nested type. return resolveNestedIdentTypeComponent(resolution, parentTy, @@ -1590,7 +1592,8 @@ static bool diagnoseAvailability(IdentTypeRepr *IdType, auto componentRange = IdType->getComponentRange(); for (auto comp : componentRange) { if (auto *typeDecl = comp->getBoundDecl()) { - if (diagnoseDeclAvailability(typeDecl, DC, comp->getIdLoc(), flags)) { + if (diagnoseDeclAvailability(typeDecl, DC, + comp->getNameLoc().getSourceRange(), flags)) { return true; } } @@ -1643,9 +1646,9 @@ Type TypeChecker::resolveIdentifierType( if (auto moduleTy = result->getAs()) { if (!options.contains(TypeResolutionFlags::SilenceErrors)) { auto moduleName = moduleTy->getModule()->getName(); - diags.diagnose(Components.back()->getIdLoc(), + diags.diagnose(Components.back()->getNameLoc(), diag::use_undeclared_type, moduleName); - diags.diagnose(Components.back()->getIdLoc(), + diags.diagnose(Components.back()->getNameLoc(), diag::note_module_as_type, moduleName); } Components.back()->setInvalid(); @@ -2195,7 +2198,7 @@ Type TypeResolver::resolveAttributedType(TypeAttributes &attrs, auto protocolName = attrs.ConventionArguments.getValue().WitnessMethodProtocol; witnessMethodProtocol = new (Context) SimpleIdentTypeRepr( - SourceLoc(), Context.getIdentifier(protocolName)); + DeclNameLoc(), protocolName); } } @@ -2549,7 +2552,7 @@ Type TypeResolver::resolveASTFunctionType( if (args->getNumElements() == 1) { if (const auto Void = dyn_cast(args->getElementType(0))) { - if (Void->getIdentifier().str() == "Void") { + if (Void->getNameRef().isSimpleName(Context.Id_Void)) { diagnose(args->getStartLoc(), diag::paren_void_probably_void) .fixItReplace(args->getSourceRange(), "()"); repr->setWarned(); @@ -3509,7 +3512,8 @@ public: auto comp = T->getComponentRange().back(); if (auto *proto = dyn_cast_or_null(comp->getBoundDecl())) { if (!proto->existentialTypeSupported()) { - Ctx.Diags.diagnose(comp->getIdLoc(), diag::unsupported_existential_type, + Ctx.Diags.diagnose(comp->getNameLoc(), + diag::unsupported_existential_type, proto->getName()); T->setInvalid(); } @@ -3526,7 +3530,7 @@ public: if (protoDecl->existentialTypeSupported()) continue; - Ctx.Diags.diagnose(comp->getIdLoc(), + Ctx.Diags.diagnose(comp->getNameLoc(), diag::unsupported_existential_type, protoDecl->getName()); T->setInvalid();