Skip to content

[NFC] Distinguish references to names from declarations of those names by type #27683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/swift/AST/ASTPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ class ASTPrinter {
ASTPrinter &operator<<(unsigned long long N);
ASTPrinter &operator<<(UUID UU);

ASTPrinter &operator<<(Identifier name);
ASTPrinter &operator<<(DeclBaseName name);
ASTPrinter &operator<<(DeclName name);
ASTPrinter &operator<<(DeclNameRef name);

// Special case for 'char', but not arbitrary things that convert to 'char'.
template <typename T>
Expand Down
4 changes: 2 additions & 2 deletions include/swift/AST/ASTScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ class ASTScopeImpl {

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

static Optional<bool>
Expand All @@ -422,7 +422,7 @@ class ASTScopeImpl {
#pragma mark - - lookup- starting point
private:
static const ASTScopeImpl *findStartingScopeForLookup(SourceFile *,
const DeclName name,
const DeclNameRef name,
const SourceLoc where,
const DeclContext *ctx);

Expand Down
62 changes: 32 additions & 30 deletions include/swift/AST/Attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class TypeAttributes {

struct Convention {
StringRef Name = {};
StringRef WitnessMethodProtocol = {};
DeclNameRef WitnessMethodProtocol = {};
StringRef ClangType = {};
// Carry the source location for diagnostics.
SourceLoc ClangTypeLoc = {};
Expand All @@ -78,7 +78,7 @@ class TypeAttributes {
/// Don't use this function if you are creating a C convention as you
/// probably need a ClangType field as well.
static Convention makeSwiftConvention(StringRef name) {
return {name, "", "", {}};
return {name, DeclNameRef(), "", {}};
}
};

Expand Down Expand Up @@ -1057,23 +1057,24 @@ 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),
Resolver(nullptr), ResolverContextData(0) {
Bits.DynamicReplacementAttr.HasTrailingLocationInfo = false;
}

DynamicReplacementAttr(DeclName name,
DynamicReplacementAttr(DeclNameRef name,
LazyMemberLoader *Resolver = nullptr,
uint64_t Data = 0)
: DeclAttribute(DAK_DynamicReplacement, SourceLoc(), SourceRange(),
Expand All @@ -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;
}

Expand Down Expand Up @@ -1630,8 +1631,8 @@ class OriginallyDefinedInAttr: public DeclAttribute {
};

/// A declaration name with location.
struct DeclNameWithLoc {
DeclName Name;
struct DeclNameRefWithLoc {
DeclNameRef Name;
DeclNameLoc Loc;
};

Expand All @@ -1652,9 +1653,9 @@ class DifferentiableAttr final
/// The number of parsed parameters specified in 'wrt:'.
unsigned NumParsedParameters = 0;
/// The JVP function.
Optional<DeclNameWithLoc> JVP;
Optional<DeclNameRefWithLoc> JVP;
/// The VJP function.
Optional<DeclNameWithLoc> VJP;
Optional<DeclNameRefWithLoc> VJP;
/// The JVP function (optional), resolved by the type checker if JVP name is
/// specified.
FuncDecl *JVPFunction = nullptr;
Expand All @@ -1674,43 +1675,43 @@ class DifferentiableAttr final
explicit DifferentiableAttr(bool implicit, SourceLoc atLoc,
SourceRange baseRange, bool linear,
ArrayRef<ParsedAutoDiffParameter> parameters,
Optional<DeclNameWithLoc> jvp,
Optional<DeclNameWithLoc> vjp,
Optional<DeclNameRefWithLoc> jvp,
Optional<DeclNameRefWithLoc> vjp,
TrailingWhereClause *clause);

explicit DifferentiableAttr(Decl *original, bool implicit, SourceLoc atLoc,
SourceRange baseRange, bool linear,
IndexSubset *parameterIndices,
Optional<DeclNameWithLoc> jvp,
Optional<DeclNameWithLoc> vjp,
Optional<DeclNameRefWithLoc> jvp,
Optional<DeclNameRefWithLoc> vjp,
GenericSignature derivativeGenericSignature);

public:
static DifferentiableAttr *create(ASTContext &context, bool implicit,
SourceLoc atLoc, SourceRange baseRange,
bool linear,
ArrayRef<ParsedAutoDiffParameter> params,
Optional<DeclNameWithLoc> jvp,
Optional<DeclNameWithLoc> vjp,
Optional<DeclNameRefWithLoc> jvp,
Optional<DeclNameRefWithLoc> vjp,
TrailingWhereClause *clause);

static DifferentiableAttr *create(AbstractFunctionDecl *original,
bool implicit, SourceLoc atLoc,
SourceRange baseRange, bool linear,
IndexSubset *parameterIndices,
Optional<DeclNameWithLoc> jvp,
Optional<DeclNameWithLoc> vjp,
Optional<DeclNameRefWithLoc> jvp,
Optional<DeclNameRefWithLoc> 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<DeclNameWithLoc> getJVP() const { return JVP; }
Optional<DeclNameRefWithLoc> 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<DeclNameWithLoc> getVJP() const { return VJP; }
Optional<DeclNameRefWithLoc> getVJP() const { return VJP; }

IndexSubset *getParameterIndices() const {
return ParameterIndices;
Expand Down Expand Up @@ -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:'.
Expand All @@ -1786,23 +1787,24 @@ class DerivativeAttr final
Optional<AutoDiffDerivativeFunctionKind> Kind = None;

explicit DerivativeAttr(bool implicit, SourceLoc atLoc, SourceRange baseRange,
DeclNameWithLoc original,
DeclNameRefWithLoc original,
ArrayRef<ParsedAutoDiffParameter> 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<ParsedAutoDiffParameter> 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 {
Expand Down
13 changes: 13 additions & 0 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2459,6 +2459,12 @@ class ValueDecl : public Decl {
/// names.
DeclBaseName getBaseName() const { return Name.getBaseName(); }

/// Generates a DeclNameRef referring to this declaration with as much
/// specificity as possible.
DeclNameRef createNameRef() const {
return DeclNameRef(getFullName());
}

/// Retrieve the name to use for this declaration when interoperating
/// with the Objective-C runtime.
///
Expand Down Expand Up @@ -6997,6 +7003,13 @@ class OperatorDecl : public Decl {
SourceLoc getNameLoc() const { return NameLoc; }
Identifier getName() const { return name; }

/// Get the list of identifiers after the colon in the operator declaration.
///
/// This list includes the names of designated types. For infix operators, the
/// first item in the list is a precedence group instead.
///
/// \todo These two purposes really ought to be in separate properties and the
/// designated type list should be of TypeReprs instead of Identifiers.
ArrayRef<Identifier> getIdentifiers() const {
return Identifiers;
}
Expand Down
7 changes: 4 additions & 3 deletions include/swift/AST/DeclContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
/// lookup.
///
/// \returns true if anything was found.
bool lookupQualified(Type type, DeclName member, NLOptions options,
bool lookupQualified(Type type, DeclNameRef member, NLOptions options,
SmallVectorImpl<ValueDecl *> &decls) const;

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

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

/// Look up all Objective-C methods with the given selector visible
Expand Down
16 changes: 11 additions & 5 deletions include/swift/AST/DiagnosticEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace swift {
int IntegerVal;
unsigned UnsignedVal;
StringRef StringVal;
DeclName IdentifierVal;
DeclNameRef IdentifierVal;
ObjCSelector ObjCSelectorVal;
ValueDecl *TheValueDecl;
Type TypeVal;
Expand Down Expand Up @@ -133,14 +133,20 @@ namespace swift {
: Kind(DiagnosticArgumentKind::Unsigned), UnsignedVal(I) {
}

DiagnosticArgument(DeclNameRef R)
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(R) {}

DiagnosticArgument(DeclName D)
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(D) {}
: Kind(DiagnosticArgumentKind::Identifier),
IdentifierVal(DeclNameRef(D)) {}

DiagnosticArgument(DeclBaseName D)
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(D) {}
: Kind(DiagnosticArgumentKind::Identifier),
IdentifierVal(DeclNameRef(D)) {}

DiagnosticArgument(Identifier I)
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(I) {
: Kind(DiagnosticArgumentKind::Identifier),
IdentifierVal(DeclNameRef(I)) {
}

DiagnosticArgument(ObjCSelector S)
Expand Down Expand Up @@ -225,7 +231,7 @@ namespace swift {
return UnsignedVal;
}

DeclName getAsIdentifier() const {
DeclNameRef getAsIdentifier() const {
assert(Kind == DiagnosticArgumentKind::Identifier);
return IdentifierVal;
}
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/DiagnosticsCommon.def
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ ERROR(lex_conflict_marker_in_file,none,
//------------------------------------------------------------------------------

NOTE(note_in_decl_extension,none,
"in %select{declaration|extension}0 of %1", (bool, Identifier))
"in %select{declaration|extension}0 of %1", (bool, DeclNameRef))
ERROR(line_directive_style_deprecated,none,
"#line directive was renamed to #sourceLocation",
())
Expand Down
Loading