Skip to content

[stdlib] Fix cc mismatch violation on swift_isClassType #39119

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
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
7 changes: 7 additions & 0 deletions stdlib/public/SwiftShims/RuntimeShims.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "SwiftStddef.h"
#include "SwiftStdint.h"
#include "SwiftStdbool.h"
#include "Visibility.h"

#ifdef __cplusplus
Expand Down Expand Up @@ -61,6 +62,12 @@ int _swift_stdlib_putc_stderr(int C);
SWIFT_RUNTIME_STDLIB_API
__swift_size_t _swift_stdlib_getHardwareConcurrency(void);

#ifdef __swift__
/// Called by ReflectionMirror in stdlib through C-calling-convention
SWIFT_RUNTIME_STDLIB_API
__swift_bool swift_isClassType(const void *type);
#endif

/// Manually allocated memory is at least 16-byte aligned in Swift.
///
/// When swift_slowAlloc is called with "default" alignment (alignMask ==
Expand Down
7 changes: 5 additions & 2 deletions stdlib/public/core/ReflectionMirror.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@

import SwiftShims

@_silgen_name("swift_isClassType")
internal func _isClassType(_: Any.Type) -> Bool
internal func _isClassType(_ type: Any.Type) -> Bool {
// a thick metatype is represented with a pointer metadata structure,
// so this unsafeBitCast is a safe operation here.
return swift_isClassType(unsafeBitCast(type, to: UnsafeRawPointer.self))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this. I guess I should look at the implementation. But this deserves a comment. You are passing the metatype structure as a pointer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to here, a thick metatype is represented with a metadata pointer.
https://github.com/apple/swift/blob/dd32711a5f5c5bd28a6401fc3ede1a0bf344b49e/lib/IRGen/GenType.cpp#L2464-L2466

So the unsafeBitCast is a safe operation. But I agree this is not clear to everyone, so it should be described in comments.

}

@_silgen_name("swift_getMetadataKind")
internal func _metadataKind(_: Any.Type) -> UInt
Expand Down