DEV Community

Stanley Horwood
Stanley Horwood

Posted on

slopc: The cursed macro Rust maintainers never anticipated

tldr ; githoob/slopc

slopc-code-snippet

So. Recently, I watched "No Boilerplate"'s video on rust's macros and gave those a try after years of ignoring it: thinking it wouldn't help my productivity that much. nah uh ! felt like discovering your car has heated seat after 2 years on a lease. But then the intrusive thoughts came in: What if those heated seats were LLM driven, on fire, and the car is now driving itself into oncoming traffic ?

The voices in my head drove me to draft up some cursed proc-macro that would make my coworkers (me and my 2 cats) loose all the respect and faith they have for my technical skills.

#[slop] is an attempt to see how far I could push codegen and how flexible the rust compiler could be.. and it's limitations. This also made me realize that proc-macros could be a legitimate supply chain attack vector. But I'm not well versed on how one could mitigate this.


The boring stuff: #[slop] replaces todo!() with LLM-generated code at compile time using the comments, fn signature and project deps (with arguably a best-attempt at type discovery) as prompt context. Then feeds rustc errors back and retries until it compiles (or gives up). It also use some flaky caching strategy (inspectable at ./target/slop-cache) to avoid burning your LLM budget too fast. (should you care)

Top comments (0)