Skip to content

Commit 06df713

Browse files
authored
Merge pull request #21173 from mikeash/rename-anykeypath-and-valistbuilder-5.0
[5.0][Stdlib] Rename AnyKeyPath's ObjC name and _VaListBuilder to avoid conflicts with older stdlibs.
2 parents 689b47a + 8c8276a commit 06df713

File tree

7 files changed

+105
-47
lines changed

7 files changed

+105
-47
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
@@ -1327,6 +1327,9 @@ ERROR(alignment_must_be_positive_integer,none,
13271327
ERROR(swift_native_objc_runtime_base_must_be_identifier,none,
13281328
"@_swift_native_objc_runtime_base class name must be an identifier", ())
13291329

1330+
ERROR(objc_runtime_name_must_be_identifier,none,
1331+
"@_objcRuntimeName name must be an identifier", ())
1332+
13301333
ERROR(attr_only_at_non_local_scope, none,
13311334
"attribute '%0' can only be used in a non-local scope", (StringRef))
13321335

lib/Parse/ParseDecl.cpp

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

903903
case DAK_RawDocComment:
904904
case DAK_ObjCBridged:
905-
case DAK_ObjCRuntimeName:
906905
case DAK_RestatedObjCConformance:
907906
case DAK_SynthesizedProtocol:
908907
case DAK_ClangImporterSynthesizedType:
@@ -1494,6 +1493,34 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
14941493
Attributes.add(attr);
14951494
break;
14961495
}
1496+
case DAK_ObjCRuntimeName: {
1497+
if (!consumeIf(tok::l_paren)) {
1498+
diagnose(Loc, diag::attr_expected_lparen, AttrName,
1499+
DeclAttribute::isDeclModifier(DK));
1500+
return false;
1501+
}
1502+
1503+
if (Tok.isNot(tok::identifier)) {
1504+
diagnose(Loc, diag::objc_runtime_name_must_be_identifier);
1505+
return false;
1506+
}
1507+
1508+
auto name = Tok.getText();
1509+
1510+
consumeToken(tok::identifier);
1511+
1512+
auto range = SourceRange(Loc, Tok.getRange().getStart());
1513+
1514+
if (!consumeIf(tok::r_paren)) {
1515+
diagnose(Loc, diag::attr_expected_rparen, AttrName,
1516+
DeclAttribute::isDeclModifier(DK));
1517+
return false;
1518+
}
1519+
1520+
Attributes.add(new (Context) ObjCRuntimeNameAttr(name, AtLoc, range,
1521+
/*implicit*/ false));
1522+
break;
1523+
}
14971524

14981525

14991526
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: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ internal typealias _VAInt = Int32
127127
@inlinable // c-abi
128128
public func withVaList<R>(_ args: [CVarArg],
129129
_ body: (CVaListPointer) -> R) -> R {
130-
let builder = _VaListBuilder()
130+
let builder = __VaListBuilder()
131131
for a in args {
132132
builder.append(a)
133133
}
@@ -137,7 +137,7 @@ public func withVaList<R>(_ args: [CVarArg],
137137
/// Invoke `body` with a C `va_list` argument derived from `builder`.
138138
@inlinable // c-abi
139139
internal func _withVaList<R>(
140-
_ builder: _VaListBuilder,
140+
_ builder: __VaListBuilder,
141141
_ body: (CVaListPointer) -> R
142142
) -> R {
143143
let result = body(builder.va_list())
@@ -168,7 +168,7 @@ internal func _withVaList<R>(
168168
/// `va_list` argument.
169169
@inlinable // c-abi
170170
public func getVaList(_ args: [CVarArg]) -> CVaListPointer {
171-
let builder = _VaListBuilder()
171+
let builder = __VaListBuilder()
172172
for a in args {
173173
builder.append(a)
174174
}
@@ -406,9 +406,12 @@ extension Float80 : CVarArg, _CVarArgAligned {
406406

407407
/// An object that can manage the lifetime of storage backing a
408408
/// `CVaListPointer`.
409+
// NOTE: older runtimes called this _VaListBuilder. The two must
410+
// coexist, so it was renamed. The old name must not be used in the new
411+
// runtime.
409412
@_fixed_layout
410413
@usableFromInline // c-abi
411-
final internal class _VaListBuilder {
414+
final internal class __VaListBuilder {
412415
@_fixed_layout // c-abi
413416
@usableFromInline
414417
internal struct Header {
@@ -503,9 +506,12 @@ final internal class _VaListBuilder {
503506

504507
/// An object that can manage the lifetime of storage backing a
505508
/// `CVaListPointer`.
509+
// NOTE: older runtimes called this _VaListBuilder. The two must
510+
// coexist, so it was renamed. The old name must not be used in the new
511+
// runtime.
506512
@_fixed_layout
507513
@usableFromInline // c-abi
508-
final internal class _VaListBuilder {
514+
final internal class __VaListBuilder {
509515

510516
@inlinable // c-abi
511517
internal init() {}
@@ -533,16 +539,16 @@ final internal class _VaListBuilder {
533539
}
534540

535541
// NB: This function *cannot* be @inlinable because it expects to project
536-
// and escape the physical storage of `_VaListBuilder.alignedStorageForEmptyVaLists`.
542+
// and escape the physical storage of `__VaListBuilder.alignedStorageForEmptyVaLists`.
537543
// Marking it inlinable will cause it to resiliently use accessors to
538-
// project `_VaListBuilder.alignedStorageForEmptyVaLists` as a computed
544+
// project `__VaListBuilder.alignedStorageForEmptyVaLists` as a computed
539545
// property.
540546
@usableFromInline // c-abi
541547
internal func va_list() -> CVaListPointer {
542548
// Use Builtin.addressof to emphasize that we are deliberately escaping this
543549
// pointer and assuming it is safe to do so.
544550
let emptyAddr = UnsafeMutablePointer<Int>(
545-
Builtin.addressof(&_VaListBuilder.alignedStorageForEmptyVaLists))
551+
Builtin.addressof(&__VaListBuilder.alignedStorageForEmptyVaLists))
546552
return CVaListPointer(_fromUnsafeMutablePointer: storage ?? emptyAddr)
547553
}
548554

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)