Skip to content

Commit c11aacc

Browse files
committed
KeyPaths: Put an override shim on swift_getKeyPath.
This will let future compilers that support new key path features backward-deploy logic for interpreting new kinds of key path patterns.
1 parent 6f91a4e commit c11aacc

File tree

4 files changed

+41
-8
lines changed

4 files changed

+41
-8
lines changed

include/swift/Runtime/Metadata.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,10 @@ void verifyMangledNameRoundtrip(const Metadata *metadata);
766766
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_API
767767
const TypeContextDescriptor *swift_getTypeContextDescriptor(const Metadata *type);
768768

769+
// Defined in KeyPath.swift in the standard library.
770+
SWIFT_RUNTIME_EXPORT
771+
const HeapObject *swift_getKeyPath(const void *pattern, const void *arguments);
772+
769773
} // end namespace swift
770774

771775
#endif // SWIFT_RUNTIME_METADATA_H

stdlib/public/core/KeyPath.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2069,7 +2069,10 @@ internal var keyPathObjectHeaderSize: Int {
20692069
}
20702070

20712071
// Runtime entry point to instantiate a key path object.
2072-
@_cdecl("swift_getKeyPath")
2072+
// Note that this has a compatibility override shim in the runtime so that
2073+
// future compilers can backward-deploy support for instantiating new key path
2074+
// pattern features.
2075+
@_cdecl("swift_getKeyPathImpl")
20732076
public func _swift_getKeyPath(pattern: UnsafeMutableRawPointer,
20742077
arguments: UnsafeRawPointer)
20752078
-> UnsafeRawPointer {

stdlib/public/runtime/CompatibilityOverride.def

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,21 @@
1717

1818
/// #define OVERRIDE(name, ret, attrs, namespace, typedArgs, namedArgs)
1919
/// Provides information about an overridable function.
20-
/// - name is the name of the function, without any leading swift_ or namespace.
20+
/// - name is the name of the function, without any leading swift_ or
21+
/// namespace.
2122
/// - ret is the return type of the function.
2223
/// - attrs is the attributes, if any, applied to the function definition.
23-
/// - namespace is the namespace, if any, the function is in, including a trailing ::
24-
/// - typedArgs is the argument list, including types, surrounded by parentheses
25-
/// - namedArgs is the list of argument names, with no types, surrounded by parentheses
24+
/// - namespace is the namespace, if any, the function is in, including a
25+
/// trailing ::
26+
/// - typedArgs is the argument list, including types, surrounded by
27+
/// parentheses
28+
/// - namedArgs is the list of argument names, with no types, surrounded by
29+
/// parentheses
2630
///
27-
/// The entries are organized by group. A user may define OVERRIDE to get all entries,
28-
/// or define one or more of OVERRIDE_METADATALOOKUP, OVERRIDE_CASTING, OVERRIDE_OBJC,
29-
/// OVERRIDE_FOREIGN, or OVERRIDE_PROTOCOLCONFORMANCE to get only those entries.
31+
/// The entries are organized by group. A user may define OVERRIDE to get all
32+
/// entries, or define one or more of OVERRIDE_METADATALOOKUP, OVERRIDE_CASTING,
33+
/// OVERRIDE_OBJC, OVERRIDE_FOREIGN, OVERRIDE_PROTOCOLCONFORMANCE,
34+
/// and OVERRIDE_KEYPATH to get only those entries.
3035

3136
// NOTE: this file is used to build the definition of OverrideSection in
3237
// CompatibilityOverride.cpp, which is part of the ABI. Do not move or remove entries
@@ -38,6 +43,7 @@
3843
# define OVERRIDE_OBJC OVERRIDE
3944
# define OVERRIDE_FOREIGN OVERRIDE
4045
# define OVERRIDE_PROTOCOLCONFORMANCE OVERRIDE
46+
# define OVERRIDE_KEYPATH OVERRIDE
4147
#else
4248
# ifndef OVERRIDE_METADATALOOKUP
4349
# define OVERRIDE_METADATALOOKUP(...)
@@ -54,6 +60,9 @@
5460
# ifndef OVERRIDE_PROTOCOLCONFORMANCE
5561
# define OVERRIDE_PROTOCOLCONFORMANCE(...)
5662
# endif
63+
# ifndef OVERRIDE_KEYPATH
64+
# define OVERRIDE_KEYPATH(...)
65+
# endif
5766
#endif
5867

5968
OVERRIDE_METADATALOOKUP(getTypeByMangledName, const Metadata *,
@@ -127,6 +136,10 @@ OVERRIDE_PROTOCOLCONFORMANCE(conformsToProtocol, const WitnessTable *, , swift::
127136
const ProtocolDescriptor *protocol),
128137
(type, protocol))
129138

139+
OVERRIDE_KEYPATH(getKeyPath, const HeapObject *, , swift::,
140+
(const void *pattern, const void *arguments),
141+
(pattern, arguments))
142+
130143
#if SWIFT_OBJC_INTEROP
131144

132145
OVERRIDE_OBJC(dynamicCastObjCClass, const void *, , swift::,
@@ -169,3 +182,4 @@ OVERRIDE_FOREIGN(dynamicCastForeignClassUnconditional, const void *, , swift::,
169182
#undef OVERRIDE_OBJC
170183
#undef OVERRIDE_FOREIGN
171184
#undef OVERRIDE_PROTOCOLCONFORMANCE
185+
#undef OVERRIDE_KEYPATH

stdlib/public/runtime/Metadata.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#endif
4747
#include "llvm/ADT/DenseMap.h"
4848
#include "llvm/ADT/Hashing.h"
49+
#include "CompatibilityOverride.h"
4950
#include "ErrorObject.h"
5051
#include "ExistentialMetadataImpl.h"
5152
#include "swift/Runtime/Debug.h"
@@ -4239,3 +4240,14 @@ void swift::verifyMangledNameRoundtrip(const Metadata *metadata) {
42394240
const TypeContextDescriptor *swift::swift_getTypeContextDescriptor(const Metadata *type) {
42404241
return type->getTypeContextDescriptor();
42414242
}
4243+
4244+
// Emit compatibility override shims for keypath runtime functionality. The
4245+
// implementation of these functions is in the standard library in
4246+
// KeyPath.swift.
4247+
4248+
SWIFT_RUNTIME_STDLIB_SPI
4249+
const HeapObject *swift_getKeyPathImpl(const void *pattern,
4250+
const void *arguments);
4251+
4252+
#define OVERRIDE_KEYPATH COMPATIBILITY_OVERRIDE
4253+
#include "CompatibilityOverride.def"

0 commit comments

Comments
 (0)