Large types cause linker failure
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
So I'm one of the maintainers of Leptos, and we're experimenting with a new static type system for our next release. The issue we're having is that for people porting existing websites/apps to the beta, experience a linker issue with link.exe, lld, mold, and ld. Our theory is that once the types reach a certain size, it will crash the linker.
In this version we're encoding the HTML tree into the type system by constructing View<> types that contain a tuple of it's descendants.
You can see what that looks like in the below code, which does not crash.
#Cargo.toml
[package]
name = "linker_issue"
version = "0.1.0"
edition = "2021"
[dependencies]
leptos = { git = "https://github.com/leptos-rs/leptos", features = ["ssr"] }
// main.rs
use leptos::html::{div, p, HtmlElement};
use leptos::prelude::*;
fn main() {
let view: HtmlElement<_, _, _, Dom> = div().child((
div().child((div(),)),
p().child((div(), div())),
div().child((div(), div(), div())),
p().child((div(), div(), div(), div())),
div().child((div(), div(), div(), div())),
p().child((div(), p(), div(), div())),
div().child((div(), div(), p(), div())),
p().child((div(), p(), div(), p())),
));
println!("type: {:?}", std::any::type_name_of_val(&view));
println!("\n\nsize: {:?}", std::mem::size_of_val(&view));
let html = view.to_html();
println!("\n\noutput: {html}");
}
So far we haven't nailed down a reasonable reproduction I can post, but I can reproduce the issue while trying to build one of our user's private projects. Running cargo leptos build, which runs cargo build --no-default-features --features=ssr, generates this error. I've put it in a gist because it is huge: https://gist.github.com/benwis/fe3a8010243c0f6b338f6aef0b0e7ad2
I'm not quite sure how to debug this, we'd love to use this system as it offers a number of benefits, but if it's going to break compilation at larger app sizes we'll have to defer. Any thoughts?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Cargo.toml and main.rs reproduction in the issue, then run cargo leptos build with the SSR features and compare the failure against the linked gist. Check whether the failure can be reduced to a reproducible type-size threshold across link.exe, lld, mold, and ld. Done means identifying the cause and a viable fix or clearly documenting the limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- build-system, compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100