leptos icon indicating copy to clipboard operation
leptos copied to clipboard

`AddAnyAttr` on `AnyView`: Large Compile Times, Overflows, & Crashes

Open geoffreygarrett opened this issue 1 month ago • 9 comments

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

  1. Compile-Time Erasure Experiments

    • PR #2905
      • Introduced --cfg=erase_components to speed up dev builds by erasing component types. Merged on 2024-10-08.
  2. 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 for AddAnyAttr on AnyView exists without causing crashes or linker errors.
  3. Latest Attempts at AnyView + AddAnyAttr

    • PR #3458
    • PR #3460
    • PR #3461
      • Attempted a direct fix for AddAnyAttr but triggered “object file too large” errors

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-op AddAnyAttr for AnyView behind a Cargo feature or cfg until a stable fix is found.

  • Alternative Implementations
    Investigate deeper trait structures, or reduce recursion/boxing within AnyView. Some attempts hoisted dyn 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

geoffreygarrett avatar Jan 10 '25 19:01 geoffreygarrett