Skip to content

Commit a39ee29

Browse files
authored
Merge pull request #21127 from mikeash/rename-anykeypath-and-valistbuilder
[Stdlib] Rename AnyKeyPath's ObjC name and _VaListBuilder to avoid conflicts with older stdlibs.
2 parents c66a445 + bdfe094 commit a39ee29

File tree

7 files changed

+109
-48
lines changed

7 files changed

+109
-48
lines changed

include/swift/AST/Attr.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ DECL_ATTR(_implements, Implements,
338338
NotSerialized, 67)
339339
DECL_ATTR(_objcRuntimeName, ObjCRuntimeName,
340340
OnClass |
341-
UserInaccessible | RejectByParser |
341+
UserInaccessible |
342342
NotSerialized, 68)
343343
SIMPLE_DECL_ATTR(_staticInitializeObjCMetadata, StaticInitializeObjCMetadata,
344344
OnClass | LongAttribute | RejectByParser |

include/swift/AST/DiagnosticsParse.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,6 +1320,9 @@ ERROR(alignment_must_be_positive_integer,none,
13201320
ERROR(swift_native_objc_runtime_base_must_be_identifier,none,
13211321
"@_swift_native_objc_runtime_base class name must be an identifier", ())
13221322

1323+
ERROR(objc_runtime_name_must_be_identifier,none,
1324+
"@_objcRuntimeName name must be an identifier", ())
1325+
13231326
ERROR(attr_only_at_non_local_scope, none,
13241327
"attribute '%0' can only be used in a non-local scope", (StringRef))
13251328

lib/Parse/ParseDecl.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,6 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
914914

915915
case DAK_RawDocComment:
916916
case DAK_ObjCBridged:
917-
case DAK_ObjCRuntimeName:
918917
case DAK_RestatedObjCConformance:
919918
case DAK_SynthesizedProtocol:
920919
case DAK_ClangImporterSynthesizedType:
@@ -1506,6 +1505,34 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
15061505
Attributes.add(attr);
15071506
break;
15081507
}
1508+
case DAK_ObjCRuntimeName: {
1509+
if (!consumeIf(tok::l_paren)) {
1510+
diagnose(Loc, diag::attr_expected_lparen, AttrName,
1511+
DeclAttribute::isDeclModifier(DK));
1512+
return false;
1513+
}
1514+
1515+
if (Tok.isNot(tok::identifier)) {
1516+
diagnose(Loc, diag::objc_runtime_name_must_be_identifier);
1517+
return false;
1518+
}
1519+
1520+
auto name = Tok.getText();
1521+
1522+
consumeToken(tok::identifier);
1523+
1524+
auto range = SourceRange(Loc, Tok.getRange().getStart());
1525+
1526+
if (!consumeIf(tok::r_paren)) {
1527+
diagnose(Loc, diag::attr_expected_rparen, AttrName,
1528+
DeclAttribute::isDeclModifier(DK));
1529+
return false;
1530+
}
1531+
1532+
Attributes.add(new (Context) ObjCRuntimeNameAttr(name, AtLoc, range,
1533+
/*implicit*/ false));
1534+
break;
1535+
}
15091536

15101537

15111538
case DAK_DynamicReplacement: {

stdlib/public/core/KeyPath.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ internal func _abstract(
2626

2727
// MARK: Type-erased abstract base classes
2828

29-
/// A type-erased key path, from any root type to any resulting value type.
29+
/// A type-erased key path, from any root type to any resulting value
30+
/// type. NOTE: older runtimes had Swift.AnyKeyPath as the ObjC name.
31+
/// The two must coexist, so it was renamed. The old name must not be
32+
/// used in the new runtime. _TtCs11_AnyKeyPath is the mangled name for
33+
/// Swift._AnyKeyPath.
34+
@_objcRuntimeName(_TtCs11_AnyKeyPath)
3035
public class AnyKeyPath: Hashable, _AppendKeyPath {
3136
/// The root type for this key path.
3237
@inlinable

stdlib/public/core/VarArgs.swift

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ internal typealias _VAInt = Int32
144144
@inlinable // c-abi
145145
public func withVaList<R>(_ args: [CVarArg],
146146
_ body: (CVaListPointer) -> R) -> R {
147-
let builder = _VaListBuilder()
147+
let builder = __VaListBuilder()
148148
for a in args {
149149
builder.append(a)
150150
}
@@ -154,7 +154,7 @@ public func withVaList<R>(_ args: [CVarArg],
154154
/// Invoke `body` with a C `va_list` argument derived from `builder`.
155155
@inlinable // c-abi
156156
internal func _withVaList<R>(
157-
_ builder: _VaListBuilder,
157+
_ builder: __VaListBuilder,
158158
_ body: (CVaListPointer) -> R
159159
) -> R {
160160
let result = body(builder.va_list())
@@ -185,7 +185,7 @@ internal func _withVaList<R>(
185185
/// `va_list` argument.
186186
@inlinable // c-abi
187187
public func getVaList(_ args: [CVarArg]) -> CVaListPointer {
188-
let builder = _VaListBuilder()
188+
let builder = __VaListBuilder()
189189
for a in args {
190190
builder.append(a)
191191
}
@@ -423,9 +423,12 @@ extension Float80 : CVarArg, _CVarArgAligned {
423423

424424
/// An object that can manage the lifetime of storage backing a
425425
/// `CVaListPointer`.
426+
// NOTE: older runtimes called this _VaListBuilder. The two must
427+
// coexist, so it was renamed. The old name must not be used in the new
428+
// runtime.
426429
@_fixed_layout
427430
@usableFromInline // c-abi
428-
final internal class _VaListBuilder {
431+
final internal class __VaListBuilder {
429432
@_fixed_layout // c-abi
430433
@usableFromInline
431434
internal struct Header {
@@ -517,9 +520,12 @@ final internal class _VaListBuilder {
517520
}
518521
#elseif arch(arm64) && os(Linux)
519522

523+
// NOTE: older runtimes called this _VaListBuilder. The two must
524+
// coexist, so it was renamed. The old name must not be used in the new
525+
// runtime.
520526
@_fixed_layout // FIXME(sil-serialize-all)
521527
@usableFromInline // FIXME(sil-serialize-all)
522-
final internal class _VaListBuilder {
528+
final internal class __VaListBuilder {
523529
@usableFromInline // FIXME(sil-serialize-all)
524530
internal init() {
525531
// Prepare the register save area.
@@ -643,9 +649,12 @@ final internal class _VaListBuilder {
643649

644650
/// An object that can manage the lifetime of storage backing a
645651
/// `CVaListPointer`.
652+
// NOTE: older runtimes called this _VaListBuilder. The two must
653+
// coexist, so it was renamed. The old name must not be used in the new
654+
// runtime.
646655
@_fixed_layout
647656
@usableFromInline // c-abi
648-
final internal class _VaListBuilder {
657+
final internal class __VaListBuilder {
649658

650659
@inlinable // c-abi
651660
internal init() {}
@@ -673,16 +682,16 @@ final internal class _VaListBuilder {
673682
}
674683

675684
// NB: This function *cannot* be @inlinable because it expects to project
676-
// and escape the physical storage of `_VaListBuilder.alignedStorageForEmptyVaLists`.
685+
// and escape the physical storage of `__VaListBuilder.alignedStorageForEmptyVaLists`.
677686
// Marking it inlinable will cause it to resiliently use accessors to
678-
// project `_VaListBuilder.alignedStorageForEmptyVaLists` as a computed
687+
// project `__VaListBuilder.alignedStorageForEmptyVaLists` as a computed
679688
// property.
680689
@usableFromInline // c-abi
681690
internal func va_list() -> CVaListPointer {
682691
// Use Builtin.addressof to emphasize that we are deliberately escaping this
683692
// pointer and assuming it is safe to do so.
684693
let emptyAddr = UnsafeMutablePointer<Int>(
685-
Builtin.addressof(&_VaListBuilder.alignedStorageForEmptyVaLists))
694+
Builtin.addressof(&__VaListBuilder.alignedStorageForEmptyVaLists))
686695
return CVaListPointer(_fromUnsafeMutablePointer: storage ?? emptyAddr)
687696
}
688697

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %s -emit-ir | %FileCheck %s
3+
4+
// REQUIRES: objc_interop
5+
6+
//import Foundation
7+
8+
class NormalEverydayClass {}
9+
// CHECK: @"$s22objc_runtime_name_attr19NormalEverydayClassCMm" = hidden global %objc_class
10+
// CHECK: @_DATA__TtC22objc_runtime_name_attr19NormalEverydayClass = private constant
11+
12+
13+
@_objcRuntimeName(RenamedClass)
14+
class ThisWillBeRenamed {}
15+
// CHECK: @"$s22objc_runtime_name_attr17ThisWillBeRenamedCMm" = hidden global %objc_class
16+
// CHECK: @_DATA_RenamedClass = private constant
17+

0 commit comments

Comments
 (0)