Skip to content

Commit e9b2c13

Browse files
committed
Preparations for special names
Special names will in the future represent names that don't have a surface language identifier like subscript. For this, change the backing type of DeclName to a new type DeclBaseName that will later be able to represent special names. ValueDecls may therefore no longer have an identifier name. Thus we move the getName method from ValueDecl to the subtypes that are guaranteed to have identifier names
1 parent c678b96 commit e9b2c13

File tree

84 files changed

+512
-367
lines changed

Some content is hidden

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

84 files changed

+512
-367
lines changed

include/swift/AST/DebuggerClient.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ class DebuggerClient {
4848
/// be consulted first. Return true if results have been added
4949
/// to RV.
5050
/// FIXME: I don't think this ever does anything useful.
51-
virtual bool lookupOverrides(Identifier Name, DeclContext *DC,
51+
virtual bool lookupOverrides(DeclBaseName Name, DeclContext *DC,
5252
SourceLoc Loc, bool IsTypeLookup,
5353
ResultVector &RV) = 0;
54-
54+
5555
/// This is the second time DebuggerClient is consulted:
5656
/// after all names in external Modules are checked, the client
5757
/// gets a chance to add names to the list of candidates that
58-
/// have been found in the external module lookup.
58+
/// have been found in the external module lookup.
5959

60-
virtual bool lookupAdditions(Identifier Name, DeclContext *DC,
60+
virtual bool lookupAdditions(DeclBaseName Name, DeclContext *DC,
6161
SourceLoc Loc, bool IsTypeLookup,
6262
ResultVector &RV) = 0;
6363

include/swift/AST/Decl.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,13 +2102,13 @@ class ValueDecl : public Decl {
21022102
}
21032103

21042104
bool hasName() const { return bool(Name); }
2105-
/// TODO: Rename to getSimpleName?
2106-
Identifier getName() const { return Name.getBaseName(); }
21072105
bool isOperator() const { return Name.isOperator(); }
21082106

21092107
/// Returns the string for the base name, or "_" if this is unnamed.
21102108
StringRef getNameStr() const {
2111-
return hasName() ? getName().str() : "_";
2109+
// TODO: Check if this function is called for special names
2110+
assert(!Name.isSpecial() && "Cannot get string for special names");
2111+
return hasName() ? Name.getBaseName().getIdentifier().str() : "_";
21122112
}
21132113

21142114
/// Retrieve the full name of the declaration.
@@ -2118,7 +2118,7 @@ class ValueDecl : public Decl {
21182118

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

21232123
/// Retrieve the name to use for this declaration when interoperating
21242124
/// with the Objective-C runtime.
@@ -2327,6 +2327,8 @@ class TypeDecl : public ValueDecl {
23272327
}
23282328

23292329
public:
2330+
Identifier getName() const { return getFullName().getBaseIdentifier(); }
2331+
23302332
/// The type of this declaration's values. For the type of the
23312333
/// declaration itself, use getInterfaceType(), which returns a
23322334
/// metatype.
@@ -4211,6 +4213,8 @@ class VarDecl : public AbstractStorageDecl {
42114213
return VarDeclBits.IsUserAccessible;
42124214
}
42134215

4216+
Identifier getName() const { return getFullName().getBaseIdentifier(); }
4217+
42144218
TypeLoc &getTypeLoc() { return typeLoc; }
42154219
TypeLoc getTypeLoc() const { return typeLoc; }
42164220

@@ -4678,6 +4682,8 @@ class AbstractFunctionDecl : public ValueDecl, public GenericContext {
46784682
}
46794683

46804684
public:
4685+
Identifier getName() const { return getFullName().getBaseIdentifier(); }
4686+
46814687
/// \brief Should this declaration be treated as if annotated with transparent
46824688
/// attribute.
46834689
bool isTransparent() const;
@@ -5299,6 +5305,8 @@ class EnumElementDecl : public ValueDecl {
52995305
EnumElementDeclBits.HasArgumentType = HasArgumentType;
53005306
}
53015307

5308+
Identifier getName() const { return getFullName().getBaseIdentifier(); }
5309+
53025310
/// \returns false if there was an error during the computation rendering the
53035311
/// EnumElementDecl invalid, true otherwise.
53045312
bool computeType();

include/swift/AST/DiagnosticEngine.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,12 @@ namespace swift {
119119
: Kind(DiagnosticArgumentKind::Unsigned), UnsignedVal(I) {
120120
}
121121

122-
DiagnosticArgument(DeclName I)
123-
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(I) {
124-
}
125-
122+
DiagnosticArgument(DeclName D)
123+
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(D) {}
124+
125+
DiagnosticArgument(DeclBaseName D)
126+
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(D) {}
127+
126128
DiagnosticArgument(Identifier I)
127129
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(I) {
128130
}

include/swift/AST/DiagnosticsCommon.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ ERROR(error_no_group_info,none,
5050

5151
NOTE(previous_decldef,none,
5252
"previous %select{declaration|definition}0 of %1 is here",
53-
(bool, Identifier))
53+
(bool, DeclBaseName))
5454

5555
NOTE(brace_stmt_suggest_do,none,
5656
"did you mean to use a 'do' statement?", ())

include/swift/AST/DiagnosticsSIL.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ ERROR(could_not_find_pointer_pointee_property,none,
7171

7272
ERROR(writeback_overlap_property,none,
7373
"inout writeback to computed property %0 occurs in multiple arguments to"
74-
" call, introducing invalid aliasing", (Identifier))
74+
" call, introducing invalid aliasing", (DeclBaseName))
7575
ERROR(writeback_overlap_subscript,none,
7676
"inout writeback through subscript occurs in multiple arguments to call,"
7777
" introducing invalid aliasing",
@@ -120,7 +120,7 @@ ERROR(self_use_before_fully_init,none,
120120
"use of 'self' in %select{method call|property access}1 %0 before "
121121
"%select{all stored properties are initialized|"
122122
"super.init initializes self|"
123-
"self.init initializes self}2", (Identifier, bool, unsigned))
123+
"self.init initializes self}2", (DeclBaseName, bool, unsigned))
124124
ERROR(use_of_self_before_fully_init,none,
125125
"'self' used before all stored properties are initialized", ())
126126
ERROR(use_of_self_before_fully_init_protocol,none,
@@ -166,7 +166,7 @@ NOTE(initial_value_provided_in_let_decl,none,
166166
ERROR(mutating_method_called_on_immutable_value,none,
167167
"mutating %select{method|property access|subscript|operator}1 %0 may not"
168168
" be used on immutable value '%2'",
169-
(Identifier, unsigned, StringRef))
169+
(DeclBaseName, unsigned, StringRef))
170170
ERROR(immutable_value_passed_inout,none,
171171
"immutable value '%0' may not be passed inout",
172172
(StringRef))

include/swift/AST/DiagnosticsSema.def

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ ERROR(ambiguous_module_type,none,
567567
"ambiguous type name %0 in module %1", (Identifier, Identifier))
568568
ERROR(use_nonmatching_operator,none,
569569
"%0 is not a %select{binary|prefix unary|postfix unary}1 operator",
570-
(Identifier, unsigned))
570+
(DeclBaseName, unsigned))
571571
ERROR(broken_associated_type_witness,none,
572572
"reference to invalid associated type %0 of type %1", (DeclName, Type))
573573

@@ -652,7 +652,7 @@ ERROR(invalid_arg_count_for_operator,none,
652652
ERROR(operator_in_local_scope,none,
653653
"operator functions can only be declared at global or in type scope", ())
654654
ERROR(nonstatic_operator_in_type,none,
655-
"operator %0 declared in type %1 must be 'static'", (Identifier, Type))
655+
"operator %0 declared in type %1 must be 'static'", (DeclBaseName, Type))
656656
ERROR(nonfinal_operator_in_class,none,
657657
"operator %0 declared in non-final class %1 must be 'final'",
658658
(Identifier, Type))
@@ -723,10 +723,10 @@ ERROR(did_not_call_function_value,none,
723723
())
724724
ERROR(did_not_call_function,none,
725725
"function %0 was used as a property; add () to call it",
726-
(Identifier))
726+
(DeclBaseName))
727727
ERROR(did_not_call_method,none,
728728
"method %0 was used as a property; add () to call it",
729-
(Identifier))
729+
(DeclBaseName))
730730

731731
ERROR(init_not_instance_member,none,
732732
"'init' is a member of the type; use 'type(of: ...)' to initialize "
@@ -782,13 +782,13 @@ ERROR(optional_chain_isnt_chaining,none,
782782
ERROR(pattern_in_expr,none,
783783
"%0 cannot appear in an expression", (PatternKind))
784784
NOTE(note_call_to_operator,none,
785-
"in call to operator %0", (Identifier))
785+
"in call to operator %0", (DeclBaseName))
786786
NOTE(note_call_to_func,none,
787-
"in call to function %0", (Identifier))
787+
"in call to function %0", (DeclBaseName))
788788
NOTE(note_call_to_initializer,none,
789789
"in call to initializer", ())
790790
NOTE(note_init_parameter,none,
791-
"in initialization of parameter %0", (Identifier))
791+
"in initialization of parameter %0", (DeclBaseName))
792792

793793

794794
ERROR(missing_nullary_call,none,
@@ -1520,10 +1520,10 @@ NOTE(optional_req_near_match_accessibility,none,
15201520
// Protocols and existentials
15211521
ERROR(assoc_type_outside_of_protocol,none,
15221522
"associated type %0 can only be used with a concrete type or "
1523-
"generic parameter base", (Identifier))
1523+
"generic parameter base", (DeclBaseName))
15241524
ERROR(typealias_outside_of_protocol,none,
15251525
"typealias %0 can only be used with a concrete type or "
1526-
"generic parameter base", (Identifier))
1526+
"generic parameter base", (DeclBaseName))
15271527

15281528
ERROR(circular_protocol_def,none,
15291529
"circular protocol inheritance %0", (StringRef))
@@ -1571,7 +1571,7 @@ ERROR(requires_same_concrete_type,none,
15711571
"generic signature requires types %0 and %1 to be the same", (Type, Type))
15721572
ERROR(protocol_typealias_conflict, none,
15731573
"typealias %0 requires types %1 and %2 to be the same",
1574-
(Identifier, Type, Type))
1574+
(DeclBaseName, Type, Type))
15751575
WARNING(redundant_same_type_to_concrete,none,
15761576
"redundant same-type constraint %0 == %1", (Type, Type))
15771577
NOTE(same_type_redundancy_here,none,
@@ -1639,22 +1639,22 @@ NOTE(multiple_override_prev,none,
16391639
"%0 previously overridden here", (DeclName))
16401640

16411641
ERROR(override_unavailable,none,
1642-
"cannot override %0 which has been marked unavailable", (Identifier))
1642+
"cannot override %0 which has been marked unavailable", (DeclBaseName))
16431643
ERROR(override_unavailable_msg, none,
16441644
"cannot override %0 which has been marked unavailable: %1",
1645-
(Identifier, StringRef))
1645+
(DeclBaseName, StringRef))
16461646

16471647
ERROR(override_less_available,none,
16481648
"overriding %0 must be as available as declaration it overrides",
1649-
(Identifier))
1649+
(DeclBaseName))
16501650

16511651
ERROR(override_accessor_less_available,none,
16521652
"overriding %0 for %1 must be as available as declaration it overrides",
1653-
(DescriptiveDeclKind, Identifier))
1653+
(DescriptiveDeclKind, DeclBaseName))
16541654

16551655
ERROR(override_let_property,none,
16561656
"cannot override immutable 'let' property %0 with the getter of a 'var'",
1657-
(Identifier))
1657+
(DeclBaseName))
16581658

16591659

16601660
ERROR(override_not_accessible,none,
@@ -1699,12 +1699,12 @@ ERROR(override_property_type_mismatch,none,
16991699
"property %0 with type %1 cannot override a property with type %2",
17001700
(Identifier, Type, Type))
17011701
ERROR(override_with_stored_property,none,
1702-
"cannot override with a stored property %0", (Identifier))
1702+
"cannot override with a stored property %0", (DeclBaseName))
17031703
ERROR(observing_readonly_property,none,
1704-
"cannot observe read-only property %0; it can't change", (Identifier))
1704+
"cannot observe read-only property %0; it can't change", (DeclBaseName))
17051705
ERROR(override_mutable_with_readonly_property,none,
17061706
"cannot override mutable property with read-only property %0",
1707-
(Identifier))
1707+
(DeclBaseName))
17081708
ERROR(override_argument_name_mismatch,none,
17091709
"argument names for %select{method|initializer}0 %1 do not match those "
17101710
"of overridden %select{method|initializer}0 %2",
@@ -1921,7 +1921,7 @@ ERROR(property_behavior_protocol_no_initStorage,none,
19211921
(Type, Type))
19221922
ERROR(property_behavior_unknown_requirement,none,
19231923
"property behavior protocol %0 has non-behavior requirement %1",
1924-
(Identifier, Identifier))
1924+
(Identifier, DeclBaseName))
19251925
NOTE(property_behavior_unknown_requirement_here,none,
19261926
"declared here", ())
19271927
NOTE(self_conformance_required_by_property_behavior,none,
@@ -2367,21 +2367,21 @@ ERROR(self_assignment_prop,none,
23672367
"assigning a property to itself", ())
23682368
ERROR(property_use_in_closure_without_explicit_self,none,
23692369
"reference to property %0 in closure requires explicit 'self.' to make"
2370-
" capture semantics explicit", (Identifier))
2370+
" capture semantics explicit", (DeclBaseName))
23712371
ERROR(method_call_in_closure_without_explicit_self,none,
23722372
"call to method %0 in closure requires explicit 'self.' to make"
2373-
" capture semantics explicit", (Identifier))
2373+
" capture semantics explicit", (DeclBaseName))
23742374
ERROR(implicit_use_of_self_in_closure,none,
23752375
"implicit use of 'self' in closure; use 'self.' to make"
23762376
" capture semantics explicit", ())
23772377
ERROR(capture_before_declaration,none,
2378-
"cannot capture %0 before it is declared", (Identifier))
2378+
"cannot capture %0 before it is declared", (DeclBaseName))
23792379
ERROR(transitive_capture_before_declaration,none,
23802380
"cannot capture %0, which would use %1 before it is declared",
2381-
(Identifier, Identifier))
2381+
(DeclBaseName, DeclBaseName))
23822382
NOTE(transitive_capture_through_here,none,
23832383
"%0, declared here, captures %1",
2384-
(Identifier, Identifier))
2384+
(DeclBaseName, DeclBaseName))
23852385

23862386
ERROR(closure_implicit_capture_without_noescape,none,
23872387
"escaping closures can only capture inout parameters explicitly by value",
@@ -2424,18 +2424,18 @@ NOTE(add_self_to_type,none,
24242424

24252425
WARNING(warn_unqualified_access,none,
24262426
"use of %0 treated as a reference to %1 in %2 %3",
2427-
(Identifier, DescriptiveDeclKind, DescriptiveDeclKind, DeclName))
2427+
(DeclBaseName, DescriptiveDeclKind, DescriptiveDeclKind, DeclName))
24282428
NOTE(fix_unqualified_access_member,none,
24292429
"use 'self.' to silence this warning", ())
24302430
NOTE(fix_unqualified_access_top_level,none,
24312431
"use '%0' to reference the %1",
2432-
(StringRef, DescriptiveDeclKind, Identifier))
2432+
(StringRef, DescriptiveDeclKind, DeclBaseName))
24332433
NOTE(fix_unqualified_access_top_level_multi,none,
24342434
"use '%0' to reference the %1 in module %2",
2435-
(StringRef, DescriptiveDeclKind, Identifier))
2435+
(StringRef, DescriptiveDeclKind, DeclBaseName))
24362436

24372437
ERROR(unsupported_special_decl_ref, none,
2438-
"referencing %0 as a function value is not implemented", (Identifier))
2438+
"referencing %0 as a function value is not implemented", (DeclBaseName))
24392439

24402440
WARNING(bitcasting_away_noescape, none,
24412441
"'unsafeBitCast' from non-escaping function type %0 to escaping "
@@ -2518,20 +2518,20 @@ NOTE(silence_optional_in_interpolation_segment_call,none,
25182518

25192519
ERROR(invalid_noescape_use,none,
25202520
"non-escaping %select{value|parameter}1 %0 may only be called",
2521-
(Identifier, bool))
2521+
(DeclBaseName, bool))
25222522
NOTE(noescape_autoclosure,none,
25232523
"parameter %0 is implicitly non-escaping because it was declared @autoclosure",
2524-
(Identifier))
2524+
(DeclBaseName))
25252525
NOTE(noescape_parameter,none,
25262526
"parameter %0 is implicitly non-escaping",
2527-
(Identifier))
2527+
(DeclBaseName))
25282528

25292529
ERROR(closure_noescape_use,none,
25302530
"closure use of non-escaping parameter %0 may allow it to escape",
2531-
(Identifier))
2531+
(DeclBaseName))
25322532
ERROR(decl_closure_noescape_use,none,
25332533
"declaration closing over non-escaping parameter %0 may allow it to escape",
2534-
(Identifier))
2534+
(DeclBaseName))
25352535
ERROR(passing_noescape_to_escaping,none,
25362536
"passing non-escaping parameter %0 to function expecting an @escaping closure",
25372537
(Identifier))
@@ -2544,7 +2544,7 @@ ERROR(general_noescape_to_escaping,none,
25442544

25452545
ERROR(capture_across_type_decl,none,
25462546
"%0 declaration cannot close over value %1 defined in outer scope",
2547-
(DescriptiveDeclKind, Identifier))
2547+
(DescriptiveDeclKind, DeclBaseName))
25482548

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

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

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

33783378
//------------------------------------------------------------------------------
33793379
// @_specialize diagnostics

0 commit comments

Comments
 (0)