Skip to content

Commit 0a73af9

Browse files
authored
Merge pull request #17174 from jckarter/getFieldType-c-callable-4.2
[4.2] Add context pointer to swift_getFieldAt function.
2 parents 1c15a8f + 2357e26 commit 0a73af9

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

include/swift/Runtime/Metadata.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4386,8 +4386,13 @@ const Metadata *_swift_class_getSuperclass(const Metadata *theClass);
43864386

43874387
SWIFT_RUNTIME_STDLIB_INTERFACE
43884388
void swift_getFieldAt(
4389-
const Metadata *type, unsigned index,
4390-
std::function<void(llvm::StringRef name, FieldType type)> callback);
4389+
const Metadata *base, unsigned index,
4390+
void (*callback)(const char *name, const Metadata *type, void *ctx), void *callbackCtx);
4391+
4392+
void _swift_getFieldAt(
4393+
const Metadata *base, unsigned index,
4394+
std::function<void(llvm::StringRef name, FieldType fieldInfo)>
4395+
callback);
43914396

43924397
} // end namespace swift
43934398

stdlib/public/runtime/MetadataLookup.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,12 @@ swift_getTypeByMangledNameImpl(const char *typeNameStart, size_t typeNameLength,
10991099
}
11001100

11011101
void swift::swift_getFieldAt(
1102+
const Metadata *base, unsigned index,
1103+
void (*callback)(const char *name, const Metadata *type, void *ctx), void *callbackCtx) {
1104+
swift::_swift_getFieldAt(base, index, [&] (llvm::StringRef name, FieldType fieldInfo) { callback(name.data(), fieldInfo.getType(), callbackCtx); });
1105+
}
1106+
1107+
void swift::_swift_getFieldAt(
11021108
const Metadata *base, unsigned index,
11031109
std::function<void(llvm::StringRef name, FieldType fieldInfo)>
11041110
callback) {

stdlib/public/runtime/ReflectionMirror.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ AnyReturn subscript(intptr_t i, const char **outName,
278278

279279
Any result;
280280

281-
swift_getFieldAt(type, i, [&](llvm::StringRef name, FieldType fieldInfo) {
281+
_swift_getFieldAt(type, i, [&](llvm::StringRef name, FieldType fieldInfo) {
282282
assert(!fieldInfo.isIndirect() && "indirect struct fields not implemented");
283283

284284
*outName = name.data();
@@ -319,7 +319,7 @@ bool isReflectable() {
319319
bool indirect = false;
320320

321321
const char *caseName = nullptr;
322-
swift_getFieldAt(type, tag, [&](llvm::StringRef name, FieldType info) {
322+
_swift_getFieldAt(type, tag, [&](llvm::StringRef name, FieldType info) {
323323
caseName = name.data();
324324
payloadType = info.getType();
325325
indirect = info.isIndirect();
@@ -435,7 +435,7 @@ AnyReturn subscript(intptr_t i, const char **outName,
435435

436436
Any result;
437437

438-
swift_getFieldAt(type, i, [&](llvm::StringRef name, FieldType fieldInfo) {
438+
_swift_getFieldAt(type, i, [&](llvm::StringRef name, FieldType fieldInfo) {
439439
assert(!fieldInfo.isIndirect() && "class indirect properties not implemented");
440440

441441
auto *bytes = *reinterpret_cast<char * const *>(value);

0 commit comments

Comments
 (0)