Skip to content

Commit 7543a89

Browse files
authored
Merge pull request #27683 from brentdax/i-understood-that-reference
[NFC] Distinguish references to names from declarations of those names by type
2 parents af3aa03 + db15d82 commit 7543a89

File tree

99 files changed

+1354
-977
lines changed

Some content is hidden

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

99 files changed

+1354
-977
lines changed

include/swift/AST/ASTPrinter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,10 @@ class ASTPrinter {
188188
ASTPrinter &operator<<(unsigned long long N);
189189
ASTPrinter &operator<<(UUID UU);
190190

191+
ASTPrinter &operator<<(Identifier name);
192+
ASTPrinter &operator<<(DeclBaseName name);
191193
ASTPrinter &operator<<(DeclName name);
194+
ASTPrinter &operator<<(DeclNameRef name);
192195

193196
// Special case for 'char', but not arbitrary things that convert to 'char'.
194197
template <typename T>

include/swift/AST/ASTScope.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ class ASTScopeImpl {
412412

413413
/// Entry point into ASTScopeImpl-land for lookups
414414
static llvm::SmallVector<const ASTScopeImpl *, 0>
415-
unqualifiedLookup(SourceFile *, DeclName, SourceLoc,
415+
unqualifiedLookup(SourceFile *, DeclNameRef, SourceLoc,
416416
const DeclContext *startingContext, DeclConsumer);
417417

418418
static Optional<bool>
@@ -422,7 +422,7 @@ class ASTScopeImpl {
422422
#pragma mark - - lookup- starting point
423423
private:
424424
static const ASTScopeImpl *findStartingScopeForLookup(SourceFile *,
425-
const DeclName name,
425+
const DeclNameRef name,
426426
const SourceLoc where,
427427
const DeclContext *ctx);
428428

include/swift/AST/Attr.h

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class TypeAttributes {
6868

6969
struct Convention {
7070
StringRef Name = {};
71-
StringRef WitnessMethodProtocol = {};
71+
DeclNameRef WitnessMethodProtocol = {};
7272
StringRef ClangType = {};
7373
// Carry the source location for diagnostics.
7474
SourceLoc ClangTypeLoc = {};
@@ -78,7 +78,7 @@ class TypeAttributes {
7878
/// Don't use this function if you are creating a C convention as you
7979
/// probably need a ClangType field as well.
8080
static Convention makeSwiftConvention(StringRef name) {
81-
return {name, "", "", {}};
81+
return {name, DeclNameRef(), "", {}};
8282
}
8383
};
8484

@@ -1057,23 +1057,24 @@ class DynamicReplacementAttr final
10571057
friend TrailingObjects;
10581058
friend class DynamicallyReplacedDeclRequest;
10591059

1060-
DeclName ReplacedFunctionName;
1060+
DeclNameRef ReplacedFunctionName;
10611061
LazyMemberLoader *Resolver = nullptr;
10621062
uint64_t ResolverContextData;
10631063

10641064
/// Create an @_dynamicReplacement(for:) attribute written in the source.
10651065
DynamicReplacementAttr(SourceLoc atLoc, SourceRange baseRange,
1066-
DeclName replacedFunctionName, SourceRange parenRange);
1066+
DeclNameRef replacedFunctionName,
1067+
SourceRange parenRange);
10671068

1068-
DynamicReplacementAttr(DeclName name, AbstractFunctionDecl *f)
1069+
DynamicReplacementAttr(DeclNameRef name, AbstractFunctionDecl *f)
10691070
: DeclAttribute(DAK_DynamicReplacement, SourceLoc(), SourceRange(),
10701071
/*Implicit=*/false),
10711072
ReplacedFunctionName(name),
10721073
Resolver(nullptr), ResolverContextData(0) {
10731074
Bits.DynamicReplacementAttr.HasTrailingLocationInfo = false;
10741075
}
10751076

1076-
DynamicReplacementAttr(DeclName name,
1077+
DynamicReplacementAttr(DeclNameRef name,
10771078
LazyMemberLoader *Resolver = nullptr,
10781079
uint64_t Data = 0)
10791080
: DeclAttribute(DAK_DynamicReplacement, SourceLoc(), SourceRange(),
@@ -1100,18 +1101,18 @@ class DynamicReplacementAttr final
11001101
public:
11011102
static DynamicReplacementAttr *
11021103
create(ASTContext &Context, SourceLoc AtLoc, SourceLoc DynReplLoc,
1103-
SourceLoc LParenLoc, DeclName replacedFunction, SourceLoc RParenLoc);
1104+
SourceLoc LParenLoc, DeclNameRef replacedFunction, SourceLoc RParenLoc);
11041105

11051106
static DynamicReplacementAttr *create(ASTContext &ctx,
1106-
DeclName replacedFunction,
1107+
DeclNameRef replacedFunction,
11071108
AbstractFunctionDecl *replacedFuncDecl);
11081109

11091110
static DynamicReplacementAttr *create(ASTContext &ctx,
1110-
DeclName replacedFunction,
1111+
DeclNameRef replacedFunction,
11111112
LazyMemberLoader *Resolver,
11121113
uint64_t Data);
11131114

1114-
DeclName getReplacedFunctionName() const {
1115+
DeclNameRef getReplacedFunctionName() const {
11151116
return ReplacedFunctionName;
11161117
}
11171118

@@ -1630,8 +1631,8 @@ class OriginallyDefinedInAttr: public DeclAttribute {
16301631
};
16311632

16321633
/// A declaration name with location.
1633-
struct DeclNameWithLoc {
1634-
DeclName Name;
1634+
struct DeclNameRefWithLoc {
1635+
DeclNameRef Name;
16351636
DeclNameLoc Loc;
16361637
};
16371638

@@ -1652,9 +1653,9 @@ class DifferentiableAttr final
16521653
/// The number of parsed parameters specified in 'wrt:'.
16531654
unsigned NumParsedParameters = 0;
16541655
/// The JVP function.
1655-
Optional<DeclNameWithLoc> JVP;
1656+
Optional<DeclNameRefWithLoc> JVP;
16561657
/// The VJP function.
1657-
Optional<DeclNameWithLoc> VJP;
1658+
Optional<DeclNameRefWithLoc> VJP;
16581659
/// The JVP function (optional), resolved by the type checker if JVP name is
16591660
/// specified.
16601661
FuncDecl *JVPFunction = nullptr;
@@ -1674,43 +1675,43 @@ class DifferentiableAttr final
16741675
explicit DifferentiableAttr(bool implicit, SourceLoc atLoc,
16751676
SourceRange baseRange, bool linear,
16761677
ArrayRef<ParsedAutoDiffParameter> parameters,
1677-
Optional<DeclNameWithLoc> jvp,
1678-
Optional<DeclNameWithLoc> vjp,
1678+
Optional<DeclNameRefWithLoc> jvp,
1679+
Optional<DeclNameRefWithLoc> vjp,
16791680
TrailingWhereClause *clause);
16801681

16811682
explicit DifferentiableAttr(Decl *original, bool implicit, SourceLoc atLoc,
16821683
SourceRange baseRange, bool linear,
16831684
IndexSubset *parameterIndices,
1684-
Optional<DeclNameWithLoc> jvp,
1685-
Optional<DeclNameWithLoc> vjp,
1685+
Optional<DeclNameRefWithLoc> jvp,
1686+
Optional<DeclNameRefWithLoc> vjp,
16861687
GenericSignature derivativeGenericSignature);
16871688

16881689
public:
16891690
static DifferentiableAttr *create(ASTContext &context, bool implicit,
16901691
SourceLoc atLoc, SourceRange baseRange,
16911692
bool linear,
16921693
ArrayRef<ParsedAutoDiffParameter> params,
1693-
Optional<DeclNameWithLoc> jvp,
1694-
Optional<DeclNameWithLoc> vjp,
1694+
Optional<DeclNameRefWithLoc> jvp,
1695+
Optional<DeclNameRefWithLoc> vjp,
16951696
TrailingWhereClause *clause);
16961697

16971698
static DifferentiableAttr *create(AbstractFunctionDecl *original,
16981699
bool implicit, SourceLoc atLoc,
16991700
SourceRange baseRange, bool linear,
17001701
IndexSubset *parameterIndices,
1701-
Optional<DeclNameWithLoc> jvp,
1702-
Optional<DeclNameWithLoc> vjp,
1702+
Optional<DeclNameRefWithLoc> jvp,
1703+
Optional<DeclNameRefWithLoc> vjp,
17031704
GenericSignature derivativeGenSig);
17041705

17051706
/// Get the optional 'jvp:' function name and location.
17061707
/// Use this instead of `getJVPFunction` to check whether the attribute has a
17071708
/// registered JVP.
1708-
Optional<DeclNameWithLoc> getJVP() const { return JVP; }
1709+
Optional<DeclNameRefWithLoc> getJVP() const { return JVP; }
17091710

17101711
/// Get the optional 'vjp:' function name and location.
17111712
/// Use this instead of `getVJPFunction` to check whether the attribute has a
17121713
/// registered VJP.
1713-
Optional<DeclNameWithLoc> getVJP() const { return VJP; }
1714+
Optional<DeclNameRefWithLoc> getVJP() const { return VJP; }
17141715

17151716
IndexSubset *getParameterIndices() const {
17161717
return ParameterIndices;
@@ -1775,7 +1776,7 @@ class DerivativeAttr final
17751776
friend TrailingObjects;
17761777

17771778
/// The original function name.
1778-
DeclNameWithLoc OriginalFunctionName;
1779+
DeclNameRefWithLoc OriginalFunctionName;
17791780
/// The original function declaration, resolved by the type checker.
17801781
AbstractFunctionDecl *OriginalFunction = nullptr;
17811782
/// The number of parsed parameters specified in 'wrt:'.
@@ -1786,23 +1787,24 @@ class DerivativeAttr final
17861787
Optional<AutoDiffDerivativeFunctionKind> Kind = None;
17871788

17881789
explicit DerivativeAttr(bool implicit, SourceLoc atLoc, SourceRange baseRange,
1789-
DeclNameWithLoc original,
1790+
DeclNameRefWithLoc original,
17901791
ArrayRef<ParsedAutoDiffParameter> params);
17911792

17921793
explicit DerivativeAttr(bool implicit, SourceLoc atLoc, SourceRange baseRange,
1793-
DeclNameWithLoc original, IndexSubset *indices);
1794+
DeclNameRefWithLoc original, IndexSubset *indices);
17941795

17951796
public:
17961797
static DerivativeAttr *create(ASTContext &context, bool implicit,
17971798
SourceLoc atLoc, SourceRange baseRange,
1798-
DeclNameWithLoc original,
1799+
DeclNameRefWithLoc original,
17991800
ArrayRef<ParsedAutoDiffParameter> params);
18001801

18011802
static DerivativeAttr *create(ASTContext &context, bool implicit,
18021803
SourceLoc atLoc, SourceRange baseRange,
1803-
DeclNameWithLoc original, IndexSubset *indices);
1804+
DeclNameRefWithLoc original,
1805+
IndexSubset *indices);
18041806

1805-
DeclNameWithLoc getOriginalFunctionName() const {
1807+
DeclNameRefWithLoc getOriginalFunctionName() const {
18061808
return OriginalFunctionName;
18071809
}
18081810
AbstractFunctionDecl *getOriginalFunction() const {

include/swift/AST/Decl.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,6 +2459,12 @@ class ValueDecl : public Decl {
24592459
/// names.
24602460
DeclBaseName getBaseName() const { return Name.getBaseName(); }
24612461

2462+
/// Generates a DeclNameRef referring to this declaration with as much
2463+
/// specificity as possible.
2464+
DeclNameRef createNameRef() const {
2465+
return DeclNameRef(getFullName());
2466+
}
2467+
24622468
/// Retrieve the name to use for this declaration when interoperating
24632469
/// with the Objective-C runtime.
24642470
///
@@ -6997,6 +7003,13 @@ class OperatorDecl : public Decl {
69977003
SourceLoc getNameLoc() const { return NameLoc; }
69987004
Identifier getName() const { return name; }
69997005

7006+
/// Get the list of identifiers after the colon in the operator declaration.
7007+
///
7008+
/// This list includes the names of designated types. For infix operators, the
7009+
/// first item in the list is a precedence group instead.
7010+
///
7011+
/// \todo These two purposes really ought to be in separate properties and the
7012+
/// designated type list should be of TypeReprs instead of Identifiers.
70007013
ArrayRef<Identifier> getIdentifiers() const {
70017014
return Identifiers;
70027015
}

include/swift/AST/DeclContext.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
505505
/// lookup.
506506
///
507507
/// \returns true if anything was found.
508-
bool lookupQualified(Type type, DeclName member, NLOptions options,
508+
bool lookupQualified(Type type, DeclNameRef member, NLOptions options,
509509
SmallVectorImpl<ValueDecl *> &decls) const;
510510

511511
/// Look for the set of declarations with the given name within the
@@ -522,12 +522,13 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
522522
/// lookup.
523523
///
524524
/// \returns true if anything was found.
525-
bool lookupQualified(ArrayRef<NominalTypeDecl *> types, DeclName member,
525+
bool lookupQualified(ArrayRef<NominalTypeDecl *> types, DeclNameRef member,
526526
NLOptions options,
527527
SmallVectorImpl<ValueDecl *> &decls) const;
528528

529529
/// Perform qualified lookup for the given member in the given module.
530-
bool lookupQualified(ModuleDecl *module, DeclName member, NLOptions options,
530+
bool lookupQualified(ModuleDecl *module, DeclNameRef member,
531+
NLOptions options,
531532
SmallVectorImpl<ValueDecl *> &decls) const;
532533

533534
/// Look up all Objective-C methods with the given selector visible

include/swift/AST/DiagnosticEngine.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ namespace swift {
105105
int IntegerVal;
106106
unsigned UnsignedVal;
107107
StringRef StringVal;
108-
DeclName IdentifierVal;
108+
DeclNameRef IdentifierVal;
109109
ObjCSelector ObjCSelectorVal;
110110
ValueDecl *TheValueDecl;
111111
Type TypeVal;
@@ -133,14 +133,20 @@ namespace swift {
133133
: Kind(DiagnosticArgumentKind::Unsigned), UnsignedVal(I) {
134134
}
135135

136+
DiagnosticArgument(DeclNameRef R)
137+
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(R) {}
138+
136139
DiagnosticArgument(DeclName D)
137-
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(D) {}
140+
: Kind(DiagnosticArgumentKind::Identifier),
141+
IdentifierVal(DeclNameRef(D)) {}
138142

139143
DiagnosticArgument(DeclBaseName D)
140-
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(D) {}
144+
: Kind(DiagnosticArgumentKind::Identifier),
145+
IdentifierVal(DeclNameRef(D)) {}
141146

142147
DiagnosticArgument(Identifier I)
143-
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(I) {
148+
: Kind(DiagnosticArgumentKind::Identifier),
149+
IdentifierVal(DeclNameRef(I)) {
144150
}
145151

146152
DiagnosticArgument(ObjCSelector S)
@@ -225,7 +231,7 @@ namespace swift {
225231
return UnsignedVal;
226232
}
227233

228-
DeclName getAsIdentifier() const {
234+
DeclNameRef getAsIdentifier() const {
229235
assert(Kind == DiagnosticArgumentKind::Identifier);
230236
return IdentifierVal;
231237
}

include/swift/AST/DiagnosticsCommon.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ NOTE(kind_declname_declared_here,none,
163163
WARNING(warn_property_wrapper_module_scope,none,
164164
"ignoring associated type %0 in favor of module-scoped property "
165165
"wrapper %0; please qualify the reference with %1",
166-
(DeclName, Identifier))
166+
(DeclNameRef, Identifier))
167167

168168
#ifndef DIAG_NO_UNDEF
169169
# if defined(DIAG)

include/swift/AST/DiagnosticsParse.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ ERROR(lex_conflict_marker_in_file,none,
207207
//------------------------------------------------------------------------------
208208

209209
NOTE(note_in_decl_extension,none,
210-
"in %select{declaration|extension}0 of %1", (bool, Identifier))
210+
"in %select{declaration|extension}0 of %1", (bool, DeclNameRef))
211211
ERROR(line_directive_style_deprecated,none,
212212
"#line directive was renamed to #sourceLocation",
213213
())

0 commit comments

Comments
 (0)