Skip to content

Commit 161b30f

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. Since special names have not been introduced yet, TODOs are left where handling of these will most likely be necessary. Furthermore the SwiftLookupTable will needs to be changed to handle special names.
1 parent 8fea2f7 commit 161b30f

File tree

88 files changed

+554
-427
lines changed

Some content is hidden

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

88 files changed

+554
-427
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
@@ -2123,13 +2123,13 @@ class ValueDecl : public Decl {
21232123
}
21242124

21252125
bool hasName() const { return bool(Name); }
2126-
/// TODO: Rename to getSimpleName?
2127-
Identifier getName() const { return Name.getBaseName(); }
21282126
bool isOperator() const { return Name.isOperator(); }
21292127

21302128
/// Returns the string for the base name, or "_" if this is unnamed.
21312129
StringRef getNameStr() const {
2132-
return hasName() ? getName().str() : "_";
2130+
// TODO: Check if this function is called for special names
2131+
assert(!Name.isSpecial() && "Cannot get string for special names");
2132+
return hasName() ? Name.getBaseName().getIdentifier().str() : "_";
21332133
}
21342134

21352135
/// Retrieve the full name of the declaration.
@@ -2139,7 +2139,7 @@ class ValueDecl : public Decl {
21392139

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

21442144
/// Retrieve the name to use for this declaration when interoperating
21452145
/// with the Objective-C runtime.
@@ -2348,6 +2348,8 @@ class TypeDecl : public ValueDecl {
23482348
}
23492349

23502350
public:
2351+
Identifier getName() const { return getFullName().getBaseIdentifier(); }
2352+
23512353
/// The type of this declaration's values. For the type of the
23522354
/// declaration itself, use getInterfaceType(), which returns a
23532355
/// metatype.
@@ -4333,6 +4335,8 @@ class VarDecl : public AbstractStorageDecl {
43334335

43344336
SourceRange getSourceRange() const;
43354337

4338+
Identifier getName() const { return getFullName().getBaseIdentifier(); }
4339+
43364340
TypeLoc &getTypeLoc() { return typeLoc; }
43374341
TypeLoc getTypeLoc() const { return typeLoc; }
43384342

@@ -4800,6 +4804,8 @@ class AbstractFunctionDecl : public ValueDecl, public GenericContext {
48004804
}
48014805

48024806
public:
4807+
Identifier getName() const { return getFullName().getBaseIdentifier(); }
4808+
48034809
/// \brief Should this declaration be treated as if annotated with transparent
48044810
/// attribute.
48054811
bool isTransparent() const;
@@ -5430,6 +5436,8 @@ class EnumElementDecl : public ValueDecl {
54305436
EnumElementDeclBits.HasArgumentType = HasArgumentType;
54315437
}
54325438

5439+
Identifier getName() const { return getFullName().getBaseIdentifier(); }
5440+
54335441
/// \returns false if there was an error during the computation rendering the
54345442
/// EnumElementDecl invalid, true otherwise.
54355443
bool computeType();

include/swift/AST/DiagnosticEngine.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,12 @@ namespace swift {
123123
: Kind(DiagnosticArgumentKind::Unsigned), UnsignedVal(I) {
124124
}
125125

126-
DiagnosticArgument(DeclName I)
127-
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(I) {
128-
}
129-
126+
DiagnosticArgument(DeclName D)
127+
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(D) {}
128+
129+
DiagnosticArgument(DeclBaseName D)
130+
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(D) {}
131+
130132
DiagnosticArgument(Identifier I)
131133
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(I) {
132134
}

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: 4 additions & 4 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",
@@ -89,7 +89,7 @@ NOTE(previous_inout_alias,none,
8989
WARNING(exclusivity_access_required,none,
9090
"simultaneous accesses to %0 %1; "
9191
"%select{initialization|read|modification|deinitialization}2 requires "
92-
"exclusive access", (DescriptiveDeclKind, Identifier, unsigned))
92+
"exclusive access", (DescriptiveDeclKind, DeclBaseName, unsigned))
9393

9494
WARNING(exclusivity_access_required_unknown_decl,none,
9595
"simultaneous accesses; "
@@ -135,7 +135,7 @@ ERROR(self_use_before_fully_init,none,
135135
"use of 'self' in %select{method call|property access}1 %0 before "
136136
"%select{all stored properties are initialized|"
137137
"super.init initializes self|"
138-
"self.init initializes self}2", (Identifier, bool, unsigned))
138+
"self.init initializes self}2", (DeclBaseName, bool, unsigned))
139139
ERROR(use_of_self_before_fully_init,none,
140140
"'self' used before all stored properties are initialized", ())
141141
ERROR(use_of_self_before_fully_init_protocol,none,
@@ -181,7 +181,7 @@ NOTE(initial_value_provided_in_let_decl,none,
181181
ERROR(mutating_method_called_on_immutable_value,none,
182182
"mutating %select{method|property access|subscript|operator}1 %0 may not"
183183
" be used on immutable value '%2'",
184-
(Identifier, unsigned, StringRef))
184+
(DeclBaseName, unsigned, StringRef))
185185
ERROR(immutable_value_passed_inout,none,
186186
"immutable value '%0' may not be passed inout",
187187
(StringRef))

include/swift/AST/DiagnosticsSema.def

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ ERROR(ambiguous_module_type,none,
595595
"ambiguous type name %0 in module %1", (Identifier, Identifier))
596596
ERROR(use_nonmatching_operator,none,
597597
"%0 is not a %select{binary|prefix unary|postfix unary}1 operator",
598-
(Identifier, unsigned))
598+
(DeclBaseName, unsigned))
599599
ERROR(broken_associated_type_witness,none,
600600
"reference to invalid associated type %0 of type %1", (DeclName, Type))
601601

@@ -680,7 +680,7 @@ ERROR(invalid_arg_count_for_operator,none,
680680
ERROR(operator_in_local_scope,none,
681681
"operator functions can only be declared at global or in type scope", ())
682682
ERROR(nonstatic_operator_in_type,none,
683-
"operator %0 declared in type %1 must be 'static'", (Identifier, Type))
683+
"operator %0 declared in type %1 must be 'static'", (DeclBaseName, Type))
684684
ERROR(nonfinal_operator_in_class,none,
685685
"operator %0 declared in non-final class %1 must be 'final'",
686686
(Identifier, Type))
@@ -751,10 +751,10 @@ ERROR(did_not_call_function_value,none,
751751
())
752752
ERROR(did_not_call_function,none,
753753
"function %0 was used as a property; add () to call it",
754-
(Identifier))
754+
(DeclBaseName))
755755
ERROR(did_not_call_method,none,
756756
"method %0 was used as a property; add () to call it",
757-
(Identifier))
757+
(DeclBaseName))
758758

759759
ERROR(init_not_instance_member,none,
760760
"'init' is a member of the type; use 'type(of: ...)' to initialize "
@@ -810,13 +810,13 @@ ERROR(optional_chain_isnt_chaining,none,
810810
ERROR(pattern_in_expr,none,
811811
"%0 cannot appear in an expression", (PatternKind))
812812
NOTE(note_call_to_operator,none,
813-
"in call to operator %0", (Identifier))
813+
"in call to operator %0", (DeclBaseName))
814814
NOTE(note_call_to_func,none,
815-
"in call to function %0", (Identifier))
815+
"in call to function %0", (DeclBaseName))
816816
NOTE(note_call_to_initializer,none,
817817
"in call to initializer", ())
818818
NOTE(note_init_parameter,none,
819-
"in initialization of parameter %0", (Identifier))
819+
"in initialization of parameter %0", (DeclBaseName))
820820

821821

822822
ERROR(missing_nullary_call,none,
@@ -1561,10 +1561,10 @@ NOTE(optional_req_near_match_accessibility,none,
15611561
// Protocols and existentials
15621562
ERROR(assoc_type_outside_of_protocol,none,
15631563
"associated type %0 can only be used with a concrete type or "
1564-
"generic parameter base", (Identifier))
1564+
"generic parameter base", (DeclBaseName))
15651565
ERROR(typealias_outside_of_protocol,none,
15661566
"type alias %0 can only be used with a concrete type or "
1567-
"generic parameter base", (Identifier))
1567+
"generic parameter base", (DeclBaseName))
15681568

15691569
ERROR(circular_protocol_def,none,
15701570
"circular protocol inheritance %0", (StringRef))
@@ -1617,7 +1617,7 @@ ERROR(requires_same_concrete_type,none,
16171617
"generic signature requires types %0 and %1 to be the same", (Type, Type))
16181618
ERROR(protocol_typealias_conflict, none,
16191619
"type alias %0 requires types %1 and %2 to be the same",
1620-
(Identifier, Type, Type))
1620+
(DeclBaseName, Type, Type))
16211621
WARNING(redundant_conformance_constraint,none,
16221622
"redundant conformance constraint %0: %1", (Type, ProtocolDecl *))
16231623
NOTE(redundant_conformance_here,none,
@@ -1713,22 +1713,22 @@ NOTE(multiple_override_prev,none,
17131713
"%0 previously overridden here", (DeclName))
17141714

17151715
ERROR(override_unavailable,none,
1716-
"cannot override %0 which has been marked unavailable", (Identifier))
1716+
"cannot override %0 which has been marked unavailable", (DeclBaseName))
17171717
ERROR(override_unavailable_msg, none,
17181718
"cannot override %0 which has been marked unavailable: %1",
1719-
(Identifier, StringRef))
1719+
(DeclBaseName, StringRef))
17201720

17211721
ERROR(override_less_available,none,
17221722
"overriding %0 must be as available as declaration it overrides",
1723-
(Identifier))
1723+
(DeclBaseName))
17241724

17251725
ERROR(override_accessor_less_available,none,
17261726
"overriding %0 for %1 must be as available as declaration it overrides",
1727-
(DescriptiveDeclKind, Identifier))
1727+
(DescriptiveDeclKind, DeclBaseName))
17281728

17291729
ERROR(override_let_property,none,
17301730
"cannot override immutable 'let' property %0 with the getter of a 'var'",
1731-
(Identifier))
1731+
(DeclBaseName))
17321732

17331733

17341734
ERROR(override_not_accessible,none,
@@ -1773,12 +1773,12 @@ ERROR(override_property_type_mismatch,none,
17731773
"property %0 with type %1 cannot override a property with type %2",
17741774
(Identifier, Type, Type))
17751775
ERROR(override_with_stored_property,none,
1776-
"cannot override with a stored property %0", (Identifier))
1776+
"cannot override with a stored property %0", (DeclBaseName))
17771777
ERROR(observing_readonly_property,none,
1778-
"cannot observe read-only property %0; it can't change", (Identifier))
1778+
"cannot observe read-only property %0; it can't change", (DeclBaseName))
17791779
ERROR(override_mutable_with_readonly_property,none,
17801780
"cannot override mutable property with read-only property %0",
1781-
(Identifier))
1781+
(DeclBaseName))
17821782
ERROR(override_argument_name_mismatch,none,
17831783
"argument names for %select{method|initializer}0 %1 do not match those "
17841784
"of overridden %select{method|initializer}0 %2",
@@ -2003,7 +2003,7 @@ ERROR(property_behavior_protocol_no_initStorage,none,
20032003
(Type, Type))
20042004
ERROR(property_behavior_unknown_requirement,none,
20052005
"property behavior protocol %0 has non-behavior requirement %1",
2006-
(Identifier, Identifier))
2006+
(Identifier, DeclBaseName))
20072007
NOTE(property_behavior_unknown_requirement_here,none,
20082008
"declared here", ())
20092009
NOTE(self_conformance_required_by_property_behavior,none,
@@ -2463,21 +2463,21 @@ ERROR(self_assignment_prop,none,
24632463
"assigning a property to itself", ())
24642464
ERROR(property_use_in_closure_without_explicit_self,none,
24652465
"reference to property %0 in closure requires explicit 'self.' to make"
2466-
" capture semantics explicit", (Identifier))
2466+
" capture semantics explicit", (DeclBaseName))
24672467
ERROR(method_call_in_closure_without_explicit_self,none,
24682468
"call to method %0 in closure requires explicit 'self.' to make"
2469-
" capture semantics explicit", (Identifier))
2469+
" capture semantics explicit", (DeclBaseName))
24702470
ERROR(implicit_use_of_self_in_closure,none,
24712471
"implicit use of 'self' in closure; use 'self.' to make"
24722472
" capture semantics explicit", ())
24732473
ERROR(capture_before_declaration,none,
2474-
"cannot capture %0 before it is declared", (Identifier))
2474+
"cannot capture %0 before it is declared", (DeclBaseName))
24752475
ERROR(transitive_capture_before_declaration,none,
24762476
"cannot capture %0, which would use %1 before it is declared",
2477-
(Identifier, Identifier))
2477+
(DeclBaseName, DeclBaseName))
24782478
NOTE(transitive_capture_through_here,none,
24792479
"%0, declared here, captures %1",
2480-
(Identifier, Identifier))
2480+
(DeclBaseName, DeclBaseName))
24812481

24822482
ERROR(closure_implicit_capture_without_noescape,none,
24832483
"escaping closures can only capture inout parameters explicitly by value",
@@ -2520,18 +2520,18 @@ NOTE(add_self_to_type,none,
25202520

25212521
WARNING(warn_unqualified_access,none,
25222522
"use of %0 treated as a reference to %1 in %2 %3",
2523-
(Identifier, DescriptiveDeclKind, DescriptiveDeclKind, DeclName))
2523+
(DeclBaseName, DescriptiveDeclKind, DescriptiveDeclKind, DeclName))
25242524
NOTE(fix_unqualified_access_member,none,
25252525
"use 'self.' to silence this warning", ())
25262526
NOTE(fix_unqualified_access_top_level,none,
25272527
"use '%0' to reference the %1",
2528-
(StringRef, DescriptiveDeclKind, Identifier))
2528+
(StringRef, DescriptiveDeclKind, DeclBaseName))
25292529
NOTE(fix_unqualified_access_top_level_multi,none,
25302530
"use '%0' to reference the %1 in module %2",
2531-
(StringRef, DescriptiveDeclKind, Identifier))
2531+
(StringRef, DescriptiveDeclKind, DeclBaseName))
25322532

25332533
ERROR(unsupported_special_decl_ref, none,
2534-
"referencing %0 as a function value is not implemented", (Identifier))
2534+
"referencing %0 as a function value is not implemented", (DeclBaseName))
25352535

25362536
WARNING(bitcasting_away_noescape, none,
25372537
"'unsafeBitCast' from non-escaping function type %0 to escaping "
@@ -2614,20 +2614,20 @@ NOTE(silence_optional_in_interpolation_segment_call,none,
26142614

26152615
ERROR(invalid_noescape_use,none,
26162616
"non-escaping %select{value|parameter}1 %0 may only be called",
2617-
(Identifier, bool))
2617+
(DeclBaseName, bool))
26182618
NOTE(noescape_autoclosure,none,
26192619
"parameter %0 is implicitly non-escaping because it was declared @autoclosure",
2620-
(Identifier))
2620+
(DeclBaseName))
26212621
NOTE(noescape_parameter,none,
26222622
"parameter %0 is implicitly non-escaping",
2623-
(Identifier))
2623+
(DeclBaseName))
26242624

26252625
ERROR(closure_noescape_use,none,
26262626
"closure use of non-escaping parameter %0 may allow it to escape",
2627-
(Identifier))
2627+
(DeclBaseName))
26282628
ERROR(decl_closure_noescape_use,none,
26292629
"declaration closing over non-escaping parameter %0 may allow it to escape",
2630-
(Identifier))
2630+
(DeclBaseName))
26312631
ERROR(passing_noescape_to_escaping,none,
26322632
"passing non-escaping parameter %0 to function expecting an @escaping closure",
26332633
(Identifier))
@@ -2640,7 +2640,7 @@ ERROR(general_noescape_to_escaping,none,
26402640

26412641
ERROR(capture_across_type_decl,none,
26422642
"%0 declaration cannot close over value %1 defined in outer scope",
2643-
(DescriptiveDeclKind, Identifier))
2643+
(DescriptiveDeclKind, DeclBaseName))
26442644

26452645
//------------------------------------------------------------------------------
26462646
// Type Check Statements
@@ -3457,12 +3457,12 @@ ERROR(fixed_layout_attr_on_internal_type,
34573457
none, "'@_fixed_layout' attribute can only be applied to '@_versioned' "
34583458
"or public declarations, but %0 is "
34593459
"%select{private|fileprivate|internal|%error|%error}1",
3460-
(Identifier, Accessibility))
3460+
(DeclBaseName, Accessibility))
34613461

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

34673467
ERROR(versioned_attr_in_protocol,none,
34683468
"'@_versioned' attribute cannot be used in protocols", ())
@@ -3507,7 +3507,7 @@ ERROR(inlineable_stored_property,
35073507
ERROR(inlineable_decl_not_public,
35083508
none, "'@_inlineable' attribute can only be applied to public declarations, "
35093509
"but %0 is %select{private|fileprivate|internal|%error|%error}1",
3510-
(Identifier, Accessibility))
3510+
(DeclBaseName, Accessibility))
35113511

35123512
//------------------------------------------------------------------------------
35133513
// @_specialize diagnostics

0 commit comments

Comments
 (0)