From addbe3e5eddfb6585ae878c692313cf5e75ef31c Mon Sep 17 00:00:00 2001 From: Brent Royal-Gordon Date: Tue, 10 Dec 2019 19:46:10 -0800 Subject: [PATCH] [NFC] Thread DeclNameRef through most of the compiler This huge commit contains as many of the mechanical changes as possible. --- include/swift/AST/Attr.h | 62 ++++----- include/swift/AST/DiagnosticsCommon.def | 2 +- include/swift/AST/DiagnosticsParse.def | 2 +- include/swift/AST/DiagnosticsSema.def | 118 +++++++++--------- include/swift/AST/Expr.h | 36 +++--- include/swift/AST/Pattern.h | 8 +- include/swift/AST/TypeRepr.h | 14 +-- include/swift/Parse/Parser.h | 23 ++-- include/swift/Parse/Scope.h | 7 +- include/swift/Sema/IDETypeChecking.h | 5 + lib/AST/Attr.cpp | 36 +++--- lib/AST/Expr.cpp | 16 +-- lib/AST/GenericSignatureBuilder.cpp | 2 +- lib/AST/NameLookup.cpp | 2 +- lib/AST/TypeRepr.cpp | 10 +- lib/ClangImporter/ImportDecl.cpp | 2 +- lib/IDE/ExprContextAnalysis.cpp | 20 +-- lib/IDE/SourceEntityWalker.cpp | 4 +- lib/Parse/ParseDecl.cpp | 30 +++-- lib/Parse/ParseExpr.cpp | 38 +++--- lib/Parse/ParseType.cpp | 4 +- lib/PrintAsObjC/DeclAndTypePrinter.cpp | 4 +- lib/Sema/BuilderTransform.cpp | 7 +- lib/Sema/CSApply.cpp | 2 +- lib/Sema/CSDiag.cpp | 15 +-- lib/Sema/CSDiagnostics.cpp | 13 +- lib/Sema/CSDiagnostics.h | 25 ++-- lib/Sema/CSFix.cpp | 16 +-- lib/Sema/CSFix.h | 44 +++---- lib/Sema/CSGen.cpp | 16 +-- lib/Sema/CSSimplify.cpp | 33 ++--- lib/Sema/Constraint.cpp | 8 +- lib/Sema/Constraint.h | 10 +- lib/Sema/ConstraintSystem.cpp | 12 +- lib/Sema/ConstraintSystem.h | 12 +- lib/Sema/DebuggerTestingTransform.cpp | 8 +- lib/Sema/DerivedConformanceCodable.cpp | 3 +- lib/Sema/DerivedConformanceCodingKey.cpp | 2 +- .../DerivedConformanceEquatableHashable.cpp | 10 +- .../DerivedConformanceRawRepresentable.cpp | 2 +- lib/Sema/InstrumenterSupport.cpp | 6 +- lib/Sema/InstrumenterSupport.h | 6 +- lib/Sema/MiscDiagnostics.cpp | 2 +- lib/Sema/PCMacro.cpp | 10 +- lib/Sema/PlaygroundTransform.cpp | 32 ++--- lib/Sema/TypeCheckAttr.cpp | 24 ++-- lib/Sema/TypeCheckConstraints.cpp | 39 +++--- lib/Sema/TypeCheckDecl.cpp | 3 +- lib/Sema/TypeCheckDeclPrimary.cpp | 3 +- lib/Sema/TypeCheckExpr.cpp | 4 +- lib/Sema/TypeCheckExprObjC.cpp | 15 ++- lib/Sema/TypeCheckNameLookup.cpp | 22 ++-- lib/Sema/TypeCheckPattern.cpp | 14 +-- lib/Sema/TypeCheckProtocol.cpp | 22 ++-- lib/Sema/TypeCheckProtocolInference.cpp | 4 +- lib/Sema/TypeCheckREPL.cpp | 7 +- lib/Sema/TypeCheckStmt.cpp | 4 +- lib/Sema/TypeCheckStorage.cpp | 2 +- lib/Sema/TypeCheckType.cpp | 10 +- lib/Sema/TypeChecker.cpp | 2 +- lib/Sema/TypeChecker.h | 10 +- lib/Sema/TypoCorrection.h | 8 +- lib/Serialization/Deserialization.cpp | 5 +- tools/swift-ast-script/ASTScriptEvaluator.cpp | 5 +- tools/swift-ide-test/swift-ide-test.cpp | 5 +- unittests/AST/SourceLocTests.cpp | 22 ++-- 66 files changed, 505 insertions(+), 464 deletions(-) diff --git a/include/swift/AST/Attr.h b/include/swift/AST/Attr.h index fc428fbc1de..b1d51a2aa0c 100644 --- a/include/swift/AST/Attr.h +++ b/include/swift/AST/Attr.h @@ -68,7 +68,7 @@ public: struct Convention { StringRef Name = {}; - DeclName WitnessMethodProtocol = {}; + DeclNameRef 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, DeclName(), "", {}}; + return {name, DeclNameRef(), "", {}}; } }; @@ -1057,15 +1057,16 @@ class DynamicReplacementAttr final friend TrailingObjects; friend class DynamicallyReplacedDeclRequest; - DeclName ReplacedFunctionName; + DeclNameRef ReplacedFunctionName; LazyMemberLoader *Resolver = nullptr; uint64_t ResolverContextData; /// Create an @_dynamicReplacement(for:) attribute written in the source. DynamicReplacementAttr(SourceLoc atLoc, SourceRange baseRange, - DeclName replacedFunctionName, SourceRange parenRange); + DeclNameRef replacedFunctionName, + SourceRange parenRange); - DynamicReplacementAttr(DeclName name, AbstractFunctionDecl *f) + DynamicReplacementAttr(DeclNameRef name, AbstractFunctionDecl *f) : DeclAttribute(DAK_DynamicReplacement, SourceLoc(), SourceRange(), /*Implicit=*/false), ReplacedFunctionName(name), @@ -1073,7 +1074,7 @@ class DynamicReplacementAttr final Bits.DynamicReplacementAttr.HasTrailingLocationInfo = false; } - DynamicReplacementAttr(DeclName name, + DynamicReplacementAttr(DeclNameRef name, LazyMemberLoader *Resolver = nullptr, uint64_t Data = 0) : DeclAttribute(DAK_DynamicReplacement, SourceLoc(), SourceRange(), @@ -1100,18 +1101,18 @@ class DynamicReplacementAttr final public: static DynamicReplacementAttr * create(ASTContext &Context, SourceLoc AtLoc, SourceLoc DynReplLoc, - SourceLoc LParenLoc, DeclName replacedFunction, SourceLoc RParenLoc); + SourceLoc LParenLoc, DeclNameRef replacedFunction, SourceLoc RParenLoc); static DynamicReplacementAttr *create(ASTContext &ctx, - DeclName replacedFunction, + DeclNameRef replacedFunction, AbstractFunctionDecl *replacedFuncDecl); static DynamicReplacementAttr *create(ASTContext &ctx, - DeclName replacedFunction, + DeclNameRef replacedFunction, LazyMemberLoader *Resolver, uint64_t Data); - DeclName getReplacedFunctionName() const { + DeclNameRef getReplacedFunctionName() const { return ReplacedFunctionName; } @@ -1630,8 +1631,8 @@ public: }; /// A declaration name with location. -struct DeclNameWithLoc { - DeclName Name; +struct DeclNameRefWithLoc { + DeclNameRef Name; DeclNameLoc Loc; }; @@ -1652,9 +1653,9 @@ class DifferentiableAttr final /// The number of parsed parameters specified in 'wrt:'. unsigned NumParsedParameters = 0; /// The JVP function. - Optional JVP; + Optional JVP; /// The VJP function. - Optional VJP; + Optional VJP; /// The JVP function (optional), resolved by the type checker if JVP name is /// specified. FuncDecl *JVPFunction = nullptr; @@ -1674,15 +1675,15 @@ class DifferentiableAttr final explicit DifferentiableAttr(bool implicit, SourceLoc atLoc, SourceRange baseRange, bool linear, ArrayRef parameters, - Optional jvp, - Optional vjp, + Optional jvp, + Optional vjp, TrailingWhereClause *clause); explicit DifferentiableAttr(Decl *original, bool implicit, SourceLoc atLoc, SourceRange baseRange, bool linear, IndexSubset *parameterIndices, - Optional jvp, - Optional vjp, + Optional jvp, + Optional vjp, GenericSignature derivativeGenericSignature); public: @@ -1690,27 +1691,27 @@ public: SourceLoc atLoc, SourceRange baseRange, bool linear, ArrayRef params, - Optional jvp, - Optional vjp, + Optional jvp, + Optional vjp, TrailingWhereClause *clause); static DifferentiableAttr *create(AbstractFunctionDecl *original, bool implicit, SourceLoc atLoc, SourceRange baseRange, bool linear, IndexSubset *parameterIndices, - Optional jvp, - Optional vjp, + Optional jvp, + Optional vjp, GenericSignature derivativeGenSig); /// Get the optional 'jvp:' function name and location. /// Use this instead of `getJVPFunction` to check whether the attribute has a /// registered JVP. - Optional getJVP() const { return JVP; } + Optional getJVP() const { return JVP; } /// Get the optional 'vjp:' function name and location. /// Use this instead of `getVJPFunction` to check whether the attribute has a /// registered VJP. - Optional getVJP() const { return VJP; } + Optional getVJP() const { return VJP; } IndexSubset *getParameterIndices() const { return ParameterIndices; @@ -1775,7 +1776,7 @@ class DerivativeAttr final friend TrailingObjects; /// The original function name. - DeclNameWithLoc OriginalFunctionName; + DeclNameRefWithLoc OriginalFunctionName; /// The original function declaration, resolved by the type checker. AbstractFunctionDecl *OriginalFunction = nullptr; /// The number of parsed parameters specified in 'wrt:'. @@ -1786,23 +1787,24 @@ class DerivativeAttr final Optional Kind = None; explicit DerivativeAttr(bool implicit, SourceLoc atLoc, SourceRange baseRange, - DeclNameWithLoc original, + DeclNameRefWithLoc original, ArrayRef params); explicit DerivativeAttr(bool implicit, SourceLoc atLoc, SourceRange baseRange, - DeclNameWithLoc original, IndexSubset *indices); + DeclNameRefWithLoc original, IndexSubset *indices); public: static DerivativeAttr *create(ASTContext &context, bool implicit, SourceLoc atLoc, SourceRange baseRange, - DeclNameWithLoc original, + DeclNameRefWithLoc original, ArrayRef params); static DerivativeAttr *create(ASTContext &context, bool implicit, SourceLoc atLoc, SourceRange baseRange, - DeclNameWithLoc original, IndexSubset *indices); + DeclNameRefWithLoc original, + IndexSubset *indices); - DeclNameWithLoc getOriginalFunctionName() const { + DeclNameRefWithLoc getOriginalFunctionName() const { return OriginalFunctionName; } AbstractFunctionDecl *getOriginalFunction() const { diff --git a/include/swift/AST/DiagnosticsCommon.def b/include/swift/AST/DiagnosticsCommon.def index 9af28487f7d..54a2334da9a 100644 --- a/include/swift/AST/DiagnosticsCommon.def +++ b/include/swift/AST/DiagnosticsCommon.def @@ -163,7 +163,7 @@ NOTE(kind_declname_declared_here,none, WARNING(warn_property_wrapper_module_scope,none, "ignoring associated type %0 in favor of module-scoped property " "wrapper %0; please qualify the reference with %1", - (DeclName, Identifier)) + (DeclNameRef, Identifier)) #ifndef DIAG_NO_UNDEF # if defined(DIAG) diff --git a/include/swift/AST/DiagnosticsParse.def b/include/swift/AST/DiagnosticsParse.def index c63421ad530..9f26b494085 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, DeclName)) + "in %select{declaration|extension}0 of %1", (bool, DeclNameRef)) 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 a25b8342bf0..0f44fbf38e7 100644 --- a/include/swift/AST/DiagnosticsSema.def +++ b/include/swift/AST/DiagnosticsSema.def @@ -57,7 +57,7 @@ NOTE(opaque_return_type_declared_here,none, //------------------------------------------------------------------------------ ERROR(ambiguous_member_overload_set,none, - "ambiguous reference to member %0", (DeclName)) + "ambiguous reference to member %0", (DeclNameRef)) ERROR(ambiguous_reference_to_decl,none, "ambiguous reference to %0 %1", (DescriptiveDeclKind, DeclName)) ERROR(no_overloads_match_exactly_in_call,none, @@ -81,25 +81,25 @@ ERROR(could_not_find_value_subscript,none, (Type)) ERROR(could_not_find_tuple_member,none, - "value of tuple type %0 has no member %1", (Type, DeclName)) + "value of tuple type %0 has no member %1", (Type, DeclNameRef)) ERROR(could_not_find_value_member,none, - "value of type %0 has no member %1", (Type, DeclName)) + "value of type %0 has no member %1", (Type, DeclNameRef)) ERROR(could_not_find_value_member_corrected,none, "value of type %0 has no member %1; did you mean %2?", - (Type, DeclName, DeclName)) + (Type, DeclNameRef, DeclName)) ERROR(could_not_find_value_dynamic_member_corrected,none, "value of type %0 has no dynamic member %2 using key path from root type %1; did you mean %3?", - (Type, Type, DeclName, DeclName)) + (Type, Type, DeclNameRef, DeclName)) ERROR(could_not_find_value_dynamic_member,none, "value of type %0 has no dynamic member %2 using key path from root type %1", - (Type, Type, DeclName)) + (Type, Type, DeclNameRef)) ERROR(could_not_find_type_member,none, - "type %0 has no member %1", (Type, DeclName)) + "type %0 has no member %1", (Type, DeclNameRef)) ERROR(could_not_find_type_member_corrected,none, "type %0 has no member %1; did you mean %2?", - (Type, DeclName, DeclName)) + (Type, DeclNameRef, DeclName)) ERROR(could_not_find_subscript_member_did_you_mean,none, "value of type %0 has no property or method named 'subscript'; " @@ -107,7 +107,8 @@ ERROR(could_not_find_subscript_member_did_you_mean,none, (Type)) ERROR(could_not_find_enum_case,none, - "enum type %0 has no case %1; did you mean %2", (Type, DeclName, DeclName)) + "enum type %0 has no case %1; did you mean %2", + (Type, DeclNameRef, DeclName)) NOTE(did_you_mean_raw_type,none, "did you mean to specify a raw type on the enum declaration?", ()) @@ -128,35 +129,35 @@ ERROR(unexpected_arguments_in_enum_case,none, "enum case %0 has no associated values", (DeclName)) ERROR(could_not_use_value_member,none, - "member %1 cannot be used on value of type %0", (Type, DeclName)) + "member %1 cannot be used on value of type %0", (Type, DeclNameRef)) ERROR(could_not_use_type_member,none, - "member %1 cannot be used on type %0", (Type, DeclName)) + "member %1 cannot be used on type %0", (Type, DeclNameRef)) ERROR(could_not_use_type_member_on_instance,none, "static member %1 cannot be used on instance of type %0", - (Type, DeclName)) + (Type, DeclNameRef)) ERROR(could_not_use_enum_element_on_instance,none, "enum case %0 cannot be used as an instance member", - (DeclName)) + (DeclNameRef)) ERROR(could_not_use_type_member_on_protocol_metatype,none, "static member %1 cannot be used on protocol metatype %0", - (Type, DeclName)) + (Type, DeclNameRef)) ERROR(could_not_use_instance_member_on_type,none, "instance member %1" "%select{| of type %2}3 cannot be used on" "%select{| instance of nested}3 type %0", - (Type, DeclName, Type, bool)) + (Type, DeclNameRef, Type, bool)) ERROR(could_not_use_member_on_existential,none, "member %1 cannot be used on value of protocol type %0; use a generic" " constraint instead", - (Type, DeclName)) + (Type, DeclNameRef)) FIXIT(replace_with_type,"%0",(Type)) FIXIT(insert_type_qualification,"%0.",(Type)) ERROR(candidate_inaccessible,none, "%0 is inaccessible due to " "'%select{private|fileprivate|internal|%error|%error}1' protection level", - (DeclName, AccessLevel)) + (DeclBaseName, AccessLevel)) NOTE(note_candidate_inaccessible,none, "%0 is inaccessible due to " @@ -577,7 +578,7 @@ WARNING(expr_keypath_swift3_objc_inference,none, (DeclName, Identifier)) ERROR(expr_keypath_type_of_property,none, "cannot refer to type member %0 within instance of type %1", - (DeclName, Type)) + (DeclNameRef, Type)) ERROR(expr_keypath_generic_type,none, "key path cannot refer to generic type %0", (DeclName)) ERROR(expr_keypath_not_property,none, @@ -781,24 +782,24 @@ NOTE(invalid_redecl_prev,none, "%0 previously declared here", (DeclName)) ERROR(ambiguous_type_base,none, - "%0 is ambiguous for type lookup in this context", (DeclName)) + "%0 is ambiguous for type lookup in this context", (DeclNameRef)) ERROR(invalid_member_type,none, - "%0 is not a member type of %1", (DeclName, Type)) + "%0 is not a member type of %1", (DeclNameRef, Type)) ERROR(invalid_member_type_suggest,none, "%0 does not have a member type named %1; did you mean %2?", - (Type, DeclName, DeclName)) + (Type, DeclNameRef, DeclName)) ERROR(invalid_member_reference,none, "%0 %1 is not a member type of %2", (DescriptiveDeclKind, DeclName, Type)) ERROR(ambiguous_member_type,none, - "ambiguous type name %0 in %1", (DeclName, Type)) + "ambiguous type name %0 in %1", (DeclNameRef, Type)) ERROR(no_module_type,none, - "no type named %0 in module %1", (DeclName, Identifier)) + "no type named %0 in module %1", (DeclNameRef, Identifier)) ERROR(ambiguous_module_type,none, - "ambiguous type name %0 in module %1", (DeclName, Identifier)) + "ambiguous type name %0 in module %1", (DeclNameRef, Identifier)) ERROR(use_nonmatching_operator,none, "%0 is not a %select{binary|prefix unary|postfix unary}1 operator", - (DeclName, unsigned)) + (DeclNameRef, unsigned)) ERROR(unsupported_recursion_in_associated_type_reference,none, "unsupported recursion for reference to %select{associated type|type alias}0 %1 of type %2", (bool, DeclName, Type)) @@ -819,18 +820,18 @@ ERROR(unspaced_unary_operator,none, ()) ERROR(use_unresolved_identifier,none, - "use of unresolved %select{identifier|operator}1 %0", (DeclName, bool)) + "use of unresolved %select{identifier|operator}1 %0", (DeclNameRef, bool)) ERROR(use_unresolved_identifier_corrected,none, "use of unresolved %select{identifier|operator}1 %0; did you mean '%2'?", - (DeclName, bool, StringRef)) + (DeclNameRef, bool, StringRef)) NOTE(confusable_character,none, "%select{identifier|operator}0 '%1' contains possibly confused characters; " "did you mean to use '%2'?", (bool, StringRef, StringRef)) ERROR(use_undeclared_type,none, - "use of undeclared type %0", (DeclName)) + "use of undeclared type %0", (DeclNameRef)) ERROR(use_undeclared_type_did_you_mean,none, - "use of undeclared type %0; did you mean to use '%1'?", (DeclName, StringRef)) + "use of undeclared type %0; did you mean to use '%1'?", (DeclNameRef, StringRef)) NOTE(note_typo_candidate_implicit_member,none, "did you mean the implicitly-synthesized %1 '%0'?", (StringRef, StringRef)) NOTE(note_remapped_type,none, @@ -847,7 +848,7 @@ NOTE(object_literal_resolve_import,none, (StringRef, StringRef, StringRef)) ERROR(use_local_before_declaration,none, - "use of local variable %0 before its declaration", (DeclName)) + "use of local variable %0 before its declaration", (DeclNameRef)) ERROR(unsupported_existential_type,none, "protocol %0 can only be used as a generic constraint because it has " "Self or associated type requirements", (Identifier)) @@ -1068,10 +1069,10 @@ NOTE(unwrap_with_guard,none, "if the optional value contains 'nil'", ()) ERROR(optional_base_not_unwrapped,none, "value of optional type %0 must be unwrapped to refer to member %1 of " - "wrapped base type %2", (Type, DeclName, Type)) + "wrapped base type %2", (Type, DeclNameRef, Type)) NOTE(optional_base_chain,none, "chain the optional using '?' to access member %0 only for non-'nil' " - "base values", (DeclName)) + "base values", (DeclNameRef)) ERROR(missing_unwrap_optional_try,none, "value of optional type %0 not unwrapped; did you mean to use 'try!' " "or chain with '?'?", @@ -1138,21 +1139,21 @@ NOTE(candidate_expected_different_labels,none, ERROR(member_shadows_global_function,none, "use of %0 refers to %1 %2 rather than %3 %4 in %5 %6", - (DeclName, DescriptiveDeclKind, DeclName, DescriptiveDeclKind, DeclName, - DescriptiveDeclKind, DeclName)) + (DeclNameRef, DescriptiveDeclKind, DeclName, DescriptiveDeclKind, + DeclName, DescriptiveDeclKind, DeclName)) ERROR(member_shadows_global_function_near_match,none, "use of %0 nearly matches %3 %4 in %5 %6 rather than %1 %2", - (DeclName, DescriptiveDeclKind, DeclName, DescriptiveDeclKind, DeclName, - DescriptiveDeclKind, DeclName)) + (DeclNameRef, DescriptiveDeclKind, DeclName, DescriptiveDeclKind, + DeclName, DescriptiveDeclKind, DeclName)) ERROR(instance_member_use_on_type,none, "instance member %1 cannot be used on type %0; " - "did you mean to use a value of this type instead?", (Type, DeclName)) + "did you mean to use a value of this type instead?", (Type, DeclNameRef)) ERROR(instance_member_in_initializer,none, "cannot use instance member %0 within property initializer; " - "property initializers run before 'self' is available", (DeclName)) + "property initializers run before 'self' is available", (DeclNameRef)) ERROR(instance_member_in_default_parameter,none, - "cannot use instance member %0 as a default parameter", (DeclName)) + "cannot use instance member %0 as a default parameter", (DeclNameRef)) ERROR(missing_argument_named,none, "missing argument for parameter %0 in call", (Identifier)) @@ -2178,10 +2179,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", (DeclName)) + "generic parameter base", (DeclNameRef)) ERROR(typealias_outside_of_protocol,none, "type alias %0 can only be used with a concrete type or " - "generic parameter base", (DeclName)) + "generic parameter base", (DeclNameRef)) ERROR(objc_protocol_inherits_non_objc_protocol,none, "@objc protocol %0 cannot refine non-@objc protocol %1", (Type, Type)) @@ -2903,7 +2904,7 @@ ERROR(no_MaxBuiltinFloatType_found,none, "standard library error: _MaxBuiltinFloatType is not properly defined", ()) ERROR(no_member_of_module,none, - "module %0 has no member named %1", (Identifier, DeclName)) + "module %0 has no member named %1", (Identifier, DeclNameRef)) ERROR(super_with_no_base_class,none, "'super' members cannot be referenced in a root class", ()) @@ -3049,9 +3050,9 @@ ERROR(collection_literal_empty,none, ERROR(unresolved_member_no_inference,none, "reference to member %0 cannot be resolved without a contextual type", - (DeclName)) + (DeclNameRef)) ERROR(cannot_infer_base_of_unresolved_member,none, - "cannot infer contextual base in reference to member %0", (DeclName)) + "cannot infer contextual base in reference to member %0", (DeclNameRef)) ERROR(unresolved_collection_literal,none, "cannot infer type for empty collection literal without a " "contextual type", ()) @@ -3138,9 +3139,9 @@ WARNING(use_of_void_pointer,none, // Ambiguities ERROR(ambiguous_decl_ref,none, - "ambiguous use of %0", (DeclName)) + "ambiguous use of %0", (DeclNameRef)) ERROR(ambiguous_operator_ref,none, - "ambiguous use of operator %0", (DeclName)) + "ambiguous use of operator %0", (DeclNameRef)) NOTE(ambiguous_because_of_trailing_closure,none, "%select{use an explicit argument label instead of a trailing closure|" "avoid using a trailing closure}0 to call %1", @@ -3213,7 +3214,7 @@ NOTE(fix_unqualified_access_top_level_multi,none, WARNING(warn_deprecated_conditional_conformance_outer_access,none, "use of %0 as reference to %1 in %2 %3 will change in future versions of Swift to reference %4 in %5 %6 " "which comes via a conditional conformance", - (DeclName, DescriptiveDeclKind, DescriptiveDeclKind, DeclName, + (DeclNameRef, DescriptiveDeclKind, DescriptiveDeclKind, DeclName, DescriptiveDeclKind, DescriptiveDeclKind, DeclName)) NOTE(fix_deprecated_conditional_conformance_outer_access,none, "use '%0' to continue to reference the %1", @@ -3425,7 +3426,7 @@ NOTE(masked_mutable_property,none, ERROR(assignment_let_property_delegating_init,none, "'let' property %0 may not be initialized directly; use " - "\"self.init(...)\" or \"self = ...\" instead", (DeclName)) + "\"self.init(...)\" or \"self = ...\" instead", (DeclNameRef)) ERROR(label_shadowed, none, "label %0 cannot be reused on an inner statement", (Identifier)) @@ -3576,7 +3577,7 @@ ERROR(cannot_convert_single_tuple_into_multiple_arguments,none, ERROR(enum_element_pattern_assoc_values_mismatch,none, "pattern with associated values does not match enum case %0", - (DeclName)) + (DeclNameRef)) NOTE(enum_element_pattern_assoc_values_remove,none, "remove associated values to make the pattern match", ()) ERROR(tuple_pattern_length_mismatch,none, @@ -3584,14 +3585,14 @@ ERROR(tuple_pattern_length_mismatch,none, ERROR(tuple_pattern_label_mismatch,none, "tuple pattern element label %0 must be %1", (Identifier, Identifier)) ERROR(enum_element_pattern_member_not_found,none, - "enum case %0 not found in type %1", (DeclName, Type)) + "enum case %0 not found in type %1", (DeclNameRef, Type)) ERROR(optional_element_pattern_not_valid_type,none, "'?' pattern cannot match values of type %0", (Type)) ERROR(condition_optional_element_pattern_not_valid_type,none, "initializer for conditional binding must have Optional type, not %0", (Type)) ERROR(enum_element_pattern_not_member_of_enum,none, - "enum case %0 is not a member of type %1", (DeclName, Type)) + "enum case %0 is not a member of type %1", (DeclNameRef, Type)) ERROR(ambiguous_enum_pattern_type,none, "generic enum type %0 is ambiguous without explicit generic parameters " "when matching value of type %1", (Type, Type)) @@ -4210,12 +4211,12 @@ ERROR(dynamic_and_library_evolution_not_supported,none, //------------------------------------------------------------------------------ ERROR(dynamic_replacement_accessor_type_mismatch, none, - "replaced accessor %0's type does not match", (DeclNameRef)) + "replaced accessor %0's type does not match", (DeclName)) ERROR(dynamic_replacement_accessor_not_dynamic, none, - "replaced accessor for %0 is not marked dynamic", (DeclNameRef)) + "replaced accessor for %0 is not marked dynamic", (DeclName)) ERROR(dynamic_replacement_accessor_not_explicit, none, "replaced accessor %select{get|set|_read|_modify|willSet|didSet|unsafeAddress|addressWithOwner|addressWithNativeOwner|unsafeMutableAddress|mutableAddressWithOwner|}0 for %1 is not explicitly defined", - (unsigned, DeclNameRef)) + (unsigned, DeclName)) ERROR(dynamic_replacement_function_not_dynamic, none, "replaced function %0 is not marked dynamic", (DeclName)) ERROR(dynamic_replacement_function_not_found, none, @@ -4231,7 +4232,8 @@ ERROR(dynamic_replacement_function_of_type_not_found, none, NOTE(dynamic_replacement_found_function_of_type, none, "found function %0 of type %1", (DeclName, Type)) ERROR(dynamic_replacement_not_in_extension, none, - "dynamicReplacement(for:) of %0 is not defined in an extension or at the file level", (DeclName)) + "dynamicReplacement(for:) of %0 is not defined in an extension or at the " + "file level", (DeclName)) ERROR(dynamic_replacement_must_not_be_dynamic, none, "dynamicReplacement(for:) of %0 must not be dynamic itself", (DeclName)) ERROR(dynamic_replacement_replaced_not_objc_dynamic, none, @@ -4239,9 +4241,9 @@ ERROR(dynamic_replacement_replaced_not_objc_dynamic, none, ERROR(dynamic_replacement_replacement_not_objc_dynamic, none, "%0 is marked @objc dynamic", (DeclName)) ERROR(dynamic_replacement_replaced_constructor_is_convenience, none, - "replaced constructor %0 is marked as convenience", (DeclName)) + "replaced constructor %0 is marked as convenience", (DeclNameRef)) ERROR(dynamic_replacement_replaced_constructor_is_not_convenience, none, - "replaced constructor %0 is not marked as convenience", (DeclName)) + "replaced constructor %0 is not marked as convenience", (DeclNameRef)) //------------------------------------------------------------------------------ // MARK: @available @@ -4675,7 +4677,7 @@ WARNING(property_wrapper_init_initialValue,none, "to 'init(wrappedValue:)'; use of 'init(initialValue:)' is deprecated", ()) ERROR(property_wrapper_projection_value_missing,none, - "could not find projection value property %0", (Identifier)) + "could not find projection value property %0", (DeclNameRef)) ERROR(property_wrapper_missing_arg_init, none, "missing argument for parameter " "%0 in property wrapper initializer; add 'wrappedValue' and %0 " "arguments in '@%1(...)'", (Identifier, StringRef)) diff --git a/include/swift/AST/Expr.h b/include/swift/AST/Expr.h index f0a149ac7f9..77c85fb9d35 100644 --- a/include/swift/AST/Expr.h +++ b/include/swift/AST/Expr.h @@ -1487,11 +1487,11 @@ public: /// sema), or may just be a use of an unknown identifier. /// class UnresolvedDeclRefExpr : public Expr { - DeclName Name; + DeclNameRef Name; DeclNameLoc Loc; public: - UnresolvedDeclRefExpr(DeclName name, DeclRefKind refKind, DeclNameLoc loc) + UnresolvedDeclRefExpr(DeclNameRef name, DeclRefKind refKind, DeclNameLoc loc) : Expr(ExprKind::UnresolvedDeclRef, /*Implicit=*/loc.isInvalid()), Name(name), Loc(loc) { Bits.UnresolvedDeclRefExpr.DeclRefKind = static_cast(refKind); @@ -1503,7 +1503,7 @@ public: static UnresolvedDeclRefExpr *createImplicit( ASTContext &C, DeclName name, DeclRefKind refKind = DeclRefKind::Ordinary) { - return new (C) UnresolvedDeclRefExpr(name, refKind, + return new (C) UnresolvedDeclRefExpr(DeclNameRef_(name), refKind, DeclNameLoc()); } @@ -1520,7 +1520,7 @@ public: } bool hasName() const { return static_cast(Name); } - DeclName getName() const { return Name; } + DeclNameRef getName() const { return Name; } DeclRefKind getRefKind() const { return static_cast(Bits.UnresolvedDeclRefExpr.DeclRefKind); @@ -1788,11 +1788,11 @@ class UnresolvedMemberExpr final public TrailingCallArguments { SourceLoc DotLoc; DeclNameLoc NameLoc; - DeclName Name; + DeclNameRef Name; Expr *Argument; UnresolvedMemberExpr(SourceLoc dotLoc, DeclNameLoc nameLoc, - DeclName name, Expr *argument, + DeclNameRef name, Expr *argument, ArrayRef argLabels, ArrayRef argLabelLocs, bool hasTrailingClosure, @@ -1801,12 +1801,12 @@ class UnresolvedMemberExpr final public: /// Create a new unresolved member expression with no arguments. static UnresolvedMemberExpr *create(ASTContext &ctx, SourceLoc dotLoc, - DeclNameLoc nameLoc, DeclName name, + DeclNameLoc nameLoc, DeclNameRef name, bool implicit); /// Create a new unresolved member expression. static UnresolvedMemberExpr *create(ASTContext &ctx, SourceLoc dotLoc, - DeclNameLoc nameLoc, DeclName name, + DeclNameLoc nameLoc, DeclNameRef name, SourceLoc lParenLoc, ArrayRef args, ArrayRef argLabels, @@ -1815,7 +1815,7 @@ public: Expr *trailingClosure, bool implicit); - DeclName getName() const { return Name; } + DeclNameRef getName() const { return Name; } DeclNameLoc getNameLoc() const { return NameLoc; } SourceLoc getDotLoc() const { return DotLoc; } Expr *getArgument() const { return Argument; } @@ -2411,12 +2411,12 @@ class UnresolvedDotExpr : public Expr { Expr *SubExpr; SourceLoc DotLoc; DeclNameLoc NameLoc; - DeclName Name; + DeclNameRef Name; ArrayRef OuterAlternatives; public: UnresolvedDotExpr( - Expr *subexpr, SourceLoc dotloc, DeclName name, DeclNameLoc nameloc, + Expr *subexpr, SourceLoc dotloc, DeclNameRef name, DeclNameLoc nameloc, bool Implicit, ArrayRef outerAlternatives = ArrayRef()) : Expr(ExprKind::UnresolvedDot, Implicit), SubExpr(subexpr), @@ -2430,7 +2430,7 @@ public: static UnresolvedDotExpr *createImplicit( ASTContext &C, Expr *base, DeclName name) { return new (C) UnresolvedDotExpr(base, SourceLoc(), - name, DeclNameLoc(), + DeclNameRef_(name), DeclNameLoc(), /*implicit=*/true); } @@ -2479,7 +2479,7 @@ public: Expr *getBase() const { return SubExpr; } void setBase(Expr *e) { SubExpr = e; } - DeclName getName() const { return Name; } + DeclNameRef getName() const { return Name; } DeclNameLoc getNameLoc() const { return NameLoc; } ArrayRef getOuterAlternatives() const { @@ -4892,7 +4892,7 @@ class KeyPathExpr : public Expr { public: /// A single stored component, which will be one of: - /// - an unresolved DeclName, which has to be type-checked + /// - an unresolved DeclNameRef, which has to be type-checked /// - a resolved ValueDecl, referring to /// - a subscript index expression, which may or may not be resolved /// - an optional chaining, forcing, or wrapping component @@ -4913,11 +4913,11 @@ public: private: union DeclNameOrRef { - DeclName UnresolvedName; + DeclNameRef UnresolvedName; ConcreteDeclRef ResolvedDecl; DeclNameOrRef() : UnresolvedName{} {} - DeclNameOrRef(DeclName un) : UnresolvedName(un) {} + DeclNameOrRef(DeclNameRef un) : UnresolvedName(un) {} DeclNameOrRef(ConcreteDeclRef rd) : ResolvedDecl(rd) {} } Decl; @@ -4958,7 +4958,7 @@ public: {} /// Create an unresolved component for a property. - static Component forUnresolvedProperty(DeclName UnresolvedName, + static Component forUnresolvedProperty(DeclNameRef UnresolvedName, SourceLoc Loc) { return Component(nullptr, UnresolvedName, nullptr, {}, {}, @@ -5173,7 +5173,7 @@ public: void setSubscriptIndexHashableConformances( ArrayRef hashables); - DeclName getUnresolvedDeclName() const { + DeclNameRef getUnresolvedDeclName() const { switch (getKind()) { case Kind::UnresolvedProperty: return Decl.UnresolvedName; diff --git a/include/swift/AST/Pattern.h b/include/swift/AST/Pattern.h index d6b92ac178b..a0f6345910d 100644 --- a/include/swift/AST/Pattern.h +++ b/include/swift/AST/Pattern.h @@ -505,13 +505,13 @@ class EnumElementPattern : public Pattern { TypeLoc ParentType; SourceLoc DotLoc; DeclNameLoc NameLoc; - DeclName Name; + DeclNameRef Name; PointerUnion ElementDeclOrUnresolvedOriginalExpr; Pattern /*nullable*/ *SubPattern; public: EnumElementPattern(TypeLoc ParentType, SourceLoc DotLoc, DeclNameLoc NameLoc, - DeclName Name, EnumElementDecl *Element, + DeclNameRef Name, EnumElementDecl *Element, Pattern *SubPattern, Optional Implicit = None) : Pattern(PatternKind::EnumElement), ParentType(ParentType), DotLoc(DotLoc), NameLoc(NameLoc), Name(Name), @@ -525,7 +525,7 @@ public: /// contextual type. EnumElementPattern(SourceLoc DotLoc, DeclNameLoc NameLoc, - DeclName Name, + DeclNameRef Name, Pattern *SubPattern, Expr *UnresolvedOriginalExpr) : Pattern(PatternKind::EnumElement), @@ -551,7 +551,7 @@ public: void setSubPattern(Pattern *p) { SubPattern = p; } - DeclName getName() const { return Name; } + DeclNameRef getName() const { return Name; } EnumElementDecl *getElementDecl() const { return ElementDeclOrUnresolvedOriginalExpr.dyn_cast(); diff --git a/include/swift/AST/TypeRepr.h b/include/swift/AST/TypeRepr.h index a1bd5e08068..e4cce80d123 100644 --- a/include/swift/AST/TypeRepr.h +++ b/include/swift/AST/TypeRepr.h @@ -263,23 +263,23 @@ class ComponentIdentTypeRepr : public IdentTypeRepr { /// /// 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, DeclNameLoc Loc, DeclName Id) + ComponentIdentTypeRepr(TypeReprKind K, DeclNameLoc Loc, DeclNameRef Id) : IdentTypeRepr(K), Loc(Loc), IdOrDecl(Id), DC(nullptr) {} public: DeclNameLoc getNameLoc() const { return Loc; } - DeclName getNameRef() const; + DeclNameRef getNameRef() const; /// Replace the identifier with a new identifier, e.g., due to typo /// correction. - void overwriteNameRef(DeclName newId) { IdOrDecl = newId; } + void overwriteNameRef(DeclNameRef newId) { IdOrDecl = newId; } /// Return true if this has been name-bound already. bool isBound() const { return IdOrDecl.is(); } @@ -312,7 +312,7 @@ protected: /// A simple identifier type like "Int". class SimpleIdentTypeRepr : public ComponentIdentTypeRepr { public: - SimpleIdentTypeRepr(DeclNameLoc Loc, DeclName Id) + SimpleIdentTypeRepr(DeclNameLoc Loc, DeclNameRef Id) : ComponentIdentTypeRepr(TypeReprKind::SimpleIdent, Loc, Id) {} // SmallVector::emplace_back will never need to call this because @@ -342,7 +342,7 @@ class GenericIdentTypeRepr final : public ComponentIdentTypeRepr, friend TrailingObjects; SourceRange AngleBrackets; - GenericIdentTypeRepr(DeclNameLoc Loc, DeclName Id, + GenericIdentTypeRepr(DeclNameLoc Loc, DeclNameRef Id, ArrayRef GenericArgs, SourceRange AngleBrackets) : ComponentIdentTypeRepr(TypeReprKind::GenericIdent, Loc, Id), @@ -360,7 +360,7 @@ class GenericIdentTypeRepr final : public ComponentIdentTypeRepr, public: static GenericIdentTypeRepr *create(const ASTContext &C, DeclNameLoc Loc, - DeclName Id, + DeclNameRef Id, ArrayRef GenericArgs, SourceRange AngleBrackets); diff --git a/include/swift/Parse/Parser.h b/include/swift/Parse/Parser.h index 16b421f0b11..9974e821215 100644 --- a/include/swift/Parse/Parser.h +++ b/include/swift/Parse/Parser.h @@ -747,7 +747,7 @@ public: getScopeInfo().addToScope(D, *this, diagnoseRedefinitions); } - ValueDecl *lookupInScope(DeclName Name) { + ValueDecl *lookupInScope(DeclNameRef Name) { if (Context.LangOpts.DisableParserLookup) return nullptr; @@ -990,7 +990,8 @@ public: /// Parse the arguments inside the @differentiable attribute. bool parseDifferentiableAttributeArguments( bool &linear, SmallVectorImpl ¶ms, - Optional &jvpSpec, Optional &vjpSpec, + Optional &jvpSpec, + Optional &vjpSpec, TrailingWhereClause *&whereClause); /// Parse a differentiation parameters clause. @@ -1421,10 +1422,10 @@ public: /// \param loc Will be populated with the location of the name. /// \param diag The diagnostic to emit if this is not a name. /// \param allowOperators Whether to allow operator basenames too. - DeclBaseName parseUnqualifiedDeclBaseName(bool afterDot, DeclNameLoc &loc, - const Diagnostic &diag, - bool allowOperators=false, - bool allowDeinitAndSubscript=false); + DeclNameRef parseUnqualifiedDeclBaseName(bool afterDot, DeclNameLoc &loc, + const Diagnostic &diag, + bool allowOperators=false, + bool allowDeinitAndSubscript=false); /// Parse an unqualified-decl-name. /// @@ -1438,11 +1439,11 @@ public: /// \param diag The diagnostic to emit if this is not a name. /// \param allowOperators Whether to allow operator basenames too. /// \param allowZeroArgCompoundNames Whether to allow empty argument lists. - DeclName parseUnqualifiedDeclName(bool afterDot, DeclNameLoc &loc, - const Diagnostic &diag, - bool allowOperators=false, - bool allowZeroArgCompoundNames=false, - bool allowDeinitAndSubscript=false); + DeclNameRef parseUnqualifiedDeclName(bool afterDot, DeclNameLoc &loc, + const Diagnostic &diag, + bool allowOperators=false, + bool allowZeroArgCompoundNames=false, + bool allowDeinitAndSubscript=false); Expr *parseExprIdentifier(); Expr *parseExprEditorPlaceholder(Token PlaceholderTok, diff --git a/include/swift/Parse/Scope.h b/include/swift/Parse/Scope.h index 45860d5903b..4fe00b028be 100644 --- a/include/swift/Parse/Scope.h +++ b/include/swift/Parse/Scope.h @@ -47,7 +47,7 @@ private: unsigned ResolvableDepth = 0; public: - ValueDecl *lookupValueName(DeclName Name); + ValueDecl *lookupValueName(DeclNameRef Name); Scope *getCurrentScope() const { return CurScope; } @@ -159,7 +159,7 @@ public: } }; -inline ValueDecl *ScopeInfo::lookupValueName(DeclName Name) { +inline ValueDecl *ScopeInfo::lookupValueName(DeclNameRef Name) { // FIXME: this check can go away when SIL parser parses everything in // a toplevel scope. if (!CurScope) @@ -169,7 +169,8 @@ inline ValueDecl *ScopeInfo::lookupValueName(DeclName Name) { // If we found nothing, or we found a decl at the top-level, return nothing. // We ignore results at the top-level because we may have overloading that // will be resolved properly by name binding. - std::pair Res = HT.lookup(CurScope->HTScope, Name); + std::pair Res = HT.lookup(CurScope->HTScope, + Name.getFullName()); if (Res.first < ResolvableDepth) return 0; return Res.second; diff --git a/include/swift/Sema/IDETypeChecking.h b/include/swift/Sema/IDETypeChecking.h index 5b5b204060a..cf58d7b7a5b 100644 --- a/include/swift/Sema/IDETypeChecking.h +++ b/include/swift/Sema/IDETypeChecking.h @@ -82,6 +82,11 @@ namespace swift { ArrayRef getMemberDecls(InterestedMemberKind Kind); }; + /// Look up a member with the given name in the given type. + /// + /// Unlike other member lookup functions, \c swift::resolveValueMember() + /// should be used when you want to look up declarations with the same name as + /// one you already have. ResolvedMemberResult resolveValueMember(DeclContext &DC, Type BaseTy, DeclName Name); diff --git a/lib/AST/Attr.cpp b/lib/AST/Attr.cpp index 2a387e5cb1a..d8eaa5a4206 100644 --- a/lib/AST/Attr.cpp +++ b/lib/AST/Attr.cpp @@ -1166,7 +1166,7 @@ PrivateImportAttr *PrivateImportAttr::create(ASTContext &Ctxt, SourceLoc AtLoc, DynamicReplacementAttr::DynamicReplacementAttr(SourceLoc atLoc, SourceRange baseRange, - DeclName name, + DeclNameRef name, SourceRange parenRange) : DeclAttribute(DAK_DynamicReplacement, atLoc, baseRange, /*Implicit=*/false), @@ -1179,7 +1179,7 @@ DynamicReplacementAttr::DynamicReplacementAttr(SourceLoc atLoc, DynamicReplacementAttr * DynamicReplacementAttr::create(ASTContext &Ctx, SourceLoc AtLoc, SourceLoc DynReplLoc, SourceLoc LParenLoc, - DeclName ReplacedFunction, SourceLoc RParenLoc) { + DeclNameRef ReplacedFunction, SourceLoc RParenLoc) { void *mem = Ctx.Allocate(totalSizeToAlloc(2), alignof(DynamicReplacementAttr)); return new (mem) DynamicReplacementAttr( @@ -1188,13 +1188,13 @@ DynamicReplacementAttr::create(ASTContext &Ctx, SourceLoc AtLoc, } DynamicReplacementAttr * -DynamicReplacementAttr::create(ASTContext &Ctx, DeclName name, +DynamicReplacementAttr::create(ASTContext &Ctx, DeclNameRef name, AbstractFunctionDecl *f) { return new (Ctx) DynamicReplacementAttr(name, f); } DynamicReplacementAttr * -DynamicReplacementAttr::create(ASTContext &Ctx, DeclName name, +DynamicReplacementAttr::create(ASTContext &Ctx, DeclNameRef name, LazyMemberLoader *Resolver, uint64_t Data) { return new (Ctx) DynamicReplacementAttr(name, Resolver, Data); } @@ -1377,8 +1377,8 @@ SpecializeAttr *SpecializeAttr::create(ASTContext &Ctx, SourceLoc atLoc, DifferentiableAttr::DifferentiableAttr(bool implicit, SourceLoc atLoc, SourceRange baseRange, bool linear, ArrayRef params, - Optional jvp, - Optional vjp, + Optional jvp, + Optional vjp, TrailingWhereClause *clause) : DeclAttribute(DAK_Differentiable, atLoc, baseRange, implicit), Linear(linear), NumParsedParameters(params.size()), JVP(std::move(jvp)), @@ -1391,8 +1391,8 @@ DifferentiableAttr::DifferentiableAttr(Decl *original, bool implicit, SourceLoc atLoc, SourceRange baseRange, bool linear, IndexSubset *parameterIndices, - Optional jvp, - Optional vjp, + Optional jvp, + Optional vjp, GenericSignature derivativeGenSig) : DeclAttribute(DAK_Differentiable, atLoc, baseRange, implicit), Linear(linear), JVP(std::move(jvp)), VJP(std::move(vjp)) { @@ -1405,8 +1405,8 @@ DifferentiableAttr::create(ASTContext &context, bool implicit, SourceLoc atLoc, SourceRange baseRange, bool linear, ArrayRef parameters, - Optional jvp, - Optional vjp, + Optional jvp, + Optional vjp, TrailingWhereClause *clause) { unsigned size = totalSizeToAlloc(parameters.size()); void *mem = context.Allocate(size, alignof(DifferentiableAttr)); @@ -1419,8 +1419,8 @@ DifferentiableAttr * DifferentiableAttr::create(AbstractFunctionDecl *original, bool implicit, SourceLoc atLoc, SourceRange baseRange, bool linear, IndexSubset *parameterIndices, - Optional jvp, - Optional vjp, + Optional jvp, + Optional vjp, GenericSignature derivativeGenSig) { auto &ctx = original->getASTContext(); void *mem = ctx.Allocate(sizeof(DifferentiableAttr), @@ -1433,13 +1433,13 @@ DifferentiableAttr::create(AbstractFunctionDecl *original, bool implicit, void DifferentiableAttr::setJVPFunction(FuncDecl *decl) { JVPFunction = decl; if (decl && !JVP) - JVP = {decl->getFullName(), DeclNameLoc(decl->getNameLoc())}; + JVP = {decl->createNameRef(), DeclNameLoc(decl->getNameLoc())}; } void DifferentiableAttr::setVJPFunction(FuncDecl *decl) { VJPFunction = decl; if (decl && !VJP) - VJP = {decl->getFullName(), DeclNameLoc(decl->getNameLoc())}; + VJP = {decl->createNameRef(), DeclNameLoc(decl->getNameLoc())}; } GenericEnvironment *DifferentiableAttr::getDerivativeGenericEnvironment( @@ -1461,7 +1461,7 @@ void DifferentiableAttr::print(llvm::raw_ostream &OS, const Decl *D, DerivativeAttr::DerivativeAttr(bool implicit, SourceLoc atLoc, SourceRange baseRange, - DeclNameWithLoc originalName, + DeclNameRefWithLoc originalName, ArrayRef params) : DeclAttribute(DAK_Derivative, atLoc, baseRange, implicit), OriginalFunctionName(std::move(originalName)), @@ -1472,7 +1472,7 @@ DerivativeAttr::DerivativeAttr(bool implicit, SourceLoc atLoc, DerivativeAttr::DerivativeAttr(bool implicit, SourceLoc atLoc, SourceRange baseRange, - DeclNameWithLoc originalName, + DeclNameRefWithLoc originalName, IndexSubset *indices) : DeclAttribute(DAK_Derivative, atLoc, baseRange, implicit), OriginalFunctionName(std::move(originalName)), ParameterIndices(indices) { @@ -1480,7 +1480,7 @@ DerivativeAttr::DerivativeAttr(bool implicit, SourceLoc atLoc, DerivativeAttr * DerivativeAttr::create(ASTContext &context, bool implicit, SourceLoc atLoc, - SourceRange baseRange, DeclNameWithLoc originalName, + SourceRange baseRange, DeclNameRefWithLoc originalName, ArrayRef params) { unsigned size = totalSizeToAlloc(params.size()); void *mem = context.Allocate(size, alignof(DerivativeAttr)); @@ -1490,7 +1490,7 @@ DerivativeAttr::create(ASTContext &context, bool implicit, SourceLoc atLoc, DerivativeAttr *DerivativeAttr::create(ASTContext &context, bool implicit, SourceLoc atLoc, SourceRange baseRange, - DeclNameWithLoc originalName, + DeclNameRefWithLoc originalName, IndexSubset *indices) { void *mem = context.Allocate(sizeof(DerivativeAttr), alignof(DerivativeAttr)); return new (mem) DerivativeAttr(implicit, atLoc, baseRange, diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 525a549c120..7eb779525f5 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1533,7 +1533,7 @@ DynamicSubscriptExpr::create(ASTContext &ctx, Expr *base, SourceLoc lSquareLoc, UnresolvedMemberExpr::UnresolvedMemberExpr(SourceLoc dotLoc, DeclNameLoc nameLoc, - DeclName name, Expr *argument, + DeclNameRef name, Expr *argument, ArrayRef argLabels, ArrayRef argLabelLocs, bool hasTrailingClosure, @@ -1550,7 +1550,7 @@ UnresolvedMemberExpr::UnresolvedMemberExpr(SourceLoc dotLoc, UnresolvedMemberExpr *UnresolvedMemberExpr::create(ASTContext &ctx, SourceLoc dotLoc, DeclNameLoc nameLoc, - DeclName name, + DeclNameRef name, bool implicit) { size_t size = totalSizeToAlloc({ }, { }, /*hasTrailingClosure=*/false); @@ -1563,7 +1563,7 @@ UnresolvedMemberExpr *UnresolvedMemberExpr::create(ASTContext &ctx, UnresolvedMemberExpr * UnresolvedMemberExpr::create(ASTContext &ctx, SourceLoc dotLoc, - DeclNameLoc nameLoc, DeclName name, + DeclNameLoc nameLoc, DeclNameRef name, SourceLoc lParenLoc, ArrayRef args, ArrayRef argLabels, @@ -1887,7 +1887,7 @@ TypeExpr *TypeExpr::createForDecl(DeclNameLoc Loc, TypeDecl *Decl, bool isImplicit) { ASTContext &C = Decl->getASTContext(); assert(Loc.isValid() || isImplicit); - auto *Repr = new (C) SimpleIdentTypeRepr(Loc, Decl->getName()); + auto *Repr = new (C) SimpleIdentTypeRepr(Loc, Decl->createNameRef()); Repr->setValue(Decl, DC); auto result = new (C) TypeExpr(TypeLoc(Repr, Type())); if (isImplicit) @@ -1908,13 +1908,13 @@ TypeExpr *TypeExpr::createForMemberDecl(DeclNameLoc ParentNameLoc, // The first component is the parent type. auto *ParentComp = new (C) SimpleIdentTypeRepr(ParentNameLoc, - Parent->getName()); + Parent->createNameRef()); ParentComp->setValue(Parent, nullptr); Components.push_back(ParentComp); // The second component is the member we just found. auto *NewComp = new (C) SimpleIdentTypeRepr(NameLoc, - Decl->getName()); + Decl->createNameRef()); NewComp->setValue(Decl, nullptr); Components.push_back(NewComp); @@ -1935,7 +1935,7 @@ TypeExpr *TypeExpr::createForMemberDecl(IdentTypeRepr *ParentTR, assert(!Components.empty()); // Add a new component for the member we just found. - auto *NewComp = new (C) SimpleIdentTypeRepr(NameLoc, Decl->getName()); + auto *NewComp = new (C) SimpleIdentTypeRepr(NameLoc, Decl->createNameRef()); NewComp->setValue(Decl, nullptr); Components.push_back(NewComp); @@ -2172,7 +2172,7 @@ void InterpolatedStringLiteralExpr::forEachSegment(ASTContext &Ctx, name = fn->getFullName(); } else if (auto unresolvedDot = dyn_cast(call->getFn())) { - name = unresolvedDot->getName(); + name = unresolvedDot->getName().getFullName(); } bool isInterpolation = (name.getBaseName() == diff --git a/lib/AST/GenericSignatureBuilder.cpp b/lib/AST/GenericSignatureBuilder.cpp index 8037d78932e..89b4dccff81 100644 --- a/lib/AST/GenericSignatureBuilder.cpp +++ b/lib/AST/GenericSignatureBuilder.cpp @@ -1886,7 +1886,7 @@ TypeDecl *EquivalenceClass::lookupNestedType( if (decl) { SmallVector foundMembers; decl->getParentModule()->lookupQualified( - decl, name, + decl, DeclNameRef_(name), NL_QualifiedDefault | NL_OnlyTypes | NL_ProtocolMembers, foundMembers); for (auto member : foundMembers) { diff --git a/lib/AST/NameLookup.cpp b/lib/AST/NameLookup.cpp index 5799083b215..6821a01d57a 100644 --- a/lib/AST/NameLookup.cpp +++ b/lib/AST/NameLookup.cpp @@ -2331,7 +2331,7 @@ CustomAttrNominalRequest::evaluate(Evaluator &evaluator, ComponentIdentTypeRepr *components[2] = { new (ctx) SimpleIdentTypeRepr(identTypeRepr->getNameLoc(), - moduleName), + DeclNameRef_(moduleName)), identTypeRepr }; diff --git a/lib/AST/TypeRepr.cpp b/lib/AST/TypeRepr.cpp index 6077454bf96..44ceb4c6919 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); } -DeclName ComponentIdentTypeRepr::getNameRef() const { - if (IdOrDecl.is()) - return IdOrDecl.get(); +DeclNameRef ComponentIdentTypeRepr::getNameRef() const { + if (IdOrDecl.is()) + return IdOrDecl.get(); - return IdOrDecl.get()->getFullName(); + return DeclNameRef_(IdOrDecl.get()->getFullName()); } static void printTypeRepr(const TypeRepr *TyR, ASTPrinter &Printer, @@ -450,7 +450,7 @@ TupleTypeRepr *TupleTypeRepr::createEmpty(const ASTContext &C, GenericIdentTypeRepr *GenericIdentTypeRepr::create(const ASTContext &C, DeclNameLoc Loc, - DeclName Id, + DeclNameRef Id, ArrayRef GenericArgs, SourceRange AngleBrackets) { auto size = totalSizeToAlloc(GenericArgs.size()); diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index fc72a2fa13c..f374c263403 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -7752,7 +7752,7 @@ static void finishTypeWitnesses( NL_OnlyTypes | NL_ProtocolMembers); - dc->lookupQualified(nominal, assocType->getFullName(), options, + dc->lookupQualified(nominal, DeclNameRef_(assocType->getFullName()), options, lookupResults); for (auto member : lookupResults) { auto typeDecl = cast(member); diff --git a/lib/IDE/ExprContextAnalysis.cpp b/lib/IDE/ExprContextAnalysis.cpp index baaf1431511..827930946e7 100644 --- a/lib/IDE/ExprContextAnalysis.cpp +++ b/lib/IDE/ExprContextAnalysis.cpp @@ -278,12 +278,13 @@ public: /// Collect function (or subscript) members with the given \p name on \p baseTy. static void collectPossibleCalleesByQualifiedLookup( - DeclContext &DC, Type baseTy, DeclBaseName name, + DeclContext &DC, Type baseTy, DeclNameRef name, SmallVectorImpl &candidates) { bool isOnMetaType = baseTy->is(); SmallVector decls; - if (!DC.lookupQualified(baseTy->getMetatypeInstanceType(), name, + if (!DC.lookupQualified(baseTy->getMetatypeInstanceType(), + name.withoutArgumentLabels(), NL_QualifiedDefault | NL_ProtocolMembers, decls)) return; @@ -341,7 +342,7 @@ static void collectPossibleCalleesByQualifiedLookup( /// Collect function (or subscript) members with the given \p name on /// \p baseExpr expression. static void collectPossibleCalleesByQualifiedLookup( - DeclContext &DC, Expr *baseExpr, DeclBaseName name, + DeclContext &DC, Expr *baseExpr, DeclNameRef name, SmallVectorImpl &candidates) { ConcreteDeclRef ref = nullptr; auto baseTyOpt = getTypeOfCompletionContextExpr( @@ -388,11 +389,12 @@ static bool collectPossibleCalleesForApply( } } else if (auto *UDE = dyn_cast(fnExpr)) { collectPossibleCalleesByQualifiedLookup( - DC, UDE->getBase(), UDE->getName().getBaseName(), candidates); + DC, UDE->getBase(), UDE->getName(), candidates); } else if (auto *DSCE = dyn_cast(fnExpr)) { if (auto *DRE = dyn_cast(DSCE->getFn())) { collectPossibleCalleesByQualifiedLookup( - DC, DSCE->getArg(), DRE->getDecl()->getBaseName(), candidates); + DC, DSCE->getArg(), DeclNameRef_(DRE->getDecl()->getFullName()), + candidates); } } @@ -409,7 +411,7 @@ static bool collectPossibleCalleesForApply( auto baseTy = AMT->getInstanceType(); if (baseTy->mayHaveMembers()) collectPossibleCalleesByQualifiedLookup( - DC, AMT, DeclBaseName::createConstructor(), candidates); + DC, AMT, DeclNameRef::createConstructor(), candidates); } } @@ -430,7 +432,7 @@ static bool collectPossibleCalleesForSubscript( } } else { collectPossibleCalleesByQualifiedLookup(DC, subscriptExpr->getBase(), - DeclBaseName::createSubscript(), + DeclNameRef::createSubscript(), candidates); } return !candidates.empty(); @@ -442,7 +444,6 @@ static bool collectPossibleCalleesForUnresolvedMember( DeclContext &DC, UnresolvedMemberExpr *unresolvedMemberExpr, SmallVectorImpl &candidates) { auto currModule = DC.getParentModule(); - auto baseName = unresolvedMemberExpr->getName().getBaseName(); // Get the context of the expression itself. ExprContextInfo contextInfo(&DC, unresolvedMemberExpr); @@ -451,7 +452,8 @@ static bool collectPossibleCalleesForUnresolvedMember( continue; SmallVector members; collectPossibleCalleesByQualifiedLookup(DC, MetatypeType::get(expectedTy), - baseName, members); + unresolvedMemberExpr->getName(), + members); for (auto member : members) { if (isReferenceableByImplicitMemberExpr(currModule, &DC, expectedTy, member.second)) diff --git a/lib/IDE/SourceEntityWalker.cpp b/lib/IDE/SourceEntityWalker.cpp index 20131c6d5de..a4548b33a0f 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); @@ -668,7 +668,7 @@ 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.getBaseIdentifier().getLength(); diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index a1f3c2ce42e..078b4b8a815 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -753,7 +753,7 @@ Parser::parseImplementsAttribute(SourceLoc AtLoc, SourceLoc Loc) { SourceLoc lParenLoc = consumeToken(); DeclNameLoc MemberNameLoc; - DeclName MemberName; + DeclNameRef MemberName; ParserResult ProtocolType; { SyntaxParsingContext ContentContext( @@ -794,9 +794,12 @@ Parser::parseImplementsAttribute(SourceLoc AtLoc, SourceLoc Loc) { return Status; } + // FIXME(ModQual): Reject module qualification on MemberName. + return ParserResult( ImplementsAttr::create(Context, AtLoc, SourceRange(Loc, rParenLoc), - ProtocolType.get(), MemberName, MemberNameLoc)); + ProtocolType.get(), MemberName.getFullName(), + MemberNameLoc)); } /// Parse a `@differentiable` attribute, returning true on error. @@ -817,8 +820,8 @@ Parser::parseDifferentiableAttribute(SourceLoc atLoc, SourceLoc loc) { SourceLoc lParenLoc = loc, rParenLoc = loc; bool linear = false; SmallVector params; - Optional jvpSpec; - Optional vjpSpec; + Optional jvpSpec; + Optional vjpSpec; TrailingWhereClause *whereClause = nullptr; // Parse '('. @@ -946,7 +949,8 @@ bool Parser::parseDifferentiationParametersClause( bool Parser::parseDifferentiableAttributeArguments( bool &linear, SmallVectorImpl ¶ms, - Optional &jvpSpec, Optional &vjpSpec, + Optional &jvpSpec, + Optional &vjpSpec, TrailingWhereClause *&whereClause) { StringRef AttrName = "differentiable"; @@ -1006,7 +1010,7 @@ bool Parser::parseDifferentiableAttributeArguments( // Function that parses a label and a function specifier, e.g. 'vjp: foo(_:)'. // Return true on error. - auto parseFuncSpec = [&](StringRef label, DeclNameWithLoc &result, + auto parseFuncSpec = [&](StringRef label, DeclNameRefWithLoc &result, bool &terminateParsingArgs) -> bool { // Parse label. if (parseSpecificIdentifier(label, @@ -1035,7 +1039,7 @@ bool Parser::parseDifferentiableAttributeArguments( if (isIdentifier(Tok, "jvp")) { SyntaxParsingContext JvpContext( SyntaxContext, SyntaxKind::DifferentiableAttributeFuncSpecifier); - jvpSpec = DeclNameWithLoc(); + jvpSpec = DeclNameRefWithLoc(); if (parseFuncSpec("jvp", *jvpSpec, terminateParsingArgs)) return errorAndSkipUntilConsumeRightParen(*this, AttrName); if (terminateParsingArgs) @@ -1048,7 +1052,7 @@ bool Parser::parseDifferentiableAttributeArguments( if (isIdentifier(Tok, "vjp")) { SyntaxParsingContext VjpContext( SyntaxContext, SyntaxKind::DifferentiableAttributeFuncSpecifier); - vjpSpec = DeclNameWithLoc(); + vjpSpec = DeclNameRefWithLoc(); if (parseFuncSpec("vjp", *vjpSpec, terminateParsingArgs)) return errorAndSkipUntilConsumeRightParen(*this, AttrName); if (terminateParsingArgs) @@ -1087,7 +1091,7 @@ ParserResult Parser::parseDerivativeAttribute(SourceLoc atLoc, SourceLoc loc) { StringRef AttrName = "derivative"; SourceLoc lParenLoc = loc, rParenLoc = loc; - DeclNameWithLoc original; + DeclNameRefWithLoc original; SmallVector params; // Parse trailing comma, if it exists, and check for errors. @@ -2033,7 +2037,7 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc, } SourceLoc LParenLoc = consumeToken(tok::l_paren); - DeclName replacedFunction; + DeclNameRef replacedFunction; { SyntaxParsingContext ContentContext( SyntaxContext, SyntaxKind::NamedAttributeStringArgument); @@ -3652,7 +3656,7 @@ Parser::parseDecl(ParseDeclOptions Flags, if (CurDeclContext) { if (auto nominal = dyn_cast(CurDeclContext)) { diagnose(nominal->getLoc(), diag::note_in_decl_extension, false, - nominal->getName()); + nominal->createNameRef()); } else if (auto extension = dyn_cast(CurDeclContext)) { if (auto repr = extension->getExtendedTypeRepr()) { if (auto idRepr = dyn_cast(repr)) { @@ -4041,8 +4045,8 @@ ParserStatus Parser::parseInheritance(SmallVectorImpl &Inherited, // Add 'AnyObject' to the inherited list. Inherited.push_back( - new (Context) SimpleIdentTypeRepr(DeclNameLoc(classLoc), - Context.getIdentifier("AnyObject"))); + new (Context) SimpleIdentTypeRepr(DeclNameLoc(classLoc), DeclNameRef_( + Context.getIdentifier("AnyObject")))); continue; } diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index 0b9866dbb01..e416fdbb3c2 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -809,7 +809,8 @@ UnresolvedDeclRefExpr *Parser::parseExprOperator() { Identifier name = Context.getIdentifier(Tok.getText()); consumeToken(); // Bypass local lookup. - return new (Context) UnresolvedDeclRefExpr(name, refKind, DeclNameLoc(loc)); + return new (Context) UnresolvedDeclRefExpr(DeclNameRef_(name), refKind, + DeclNameLoc(loc)); } static VarDecl *getImplicitSelfDeclForSuperContext(Parser &P, @@ -823,7 +824,7 @@ static VarDecl *getImplicitSelfDeclForSuperContext(Parser &P, // Do an actual lookup for 'self' in case it shows up in a capture list. auto *methodSelf = methodContext->getImplicitSelfDecl(); - auto *lookupSelf = P.lookupInScope(P.Context.Id_self); + auto *lookupSelf = P.lookupInScope(DeclNameRef_(P.Context.Id_self)); if (lookupSelf && lookupSelf != methodSelf) { // FIXME: This is the wrong diagnostic for if someone manually declares a // variable named 'self' using backticks. @@ -1073,7 +1074,7 @@ Parser::parseExprPostfixSuffix(ParserResult Result, bool isExprBasic, // Handle "x.42" - a tuple index. if (Tok.is(tok::integer_literal)) { - DeclName name = Context.getIdentifier(Tok.getText()); + auto name = DeclNameRef_(Context.getIdentifier(Tok.getText())); SourceLoc nameLoc = consumeToken(tok::integer_literal); SyntaxContext->createNodeInPlace(SyntaxKind::MemberAccessExpr); @@ -1130,7 +1131,7 @@ Parser::parseExprPostfixSuffix(ParserResult Result, bool isExprBasic, Diag<> D = isa(Result.get()) ? diag::expected_identifier_after_super_dot_expr : diag::expected_member_name; - DeclName Name = parseUnqualifiedDeclName(/*afterDot=*/true, NameLoc, D); + DeclNameRef Name = parseUnqualifiedDeclName(/*afterDot=*/true, NameLoc, D); if (!Name) return nullptr; SyntaxContext->createNodeInPlace(SyntaxKind::MemberAccessExpr); @@ -1566,7 +1567,7 @@ ParserResult Parser::parseExprPrimary(Diag<> ID, bool isExprBasic) { /*Implicit=*/false)); } - DeclName Name; + DeclNameRef Name; DeclNameLoc NameLoc; if (Tok.is(tok::code_complete)) { @@ -1752,8 +1753,9 @@ parseStringSegments(SmallVectorImpl &Segments, ParsedTrivia EmptyTrivia; bool First = true; - DeclName appendLiteral(Context, Context.Id_appendLiteral, { Identifier() }); - DeclName appendInterpolation(Context.Id_appendInterpolation); + auto appendLiteral = DeclNameRef_(DeclName(Context, Context.Id_appendLiteral, + { Identifier() })); + auto appendInterpolation = DeclNameRef_(Context.Id_appendInterpolation); for (auto Segment : Segments) { auto InterpolationVarRef = @@ -2077,7 +2079,7 @@ void Parser::parseOptionalArgumentLabel(Identifier &name, SourceLoc &loc) { } } -DeclBaseName Parser::parseUnqualifiedDeclBaseName( +DeclNameRef Parser::parseUnqualifiedDeclBaseName( bool afterDot, DeclNameLoc &loc, const Diagnostic &diag, @@ -2111,15 +2113,15 @@ DeclBaseName Parser::parseUnqualifiedDeclBaseName( baseName = Context.getIdentifier(Tok.getText()); checkForInputIncomplete(); diagnose(Tok, diag); - return DeclName(); + return DeclNameRef(); } loc = DeclNameLoc(baseNameLoc); - return baseName; + return DeclNameRef_(baseName); } -DeclName Parser::parseUnqualifiedDeclName(bool afterDot, +DeclNameRef Parser::parseUnqualifiedDeclName(bool afterDot, DeclNameLoc &loc, const Diagnostic &diag, bool allowOperators, @@ -2147,7 +2149,7 @@ DeclName Parser::parseUnqualifiedDeclName(bool afterDot, leadingTriviaLoc(), *SyntaxContext)); consumeToken(tok::r_paren); SmallVector argumentLabels; - return DeclName(Context, baseName, argumentLabels); + return baseName.withArgumentLabels(Context, argumentLabels); } // If the token after that isn't an argument label or ':', we don't have a @@ -2202,7 +2204,7 @@ DeclName Parser::parseUnqualifiedDeclName(bool afterDot, loc = DeclNameLoc(Context, loc.getBaseNameLoc(), lparenLoc, argumentLabelLocs, rparenLoc); - return DeclName(Context, baseName, argumentLabels); + return baseName.withArgumentLabels(Context, argumentLabels); } /// expr-identifier: @@ -2215,8 +2217,8 @@ Expr *Parser::parseExprIdentifier() { // Parse the unqualified-decl-name. DeclNameLoc loc; - DeclName name = parseUnqualifiedDeclName(/*afterDot=*/false, loc, - diag::expected_expr); + DeclNameRef name = parseUnqualifiedDeclName(/*afterDot=*/false, loc, + diag::expected_expr); SmallVector args; SourceLoc LAngleLoc, RAngleLoc; @@ -2254,7 +2256,7 @@ Expr *Parser::parseExprIdentifier() { } } else { for (auto activeVar : DisabledVars) { - if (activeVar->getFullName() == name) { + if (activeVar->getFullName() == name.getFullName()) { diagnose(loc.getBaseNameLoc(), DisabledVarReason); return new (Context) ErrorExpr(loc.getSourceRange()); } @@ -2895,8 +2897,8 @@ Expr *Parser::parseExprAnonClosureArg() { if (Context.LangOpts.DebuggerSupport) { auto refKind = DeclRefKind::Ordinary; auto identifier = Context.getIdentifier(Name); - return new (Context) UnresolvedDeclRefExpr(DeclName(identifier), refKind, - DeclNameLoc(Loc)); + return new (Context) UnresolvedDeclRefExpr(DeclNameRef_(identifier), + refKind, DeclNameLoc(Loc)); } diagnose(Loc, diag::anon_closure_arg_not_in_closure); return new (Context) ErrorExpr(Loc); diff --git a/lib/Parse/ParseType.cpp b/lib/Parse/ParseType.cpp index 80daf5ca87e..6d7e84cd2c6 100644 --- a/lib/Parse/ParseType.cpp +++ b/lib/Parse/ParseType.cpp @@ -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->overwriteNameRef(genericParam->getName()); + ident->overwriteNameRef(genericParam->createNameRef()); } } return true; @@ -667,7 +667,7 @@ ParserResult Parser::parseTypeIdentifier() { SourceLoc EndLoc; while (true) { DeclNameLoc Loc; - DeclName Name = parseUnqualifiedDeclBaseName( + DeclNameRef Name = parseUnqualifiedDeclBaseName( /*afterDot=*/false, Loc, diag::expected_identifier_in_dotted_type); if (!Name) diff --git a/lib/PrintAsObjC/DeclAndTypePrinter.cpp b/lib/PrintAsObjC/DeclAndTypePrinter.cpp index 9d48481332b..c1934a25f9c 100644 --- a/lib/PrintAsObjC/DeclAndTypePrinter.cpp +++ b/lib/PrintAsObjC/DeclAndTypePrinter.cpp @@ -895,7 +895,7 @@ private: const ParsedDeclName renamedParsedDeclName) { auto declContext = D->getDeclContext(); ASTContext &astContext = D->getASTContext(); - auto renamedDeclName = renamedParsedDeclName.formDeclName(astContext); + auto renamedDeclName = renamedParsedDeclName.formDeclNameRef(astContext); if (isa(D) || isa(D)) { if (!renamedParsedDeclName.ContextName.empty()) { @@ -903,7 +903,7 @@ private: } SmallVector decls; declContext->lookupQualified(declContext->getParentModule(), - renamedDeclName.getBaseIdentifier(), + renamedDeclName.withoutArgumentLabels(), NL_OnlyTypes, decls); if (decls.size() == 1) diff --git a/lib/Sema/BuilderTransform.cpp b/lib/Sema/BuilderTransform.cpp index e992d6e1f59..f6cfce02080 100644 --- a/lib/Sema/BuilderTransform.cpp +++ b/lib/Sema/BuilderTransform.cpp @@ -80,7 +80,8 @@ private: typeExpr->setImplicit(); auto memberRef = new (ctx) UnresolvedDotExpr( - typeExpr, loc, fnName, DeclNameLoc(loc), /*implicit=*/true); + typeExpr, loc, DeclNameRef_(fnName), DeclNameLoc(loc), + /*implicit=*/true); SourceLoc openLoc = args.empty() ? loc : args.front()->getStartLoc(); SourceLoc closeLoc = args.empty() ? loc : args.back()->getEndLoc(); Expr *result = CallExpr::create(ctx, memberRef, openLoc, args, @@ -450,7 +451,7 @@ public: auto optionalTypeExpr = TypeExpr::createImplicitHack(loc, optionalType, ctx); auto someRef = new (ctx) UnresolvedDotExpr( - optionalTypeExpr, loc, ctx.getIdentifier("some"), + optionalTypeExpr, loc, DeclNameRef_(ctx.getIdentifier("some")), DeclNameLoc(loc), /*implicit=*/true); return CallExpr::createImplicit(ctx, someRef, arg, { }); } @@ -462,7 +463,7 @@ public: auto optionalTypeExpr = TypeExpr::createImplicitHack(endLoc, optionalType, ctx); return new (ctx) UnresolvedDotExpr( - optionalTypeExpr, endLoc, ctx.getIdentifier("none"), + optionalTypeExpr, endLoc, DeclNameRef_(ctx.getIdentifier("none")), DeclNameLoc(endLoc), /*implicit=*/true); } diff --git a/lib/Sema/CSApply.cpp b/lib/Sema/CSApply.cpp index 6a2d3c401c7..b492d1e18c9 100644 --- a/lib/Sema/CSApply.cpp +++ b/lib/Sema/CSApply.cpp @@ -2440,7 +2440,7 @@ namespace { ->getNominalOrBoundGenericNominal(); auto results = TypeChecker::lookupMember( baseTyNominalDecl->getModuleContext(), baseTyUnwrapped, - memberName, defaultMemberLookupOptions); + DeclNameRef_(memberName), defaultMemberLookupOptions); // Filter out any functions, instance members, enum cases with // associated values or variables whose type does not match the diff --git a/lib/Sema/CSDiag.cpp b/lib/Sema/CSDiag.cpp index 6d6a48253eb..bc41fd1e9c6 100644 --- a/lib/Sema/CSDiag.cpp +++ b/lib/Sema/CSDiag.cpp @@ -239,12 +239,13 @@ private: /// unviable ones. void diagnoseUnviableLookupResults(MemberLookupResult &lookupResults, Expr *expr, Type baseObjTy, Expr *baseExpr, - DeclName memberName, DeclNameLoc nameLoc, - SourceLoc loc); + DeclNameRef memberName, + DeclNameLoc nameLoc, SourceLoc loc); bool diagnoseMemberFailures( - Expr *E, Expr *baseEpxr, ConstraintKind lookupKind, DeclName memberName, - FunctionRefKind funcRefKind, ConstraintLocator *locator, + Expr *E, Expr *baseEpxr, ConstraintKind lookupKind, + DeclNameRef memberName, FunctionRefKind funcRefKind, + ConstraintLocator *locator, Optional)>> callback = None, bool includeInaccessibleMembers = true); @@ -274,7 +275,7 @@ private: /// unviable ones. void FailureDiagnosis::diagnoseUnviableLookupResults( MemberLookupResult &result, Expr *E, Type baseObjTy, Expr *baseExpr, - DeclName memberName, DeclNameLoc nameLoc, SourceLoc loc) { + DeclNameRef memberName, DeclNameLoc nameLoc, SourceLoc loc) { SourceRange baseRange = baseExpr ? baseExpr->getSourceRange() : SourceRange(); // If we found no results at all, mention that fact. @@ -1626,7 +1627,7 @@ bool FailureDiagnosis::diagnoseSubscriptErrors(SubscriptExpr *SE, CS.getConstraintLocator(SE, ConstraintLocator::SubscriptMember); return diagnoseMemberFailures(SE, baseExpr, ConstraintKind::ValueMember, - DeclBaseName::createSubscript(), + DeclNameRef::createSubscript(), FunctionRefKind::DoubleApply, locator, callback); } @@ -2671,7 +2672,7 @@ bool FailureDiagnosis::visitUnresolvedMemberExpr(UnresolvedMemberExpr *E) { } bool FailureDiagnosis::diagnoseMemberFailures( - Expr *E, Expr *baseExpr, ConstraintKind lookupKind, DeclName memberName, + Expr *E, Expr *baseExpr, ConstraintKind lookupKind, DeclNameRef memberName, FunctionRefKind funcRefKind, ConstraintLocator *locator, Optional)>> callback, bool includeInaccessibleMembers) { diff --git a/lib/Sema/CSDiagnostics.cpp b/lib/Sema/CSDiagnostics.cpp index eff9dc92d3a..7317936ce8b 100644 --- a/lib/Sema/CSDiagnostics.cpp +++ b/lib/Sema/CSDiagnostics.cpp @@ -1259,7 +1259,7 @@ bool RValueTreatedAsLValueFailure::diagnoseAsError() { emitDiagnostic(loc, diag::assignment_let_property_delegating_init, member->getName()); if (auto *ref = getResolvedMemberRef(member)) { - emitDiagnostic(ref, diag::decl_declared_here, member->getName()); + emitDiagnostic(ref, diag::decl_declared_here, ref->getFullName()); } return true; } @@ -3042,7 +3042,7 @@ bool SubscriptMisuseFailure::diagnoseAsNote() { /// meaning their lower case counterparts are identical. /// - DeclName is valid when such a correct case is found; invalid otherwise. DeclName MissingMemberFailure::findCorrectEnumCaseName( - Type Ty, TypoCorrectionResults &corrections, DeclName memberName) { + Type Ty, TypoCorrectionResults &corrections, DeclNameRef memberName) { if (memberName.isSpecial() || !memberName.isSimpleName()) return DeclName(); if (!Ty->getEnumOrBoundGenericEnum()) @@ -3146,10 +3146,9 @@ bool MissingMemberFailure::diagnoseAsError() { getName().getBaseName() == DeclBaseName::createConstructor()) { auto &cs = getConstraintSystem(); - auto memberName = getName().getBaseName(); auto result = cs.performMemberLookup( - ConstraintKind::ValueMember, memberName, metatypeTy, - FunctionRefKind::DoubleApply, getLocator(), + ConstraintKind::ValueMember, getName().withoutArgumentLabels(), + metatypeTy, FunctionRefKind::DoubleApply, getLocator(), /*includeInaccessibleMembers=*/true); // If there are no `init` members at all produce a tailored @@ -3470,10 +3469,10 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() { // static members doesn't make a whole lot of sense if (auto TAD = dyn_cast(Member)) { Diag.emplace(emitDiagnostic(loc, diag::typealias_outside_of_protocol, - TAD->getName())); + Name)); } else if (auto ATD = dyn_cast(Member)) { Diag.emplace(emitDiagnostic(loc, diag::assoc_type_outside_of_protocol, - ATD->getName())); + Name)); } else if (isa(Member)) { Diag.emplace(emitDiagnostic(loc, diag::construct_protocol_by_name, instanceTy)); diff --git a/lib/Sema/CSDiagnostics.h b/lib/Sema/CSDiagnostics.h index 4e891003b32..9eaa42981e2 100644 --- a/lib/Sema/CSDiagnostics.h +++ b/lib/Sema/CSDiagnostics.h @@ -461,13 +461,13 @@ private: /// Diagnose failures related to attempting member access on optional base /// type without optional chaining or force-unwrapping it first. class MemberAccessOnOptionalBaseFailure final : public FailureDiagnostic { - DeclName Member; + DeclNameRef Member; bool ResultTypeIsOptional; public: MemberAccessOnOptionalBaseFailure(ConstraintSystem &cs, ConstraintLocator *locator, - DeclName memberName, bool resultOptional) + DeclNameRef memberName, bool resultOptional) : FailureDiagnostic(cs, locator), Member(memberName), ResultTypeIsOptional(resultOptional) {} @@ -977,17 +977,17 @@ public: class InvalidMemberRefFailure : public FailureDiagnostic { Type BaseType; - DeclName Name; + DeclNameRef Name; public: InvalidMemberRefFailure(ConstraintSystem &cs, Type baseType, - DeclName memberName, ConstraintLocator *locator) + DeclNameRef memberName, ConstraintLocator *locator) : FailureDiagnostic(cs, locator), BaseType(baseType->getRValueType()), Name(memberName) {} protected: Type getBaseType() const { return BaseType; } - DeclName getName() const { return Name; } + DeclNameRef getName() const { return Name; } }; /// Diagnose situations when member referenced by name is missing @@ -1002,7 +1002,7 @@ protected: class MissingMemberFailure final : public InvalidMemberRefFailure { public: MissingMemberFailure(ConstraintSystem &cs, Type baseType, - DeclName memberName, ConstraintLocator *locator) + DeclNameRef memberName, ConstraintLocator *locator) : InvalidMemberRefFailure(cs, baseType, memberName, locator) {} bool diagnoseAsError() override; @@ -1016,7 +1016,7 @@ private: static DeclName findCorrectEnumCaseName(Type Ty, TypoCorrectionResults &corrections, - DeclName memberName); + DeclNameRef memberName); }; /// Diagnose cases where a member only accessible on generic constraints @@ -1035,7 +1035,7 @@ private: class InvalidMemberRefOnExistential final : public InvalidMemberRefFailure { public: InvalidMemberRefOnExistential(ConstraintSystem &cs, Type baseType, - DeclName memberName, ConstraintLocator *locator) + DeclNameRef memberName, ConstraintLocator *locator) : InvalidMemberRefFailure(cs, baseType, memberName, locator) {} bool diagnoseAsError() override; @@ -1060,12 +1060,12 @@ public: class AllowTypeOrInstanceMemberFailure final : public FailureDiagnostic { Type BaseType; ValueDecl *Member; - DeclName Name; + DeclNameRef Name; public: AllowTypeOrInstanceMemberFailure(ConstraintSystem &cs, Type baseType, ValueDecl *member, - DeclName name, ConstraintLocator *locator) + DeclNameRef name, ConstraintLocator *locator) : FailureDiagnostic(cs, locator), BaseType(baseType->getRValueType()), Member(member), Name(name) { assert(member); @@ -1884,10 +1884,11 @@ private: }; class MissingContextualBaseInMemberRefFailure final : public FailureDiagnostic { - DeclName MemberName; + DeclNameRef MemberName; public: - MissingContextualBaseInMemberRefFailure(ConstraintSystem &cs, DeclName member, + MissingContextualBaseInMemberRefFailure(ConstraintSystem &cs, + DeclNameRef member, ConstraintLocator *locator) : FailureDiagnostic(cs, locator), MemberName(member) {} diff --git a/lib/Sema/CSFix.cpp b/lib/Sema/CSFix.cpp index d29af555c9d..9d53a39bcad 100644 --- a/lib/Sema/CSFix.cpp +++ b/lib/Sema/CSFix.cpp @@ -88,14 +88,14 @@ bool UnwrapOptionalBase::diagnose(bool asNote) const { } UnwrapOptionalBase *UnwrapOptionalBase::create(ConstraintSystem &cs, - DeclName member, + DeclNameRef member, ConstraintLocator *locator) { return new (cs.getAllocator()) UnwrapOptionalBase(cs, FixKind::UnwrapOptionalBase, member, locator); } UnwrapOptionalBase *UnwrapOptionalBase::createWithOptionalResult( - ConstraintSystem &cs, DeclName member, ConstraintLocator *locator) { + ConstraintSystem &cs, DeclNameRef member, ConstraintLocator *locator) { return new (cs.getAllocator()) UnwrapOptionalBase( cs, FixKind::UnwrapOptionalBaseWithOptionalResult, member, locator); } @@ -428,14 +428,14 @@ bool DefineMemberBasedOnUse::diagnose(bool asNote) const { DefineMemberBasedOnUse * DefineMemberBasedOnUse::create(ConstraintSystem &cs, Type baseType, - DeclName member, ConstraintLocator *locator) { + DeclNameRef member, ConstraintLocator *locator) { return new (cs.getAllocator()) DefineMemberBasedOnUse(cs, baseType, member, locator); } AllowMemberRefOnExistential * AllowMemberRefOnExistential::create(ConstraintSystem &cs, Type baseType, - ValueDecl *member, DeclName memberName, + ValueDecl *member, DeclNameRef memberName, ConstraintLocator *locator) { return new (cs.getAllocator()) AllowMemberRefOnExistential(cs, baseType, memberName, member, locator); @@ -457,7 +457,7 @@ bool AllowTypeOrInstanceMember::diagnose(bool asNote) const { AllowTypeOrInstanceMember * AllowTypeOrInstanceMember::create(ConstraintSystem &cs, Type baseType, - ValueDecl *member, DeclName usedName, + ValueDecl *member, DeclNameRef usedName, ConstraintLocator *locator) { return new (cs.getAllocator()) AllowTypeOrInstanceMember(cs, baseType, member, usedName, locator); @@ -618,7 +618,7 @@ bool AllowInaccessibleMember::diagnose(bool asNote) const { AllowInaccessibleMember * AllowInaccessibleMember::create(ConstraintSystem &cs, Type baseType, - ValueDecl *member, DeclName name, + ValueDecl *member, DeclNameRef name, ConstraintLocator *locator) { return new (cs.getAllocator()) AllowInaccessibleMember(cs, baseType, member, name, locator); @@ -793,7 +793,7 @@ bool AllowMutatingMemberOnRValueBase::diagnose(bool asNote) const { AllowMutatingMemberOnRValueBase * AllowMutatingMemberOnRValueBase::create(ConstraintSystem &cs, Type baseType, - ValueDecl *member, DeclName name, + ValueDecl *member, DeclNameRef name, ConstraintLocator *locator) { return new (cs.getAllocator()) AllowMutatingMemberOnRValueBase(cs, baseType, member, name, locator); @@ -1102,7 +1102,7 @@ bool SpecifyBaseTypeForContextualMember::diagnose(bool asNote) const { } SpecifyBaseTypeForContextualMember *SpecifyBaseTypeForContextualMember::create( - ConstraintSystem &cs, DeclName member, ConstraintLocator *locator) { + ConstraintSystem &cs, DeclNameRef member, ConstraintLocator *locator) { return new (cs.getAllocator()) SpecifyBaseTypeForContextualMember(cs, member, locator); } diff --git a/lib/Sema/CSFix.h b/lib/Sema/CSFix.h index d54f6fcbec0..7d7076622eb 100644 --- a/lib/Sema/CSFix.h +++ b/lib/Sema/CSFix.h @@ -284,9 +284,9 @@ protected: /// Unwrap an optional base when we have a member access. class UnwrapOptionalBase final : public ConstraintFix { - DeclName MemberName; + DeclNameRef MemberName; - UnwrapOptionalBase(ConstraintSystem &cs, FixKind kind, DeclName member, + UnwrapOptionalBase(ConstraintSystem &cs, FixKind kind, DeclNameRef member, ConstraintLocator *locator) : ConstraintFix(cs, kind, locator), MemberName(member) { assert(kind == FixKind::UnwrapOptionalBase || @@ -300,11 +300,11 @@ public: bool diagnose(bool asNote = false) const override; - static UnwrapOptionalBase *create(ConstraintSystem &cs, DeclName member, + static UnwrapOptionalBase *create(ConstraintSystem &cs, DeclNameRef member, ConstraintLocator *locator); static UnwrapOptionalBase * - createWithOptionalResult(ConstraintSystem &cs, DeclName member, + createWithOptionalResult(ConstraintSystem &cs, DeclNameRef member, ConstraintLocator *locator); }; @@ -801,9 +801,9 @@ public: class DefineMemberBasedOnUse final : public ConstraintFix { Type BaseType; - DeclName Name; + DeclNameRef Name; - DefineMemberBasedOnUse(ConstraintSystem &cs, Type baseType, DeclName member, + DefineMemberBasedOnUse(ConstraintSystem &cs, Type baseType, DeclNameRef member, ConstraintLocator *locator) : ConstraintFix(cs, FixKind::DefineMemberBasedOnUse, locator), BaseType(baseType), Name(member) {} @@ -819,18 +819,18 @@ public: bool diagnose(bool asNote = false) const override; static DefineMemberBasedOnUse *create(ConstraintSystem &cs, Type baseType, - DeclName member, + DeclNameRef member, ConstraintLocator *locator); }; class AllowInvalidMemberRef : public ConstraintFix { Type BaseType; ValueDecl *Member; - DeclName Name; + DeclNameRef Name; protected: AllowInvalidMemberRef(ConstraintSystem &cs, FixKind kind, Type baseType, - ValueDecl *member, DeclName name, + ValueDecl *member, DeclNameRef name, ConstraintLocator *locator) : ConstraintFix(cs, kind, locator), BaseType(baseType), Member(member), Name(name) {} @@ -840,12 +840,12 @@ public: ValueDecl *getMember() const { return Member; } - DeclName getMemberName() const { return Name; } + DeclNameRef getMemberName() const { return Name; } }; class AllowMemberRefOnExistential final : public AllowInvalidMemberRef { AllowMemberRefOnExistential(ConstraintSystem &cs, Type baseType, - DeclName memberName, ValueDecl *member, + DeclNameRef memberName, ValueDecl *member, ConstraintLocator *locator) : AllowInvalidMemberRef(cs, FixKind::AllowMemberRefOnExistential, baseType, member, memberName, locator) {} @@ -862,13 +862,13 @@ public: static AllowMemberRefOnExistential *create(ConstraintSystem &cs, Type baseType, ValueDecl *member, - DeclName memberName, + DeclNameRef memberName, ConstraintLocator *locator); }; class AllowTypeOrInstanceMember final : public AllowInvalidMemberRef { AllowTypeOrInstanceMember(ConstraintSystem &cs, Type baseType, - ValueDecl *member, DeclName name, + ValueDecl *member, DeclNameRef name, ConstraintLocator *locator) : AllowInvalidMemberRef(cs, FixKind::AllowTypeOrInstanceMember, baseType, member, name, locator) { @@ -883,7 +883,7 @@ public: bool diagnose(bool asNote = false) const override; static AllowTypeOrInstanceMember *create(ConstraintSystem &cs, Type baseType, - ValueDecl *member, DeclName usedName, + ValueDecl *member, DeclNameRef usedName, ConstraintLocator *locator); }; @@ -989,7 +989,7 @@ public: class AllowMutatingMemberOnRValueBase final : public AllowInvalidMemberRef { AllowMutatingMemberOnRValueBase(ConstraintSystem &cs, Type baseType, - ValueDecl *member, DeclName name, + ValueDecl *member, DeclNameRef name, ConstraintLocator *locator) : AllowInvalidMemberRef(cs, FixKind::AllowMutatingMemberOnRValueBase, baseType, member, name, locator) {} @@ -1002,8 +1002,8 @@ public: bool diagnose(bool asNote = false) const override; static AllowMutatingMemberOnRValueBase * - create(ConstraintSystem &cs, Type baseType, ValueDecl *member, DeclName name, - ConstraintLocator *locator); + create(ConstraintSystem &cs, Type baseType, ValueDecl *member, + DeclNameRef name, ConstraintLocator *locator); }; class AllowClosureParamDestructuring final : public ConstraintFix { @@ -1145,7 +1145,7 @@ public: class AllowInaccessibleMember final : public AllowInvalidMemberRef { AllowInaccessibleMember(ConstraintSystem &cs, Type baseType, - ValueDecl *member, DeclName name, + ValueDecl *member, DeclNameRef name, ConstraintLocator *locator) : AllowInvalidMemberRef(cs, FixKind::AllowInaccessibleMember, baseType, member, name, locator) {} @@ -1158,7 +1158,7 @@ public: bool diagnose(bool asNote = false) const override; static AllowInaccessibleMember *create(ConstraintSystem &cs, Type baseType, - ValueDecl *member, DeclName name, + ValueDecl *member, DeclNameRef name, ConstraintLocator *locator); }; @@ -1557,9 +1557,9 @@ public: }; class SpecifyBaseTypeForContextualMember final : public ConstraintFix { - DeclName MemberName; + DeclNameRef MemberName; - SpecifyBaseTypeForContextualMember(ConstraintSystem &cs, DeclName member, + SpecifyBaseTypeForContextualMember(ConstraintSystem &cs, DeclNameRef member, ConstraintLocator *locator) : ConstraintFix(cs, FixKind::SpecifyBaseTypeForContextualMember, locator), MemberName(member) {} @@ -1574,7 +1574,7 @@ public: bool diagnose(bool asNote = false) const; static SpecifyBaseTypeForContextualMember * - create(ConstraintSystem &cs, DeclName member, ConstraintLocator *locator); + create(ConstraintSystem &cs, DeclNameRef member, ConstraintLocator *locator); }; } // end namespace constraints diff --git a/lib/Sema/CSGen.cpp b/lib/Sema/CSGen.cpp index c7d45a660a4..3b23356eda6 100644 --- a/lib/Sema/CSGen.cpp +++ b/lib/Sema/CSGen.cpp @@ -932,7 +932,7 @@ namespace { /// Add constraints for a reference to a named member of the given /// base type, and return the type of such a reference. - Type addMemberRefConstraints(Expr *expr, Expr *base, DeclName name, + Type addMemberRefConstraints(Expr *expr, Expr *base, DeclNameRef name, FunctionRefKind functionRefKind, ArrayRef outerAlternatives) { // The base must have a member of the given name, such that accessing @@ -1077,7 +1077,7 @@ namespace { CS.addBindOverloadConstraint(memberTy, choice, memberLocator, CurDC); } else { - CS.addValueMemberConstraint(baseTy, DeclBaseName::createSubscript(), + CS.addValueMemberConstraint(baseTy, DeclNameRef::createSubscript(), memberTy, CurDC, FunctionRefKind::DoubleApply, /*outerAlternatives=*/{}, @@ -2043,8 +2043,8 @@ namespace { Type visitTupleElementExpr(TupleElementExpr *expr) { ASTContext &context = CS.getASTContext(); - Identifier name - = context.getIdentifier(llvm::utostr(expr->getFieldNumber())); + auto name = DeclNameRef_( + context.getIdentifier(llvm::utostr(expr->getFieldNumber()))); return addMemberRefConstraints(expr, expr->getBase(), name, FunctionRefKind::Unapplied, /*outerAlternatives=*/{}); @@ -3053,8 +3053,8 @@ namespace { TVO_CanBindToNoEscape); componentTypeVars.push_back(memberTy); auto lookupName = kind == KeyPathExpr::Component::Kind::UnresolvedProperty - ? component.getUnresolvedDeclName() - : component.getDeclRef().getDecl()->getFullName(); + ? DeclNameRef(component.getUnresolvedDeclName()) // FIXME: type change needed + : component.getDeclRef().getDecl()->createNameRef(); auto refKind = lookupName.isSimpleName() ? FunctionRefKind::Unapplied @@ -3874,8 +3874,8 @@ swift::resolveValueMember(DeclContext &DC, Type BaseTy, DeclName Name) { // Look up all members of BaseTy with the given Name. MemberLookupResult LookupResult = CS.performMemberLookup( - ConstraintKind::ValueMember, Name, BaseTy, FunctionRefKind::SingleApply, - nullptr, false); + ConstraintKind::ValueMember, DeclNameRef_(Name), BaseTy, + FunctionRefKind::SingleApply, nullptr, false); // Keep track of all the unviable members. for (auto Can : LookupResult.UnviableCandidates) diff --git a/lib/Sema/CSSimplify.cpp b/lib/Sema/CSSimplify.cpp index 2289b0da158..59bdbbe9cdb 100644 --- a/lib/Sema/CSSimplify.cpp +++ b/lib/Sema/CSSimplify.cpp @@ -4660,7 +4660,7 @@ ConstraintSystem::simplifyConstructionConstraint( // variable T. T2 is the result type provided via the construction // constraint itself. addValueMemberConstraint(MetatypeType::get(valueType, getASTContext()), - DeclBaseName::createConstructor(), + DeclNameRef::createConstructor(), memberType, useDC, functionRefKind, /*outerAlternatives=*/{}, @@ -5372,7 +5372,7 @@ static bool isSelfRecursiveKeyPathDynamicMemberLookup( /// try to identify and classify inaccessible members that may be being /// referenced. MemberLookupResult ConstraintSystem:: -performMemberLookup(ConstraintKind constraintKind, DeclName memberName, +performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName, Type baseTy, FunctionRefKind functionRefKind, ConstraintLocator *memberLocator, bool includeInaccessibleMembers) { @@ -5446,8 +5446,8 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName, // anything else, because the cost of the general search is so // high. if (auto info = getArgumentInfo(memberLocator)) { - memberName = DeclName(ctx, memberName.getBaseName(), - info->Labels); + memberName.getFullName() = DeclName(ctx, memberName.getBaseName(), + info->Labels); } } @@ -5767,7 +5767,7 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName, memberName.getBaseName() == DeclBaseName::createConstructor() && !isImplicitInit) { auto &compatLookup = lookupMember(instanceTy, - ctx.getIdentifier("init")); + DeclNameRef_(ctx.getIdentifier("init"))); for (auto result : compatLookup) addChoice(getOverloadChoice(result.getValueDecl(), /*isBridged=*/false, @@ -5840,8 +5840,8 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName, auto subscriptName = DeclName(ctx, DeclBaseName::createSubscript(), ctx.Id_dynamicMember); auto subscripts = performMemberLookup( - constraintKind, subscriptName, baseTy, functionRefKind, memberLocator, - includeInaccessibleMembers); + constraintKind, DeclNameRef_(subscriptName), baseTy, functionRefKind, + memberLocator, includeInaccessibleMembers); // Reflect the candidates found as `DynamicMemberLookup` results. auto name = memberName.getBaseIdentifier(); @@ -6052,7 +6052,7 @@ static ConstraintFix *validateInitializerRef(ConstraintSystem &cs, static ConstraintFix * fixMemberRef(ConstraintSystem &cs, Type baseTy, - DeclName memberName, const OverloadChoice &choice, + DeclNameRef memberName, const OverloadChoice &choice, ConstraintLocator *locator, Optional reason = None) { // Not all of the choices handled here are going @@ -6120,7 +6120,7 @@ fixMemberRef(ConstraintSystem &cs, Type baseTy, } ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint( - ConstraintKind kind, Type baseTy, DeclName member, Type memberTy, + ConstraintKind kind, Type baseTy, DeclNameRef member, Type memberTy, DeclContext *useDC, FunctionRefKind functionRefKind, ArrayRef outerAlternatives, TypeMatchOptions flags, ConstraintLocatorBuilder locatorB) { @@ -6339,7 +6339,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint( } auto solveWithNewBaseOrName = [&](Type baseType, - DeclName memberName) -> SolutionKind { + DeclNameRef memberName) -> SolutionKind { return simplifyMemberConstraint(kind, baseType, memberName, memberTy, useDC, functionRefKind, outerAlternatives, flags | TMF_ApplyingFix, locatorB); @@ -6382,7 +6382,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint( // Instead of using subscript operator spelled out `subscript` directly. if (member.getBaseName() == getTokenText(tok::kw_subscript)) { auto result = - solveWithNewBaseOrName(baseTy, DeclBaseName::createSubscript()); + solveWithNewBaseOrName(baseTy, DeclNameRef::createSubscript()); // Looks like it was indeed meant to be a subscript operator. if (result == SolutionKind::Solved) return recordFix(UseSubscriptOperator::create(*this, locator)) @@ -7474,7 +7474,8 @@ ConstraintSystem::simplifyApplicableFnConstraint( // Static member constraint requires `FunctionRefKind::DoubleApply`. // TODO: Use a custom locator element to identify this member constraint // instead of just pointing to the function expr. - addValueMemberConstraint(origLValueType2, DeclName(ctx.Id_callAsFunction), + addValueMemberConstraint(origLValueType2, + DeclNameRef_(ctx.Id_callAsFunction), memberTy, DC, FunctionRefKind::SingleApply, /*outerAlternatives*/ {}, locator); // Add new applicable function constraint based on the member type @@ -7608,7 +7609,7 @@ lookupDynamicCallableMethods(Type type, ConstraintSystem &CS, auto decl = type->getAnyNominal(); auto methodName = DeclName(ctx, ctx.Id_dynamicallyCall, { argumentName }); auto matches = CS.performMemberLookup(ConstraintKind::ValueMember, - methodName, type, + DeclNameRef_(methodName), type, FunctionRefKind::SingleApply, CS.getConstraintLocator(locator), /*includeInaccessibleMembers*/ false); @@ -7845,9 +7846,9 @@ ConstraintSystem::simplifyDynamicCallableApplicableFnConstraint( // TODO(diagnostics): This is not going to be necessary once // `@dynamicCallable` uses existing `member` machinery. - auto memberName = DeclName( - ctx, ctx.Id_dynamicallyCall, - {useKwargsMethod ? ctx.Id_withKeywordArguments : ctx.Id_withArguments}); + auto argLabel = useKwargsMethod ? ctx.Id_withKeywordArguments + : ctx.Id_withArguments; + DeclNameRef memberName({ ctx, ctx.Id_dynamicallyCall, {argLabel} }); auto *fix = DefineMemberBasedOnUse::create( *this, desugar2, memberName, diff --git a/lib/Sema/Constraint.cpp b/lib/Sema/Constraint.cpp index 1e743d565d9..0a41efe4197 100644 --- a/lib/Sema/Constraint.cpp +++ b/lib/Sema/Constraint.cpp @@ -150,7 +150,7 @@ Constraint::Constraint(ConstraintKind Kind, Type First, Type Second, Type Third, } Constraint::Constraint(ConstraintKind kind, Type first, Type second, - DeclName member, DeclContext *useDC, + DeclNameRef member, DeclContext *useDC, FunctionRefKind functionRefKind, ConstraintLocator *locator, ArrayRef typeVars) @@ -610,7 +610,7 @@ Constraint *Constraint::create(ConstraintSystem &cs, ConstraintKind kind, Constraint *Constraint::createMemberOrOuterDisjunction( ConstraintSystem &cs, ConstraintKind kind, Type first, Type second, - DeclName member, DeclContext *useDC, FunctionRefKind functionRefKind, + DeclNameRef member, DeclContext *useDC, FunctionRefKind functionRefKind, ArrayRef outerAlternatives, ConstraintLocator *locator) { auto memberConstraint = createMember(cs, kind, first, second, member, useDC, functionRefKind, locator); @@ -629,8 +629,8 @@ Constraint *Constraint::createMemberOrOuterDisjunction( } Constraint *Constraint::createMember(ConstraintSystem &cs, ConstraintKind kind, - Type first, Type second, DeclName member, - DeclContext *useDC, + Type first, Type second, + DeclNameRef member, DeclContext *useDC, FunctionRefKind functionRefKind, ConstraintLocator *locator) { // Collect type variables. diff --git a/lib/Sema/Constraint.h b/lib/Sema/Constraint.h index 17bf0908bb1..6af00f357f2 100644 --- a/lib/Sema/Constraint.h +++ b/lib/Sema/Constraint.h @@ -317,7 +317,7 @@ class Constraint final : public llvm::ilist_node, /// If non-null, the name of a member of the first type is that /// being related to the second type. - DeclName Member; + DeclNameRef Member; /// The DC in which the use appears. DeclContext *UseDC; @@ -360,7 +360,7 @@ class Constraint final : public llvm::ilist_node, ArrayRef typeVars); /// Construct a new member constraint. - Constraint(ConstraintKind kind, Type first, Type second, DeclName member, + Constraint(ConstraintKind kind, Type first, Type second, DeclNameRef member, DeclContext *useDC, FunctionRefKind functionRefKind, ConstraintLocator *locator, ArrayRef typeVars); @@ -400,12 +400,12 @@ public: /// alternatives. static Constraint *createMemberOrOuterDisjunction( ConstraintSystem &cs, ConstraintKind kind, Type first, Type second, - DeclName member, DeclContext *useDC, FunctionRefKind functionRefKind, + DeclNameRef member, DeclContext *useDC, FunctionRefKind functionRefKind, ArrayRef outerAlternatives, ConstraintLocator *locator); /// Create a new member constraint. static Constraint *createMember(ConstraintSystem &cs, ConstraintKind kind, - Type first, Type second, DeclName member, + Type first, Type second, DeclNameRef member, DeclContext *useDC, FunctionRefKind functionRefKind, ConstraintLocator *locator); @@ -586,7 +586,7 @@ public: ProtocolDecl *getProtocol() const; /// Retrieve the name of the member for a member constraint. - DeclName getMember() const { + DeclNameRef getMember() const { assert(Kind == ConstraintKind::ValueMember || Kind == ConstraintKind::UnresolvedValueMember); return Member.Member; diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp index 40dbf65b963..31792f740f3 100644 --- a/lib/Sema/ConstraintSystem.cpp +++ b/lib/Sema/ConstraintSystem.cpp @@ -232,7 +232,7 @@ getDynamicResultSignature(ValueDecl *decl) { llvm_unreachable("Not a valid @objc member"); } -LookupResult &ConstraintSystem::lookupMember(Type base, DeclName name) { +LookupResult &ConstraintSystem::lookupMember(Type base, DeclNameRef name) { // Check whether we've already performed this lookup. auto &result = MemberLookups[{base, name}]; if (result) return *result; @@ -2048,8 +2048,10 @@ std::pair ConstraintSystem::adjustTypeOfOverloadReference( // Attempt to lookup a member with a give name in the root type and // assign result to the leaf type of the keypath. bool isSubscriptRef = locator->isSubscriptMemberRef(); - DeclName memberName = - isSubscriptRef ? DeclBaseName::createSubscript() : choice.getName(); + DeclNameRef memberName = isSubscriptRef + ? DeclNameRef::createSubscript() + // FIXME: Should propagate name-as-written through. + : DeclNameRef_(choice.getName()); auto *memberRef = Constraint::createMember( *this, ConstraintKind::ValueMember, LValueType::get(rootTy), memberTy, @@ -2958,7 +2960,9 @@ bool ConstraintSystem::diagnoseAmbiguity(ArrayRef solutions) { // depth-first numbering of expressions. if (bestOverload) { auto &overload = diff.overloads[*bestOverload]; - auto name = getOverloadChoiceName(overload.choices); + // FIXME: We would prefer to emit the name as written, but that information + // is not sufficiently centralized in the AST. + auto name = DeclNameRef_(getOverloadChoiceName(overload.choices)); auto anchor = simplifyLocatorToAnchor(overload.locator); // Emit the ambiguity diagnostic. diff --git a/lib/Sema/ConstraintSystem.h b/lib/Sema/ConstraintSystem.h index 65537c15486..04f29a404a5 100644 --- a/lib/Sema/ConstraintSystem.h +++ b/lib/Sema/ConstraintSystem.h @@ -1177,7 +1177,7 @@ private: size_t MaxMemory = 0; /// Cached member lookups. - llvm::DenseMap, Optional> + llvm::DenseMap, Optional> MemberLookups; /// Cached sets of "alternative" literal types. @@ -1907,7 +1907,7 @@ public: /// and no new names are introduced after name binding. /// /// \returns A reference to the member-lookup result. - LookupResult &lookupMember(Type base, DeclName name); + LookupResult &lookupMember(Type base, DeclNameRef name); /// Retrieve the set of "alternative" literal types that we'll explore /// for a given literal protocol kind. @@ -2306,7 +2306,7 @@ public: } /// Add a value member constraint to the constraint system. - void addValueMemberConstraint(Type baseTy, DeclName name, Type memberTy, + void addValueMemberConstraint(Type baseTy, DeclNameRef name, Type memberTy, DeclContext *useDC, FunctionRefKind functionRefKind, ArrayRef outerAlternatives, @@ -2336,7 +2336,7 @@ public: /// Add a value member constraint for an UnresolvedMemberRef /// to the constraint system. - void addUnresolvedValueMemberConstraint(Type baseTy, DeclName name, + void addUnresolvedValueMemberConstraint(Type baseTy, DeclNameRef name, Type memberTy, DeclContext *useDC, FunctionRefKind functionRefKind, ConstraintLocatorBuilder locator) { @@ -3181,7 +3181,7 @@ public: /// try to identify and classify inaccessible members that may be being /// referenced. MemberLookupResult performMemberLookup(ConstraintKind constraintKind, - DeclName memberName, Type baseTy, + DeclNameRef memberName, Type baseTy, FunctionRefKind functionRefKind, ConstraintLocator *memberLocator, bool includeInaccessibleMembers); @@ -3258,7 +3258,7 @@ private: /// Attempt to simplify the given member constraint. SolutionKind simplifyMemberConstraint( - ConstraintKind kind, Type baseType, DeclName member, Type memberType, + ConstraintKind kind, Type baseType, DeclNameRef member, Type memberType, DeclContext *useDC, FunctionRefKind functionRefKind, ArrayRef outerAlternatives, TypeMatchOptions flags, ConstraintLocatorBuilder locator); diff --git a/lib/Sema/DebuggerTestingTransform.cpp b/lib/Sema/DebuggerTestingTransform.cpp index 93f7781a7c8..901af551b1d 100644 --- a/lib/Sema/DebuggerTestingTransform.cpp +++ b/lib/Sema/DebuggerTestingTransform.cpp @@ -67,14 +67,14 @@ class DebuggerTestingTransform : public ASTWalker { ASTContext &Ctx; DiscriminatorFinder &DF; std::vector LocalDeclContextStack; - const DeclName StringForPrintObjectName; - const DeclName DebuggerTestingCheckExpectName; + const DeclNameRef StringForPrintObjectName; + const DeclNameRef DebuggerTestingCheckExpectName; public: DebuggerTestingTransform(ASTContext &Ctx, DiscriminatorFinder &DF) : Ctx(Ctx), DF(DF), - StringForPrintObjectName((Ctx.getIdentifier("_stringForPrintObject"))), - DebuggerTestingCheckExpectName((Ctx.getIdentifier("_debuggerTestingCheckExpect"))) {} + StringForPrintObjectName(DeclNameRef_(Ctx.getIdentifier("_stringForPrintObject"))), + DebuggerTestingCheckExpectName(DeclNameRef_(Ctx.getIdentifier("_debuggerTestingCheckExpect"))) {} bool walkToDeclPre(Decl *D) override { pushLocalDeclContext(D); diff --git a/lib/Sema/DerivedConformanceCodable.cpp b/lib/Sema/DerivedConformanceCodable.cpp index 68d9577b2fd..dc2eb9ebbf3 100644 --- a/lib/Sema/DerivedConformanceCodable.cpp +++ b/lib/Sema/DerivedConformanceCodable.cpp @@ -999,7 +999,8 @@ static bool canSynthesize(DerivedConformance &derived, ValueDecl *requirement) { } auto result = - TypeChecker::lookupMember(superclassDecl, superType, memberName); + TypeChecker::lookupMember(superclassDecl, superType, + DeclNameRef_(memberName)); if (result.empty()) { // No super initializer for us to call. diff --git a/lib/Sema/DerivedConformanceCodingKey.cpp b/lib/Sema/DerivedConformanceCodingKey.cpp index fb277906a85..9b72cbebb22 100644 --- a/lib/Sema/DerivedConformanceCodingKey.cpp +++ b/lib/Sema/DerivedConformanceCodingKey.cpp @@ -214,7 +214,7 @@ deriveBodyCodingKey_enum_stringValue(AbstractFunctionDecl *strValDecl, void *) { for (auto *elt : elements) { auto *pat = new (C) EnumElementPattern(TypeLoc::withoutLoc(enumType), SourceLoc(), DeclNameLoc(), - DeclName(), elt, nullptr); + DeclNameRef(), elt, nullptr); pat->setImplicit(); auto labelItem = CaseLabelItem(pat); diff --git a/lib/Sema/DerivedConformanceEquatableHashable.cpp b/lib/Sema/DerivedConformanceEquatableHashable.cpp index 0964197547a..2e4eb62bf17 100644 --- a/lib/Sema/DerivedConformanceEquatableHashable.cpp +++ b/lib/Sema/DerivedConformanceEquatableHashable.cpp @@ -309,7 +309,7 @@ static DeclRefExpr *convertEnumToIndex(SmallVectorImpl &stmts, // generate: case .: auto pat = new (C) EnumElementPattern(TypeLoc::withoutLoc(enumType), SourceLoc(), DeclNameLoc(), - DeclName(), elt, nullptr); + DeclNameRef(), elt, nullptr); pat->setImplicit(); pat->setType(enumType); @@ -369,7 +369,7 @@ static GuardStmt *returnIfNotEqualGuard(ASTContext &C, // Next, generate the condition being checked. // lhs == rhs auto cmpFuncExpr = new (C) UnresolvedDeclRefExpr( - DeclName(C.getIdentifier("==")), DeclRefKind::BinaryOperator, + DeclNameRef_(C.Id_EqualsOperator), DeclRefKind::BinaryOperator, DeclNameLoc()); auto cmpArgsTuple = TupleExpr::create(C, SourceLoc(), { lhsExpr, rhsExpr }, @@ -512,7 +512,7 @@ deriveBodyEquatable_enum_hasAssociatedValues_eq(AbstractFunctionDecl *eqDecl, lhsPayloadVars); auto lhsElemPat = new (C) EnumElementPattern(TypeLoc::withoutLoc(enumType), SourceLoc(), DeclNameLoc(), - DeclName(), elt, + DeclNameRef(), elt, lhsSubpattern); lhsElemPat->setImplicit(); @@ -522,7 +522,7 @@ deriveBodyEquatable_enum_hasAssociatedValues_eq(AbstractFunctionDecl *eqDecl, rhsPayloadVars); auto rhsElemPat = new (C) EnumElementPattern(TypeLoc::withoutLoc(enumType), SourceLoc(), DeclNameLoc(), - DeclName(), elt, + DeclNameRef(), elt, rhsSubpattern); rhsElemPat->setImplicit(); @@ -1034,7 +1034,7 @@ deriveBodyHashable_enum_hasAssociatedValues_hashInto( payloadVars); auto pat = new (C) EnumElementPattern(TypeLoc::withoutLoc(enumType), SourceLoc(), DeclNameLoc(), - elt->getName(), elt, + DeclNameRef_(elt->getName()), elt, payloadPattern); pat->setImplicit(); diff --git a/lib/Sema/DerivedConformanceRawRepresentable.cpp b/lib/Sema/DerivedConformanceRawRepresentable.cpp index 2f70cbeb1a9..fd6dc513a36 100644 --- a/lib/Sema/DerivedConformanceRawRepresentable.cpp +++ b/lib/Sema/DerivedConformanceRawRepresentable.cpp @@ -110,7 +110,7 @@ deriveBodyRawRepresentable_raw(AbstractFunctionDecl *toRawDecl, void *) { for (auto elt : enumDecl->getAllElements()) { auto pat = new (C) EnumElementPattern(TypeLoc::withoutLoc(enumType), SourceLoc(), DeclNameLoc(), - DeclName(), elt, nullptr); + DeclNameRef(), elt, nullptr); pat->setImplicit(); auto labelItem = CaseLabelItem(pat); diff --git a/lib/Sema/InstrumenterSupport.cpp b/lib/Sema/InstrumenterSupport.cpp index e02a76a73cd..9cac1aeb20b 100644 --- a/lib/Sema/InstrumenterSupport.cpp +++ b/lib/Sema/InstrumenterSupport.cpp @@ -91,7 +91,7 @@ InstrumenterBase::InstrumenterBase(ASTContext &C, DeclContext *DC) moduleIdentifier, NLKind::UnqualifiedLookup, results); if (results.size() == 1) - ModuleIdentifier = results.front()->getFullName(); + ModuleIdentifier = results.front()->createNameRef(); // Setup File identifier StringRef filePath = TypeCheckDC->getParentSourceFile()->getFilename(); @@ -108,7 +108,7 @@ InstrumenterBase::InstrumenterBase(ASTContext &C, DeclContext *DC) fileIdentifier, NLKind::UnqualifiedLookup, results); if (results.size() == 1) - FileIdentifier = results.front()->getFullName(); + FileIdentifier = results.front()->createNameRef(); } void InstrumenterBase::anchor() {} @@ -131,7 +131,7 @@ bool InstrumenterBase::doTypeCheckImpl(ASTContext &Ctx, DeclContext *DC, return false; } -Expr *InstrumenterBase::buildIDArgumentExpr(Optional name, +Expr *InstrumenterBase::buildIDArgumentExpr(Optional name, SourceRange SR) { if (!name) return IntegerLiteralExpr::createFromUnsigned(Context, 0); diff --git a/lib/Sema/InstrumenterSupport.h b/lib/Sema/InstrumenterSupport.h index dacd55315c6..28c4645862f 100644 --- a/lib/Sema/InstrumenterSupport.h +++ b/lib/Sema/InstrumenterSupport.h @@ -42,8 +42,8 @@ class InstrumenterBase { protected: ASTContext &Context; DeclContext *TypeCheckDC; - Optional ModuleIdentifier; - Optional FileIdentifier; + Optional ModuleIdentifier; + Optional FileIdentifier; InstrumenterBase(ASTContext &C, DeclContext *DC); virtual ~InstrumenterBase() = default; @@ -53,7 +53,7 @@ protected: /// Create an expression which retrieves a valid ModuleIdentifier or /// FileIdentifier, if available. - Expr *buildIDArgumentExpr(Optional name, SourceRange SR); + Expr *buildIDArgumentExpr(Optional name, SourceRange SR); class ClosureFinder : public ASTWalker { private: diff --git a/lib/Sema/MiscDiagnostics.cpp b/lib/Sema/MiscDiagnostics.cpp index 47fb672f1b0..3ab2e389ddb 100644 --- a/lib/Sema/MiscDiagnostics.cpp +++ b/lib/Sema/MiscDiagnostics.cpp @@ -3177,7 +3177,7 @@ class ObjCSelectorWalker : public ASTWalker { auto nominal = method->getDeclContext()->getSelfNominalTypeDecl(); auto result = TypeChecker::lookupMember( const_cast(DC), nominal->getDeclaredInterfaceType(), - lookupName, + DeclNameRef_(lookupName), (defaultMemberLookupOptions | NameLookupFlags::KnownPrivate)); // If we didn't find multiple methods, there is no ambiguity. diff --git a/lib/Sema/PCMacro.cpp b/lib/Sema/PCMacro.cpp index e48d5331e70..1c554e18947 100644 --- a/lib/Sema/PCMacro.cpp +++ b/lib/Sema/PCMacro.cpp @@ -40,14 +40,14 @@ namespace { class Instrumenter : InstrumenterBase { private: unsigned &TmpNameIndex; - DeclName LogBeforeName; - DeclName LogAfterName; + DeclNameRef LogBeforeName; + DeclNameRef LogAfterName; public: Instrumenter(ASTContext &C, DeclContext *DC, unsigned &TmpNameIndex) : InstrumenterBase(C, DC), TmpNameIndex(TmpNameIndex), - LogBeforeName((C.getIdentifier("__builtin_pc_before"))), - LogAfterName((C.getIdentifier("__builtin_pc_after"))) {} + LogBeforeName(DeclNameRef_(C.getIdentifier("__builtin_pc_before"))), + LogAfterName(DeclNameRef_(C.getIdentifier("__builtin_pc_after"))) {} Stmt *transformStmt(Stmt *S) { switch (S->getKind()) { @@ -592,7 +592,7 @@ public: return *AddedGet; } - Added buildLoggerCallWithArgs(DeclName LoggerName, + Added buildLoggerCallWithArgs(DeclNameRef LoggerName, SourceRange SR) { if (!SR.isValid()) { return nullptr; diff --git a/lib/Sema/PlaygroundTransform.cpp b/lib/Sema/PlaygroundTransform.cpp index 0abc4178849..2c667546dcb 100644 --- a/lib/Sema/PlaygroundTransform.cpp +++ b/lib/Sema/PlaygroundTransform.cpp @@ -42,13 +42,13 @@ private: unsigned &TmpNameIndex; bool HighPerformance; - DeclName DebugPrintName; - DeclName PrintName; - DeclName PostPrintName; - DeclName LogWithIDName; - DeclName LogScopeExitName; - DeclName LogScopeEntryName; - DeclName SendDataName; + DeclNameRef DebugPrintName; + DeclNameRef PrintName; + DeclNameRef PostPrintName; + DeclNameRef LogWithIDName; + DeclNameRef LogScopeExitName; + DeclNameRef LogScopeEntryName; + DeclNameRef SendDataName; struct BracePair { public: @@ -126,13 +126,13 @@ public: unsigned &TmpNameIndex) : InstrumenterBase(C, DC), RNG(RNG), TmpNameIndex(TmpNameIndex), HighPerformance(HP), - DebugPrintName((C.getIdentifier("__builtin_debugPrint"))), - PrintName((C.getIdentifier("__builtin_print"))), - PostPrintName((C.getIdentifier("__builtin_postPrint"))), - LogWithIDName((C.getIdentifier("__builtin_log_with_id"))), - LogScopeExitName((C.getIdentifier("__builtin_log_scope_exit"))), - LogScopeEntryName((C.getIdentifier("__builtin_log_scope_entry"))), - SendDataName((C.getIdentifier("__builtin_send_data"))) { } + DebugPrintName(DeclNameRef_(C.getIdentifier("__builtin_debugPrint"))), + PrintName(DeclNameRef_(C.getIdentifier("__builtin_print"))), + PostPrintName(DeclNameRef_(C.getIdentifier("__builtin_postPrint"))), + LogWithIDName(DeclNameRef_(C.getIdentifier("__builtin_log_with_id"))), + LogScopeExitName(DeclNameRef_(C.getIdentifier("__builtin_log_scope_exit"))), + LogScopeEntryName(DeclNameRef_(C.getIdentifier("__builtin_log_scope_entry"))), + SendDataName(DeclNameRef_(C.getIdentifier("__builtin_send_data"))) { } Stmt *transformStmt(Stmt *S) { switch (S->getKind()) { @@ -714,7 +714,7 @@ public: Added logPrint(bool isDebugPrint, ApplyExpr *AE, PatternBindingDecl *&ArgPattern, VarDecl *&ArgVariable) { - DeclName LoggerName = isDebugPrint ? DebugPrintName : PrintName; + DeclNameRef LoggerName = isDebugPrint ? DebugPrintName : PrintName; UnresolvedDeclRefExpr *LoggerRef = new (Context) UnresolvedDeclRefExpr( LoggerName, DeclRefKind::Ordinary, @@ -801,7 +801,7 @@ public: return buildLoggerCallWithArgs(LoggerName, MutableArrayRef(), SR); } - Added buildLoggerCallWithArgs(DeclName LoggerName, + Added buildLoggerCallWithArgs(DeclNameRef LoggerName, MutableArrayRef Args, SourceRange SR) { // If something doesn't have a valid source range it can not be playground diff --git a/lib/Sema/TypeCheckAttr.cpp b/lib/Sema/TypeCheckAttr.cpp index b3685eb5dc5..72c398e1552 100644 --- a/lib/Sema/TypeCheckAttr.cpp +++ b/lib/Sema/TypeCheckAttr.cpp @@ -1127,8 +1127,8 @@ static bool hasValidDynamicCallableMethod(NominalTypeDecl *decl, bool hasKeywordArgs) { auto &ctx = decl->getASTContext(); auto declType = decl->getDeclaredType(); - auto methodName = DeclName(ctx, DeclBaseName(ctx.Id_dynamicallyCall), - { argumentName }); + auto methodName = DeclNameRef_(DeclName(ctx, ctx.Id_dynamicallyCall, + { argumentName })); auto candidates = TypeChecker::lookupMember(decl, declType, methodName); if (candidates.empty()) return false; @@ -1252,8 +1252,8 @@ visitDynamicMemberLookupAttr(DynamicMemberLookupAttr *attr) { }; // Look up `subscript(dynamicMember:)` candidates. - auto subscriptName = - DeclName(ctx, DeclBaseName::createSubscript(), ctx.Id_dynamicMember); + auto subscriptName = DeclNameRef_( + DeclName(ctx, DeclBaseName::createSubscript(), ctx.Id_dynamicMember)); auto candidates = TypeChecker::lookupMember(decl, type, subscriptName); if (!candidates.empty()) { @@ -1278,7 +1278,7 @@ visitDynamicMemberLookupAttr(DynamicMemberLookupAttr *attr) { // // Let's do another lookup using just the base name. auto newCandidates = - TypeChecker::lookupMember(decl, type, DeclBaseName::createSubscript()); + TypeChecker::lookupMember(decl, type, DeclNameRef::createSubscript()); // Validate the candidates while ignoring the label. newCandidates.filter([&](const LookupResultEntry entry, bool isOuter) { @@ -2194,7 +2194,7 @@ static FuncDecl *findReplacedAccessor(DeclNameRef replacedVarName, if (!origStorage->isDynamic()) { Diags.diagnose(attr->getLocation(), diag::dynamic_replacement_accessor_not_dynamic, - replacedVarName); + origStorage->getFullName()); attr->setInvalid(); return nullptr; } @@ -2210,7 +2210,8 @@ static FuncDecl *findReplacedAccessor(DeclNameRef replacedVarName, origStorage->getWriteImpl() == WriteImplKind::Stored)) { Diags.diagnose(attr->getLocation(), diag::dynamic_replacement_accessor_not_explicit, - (unsigned)origAccessor->getAccessorKind(), replacedVarName); + (unsigned)origAccessor->getAccessorKind(), + origStorage->getFullName()); attr->setInvalid(); return nullptr; } @@ -2333,13 +2334,13 @@ void AttributeChecker::visitDynamicReplacementAttr(DynamicReplacementAttr *attr) if (original->isObjC() && !replacement->isObjC()) { diagnose(attr->getLocation(), diag::dynamic_replacement_replacement_not_objc_dynamic, - attr->getReplacedFunctionName()); + replacement->getFullName()); attr->setInvalid(); } if (!original->isObjC() && replacement->isObjC()) { diagnose(attr->getLocation(), diag::dynamic_replacement_replaced_not_objc_dynamic, - attr->getReplacedFunctionName()); + original->getFullName()); attr->setInvalid(); } @@ -2384,8 +2385,9 @@ void AttributeChecker::visitImplementsAttr(ImplementsAttr *attr) { ProtocolDecl *PD = PT->getDecl(); // Check that the ProtocolType has the specified member. - LookupResult R = TypeChecker::lookupMember(PD->getDeclContext(), - PT, attr->getMemberName()); + LookupResult R = + TypeChecker::lookupMember(PD->getDeclContext(), PT, + DeclNameRef_(attr->getMemberName())); if (!R) { diagnose(attr->getLocation(), diag::implements_attr_protocol_lacks_member, diff --git a/lib/Sema/TypeCheckConstraints.cpp b/lib/Sema/TypeCheckConstraints.cpp index eb9c508418a..c5d5e801ee4 100644 --- a/lib/Sema/TypeCheckConstraints.cpp +++ b/lib/Sema/TypeCheckConstraints.cpp @@ -295,8 +295,8 @@ static bool diagnoseOperatorJuxtaposition(UnresolvedDeclRefExpr *UDRE, if (!Lexer::isOperator(startStr) || !Lexer::isOperator(endStr)) continue; - auto startName = Context.getIdentifier(startStr); - auto endName = Context.getIdentifier(endStr); + auto startName = DeclNameRef_(Context.getIdentifier(startStr)); + auto endName = DeclNameRef_(Context.getIdentifier(endStr)); // Perform name lookup for the first and second pieces. If either fail to // be found, then it isn't a valid split. @@ -378,7 +378,7 @@ static bool diagnoseRangeOperatorMisspell(DiagnosticEngine &Diags, if (!corrected.empty()) { Diags .diagnose(UDRE->getLoc(), diag::use_unresolved_identifier_corrected, - name, true, corrected) + UDRE->getName(), true, corrected) .highlight(UDRE->getSourceRange()) .fixItReplace(UDRE->getSourceRange(), corrected); @@ -402,7 +402,7 @@ static bool diagnoseIncDecOperator(DiagnosticEngine &Diags, if (!corrected.empty()) { Diags .diagnose(UDRE->getLoc(), diag::use_unresolved_identifier_corrected, - name, true, corrected) + UDRE->getName(), true, corrected) .highlight(UDRE->getSourceRange()); return true; @@ -442,7 +442,7 @@ static bool findNonMembers(ArrayRef lookupResults, /// /// This is very restrictive because it's a source compatibility issue (see the /// if (AllConditionalConformances) { (void)findNonMembers(...); } below). -static bool shouldConsiderOuterResultsFor(DeclName name) { +static bool shouldConsiderOuterResultsFor(DeclNameRef name) { const StringRef specialNames[] = {"min", "max"}; for (auto specialName : specialNames) if (name.isSimpleName(specialName)) @@ -457,7 +457,7 @@ static bool shouldConsiderOuterResultsFor(DeclName name) { Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, DeclContext *DC) { // Process UnresolvedDeclRefExpr by doing an unqualified lookup. - DeclName Name = UDRE->getName(); + DeclNameRef Name = UDRE->getName(); DeclNameLoc Loc = UDRE->getNameLoc(); // Perform standard value name lookup. @@ -492,7 +492,7 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, // FIXME: What if the unviable candidates have different levels of access? const ValueDecl *first = inaccessibleResults.front().getValueDecl(); Context.Diags.diagnose( - Loc, diag::candidate_inaccessible, Name, + Loc, diag::candidate_inaccessible, first->getBaseName(), first->getFormalAccessScope().accessLevelForDiagnostics()); // FIXME: If any of the candidates (usually just one) are in the same @@ -541,7 +541,7 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, }; if (!isConfused) { - if (Name == Context.Id_Self) { + if (Name.isSimpleName(Context.Id_Self)) { if (DeclContext *typeContext = DC->getInnermostTypeContext()){ Type SelfType = typeContext->getSelfInterfaceType(); @@ -624,7 +624,8 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, while (localDeclAfterUse) { if (Lookup.outerResults().empty()) { Context.Diags.diagnose(Loc, diag::use_local_before_declaration, Name); - Context.Diags.diagnose(innerDecl, diag::decl_declared_here, Name); + Context.Diags.diagnose(innerDecl, diag::decl_declared_here, + localDeclAfterUse->getFullName()); Expr *error = new (Context) ErrorExpr(UDRE->getSourceRange()); return error; } @@ -1027,7 +1028,7 @@ namespace { if (newArg) { auto newCallee = new (Context) UnresolvedDotExpr( callee->getBase(), /*dotloc=*/SourceLoc(), - DeclName(Context.Id_appendInterpolation), + DeclNameRef_(Context.Id_appendInterpolation), /*nameloc=*/DeclNameLoc(), /*Implicit=*/true); E = CallExpr::create(Context, newCallee, lParen, {newArg}, @@ -1399,7 +1400,7 @@ TypeExpr *PreCheckExpression::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) { UDE->getName().isSpecial()) return nullptr; - auto Name = UDE->getName().getBaseIdentifier(); + auto Name = UDE->getName(); auto NameLoc = UDE->getNameLoc(); // Qualified type lookup with a module base is represented as a DeclRefExpr @@ -1435,7 +1436,7 @@ TypeExpr *PreCheckExpression::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) { return nullptr; // Fold 'T.Protocol' into a protocol metatype. - if (Name == getASTContext().Id_Protocol) { + if (Name.isSimpleName(getASTContext().Id_Protocol)) { auto *NewTypeRepr = new (getASTContext()) ProtocolTypeRepr(InnerTypeRepr, NameLoc.getBaseNameLoc()); @@ -1444,7 +1445,7 @@ TypeExpr *PreCheckExpression::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) { // Fold 'T.Type' into an existential metatype if 'T' is a protocol, // or an ordinary metatype otherwise. - if (Name == getASTContext().Id_Type) { + if (Name.isSimpleName(getASTContext().Id_Type)) { auto *NewTypeRepr = new (getASTContext()) MetatypeTypeRepr(InnerTypeRepr, NameLoc.getBaseNameLoc()); @@ -2529,7 +2530,7 @@ TypeChecker::getTypeOfCompletionOperator(DeclContext *DC, Expr *LHS, // Build temporary expression to typecheck. // We allocate these expressions on the stack because we know they can't // escape and there isn't a better way to allocate scratch Expr nodes. - UnresolvedDeclRefExpr UDRE(opName, refKind, DeclNameLoc(Loc)); + UnresolvedDeclRefExpr UDRE(DeclNameRef_(opName), refKind, DeclNameLoc(Loc)); auto *opExpr = TypeChecker::resolveDeclRefExpr(&UDRE, DC); switch (refKind) { @@ -2614,7 +2615,7 @@ bool TypeChecker::typeCheckBinding(Pattern *&pattern, Expr *&initializer, loc = cs->getConstraintLocator(loc, ConstraintLocator::Member); Type memberType = cs->createTypeVariable(loc, TVO_CanBindToLValue); cs->addValueMemberConstraint( - valueType, wrapperInfo.valueVar->getFullName(), + valueType, wrapperInfo.valueVar->createNameRef(), memberType, dc, FunctionRefKind::Unapplied, { }, loc); valueType = memberType; } @@ -3113,8 +3114,9 @@ bool TypeChecker::typeCheckExprPattern(ExprPattern *EP, DeclContext *DC, // Find '~=' operators for the match. auto lookupOptions = defaultUnqualifiedLookupOptions; lookupOptions |= NameLookupFlags::KnownPrivate; - auto matchLookup = lookupUnqualified(DC, Context.Id_MatchOperator, - SourceLoc(), lookupOptions); + auto matchLookup = + lookupUnqualified(DC, DeclNameRef_(Context.Id_MatchOperator), SourceLoc(), + lookupOptions); auto &diags = DC->getASTContext().Diags; if (!matchLookup) { diags.diagnose(EP->getLoc(), diag::no_match_operator); @@ -4574,7 +4576,8 @@ IsCallableNominalTypeRequest::evaluate(Evaluator &evaluator, CanType ty, // Look for a callAsFunction method. auto &ctx = ty->getASTContext(); auto results = - TypeChecker::lookupMember(dc, ty, ctx.Id_callAsFunction, options); + TypeChecker::lookupMember(dc, ty, DeclNameRef_(ctx.Id_callAsFunction), + options); return llvm::any_of(results, [](LookupResultEntry entry) -> bool { if (auto *fd = dyn_cast(entry.getValueDecl())) return fd->isCallAsFunctionMethod(); diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp index 8afee4886a9..0f85d90f8c5 100644 --- a/lib/Sema/TypeCheckDecl.cpp +++ b/lib/Sema/TypeCheckDecl.cpp @@ -1349,7 +1349,8 @@ 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(DeclNameLoc(loc), ident); + auto *TyR = new (Ctx) SimpleIdentTypeRepr(DeclNameLoc(loc), + DeclNameRef_(ident)); TypeLoc typeLoc = TypeLoc(TyR); TypeResolutionOptions options = TypeResolverContext::TypeAliasDecl; diff --git a/lib/Sema/TypeCheckDeclPrimary.cpp b/lib/Sema/TypeCheckDeclPrimary.cpp index 05a8860b7e6..c046107096a 100644 --- a/lib/Sema/TypeCheckDeclPrimary.cpp +++ b/lib/Sema/TypeCheckDeclPrimary.cpp @@ -964,7 +964,8 @@ static void diagnoseClassWithoutInitializers(ClassDecl *classDecl) { // We're going to diagnose on the concrete init(from:) decl if it exists // and isn't implicit; otherwise, on the subclass itself. ValueDecl *diagDest = classDecl; - auto initFrom = DeclName(C, DeclBaseName::createConstructor(), C.Id_from); + auto initFrom = DeclNameRef_( + DeclName(C, DeclBaseName::createConstructor(), C.Id_from)); auto result = TypeChecker::lookupMember(superclassDecl, superclassType, initFrom, NameLookupFlags::ProtocolMembers | diff --git a/lib/Sema/TypeCheckExpr.cpp b/lib/Sema/TypeCheckExpr.cpp index 699f31c96e2..2a6c2770adc 100644 --- a/lib/Sema/TypeCheckExpr.cpp +++ b/lib/Sema/TypeCheckExpr.cpp @@ -623,9 +623,9 @@ static Type lookupDefaultLiteralType(const DeclContext *dc, auto lookupOptions = defaultUnqualifiedLookupOptions; if (isa(dc)) lookupOptions |= NameLookupFlags::KnownPrivate; + auto nameRef = DeclNameRef_(ctx.getIdentifier(name)); auto lookup = TypeChecker::lookupUnqualified(dc->getModuleScopeContext(), - ctx.getIdentifier(name), - SourceLoc(), + nameRef, SourceLoc(), lookupOptions); TypeDecl *TD = lookup.getSingleTypeResult(); if (!TD) diff --git a/lib/Sema/TypeCheckExprObjC.cpp b/lib/Sema/TypeCheckExprObjC.cpp index 0b88e5b1a00..d29415397e7 100644 --- a/lib/Sema/TypeCheckExprObjC.cpp +++ b/lib/Sema/TypeCheckExprObjC.cpp @@ -162,7 +162,7 @@ Optional TypeChecker::checkObjCKeyPathExpr(DeclContext *dc, }; // Local function to perform name lookup for the current index. - auto performLookup = [&](DeclBaseName componentName, + auto performLookup = [&](DeclNameRef componentName, SourceLoc componentNameLoc, Type &lookupType) -> LookupResult { if (state == Beginning) @@ -186,7 +186,7 @@ Optional TypeChecker::checkObjCKeyPathExpr(DeclContext *dc, // Local function to print a component to the string. bool needDot = false; - auto printComponent = [&](DeclBaseName component) { + auto printComponent = [&](DeclName component) { if (needDot) keyPathOS << "."; else @@ -224,20 +224,19 @@ Optional TypeChecker::checkObjCKeyPathExpr(DeclContext *dc, llvm_unreachable("already resolved!"); } - auto componentFullName = component.getUnresolvedDeclName(); - if (!componentFullName.isSimpleName()) { + auto componentName = component.getUnresolvedDeclName(); + if (!componentName.isSimpleName()) { diags.diagnose(componentNameLoc, diag::expr_unsupported_objc_key_path_compound_name); continue; } - auto componentName = componentFullName.getBaseName(); // If we are resolving into a dictionary, any component is // well-formed because the keys are unknown dynamically. if (state == ResolvingDictionary) { // Just print the component unchanged; there's no checking we // can do here. - printComponent(componentName); + printComponent(componentName.getBaseName()); // From here, we're resolving a property. Use the current type. updateState(/*isProperty=*/true, currentType); @@ -330,7 +329,7 @@ Optional TypeChecker::checkObjCKeyPathExpr(DeclContext *dc, // Check that the property is @objc. if (!var->isObjC()) { diags.diagnose(componentNameLoc, diag::expr_keypath_non_objc_property, - componentName); + var->getFullName()); if (var->getLoc().isValid() && var->getDeclContext()->isTypeContext()) { diags.diagnose(var, diag::make_decl_objc, var->getDescriptiveKind()) @@ -374,7 +373,7 @@ Optional TypeChecker::checkObjCKeyPathExpr(DeclContext *dc, // We cannot refer to a generic type. if (type->getDeclaredInterfaceType()->hasTypeParameter()) { diags.diagnose(componentNameLoc, diag::expr_keypath_generic_type, - componentName); + type->getFullName()); isInvalid = true; break; } diff --git a/lib/Sema/TypeCheckNameLookup.cpp b/lib/Sema/TypeCheckNameLookup.cpp index b0984a71bb8..de310517555 100644 --- a/lib/Sema/TypeCheckNameLookup.cpp +++ b/lib/Sema/TypeCheckNameLookup.cpp @@ -254,7 +254,7 @@ static void installPropertyWrapperMembersIfNeeded(NominalTypeDecl *target, } } -LookupResult TypeChecker::lookupUnqualified(DeclContext *dc, DeclName name, +LookupResult TypeChecker::lookupUnqualified(DeclContext *dc, DeclNameRef name, SourceLoc loc, NameLookupOptions options) { auto ulOptions = convertToUnqualifiedLookupOptions(options); @@ -262,7 +262,7 @@ LookupResult TypeChecker::lookupUnqualified(DeclContext *dc, DeclName name, // Make sure we've resolved implicit members, if we need them. if (auto *current = dc->getInnermostTypeContext()) { installPropertyWrapperMembersIfNeeded(current->getSelfNominalTypeDecl(), - name); + name.getFullName()); } auto &ctx = dc->getASTContext(); @@ -294,7 +294,7 @@ LookupResult TypeChecker::lookupUnqualified(DeclContext *dc, DeclName name, } LookupResult -TypeChecker::lookupUnqualifiedType(DeclContext *dc, DeclName name, +TypeChecker::lookupUnqualifiedType(DeclContext *dc, DeclNameRef name, SourceLoc loc, NameLookupOptions options) { auto &ctx = dc->getASTContext(); @@ -327,7 +327,7 @@ TypeChecker::lookupUnqualifiedType(DeclContext *dc, DeclName name, } LookupResult TypeChecker::lookupMember(DeclContext *dc, - Type type, DeclName name, + Type type, DeclNameRef name, NameLookupOptions options) { assert(type->mayHaveMembers()); @@ -350,8 +350,8 @@ LookupResult TypeChecker::lookupMember(DeclContext *dc, // Make sure we've resolved implicit members, if we need them. if (auto *current = type->getAnyNominal()) { - current->synthesizeSemanticMembersIfNeeded(name); - installPropertyWrapperMembersIfNeeded(current, name); + current->synthesizeSemanticMembersIfNeeded(name.getFullName()); + installPropertyWrapperMembersIfNeeded(current, name.getFullName()); } LookupResultBuilder builder(result, dc, options); @@ -413,7 +413,7 @@ bool TypeChecker::isUnsupportedMemberTypeAccess(Type type, TypeDecl *typeDecl) { } LookupTypeResult TypeChecker::lookupMemberType(DeclContext *dc, - Type type, Identifier name, + Type type, DeclNameRef name, NameLookupOptions options) { LookupTypeResult result; @@ -430,8 +430,8 @@ LookupTypeResult TypeChecker::lookupMemberType(DeclContext *dc, // Make sure we've resolved implicit members, if we need them. if (auto *current = type->getAnyNominal()) { - current->synthesizeSemanticMembersIfNeeded(name); - installPropertyWrapperMembersIfNeeded(current, name); + current->synthesizeSemanticMembersIfNeeded(name.getFullName()); + installPropertyWrapperMembersIfNeeded(current, name.getFullName()); } if (!dc->lookupQualified(type, name, subOptions, decls)) @@ -555,7 +555,7 @@ LookupResult TypeChecker::lookupConstructors(DeclContext *dc, Type type, return lookupMember(dc, type, DeclNameRef::createConstructor(), options); } -unsigned TypeChecker::getCallEditDistance(DeclName writtenName, +unsigned TypeChecker::getCallEditDistance(DeclNameRef writtenName, DeclName correctedName, unsigned maxEditDistance) { // TODO: consider arguments. @@ -591,7 +591,7 @@ unsigned TypeChecker::getCallEditDistance(DeclName writtenName, return distance; } -static bool isPlausibleTypo(DeclRefKind refKind, DeclName typedName, +static bool isPlausibleTypo(DeclRefKind refKind, DeclNameRef typedName, ValueDecl *candidate) { // Ignore anonymous declarations. if (!candidate->hasName()) diff --git a/lib/Sema/TypeCheckPattern.cpp b/lib/Sema/TypeCheckPattern.cpp index 521fe8c8ee5..63bff0af884 100644 --- a/lib/Sema/TypeCheckPattern.cpp +++ b/lib/Sema/TypeCheckPattern.cpp @@ -113,10 +113,10 @@ filterForEnumElement(DeclContext *DC, SourceLoc UseLoc, /// Find an unqualified enum element. static EnumElementDecl * -lookupUnqualifiedEnumMemberElement(DeclContext *DC, DeclName name, +lookupUnqualifiedEnumMemberElement(DeclContext *DC, DeclNameRef name, SourceLoc UseLoc) { // FIXME: We should probably pay attention to argument labels someday. - name = name.getBaseName(); + name = name.withoutArgumentLabels(); auto lookupOptions = defaultUnqualifiedLookupOptions; lookupOptions |= NameLookupFlags::KnownPrivate; @@ -129,12 +129,12 @@ lookupUnqualifiedEnumMemberElement(DeclContext *DC, DeclName name, /// Find an enum element in an enum type. static EnumElementDecl * lookupEnumMemberElement(DeclContext *DC, Type ty, - DeclName name, SourceLoc UseLoc) { + DeclNameRef name, SourceLoc UseLoc) { if (!ty->mayHaveMembers()) return nullptr; // FIXME: We should probably pay attention to argument labels someday. - name = name.getBaseName(); + name = name.withoutArgumentLabels(); // Look up the case inside the enum. // FIXME: We should be able to tell if this is a private lookup. @@ -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->getNameLoc(), td->getName())); + new (C) SimpleIdentTypeRepr(dre->getNameLoc(), td->createNameRef())); components.back()->setValue(td, nullptr); return true; } @@ -1134,7 +1134,7 @@ recur: P = new (Context) EnumElementPattern(TypeLoc::withoutLoc(type), NLE->getLoc(), DeclNameLoc(NLE->getLoc()), - NoneEnumElement->getFullName(), + NoneEnumElement->createNameRef(), NoneEnumElement, nullptr, false); return TypeChecker::coercePatternToType(P, resolution, type, options); } @@ -1169,7 +1169,7 @@ recur: sub = new (Context) EnumElementPattern(TypeLoc(), IP->getStartLoc(), DeclNameLoc(IP->getEndLoc()), - some->getFullName(), + some->createNameRef(), nullptr, sub, /*Implicit=*/true); } diff --git a/lib/Sema/TypeCheckProtocol.cpp b/lib/Sema/TypeCheckProtocol.cpp index 1a038e6b039..1906aca37a5 100644 --- a/lib/Sema/TypeCheckProtocol.cpp +++ b/lib/Sema/TypeCheckProtocol.cpp @@ -898,8 +898,8 @@ WitnessChecker::lookupValueWitnessesViaImplementsAttr( auto lookupOptions = defaultMemberTypeLookupOptions; lookupOptions -= NameLookupFlags::PerformConformanceCheck; lookupOptions |= NameLookupFlags::IncludeAttributeImplements; - auto candidates = - TypeChecker::lookupMember(DC, Adoptee, req->getFullName(), lookupOptions); + auto candidates = TypeChecker::lookupMember(DC, Adoptee, req->createNameRef(), + lookupOptions); for (auto candidate : candidates) { if (witnessHasImplementsAttrForExactRequirement(candidate.getValueDecl(), req)) { witnesses.push_back(candidate.getValueDecl()); @@ -918,14 +918,17 @@ WitnessChecker::lookupValueWitnesses(ValueDecl *req, bool *ignoringNames) { // for this requirement. lookupValueWitnessesViaImplementsAttr(req, witnesses); + auto reqName = req->createNameRef(); + auto reqBaseName = reqName.withoutArgumentLabels(); + if (req->isOperator()) { // Operator lookup is always global. auto lookupOptions = defaultUnqualifiedLookupOptions; if (!DC->isCascadingContextForLookup(false)) lookupOptions |= NameLookupFlags::KnownPrivate; auto lookup = TypeChecker::lookupUnqualified(DC->getModuleScopeContext(), - req->getBaseName(), - SourceLoc(), lookupOptions); + reqBaseName, SourceLoc(), + lookupOptions); for (auto candidate : lookup) { auto decl = candidate.getValueDecl(); if (swift::isMemberOperator(cast(decl), Adoptee)) { @@ -937,13 +940,13 @@ WitnessChecker::lookupValueWitnesses(ValueDecl *req, bool *ignoringNames) { auto lookupOptions = defaultMemberTypeLookupOptions; lookupOptions -= NameLookupFlags::PerformConformanceCheck; - auto candidates = TypeChecker::lookupMember(DC, Adoptee, req->getFullName(), + auto candidates = TypeChecker::lookupMember(DC, Adoptee, reqName, lookupOptions); // If we didn't find anything with the appropriate name, look // again using only the base name. if (candidates.empty() && ignoringNames) { - candidates = TypeChecker::lookupMember(DC, Adoptee, req->getBaseName(), + candidates = TypeChecker::lookupMember(DC, Adoptee, reqBaseName, lookupOptions); *ignoringNames = true; } @@ -997,7 +1000,7 @@ bool WitnessChecker::findBestWitness( auto lookupOptions = defaultUnqualifiedLookupOptions; lookupOptions |= NameLookupFlags::KnownPrivate; auto lookup = TypeChecker::lookupUnqualified( - overlay, requirement->getBaseName(), SourceLoc(), lookupOptions); + overlay, requirement->createNameRef(), SourceLoc(), lookupOptions); for (auto candidate : lookup) witnesses.push_back(candidate.getValueDecl()); break; @@ -3534,7 +3537,8 @@ ResolveWitnessResult ConformanceChecker::resolveTypeWitnessViaLookup( // Look for a member type with the same name as the associated type. auto candidates = TypeChecker::lookupMemberType( - DC, Adoptee, assocType->getName(), NameLookupFlags::ProtocolMembers); + DC, Adoptee, assocType->createNameRef(), + NameLookupFlags::ProtocolMembers); // If there aren't any candidates, we're done. if (!candidates) { @@ -4797,7 +4801,7 @@ diagnoseMissingAppendInterpolationMethod(NominalTypeDecl *typeDecl) { SmallVectorImpl &invalid) { auto type = typeDecl->getDeclaredType(); auto baseName = - DeclName(typeDecl->getASTContext().Id_appendInterpolation); + DeclNameRef_(typeDecl->getASTContext().Id_appendInterpolation); auto lookupOptions = defaultMemberTypeLookupOptions; lookupOptions -= NameLookupFlags::PerformConformanceCheck; diff --git a/lib/Sema/TypeCheckProtocolInference.cpp b/lib/Sema/TypeCheckProtocolInference.cpp index ffa58350ce9..90431ad3ca3 100644 --- a/lib/Sema/TypeCheckProtocolInference.cpp +++ b/lib/Sema/TypeCheckProtocolInference.cpp @@ -563,7 +563,7 @@ AssociatedTypeInference::inferTypeWitnessesViaAssociatedType( const llvm::SetVector &allUnresolved, AssociatedTypeDecl *assocType) { // Form the default name _Default_Foo. - Identifier defaultName; + DeclNameRef defaultName; { SmallString<32> defaultNameStr; { @@ -572,7 +572,7 @@ AssociatedTypeInference::inferTypeWitnessesViaAssociatedType( out << assocType->getName().str(); } - defaultName = getASTContext().getIdentifier(defaultNameStr); + defaultName = DeclNameRef_(getASTContext().getIdentifier(defaultNameStr)); } // Look for types with the given default name that have appropriate diff --git a/lib/Sema/TypeCheckREPL.cpp b/lib/Sema/TypeCheckREPL.cpp index cc76489d074..d8ff5d08443 100644 --- a/lib/Sema/TypeCheckREPL.cpp +++ b/lib/Sema/TypeCheckREPL.cpp @@ -75,7 +75,7 @@ struct REPLContext { auto *stdlib = TypeChecker::getStdlibModule(&SF); { - Identifier Id(Context.getIdentifier("_replPrintLiteralString")); + auto Id = DeclNameRef_(Context.getIdentifier("_replPrintLiteralString")); auto lookup = TypeChecker::lookupUnqualified(stdlib, Id, SourceLoc()); if (!lookup) return true; @@ -83,7 +83,7 @@ struct REPLContext { PrintDecls.push_back(result.getValueDecl()); } { - Identifier Id(Context.getIdentifier("_replDebugPrintln")); + auto Id = DeclNameRef_(Context.getIdentifier("_replDebugPrintln")); auto lookup = TypeChecker::lookupUnqualified(stdlib, Id, SourceLoc()); if (!lookup) return true; @@ -451,7 +451,8 @@ Identifier REPLChecker::getNextResponseVariableName(DeclContext *DC) { names << "r" << NextResponseVariableIndex++; ident = Context.getIdentifier(names.str()); - nameUsed = (bool)TypeChecker::lookupUnqualified(DC, ident, SourceLoc()); + nameUsed = (bool)TypeChecker::lookupUnqualified(DC, DeclNameRef_(ident), + SourceLoc()); } while (nameUsed); return ident; diff --git a/lib/Sema/TypeCheckStmt.cpp b/lib/Sema/TypeCheckStmt.cpp index 2d77e8b73fa..7b143ffc00f 100644 --- a/lib/Sema/TypeCheckStmt.cpp +++ b/lib/Sema/TypeCheckStmt.cpp @@ -925,7 +925,7 @@ public: } else { unsigned distance = TypeChecker::getCallEditDistance( - S->getTargetName(), (*I)->getLabelInfo().Name, + DeclNameRef_(S->getTargetName()), (*I)->getLabelInfo().Name, TypeChecker::UnreasonableCallEditDistance); if (distance < TypeChecker::UnreasonableCallEditDistance) labelCorrections.insert(distance, std::move(*I)); @@ -990,7 +990,7 @@ public: } else { unsigned distance = TypeChecker::getCallEditDistance( - S->getTargetName(), (*I)->getLabelInfo().Name, + DeclNameRef_(S->getTargetName()), (*I)->getLabelInfo().Name, TypeChecker::UnreasonableCallEditDistance); if (distance < TypeChecker::UnreasonableCallEditDistance) labelCorrections.insert(distance, std::move(*I)); diff --git a/lib/Sema/TypeCheckStorage.cpp b/lib/Sema/TypeCheckStorage.cpp index 37dd1a5e4d3..87848cede86 100644 --- a/lib/Sema/TypeCheckStorage.cpp +++ b/lib/Sema/TypeCheckStorage.cpp @@ -2127,7 +2127,7 @@ static VarDecl *synthesizePropertyWrapperStorageWrapperProperty( // that to find the storage wrapper property. if (auto attr = var->getAttrs().getAttribute()){ SmallVector declsFound; - auto projectionName = attr->ProjectionPropertyName; + auto projectionName = DeclNameRef_(attr->ProjectionPropertyName); auto dc = var->getDeclContext(); if (dc->isTypeContext()) { dc->lookupQualified(dc->getSelfNominalTypeDecl(), projectionName, diff --git a/lib/Sema/TypeCheckType.cpp b/lib/Sema/TypeCheckType.cpp index 16606e77e02..bc5f8e88e8d 100644 --- a/lib/Sema/TypeCheckType.cpp +++ b/lib/Sema/TypeCheckType.cpp @@ -209,7 +209,7 @@ Type TypeResolution::resolveDependentMemberType( singleType->getBaseName().userFacingName()); // Correct to the single type result. - ref->overwriteNameRef(singleType->getFullName()); + ref->overwriteNameRef(singleType->createNameRef()); ref->setValue(singleType, nullptr); } @@ -1089,7 +1089,7 @@ static Type diagnoseUnknownType(TypeResolution resolution, auto type = resolution.mapTypeIntoContext( dc->getInnermostTypeContext()->getSelfInterfaceType()); - comp->overwriteNameRef(nominal->getName()); + comp->overwriteNameRef(DeclNameRef_(nominal->getName())); comp->setValue(nominal, nominalDC->getParent()); return type; } @@ -1140,7 +1140,7 @@ static Type diagnoseUnknownType(TypeResolution resolution, .fixItReplace(R, RemappedTy); // Replace the computed type with the suggested type. - comp->overwriteNameRef(ctx.getIdentifier(RemappedTy)); + comp->overwriteNameRef(DeclNameRef_(ctx.getIdentifier(RemappedTy))); // HACK: 'NSUInteger' suggests both 'UInt' and 'Int'. if (TypeName == ctx.getSwiftName(KnownFoundationEntity::NSUInteger)) { @@ -1394,7 +1394,7 @@ resolveTopLevelIdentTypeComponent(TypeResolution resolution, } static void diagnoseAmbiguousMemberType(Type baseTy, SourceRange baseRange, - DeclName name, DeclNameLoc nameLoc, + DeclNameRef name, DeclNameLoc nameLoc, LookupTypeResult &lookup) { ASTContext &ctx = baseTy->getASTContext(); auto &diags = ctx.Diags; @@ -1647,7 +1647,7 @@ Type TypeChecker::resolveIdentifierType( if (!options.contains(TypeResolutionFlags::SilenceErrors)) { auto moduleName = moduleTy->getModule()->getName(); diags.diagnose(Components.back()->getNameLoc(), - diag::use_undeclared_type, moduleName); + diag::use_undeclared_type, DeclNameRef_(moduleName)); diags.diagnose(Components.back()->getNameLoc(), diag::note_module_as_type, moduleName); } diff --git a/lib/Sema/TypeChecker.cpp b/lib/Sema/TypeChecker.cpp index be510940fc0..4918500c12e 100644 --- a/lib/Sema/TypeChecker.cpp +++ b/lib/Sema/TypeChecker.cpp @@ -715,5 +715,5 @@ void swift::bindExtensions(SourceFile &SF) { LookupResult swift::lookupSemanticMember(DeclContext *DC, Type ty, DeclName name) { - return TypeChecker::lookupMember(DC, ty, name, None); + return TypeChecker::lookupMember(DC, ty, DeclNameRef(name), None); } diff --git a/lib/Sema/TypeChecker.h b/lib/Sema/TypeChecker.h index f7e9edf32ca..bdd59f24c9c 100644 --- a/lib/Sema/TypeChecker.h +++ b/lib/Sema/TypeChecker.h @@ -1238,7 +1238,7 @@ public: /// \param name The name of the entity to look for. /// \param loc The source location at which name lookup occurs. /// \param options Options that control name lookup. - static LookupResult lookupUnqualified(DeclContext *dc, DeclName name, + static LookupResult lookupUnqualified(DeclContext *dc, DeclNameRef name, SourceLoc loc, NameLookupOptions options = defaultUnqualifiedLookupOptions); @@ -1251,7 +1251,7 @@ public: /// \param loc The source location at which name lookup occurs. /// \param options Options that control name lookup. LookupResult - static lookupUnqualifiedType(DeclContext *dc, DeclName name, SourceLoc loc, + static lookupUnqualifiedType(DeclContext *dc, DeclNameRef name, SourceLoc loc, NameLookupOptions options = defaultUnqualifiedLookupOptions); @@ -1263,7 +1263,7 @@ public: /// \param options Options that control name lookup. /// /// \returns The result of name lookup. - static LookupResult lookupMember(DeclContext *dc, Type type, DeclName name, + static LookupResult lookupMember(DeclContext *dc, Type type, DeclNameRef name, NameLookupOptions options = defaultMemberLookupOptions); @@ -1279,7 +1279,7 @@ public: /// /// \returns The result of name lookup. static LookupTypeResult lookupMemberType(DeclContext *dc, Type type, - Identifier name, + DeclNameRef name, NameLookupOptions options = defaultMemberTypeLookupOptions); @@ -1566,7 +1566,7 @@ public: static Optional omitNeedlessWords(VarDecl *var); /// Calculate edit distance between declaration names. - static unsigned getCallEditDistance(DeclName writtenName, + static unsigned getCallEditDistance(DeclNameRef writtenName, DeclName correctedName, unsigned maxEditDistance); diff --git a/lib/Sema/TypoCorrection.h b/lib/Sema/TypoCorrection.h index f282c972952..2f2dc8c927e 100644 --- a/lib/Sema/TypoCorrection.h +++ b/lib/Sema/TypoCorrection.h @@ -34,11 +34,11 @@ class TypeChecker; /// correction even if the corrected name resolves to an overload set. class SyntacticTypoCorrection { public: - DeclName WrittenName; + DeclNameRef WrittenName; DeclNameLoc Loc; DeclName CorrectedName; - SyntacticTypoCorrection(DeclName writtenName, DeclNameLoc writtenLoc, + SyntacticTypoCorrection(DeclNameRef writtenName, DeclNameLoc writtenLoc, DeclName correctedName) : WrittenName(writtenName), Loc(writtenLoc), CorrectedName(correctedName) {} @@ -48,13 +48,13 @@ public: /// A collection of typo-correction candidates. class TypoCorrectionResults { public: - DeclName WrittenName; + DeclNameRef WrittenName; DeclNameLoc Loc; bool ClaimedCorrection = false; SmallVector Candidates; - TypoCorrectionResults(DeclName writtenName, DeclNameLoc loc) + TypoCorrectionResults(DeclNameRef writtenName, DeclNameLoc loc) : WrittenName(writtenName), Loc(loc) {} /// Try to claim a unique correction from this collection that's simple diff --git a/lib/Serialization/Deserialization.cpp b/lib/Serialization/Deserialization.cpp index 87eef142c52..67a0d01acac 100644 --- a/lib/Serialization/Deserialization.cpp +++ b/lib/Serialization/Deserialization.cpp @@ -4124,8 +4124,9 @@ llvm::Error DeclDeserializer::deserializeDeclAttributes() { assert(numArgs != 0); assert(!isImplicit && "Need to update for implicit"); Attr = DynamicReplacementAttr::create( - ctx, DeclName(ctx, baseName, ArrayRef(pieces)), &MF, - replacedFunID); + ctx, + DeclNameRef_(DeclName(ctx, baseName, ArrayRef(pieces))), + &MF, replacedFunID); break; } diff --git a/tools/swift-ast-script/ASTScriptEvaluator.cpp b/tools/swift-ast-script/ASTScriptEvaluator.cpp index 8158783563e..1979407d262 100644 --- a/tools/swift-ast-script/ASTScriptEvaluator.cpp +++ b/tools/swift-ast-script/ASTScriptEvaluator.cpp @@ -115,8 +115,9 @@ bool ASTScript::execute() const { return true; } - auto descriptor = UnqualifiedLookupDescriptor(ctx.getIdentifier("View"), - swiftUI); + auto descriptor = + UnqualifiedLookupDescriptor(DeclNameRef_(ctx.getIdentifier("View")), + swiftUI); auto viewLookup = evaluateOrDefault(ctx.evaluator, UnqualifiedLookupRequest{descriptor}, {}); auto viewProtocol = diff --git a/tools/swift-ide-test/swift-ide-test.cpp b/tools/swift-ide-test/swift-ide-test.cpp index c8c47f56dfd..7b8338cb63f 100644 --- a/tools/swift-ide-test/swift-ide-test.cpp +++ b/tools/swift-ide-test/swift-ide-test.cpp @@ -2259,8 +2259,9 @@ static int doPrintDecls(const CompilerInvocation &InitInvok, for (const auto &name : DeclsToPrint) { ASTContext &ctx = CI.getASTContext(); - auto descriptor = UnqualifiedLookupDescriptor(ctx.getIdentifier(name), - CI.getPrimarySourceFile()); + auto descriptor = + UnqualifiedLookupDescriptor(DeclNameRef_(ctx.getIdentifier(name)), + CI.getPrimarySourceFile()); auto lookup = evaluateOrDefault(ctx.evaluator, UnqualifiedLookupRequest{descriptor}, {}); for (auto result : lookup) { diff --git a/unittests/AST/SourceLocTests.cpp b/unittests/AST/SourceLocTests.cpp index fe1d7147126..6442bf9d0d5 100644 --- a/unittests/AST/SourceLocTests.cpp +++ b/unittests/AST/SourceLocTests.cpp @@ -42,42 +42,42 @@ TEST(SourceLoc, AssignExpr) { SourceLoc start = C.Ctx.SourceMgr.getLocForBufferStart(bufferID); auto destBase = new (C.Ctx) UnresolvedDeclRefExpr( - C.Ctx.getIdentifier("aa"), + DeclNameRef_(C.Ctx.getIdentifier("aa")), DeclRefKind::Ordinary, DeclNameLoc(start)); auto dest = new (C.Ctx) UnresolvedDotExpr( destBase, start.getAdvancedLoc(2), - C.Ctx.getIdentifier("bb"), + DeclNameRef_(C.Ctx.getIdentifier("bb")), DeclNameLoc(start.getAdvancedLoc(3)), /*implicit*/false); auto destImplicit = new (C.Ctx) UnresolvedDotExpr( destBase, start.getAdvancedLoc(2), - C.Ctx.getIdentifier("bb"), + DeclNameRef_(C.Ctx.getIdentifier("bb")), DeclNameLoc(start.getAdvancedLoc(3)), /*implicit*/true); auto sourceBase = new (C.Ctx) UnresolvedDeclRefExpr( - C.Ctx.getIdentifier("cc"), + DeclNameRef_(C.Ctx.getIdentifier("cc")), DeclRefKind::Ordinary, DeclNameLoc(start.getAdvancedLoc(8))); auto source = new (C.Ctx) UnresolvedDotExpr( sourceBase, start.getAdvancedLoc(10), - C.Ctx.getIdentifier("dd"), + DeclNameRef_(C.Ctx.getIdentifier("dd")), DeclNameLoc(start.getAdvancedLoc(11)), /*implicit*/false); auto sourceImplicit = new (C.Ctx) UnresolvedDotExpr( sourceBase, start.getAdvancedLoc(10), - C.Ctx.getIdentifier("dd"), + DeclNameRef_(C.Ctx.getIdentifier("dd")), DeclNameLoc(start.getAdvancedLoc(11)), /*implicit*/true); auto invalid = new (C.Ctx) UnresolvedDeclRefExpr( - C.Ctx.getIdentifier("invalid"), + DeclNameRef_(C.Ctx.getIdentifier("invalid")), DeclRefKind::Ordinary, DeclNameLoc()); @@ -223,22 +223,22 @@ TEST(SourceLoc, TupleExpr) { SourceLoc start = C.Ctx.SourceMgr.getLocForBufferStart(bufferID); auto one = new (C.Ctx) UnresolvedDeclRefExpr( - C.Ctx.getIdentifier("one"), + DeclNameRef_(C.Ctx.getIdentifier("one")), DeclRefKind::Ordinary, DeclNameLoc(start)); auto two = new (C.Ctx) UnresolvedDeclRefExpr( - C.Ctx.getIdentifier("two"), + DeclNameRef_(C.Ctx.getIdentifier("two")), DeclRefKind::Ordinary, DeclNameLoc()); auto three = new (C.Ctx) UnresolvedDeclRefExpr( - C.Ctx.getIdentifier("three"), + DeclNameRef_(C.Ctx.getIdentifier("three")), DeclRefKind::Ordinary, DeclNameLoc()); auto four = new (C.Ctx) UnresolvedDeclRefExpr( - C.Ctx.getIdentifier("four"), + DeclNameRef_(C.Ctx.getIdentifier("four")), DeclRefKind::Ordinary, DeclNameLoc(start.getAdvancedLoc(4)));