Skip to content

Conversation

egorzhdan
Copy link
Contributor

This removes erroneous references to _OBJC_CLASS_$__xyz symbols that Swift was emitting for certain usages of C/C++ foreign reference types. This was discovered when trying to iterate over a Swift array of foreign reference types using a Swift for-in loop.

Builtin.canBeClass was returning true for foreign reference types, which led to the optimizer specializing the generic canBeClass<T> function to unconditionally return true for foreign reference types. This meant that _isClassOrObjCExistential for a foreign reference type evaluated to true, which made the Swift stdlib take the code path that was intended for Objective-C classes in ArrayBuffer.getElement, which assumed that the Element type conforms to AnyObject. Foreign reference types do not actually conform to AnyObject.

rdar://161814644

…C++ foreign reference types

This removes erroneous references to `_OBJC_CLASS_$__xyz` symbols that Swift was emitting for certain usages of C/C++ foreign reference types. This was discovered when trying to iterate over a Swift array of foreign reference types using a Swift for-in loop.

`Builtin.canBeClass` was returning true for foreign reference types, which led to the optimizer specializing the generic `canBeClass<T>` function to unconditionally return true for foreign reference types. This meant that `_isClassOrObjCExistential` for a foreign reference type evaluated to true, which made the Swift stdlib take the code path that was intended for Objective-C classes in `ArrayBuffer.getElement`, which assumed that the `Element` type conforms to `AnyObject`. Foreign reference types do not actually conform to `AnyObject`.

rdar://161814644
@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Oct 3, 2025
@egorzhdan egorzhdan requested a review from eeckstein October 3, 2025 14:03
@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan
Copy link
Contributor Author

@swift-ci please test macOS

@egorzhdan
Copy link
Contributor Author

@swift-ci please test Linux

@egorzhdan
Copy link
Contributor Author

@swift-ci please test macOS

1 similar comment
@azharudd
Copy link
Contributor

azharudd commented Oct 4, 2025

@swift-ci please test macOS

@egorzhdan egorzhdan merged commit c6a9226 into swiftlang:main Oct 6, 2025
5 checks passed
@egorzhdan egorzhdan deleted the egorzhdan/frt-objc-class branch October 6, 2025 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants