CxxInterop: Swift does not synthesize CxxConvertibleToContainer iterator operator== in some cases #77607
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
triage needed
This issue needs more specific labels
Description
In Ladybird, all iterators for our AK containers inherit from AK::SimpleIterator: https://github.com/LadybirdBrowser/ladybird/blob/3b04c983f14a3838870f202fe38fe081cb0771b4/AK/Iterator.h#L16
When I tried to use
myVec.forEach { elem in ... }
in my new code, I ran into two issues:In code that was importing both AK and another module that uses AK, the compiler informed me that the forEach method on my container did not exist.
In code that only imports AK (a test file), the compiler confirmed that the exact type used in the other module is indeed a CxxConvertibleToContainer type, but failed with a bogus linker error.
This issue contains a repro for the second issue, since I suspect they are linked.
Reproduction
Apply this patch:
Result:
Expected behavior
The test should compile, link, and run without issue.
Environment
$ swiftc -version
Swift version 6.1-dev (LLVM 9d655fdc6103926, Swift 0d16cbf)
Target: x86_64-unknown-linux-gnu
Distro: Ubuntu 24.04
uname -a: Linux Andrew-Workstation 6.8.0-48-generic #48-Ubuntu SMP PREEMPT_DYNAMIC Fri Sep 27 14:04:52 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Additional information
operator== on the iterator type is defined as
Removing constexpr has no effect.
Adding a translation unit to force generation of the operator== (see details pane below) adds the operator== as LOCAL HIDDEN symbols. Clang seems to expect each TU to generate these symbols if it needs them.
Patch to liblagom-ak.so to contain the missing symbols
The symbols appear like so, with that patch applied:
The text was updated successfully, but these errors were encountered: