leptos
leptos copied to clipboard
`AddAnyAttr` on `AnyView`: Large Compile Times, Overflows, & Crashes
Below is a concise timeline of attempts and discussions related to enabling AddAnyAttr
on AnyView
. These efforts have repeatedly run into problems like extremely large compile times, linker or LLVM errors (e.g. “cannot encode offset of relocations; object file too large”), and recursion issues. All references below are from the leptos-rs/leptos repository.
Timeline
-
Compile-Time Erasure Experiments
-
PR #2905
- Introduced
--cfg=erase_components
to speed up dev builds by erasing component types. Merged on 2024-10-08.
- Introduced
-
PR #2905
-
Discovery of
AddAnyAttr
Incompatibilities-
Issue #3156
- Reported that with
--cfg=erase_components
turned on,attr:
was ignored in some components. Also noted that no working implementation forAddAnyAttr
onAnyView
exists without causing crashes or linker errors.
- Reported that with
-
Issue #3156
-
Latest Attempts at
AnyView
+AddAnyAttr
- PR #3458
- PR #3460
-
PR #3461
- Attempted a direct fix for
AddAnyAttr
but triggered “object file too large” errors
- Attempted a direct fix for
In all these PRs, @zakstucke consistently reports the crash on larger codebases (macOS toolchain often yields cannot encode offset of relocations; object file too large
). Removing or neutering the AnyView
+ AddAnyAttr
relationship immediately fixes these crashes.
Potential Directions
-
Feature-Gating
Temporarily hide or no-opAddAnyAttr
forAnyView
behind a Cargo feature orcfg
until a stable fix is found. -
Alternative Implementations
Investigate deeper trait structures, or reduce recursion/boxing withinAnyView
. Some attempts hoisteddyn
trait objects for attribute application but still triggered compiler blow-ups. -
Compiler/LLVM Investigation
The final crash is an LLVM Mach-O back-end limitation (see MachObjectWriter.cpp:925-931 for the relevant lines). Possibly open an LLVM bug or check if we can reduce the code path that leads to “object file too large.”
If anyone has fresh ideas or wants to collaborate on a fix, please chime in here!
@zakstucke @gbj @geoffreygarrett @sabify