Skip to content

[Stdlib] Rename AnyKeyPath's ObjC name and _VaListBuilder to avoid conflicts with older stdlibs. #21127

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

Merged
merged 4 commits into from
Dec 10, 2018
Merged
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
2 changes: 1 addition & 1 deletion include/swift/AST/Attr.def
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ DECL_ATTR(_implements, Implements,
NotSerialized, 67)
DECL_ATTR(_objcRuntimeName, ObjCRuntimeName,
OnClass |
UserInaccessible | RejectByParser |
UserInaccessible |
NotSerialized, 68)
SIMPLE_DECL_ATTR(_staticInitializeObjCMetadata, StaticInitializeObjCMetadata,
OnClass | LongAttribute | RejectByParser |
Expand Down
3 changes: 3 additions & 0 deletions include/swift/AST/DiagnosticsParse.def
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,9 @@ ERROR(alignment_must_be_positive_integer,none,
ERROR(swift_native_objc_runtime_base_must_be_identifier,none,
"@_swift_native_objc_runtime_base class name must be an identifier", ())

ERROR(objc_runtime_name_must_be_identifier,none,
"@_objcRuntimeName name must be an identifier", ())

ERROR(attr_only_at_non_local_scope, none,
"attribute '%0' can only be used in a non-local scope", (StringRef))

Expand Down
29 changes: 28 additions & 1 deletion lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,6 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,

case DAK_RawDocComment:
case DAK_ObjCBridged:
case DAK_ObjCRuntimeName:
case DAK_RestatedObjCConformance:
case DAK_SynthesizedProtocol:
case DAK_ClangImporterSynthesizedType:
Expand Down Expand Up @@ -1506,6 +1505,34 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
Attributes.add(attr);
break;
}
case DAK_ObjCRuntimeName: {
if (!consumeIf(tok::l_paren)) {
diagnose(Loc, diag::attr_expected_lparen, AttrName,
DeclAttribute::isDeclModifier(DK));
return false;
}

if (Tok.isNot(tok::identifier)) {
diagnose(Loc, diag::objc_runtime_name_must_be_identifier);
return false;
}

auto name = Tok.getText();

consumeToken(tok::identifier);

auto range = SourceRange(Loc, Tok.getRange().getStart());

if (!consumeIf(tok::r_paren)) {
diagnose(Loc, diag::attr_expected_rparen, AttrName,
DeclAttribute::isDeclModifier(DK));
return false;
}

Attributes.add(new (Context) ObjCRuntimeNameAttr(name, AtLoc, range,
/*implicit*/ false));
break;
}


case DAK_DynamicReplacement: {
Expand Down
7 changes: 6 additions & 1 deletion stdlib/public/core/KeyPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ internal func _abstract(

// MARK: Type-erased abstract base classes

/// A type-erased key path, from any root type to any resulting value type.
/// A type-erased key path, from any root type to any resulting value
/// type. NOTE: older runtimes had Swift.AnyKeyPath as the ObjC name.
/// The two must coexist, so it was renamed. The old name must not be
/// used in the new runtime. _TtCs11_AnyKeyPath is the mangled name for
/// Swift._AnyKeyPath.
@_objcRuntimeName(_TtCs11_AnyKeyPath)
public class AnyKeyPath: Hashable, _AppendKeyPath {
/// The root type for this key path.
@inlinable
Expand Down
27 changes: 18 additions & 9 deletions stdlib/public/core/VarArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ internal typealias _VAInt = Int32
@inlinable // c-abi
public func withVaList<R>(_ args: [CVarArg],
_ body: (CVaListPointer) -> R) -> R {
let builder = _VaListBuilder()
let builder = __VaListBuilder()
for a in args {
builder.append(a)
}
Expand All @@ -154,7 +154,7 @@ public func withVaList<R>(_ args: [CVarArg],
/// Invoke `body` with a C `va_list` argument derived from `builder`.
@inlinable // c-abi
internal func _withVaList<R>(
_ builder: _VaListBuilder,
_ builder: __VaListBuilder,
_ body: (CVaListPointer) -> R
) -> R {
let result = body(builder.va_list())
Expand Down Expand Up @@ -185,7 +185,7 @@ internal func _withVaList<R>(
/// `va_list` argument.
@inlinable // c-abi
public func getVaList(_ args: [CVarArg]) -> CVaListPointer {
let builder = _VaListBuilder()
let builder = __VaListBuilder()
for a in args {
builder.append(a)
}
Expand Down Expand Up @@ -423,9 +423,12 @@ extension Float80 : CVarArg, _CVarArgAligned {

/// An object that can manage the lifetime of storage backing a
/// `CVaListPointer`.
// NOTE: older runtimes called this _VaListBuilder. The two must
// coexist, so it was renamed. The old name must not be used in the new
// runtime.
@_fixed_layout
@usableFromInline // c-abi
final internal class _VaListBuilder {
final internal class __VaListBuilder {
@_fixed_layout // c-abi
@usableFromInline
internal struct Header {
Expand Down Expand Up @@ -517,9 +520,12 @@ final internal class _VaListBuilder {
}
#elseif arch(arm64) && os(Linux)

// NOTE: older runtimes called this _VaListBuilder. The two must
// coexist, so it was renamed. The old name must not be used in the new
// runtime.
@_fixed_layout // FIXME(sil-serialize-all)
@usableFromInline // FIXME(sil-serialize-all)
final internal class _VaListBuilder {
final internal class __VaListBuilder {
@usableFromInline // FIXME(sil-serialize-all)
internal init() {
// Prepare the register save area.
Expand Down Expand Up @@ -643,9 +649,12 @@ final internal class _VaListBuilder {

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

@inlinable // c-abi
internal init() {}
Expand Down Expand Up @@ -673,16 +682,16 @@ final internal class _VaListBuilder {
}

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

Expand Down
17 changes: 17 additions & 0 deletions test/IRGen/objc_runtime_name_attr.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -emit-ir | %FileCheck %s

// REQUIRES: objc_interop

//import Foundation

class NormalEverydayClass {}
// CHECK: @"$s22objc_runtime_name_attr19NormalEverydayClassCMm" = hidden global %objc_class
// CHECK: @_DATA__TtC22objc_runtime_name_attr19NormalEverydayClass = private constant


@_objcRuntimeName(RenamedClass)
class ThisWillBeRenamed {}
// CHECK: @"$s22objc_runtime_name_attr17ThisWillBeRenamedCMm" = hidden global %objc_class
// CHECK: @_DATA_RenamedClass = private constant

Loading