Skip to content

Introduce special DeclNames for subscripts #6848

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

Closed
Closed
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
8 changes: 4 additions & 4 deletions include/swift/AST/DebuggerClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ class DebuggerClient {
/// be consulted first. Return true if results have been added
/// to RV.
/// FIXME: I don't think this ever does anything useful.
virtual bool lookupOverrides(Identifier Name, DeclContext *DC,
virtual bool lookupOverrides(DeclBaseName Name, DeclContext *DC,
SourceLoc Loc, bool IsTypeLookup,
ResultVector &RV) = 0;

/// This is the second time DebuggerClient is consulted:
/// after all names in external Modules are checked, the client
/// gets a chance to add names to the list of candidates that
/// have been found in the external module lookup.
/// have been found in the external module lookup.

virtual bool lookupAdditions(Identifier Name, DeclContext *DC,
virtual bool lookupAdditions(DeclBaseName Name, DeclContext *DC,
SourceLoc Loc, bool IsTypeLookup,
ResultVector &RV) = 0;

Expand Down
41 changes: 33 additions & 8 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2102,23 +2102,16 @@ class ValueDecl : public Decl {
}

bool hasName() const { return bool(Name); }
/// TODO: Rename to getSimpleName?
Identifier getName() const { return Name.getBaseName(); }
bool isOperator() const { return Name.isOperator(); }

/// Returns the string for the base name, or "_" if this is unnamed.
StringRef getNameStr() const {
return hasName() ? getName().str() : "_";
}

/// Retrieve the full name of the declaration.
/// TODO: Rename to getName?
DeclName getFullName() const { return Name; }
void setName(DeclName name) { Name = name; }

/// Retrieve the base name of the declaration, ignoring any argument
/// names.
DeclName getBaseName() const { return Name.getBaseName(); }
DeclBaseName getBaseName() const { return Name.getBaseName(); }

/// Retrieve the name to use for this declaration when interoperating
/// with the Objective-C runtime.
Expand Down Expand Up @@ -2327,6 +2320,14 @@ class TypeDecl : public ValueDecl {
}

public:
Identifier getName() const { return getFullName().getBaseIdentifier(); }

/// Returns the string for the base name, or "_" if this is unnamed.
StringRef getNameStr() const {
assert(!getFullName().isSpecial() && "Cannot get string for special names");
return hasName() ? getBaseName().getIdentifier().str() : "_";
}

/// The type of this declaration's values. For the type of the
/// declaration itself, use getInterfaceType(), which returns a
/// metatype.
Expand Down Expand Up @@ -4211,6 +4212,14 @@ class VarDecl : public AbstractStorageDecl {
return VarDeclBits.IsUserAccessible;
}

Identifier getName() const { return getFullName().getBaseIdentifier(); }

/// Returns the string for the base name, or "_" if this is unnamed.
StringRef getNameStr() const {
assert(!getFullName().isSpecial() && "Cannot get string for special names");
return hasName() ? getBaseName().getIdentifier().str() : "_";
}

TypeLoc &getTypeLoc() { return typeLoc; }
TypeLoc getTypeLoc() const { return typeLoc; }

Expand Down Expand Up @@ -4678,6 +4687,14 @@ class AbstractFunctionDecl : public ValueDecl, public GenericContext {
}

public:
Identifier getName() const { return getFullName().getBaseIdentifier(); }

/// Returns the string for the base name, or "_" if this is unnamed.
StringRef getNameStr() const {
assert(!getFullName().isSpecial() && "Cannot get string for special names");
return hasName() ? getBaseName().getIdentifier().str() : "_";
}

/// \brief Should this declaration be treated as if annotated with transparent
/// attribute.
bool isTransparent() const;
Expand Down Expand Up @@ -5299,6 +5316,14 @@ class EnumElementDecl : public ValueDecl {
EnumElementDeclBits.HasArgumentType = HasArgumentType;
}

Identifier getName() const { return getFullName().getBaseIdentifier(); }

/// Returns the string for the base name, or "_" if this is unnamed.
StringRef getNameStr() const {
assert(!getFullName().isSpecial() && "Cannot get string for special names");
return hasName() ? getBaseName().getIdentifier().str() : "_";
}

/// \returns false if there was an error during the computation rendering the
/// EnumElementDecl invalid, true otherwise.
bool computeType();
Expand Down
10 changes: 6 additions & 4 deletions include/swift/AST/DiagnosticEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,12 @@ namespace swift {
: Kind(DiagnosticArgumentKind::Unsigned), UnsignedVal(I) {
}

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

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

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

DiagnosticArgument(Identifier I)
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(I) {
}
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 @@ -50,7 +50,7 @@ ERROR(error_no_group_info,none,

NOTE(previous_decldef,none,
"previous %select{declaration|definition}0 of %1 is here",
(bool, Identifier))
(bool, DeclBaseName))

NOTE(brace_stmt_suggest_do,none,
"did you mean to use a 'do' statement?", ())
Expand Down
6 changes: 3 additions & 3 deletions include/swift/AST/DiagnosticsSIL.def
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ERROR(could_not_find_pointer_pointee_property,none,

ERROR(writeback_overlap_property,none,
"inout writeback to computed property %0 occurs in multiple arguments to"
" call, introducing invalid aliasing", (Identifier))
" call, introducing invalid aliasing", (DeclBaseName))
ERROR(writeback_overlap_subscript,none,
"inout writeback through subscript occurs in multiple arguments to call,"
" introducing invalid aliasing",
Expand Down Expand Up @@ -120,7 +120,7 @@ ERROR(self_use_before_fully_init,none,
"use of 'self' in %select{method call|property access}1 %0 before "
"%select{all stored properties are initialized|"
"super.init initializes self|"
"self.init initializes self}2", (Identifier, bool, unsigned))
"self.init initializes self}2", (DeclBaseName, bool, unsigned))
ERROR(use_of_self_before_fully_init,none,
"'self' used before all stored properties are initialized", ())
ERROR(use_of_self_before_fully_init_protocol,none,
Expand Down Expand Up @@ -166,7 +166,7 @@ NOTE(initial_value_provided_in_let_decl,none,
ERROR(mutating_method_called_on_immutable_value,none,
"mutating %select{method|property access|subscript|operator}1 %0 may not"
" be used on immutable value '%2'",
(Identifier, unsigned, StringRef))
(DeclBaseName, unsigned, StringRef))
ERROR(immutable_value_passed_inout,none,
"immutable value '%0' may not be passed inout",
(StringRef))
Expand Down
74 changes: 37 additions & 37 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ ERROR(ambiguous_module_type,none,
"ambiguous type name %0 in module %1", (Identifier, Identifier))
ERROR(use_nonmatching_operator,none,
"%0 is not a %select{binary|prefix unary|postfix unary}1 operator",
(Identifier, unsigned))
(DeclBaseName, unsigned))
ERROR(broken_associated_type_witness,none,
"reference to invalid associated type %0 of type %1", (DeclName, Type))

Expand Down Expand Up @@ -652,7 +652,7 @@ ERROR(invalid_arg_count_for_operator,none,
ERROR(operator_in_local_scope,none,
"operator functions can only be declared at global or in type scope", ())
ERROR(nonstatic_operator_in_type,none,
"operator %0 declared in type %1 must be 'static'", (Identifier, Type))
"operator %0 declared in type %1 must be 'static'", (DeclBaseName, Type))
ERROR(nonfinal_operator_in_class,none,
"operator %0 declared in non-final class %1 must be 'final'",
(Identifier, Type))
Expand Down Expand Up @@ -723,10 +723,10 @@ ERROR(did_not_call_function_value,none,
())
ERROR(did_not_call_function,none,
"function %0 was used as a property; add () to call it",
(Identifier))
(DeclBaseName))
ERROR(did_not_call_method,none,
"method %0 was used as a property; add () to call it",
(Identifier))
(DeclBaseName))

ERROR(init_not_instance_member,none,
"'init' is a member of the type; use 'type(of: ...)' to initialize "
Expand Down Expand Up @@ -782,13 +782,13 @@ ERROR(optional_chain_isnt_chaining,none,
ERROR(pattern_in_expr,none,
"%0 cannot appear in an expression", (PatternKind))
NOTE(note_call_to_operator,none,
"in call to operator %0", (Identifier))
"in call to operator %0", (DeclBaseName))
NOTE(note_call_to_func,none,
"in call to function %0", (Identifier))
"in call to function %0", (DeclBaseName))
NOTE(note_call_to_initializer,none,
"in call to initializer", ())
NOTE(note_init_parameter,none,
"in initialization of parameter %0", (Identifier))
"in initialization of parameter %0", (DeclBaseName))


ERROR(missing_nullary_call,none,
Expand Down Expand Up @@ -1520,10 +1520,10 @@ NOTE(optional_req_near_match_accessibility,none,
// Protocols and existentials
ERROR(assoc_type_outside_of_protocol,none,
"associated type %0 can only be used with a concrete type or "
"generic parameter base", (Identifier))
"generic parameter base", (DeclBaseName))
ERROR(typealias_outside_of_protocol,none,
"typealias %0 can only be used with a concrete type or "
"generic parameter base", (Identifier))
"generic parameter base", (DeclBaseName))

ERROR(circular_protocol_def,none,
"circular protocol inheritance %0", (StringRef))
Expand Down Expand Up @@ -1571,7 +1571,7 @@ ERROR(requires_same_concrete_type,none,
"generic signature requires types %0 and %1 to be the same", (Type, Type))
ERROR(protocol_typealias_conflict, none,
"typealias %0 requires types %1 and %2 to be the same",
(Identifier, Type, Type))
(DeclBaseName, Type, Type))
WARNING(redundant_same_type_to_concrete,none,
"redundant same-type constraint %0 == %1", (Type, Type))
NOTE(same_type_redundancy_here,none,
Expand Down Expand Up @@ -1639,22 +1639,22 @@ NOTE(multiple_override_prev,none,
"%0 previously overridden here", (DeclName))

ERROR(override_unavailable,none,
"cannot override %0 which has been marked unavailable", (Identifier))
"cannot override %0 which has been marked unavailable", (DeclBaseName))
ERROR(override_unavailable_msg, none,
"cannot override %0 which has been marked unavailable: %1",
(Identifier, StringRef))
(DeclBaseName, StringRef))

ERROR(override_less_available,none,
"overriding %0 must be as available as declaration it overrides",
(Identifier))
(DeclBaseName))

ERROR(override_accessor_less_available,none,
"overriding %0 for %1 must be as available as declaration it overrides",
(DescriptiveDeclKind, Identifier))
(DescriptiveDeclKind, DeclBaseName))

ERROR(override_let_property,none,
"cannot override immutable 'let' property %0 with the getter of a 'var'",
(Identifier))
(DeclBaseName))


ERROR(override_not_accessible,none,
Expand Down Expand Up @@ -1699,12 +1699,12 @@ ERROR(override_property_type_mismatch,none,
"property %0 with type %1 cannot override a property with type %2",
(Identifier, Type, Type))
ERROR(override_with_stored_property,none,
"cannot override with a stored property %0", (Identifier))
"cannot override with a stored property %0", (DeclBaseName))
ERROR(observing_readonly_property,none,
"cannot observe read-only property %0; it can't change", (Identifier))
"cannot observe read-only property %0; it can't change", (DeclBaseName))
ERROR(override_mutable_with_readonly_property,none,
"cannot override mutable property with read-only property %0",
(Identifier))
(DeclBaseName))
ERROR(override_argument_name_mismatch,none,
"argument names for %select{method|initializer}0 %1 do not match those "
"of overridden %select{method|initializer}0 %2",
Expand Down Expand Up @@ -1921,7 +1921,7 @@ ERROR(property_behavior_protocol_no_initStorage,none,
(Type, Type))
ERROR(property_behavior_unknown_requirement,none,
"property behavior protocol %0 has non-behavior requirement %1",
(Identifier, Identifier))
(Identifier, DeclBaseName))
NOTE(property_behavior_unknown_requirement_here,none,
"declared here", ())
NOTE(self_conformance_required_by_property_behavior,none,
Expand Down Expand Up @@ -2367,21 +2367,21 @@ ERROR(self_assignment_prop,none,
"assigning a property to itself", ())
ERROR(property_use_in_closure_without_explicit_self,none,
"reference to property %0 in closure requires explicit 'self.' to make"
" capture semantics explicit", (Identifier))
" capture semantics explicit", (DeclBaseName))
ERROR(method_call_in_closure_without_explicit_self,none,
"call to method %0 in closure requires explicit 'self.' to make"
" capture semantics explicit", (Identifier))
" capture semantics explicit", (DeclBaseName))
ERROR(implicit_use_of_self_in_closure,none,
"implicit use of 'self' in closure; use 'self.' to make"
" capture semantics explicit", ())
ERROR(capture_before_declaration,none,
"cannot capture %0 before it is declared", (Identifier))
"cannot capture %0 before it is declared", (DeclBaseName))
ERROR(transitive_capture_before_declaration,none,
"cannot capture %0, which would use %1 before it is declared",
(Identifier, Identifier))
(DeclBaseName, DeclBaseName))
NOTE(transitive_capture_through_here,none,
"%0, declared here, captures %1",
(Identifier, Identifier))
(DeclBaseName, DeclBaseName))

ERROR(closure_implicit_capture_without_noescape,none,
"escaping closures can only capture inout parameters explicitly by value",
Expand Down Expand Up @@ -2424,18 +2424,18 @@ NOTE(add_self_to_type,none,

WARNING(warn_unqualified_access,none,
"use of %0 treated as a reference to %1 in %2 %3",
(Identifier, DescriptiveDeclKind, DescriptiveDeclKind, DeclName))
(DeclBaseName, DescriptiveDeclKind, DescriptiveDeclKind, DeclName))
NOTE(fix_unqualified_access_member,none,
"use 'self.' to silence this warning", ())
NOTE(fix_unqualified_access_top_level,none,
"use '%0' to reference the %1",
(StringRef, DescriptiveDeclKind, Identifier))
(StringRef, DescriptiveDeclKind, DeclBaseName))
NOTE(fix_unqualified_access_top_level_multi,none,
"use '%0' to reference the %1 in module %2",
(StringRef, DescriptiveDeclKind, Identifier))
(StringRef, DescriptiveDeclKind, DeclBaseName))

ERROR(unsupported_special_decl_ref, none,
"referencing %0 as a function value is not implemented", (Identifier))
"referencing %0 as a function value is not implemented", (DeclBaseName))

WARNING(bitcasting_away_noescape, none,
"'unsafeBitCast' from non-escaping function type %0 to escaping "
Expand Down Expand Up @@ -2518,20 +2518,20 @@ NOTE(silence_optional_in_interpolation_segment_call,none,

ERROR(invalid_noescape_use,none,
"non-escaping %select{value|parameter}1 %0 may only be called",
(Identifier, bool))
(DeclBaseName, bool))
NOTE(noescape_autoclosure,none,
"parameter %0 is implicitly non-escaping because it was declared @autoclosure",
(Identifier))
(DeclBaseName))
NOTE(noescape_parameter,none,
"parameter %0 is implicitly non-escaping",
(Identifier))
(DeclBaseName))

ERROR(closure_noescape_use,none,
"closure use of non-escaping parameter %0 may allow it to escape",
(Identifier))
(DeclBaseName))
ERROR(decl_closure_noescape_use,none,
"declaration closing over non-escaping parameter %0 may allow it to escape",
(Identifier))
(DeclBaseName))
ERROR(passing_noescape_to_escaping,none,
"passing non-escaping parameter %0 to function expecting an @escaping closure",
(Identifier))
Expand All @@ -2544,7 +2544,7 @@ ERROR(general_noescape_to_escaping,none,

ERROR(capture_across_type_decl,none,
"%0 declaration cannot close over value %1 defined in outer scope",
(DescriptiveDeclKind, Identifier))
(DescriptiveDeclKind, DeclBaseName))

//------------------------------------------------------------------------------
// Type Check Statements
Expand Down Expand Up @@ -3323,12 +3323,12 @@ ERROR(fixed_layout_attr_on_internal_type,
none, "'@_fixed_layout' attribute can only be applied to '@_versioned' "
"or public declarations, but %0 is "
"%select{private|fileprivate|internal|%error|%error}1",
(Identifier, Accessibility))
(DeclBaseName, Accessibility))

ERROR(versioned_attr_with_explicit_accessibility,
none, "'@_versioned' attribute can only be applied to internal "
"declarations, but %0 is %select{private|fileprivate|%error|public|open}1",
(Identifier, Accessibility))
(DeclBaseName, Accessibility))

ERROR(versioned_attr_in_protocol,none,
"'@_versioned' attribute cannot be used in protocols", ())
Expand Down Expand Up @@ -3373,7 +3373,7 @@ ERROR(inlineable_stored_property,
ERROR(inlineable_decl_not_public,
none, "'@_inlineable' attribute can only be applied to public declarations, "
"but %0 is %select{private|fileprivate|internal|%error|%error}1",
(Identifier, Accessibility))
(DeclBaseName, Accessibility))

//------------------------------------------------------------------------------
// @_specialize diagnostics
Expand Down
Loading