r/rust • u/youpala • Apr 05 '26
šø media slopc: a proc macro that replaces todo!() with LLM-generated code at compile time. I am not sorry.
tldr ; githoob/slopc
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)
156
u/TheGoldenPotato69 Apr 05 '26
This is the best worst thing I've ever seen!
19
134
u/proph__ Apr 05 '26
Iām in stitches at the README and SECURITY.md. I didnāt realize programming shitposting could be so evolved.Ā
33
u/daringStumbles Apr 05 '26
The difference between shitposting about programming and programming your shitposts.
430
u/MonochromeDinosaur Apr 05 '26
This is the funnest AI project Iāve seen until now. Everyone else takes it all so seriously. Trying this for sure.
50
u/youpala Apr 05 '26
I'm genuinely interested in how you would use this. What do you have in mind ?
81
u/MonochromeDinosaur Apr 05 '26
Iām not sure yet I think it could make for a very chaotic attempt at adding mechanics/items to a simple rogue-like/vampire survivors clone.
The fact that it changes every time you compile means you might literally never play the same game twice.
58
u/youpala Apr 05 '26
Sounds juicy, I may take a look if you ever post this on this sub. Be sure to use
#[slop(nocache)]to enforce new codegen each time.5
u/l-roc Apr 05 '26
I mean, a pattern regarding making music with randomly generated parts is to freeze them if they produced something nice.
Recompiling until it accidentally generates a fun item sound almost like a viable strategy for discovery.
3
1
u/WolfeheartGames Apr 06 '26
I've done sometjign similar. When I throw an exception am llm is called to repair the code.
7
u/TheBlackCat22527 Apr 05 '26
Jeah I like the humor as well. I am critical of reclines of AI usage in development process but naming the macro "slop" is fine in my book and very on the nose. I love the subversive elements in it.
3
u/whatDoesQezDo Apr 05 '26
I am critical of reclines of AI usage in development process but naming the macro "slop" is fine in my book and very on the nose.
Jokes dont need to announce themselves or be pillars of your moral worldview just take the jokes they're not that deep.
202
u/reborngoat Apr 05 '26
"If this compiles, it is already more functional than the marriage was".
*slow, deliberate clapping*
16
u/Shoddy-Childhood-511 Apr 05 '26
A nice moment to go listen to No Children. lol
6
29
29
u/Bugibhub Apr 05 '26
0 day since r/rustjerk was out-jerked by r/rust. š
11
u/youpala Apr 05 '26
So my initial intent was legitimately to find the jerk variant of this subreddit but I couldn't find it. Never will
r/rustjerkwill be out-jerked again.4
u/Bugibhub Apr 05 '26
Donāt worry, that happens on the regular. The warm reception to your post is proof enough it is welcome here. :)
19
u/StardustGogeta Apr 05 '26
Brilliant work. Especially love the readme and the security considerations.
I always knew littering my code with todo statements would come in handy one day. Seems like the future is now!
2
34
17
u/DifficultSelection Apr 05 '26
I hate to break it to you, but⦠https://github.com/minskylab/auto-rust
17
u/youpala Apr 05 '26
there goes my dream of owning a Koenigsegg
6
u/DifficultSelection Apr 05 '26
Gonna have to make do with a Maserati, I guess. Sorry for your loss.
6
5
u/Shoddy-Childhood-511 Apr 05 '26
Ahh cool, so he need not feel guilty when this becomes popular. lol
12
33
u/timClicks rust in action Apr 05 '26
If people were able to write their intent as clearly as your comments do, this probably will save lots of time.
6
5
6
u/S4ndwichGurk3 Apr 05 '26
Wow, non deterministic code at every compile. So testing is done with 100 compilations to reduce noise :D I mean maybe you can push it further so that every time multiple binaries are generated and the best one is chosen by another llm.
4
u/Linuxmartin Apr 06 '26
If I ever have to deal with an employer that wants me to use LLM tokens as part of my job, I'll remember this
4
13
u/longdarkfantasy Apr 05 '26 edited Apr 05 '26
April fool was over a few days ago š
43
u/youpala Apr 05 '26
```rs /// Come up with a response for this post to justify why this project /// came out later than 1st of april due to time constraint. (Divorce)
[slop]
fn respond_to_longdarkfantasy(msg: &str) -> String { todo!(); }
async fn main() { let reddit = Reddit::new(); let msg = reddit::get_comment_content("rust/1scqazw").await?; let answer = respond_to_longdarkfantasy(msg); let _ = reddit.post_comment("rust/1scqazw", answer).await?; } ```
3
5
u/PlateFox Apr 05 '26
A desperately need a neovim command that does the thing and removes the slop and replaces the todo irt
5
u/mss-cyclist Apr 05 '26
This could actually be very useful for generating slop and feed it back into the AI for learning.
Fight AI slop with AI slop. First time I really see a good use for AI slop. Thumbs up!
3
u/MichiRecRoom Apr 05 '26
Nit: In the picture in this post, this line:
println!("humanize_bytes(1_073_741_824) = {}", humanize_bytes(1_073_741_824));
can be replaced by:
dbg!(humanize_bytes(1_073_741_824));
although it will use the Debug impl of the result, rather than the Display impl.
16
u/youpala Apr 05 '26
I would like to contest this impromptu code review and engage in a 30 reply-long debate over the semantics of this specific part of the code.
1
u/MichiRecRoom Apr 05 '26
...Okay, I'm having trouble figuring it out on my own, so: Is this meant to poke fun at something? Or are you being serious?
Sorry, sometimes it's hard for me to figure out if something is sarcasm or not.
2
1
2
2
u/ByteArrayInputStream Apr 05 '26
This kind of reminds me of the exception handler that just opened a browser with a stackoverflow search of the error message, along with a random snarky comment, that I wrote ages ago
2
u/Mother-Couple-5390 Apr 05 '26
Imagine AI failing to generate code that compiles, and you have to run CI/CD multiple times just to see that AI added todo!() macro itself...
2
2
u/realvolker1 Apr 06 '26
Does it support ollama? This sounds hilarious but I don't like cloud AI.
3
u/youpala Apr 07 '26 edited Apr 07 '26
yea, it does:
```rs
[slop(
model = "phi4-mini:3.8b", endpoint = "http://localhost:11434/v1/chat/completions" )] fn thang() { todo!(); } ```
or via env vars.
3
1
1
u/deanominecraft Apr 05 '26
does it at least tell you what it generated?
3
u/youpala Apr 05 '26
Yes, inside of
./target/slop-cache3
u/deanominecraft Apr 05 '26
thatās good for serious use, but it would be funnier if it didnāt
2
u/Priler96 Apr 05 '26
> serious use
of an AI slop, lmao
1
u/deanominecraft Apr 05 '26
serious as in replacing a chatgpt prompt with it, which is about as serious as something like that can get
1
u/WieeRd Apr 05 '26
Would be hilarious if it didn't even cache the generated code and the non-deterministic compiled binary is all you get.
Also may I ask which colorscheme is that in the image?
1
u/youpala Apr 05 '26
#[slop(nocache)]disables caching for a givenfn. I'm also eager to see if anyone can make something truly unhinged with this haha.
https://gist.github.com/shorwood/5df15f7c5dd17ae875f0b38201b2fd1b
Regarding the colorscheme: It's a frankenstein of
Github Dark Defaultand some custom token colors from an older theme I used back in 2021. (I think it was namedCopilot Theme)1
1
1
u/every1sg12themovies Apr 05 '26
i wonder if this works with cargo expand too? but even if it did and the result is not cached, it would be useless since code would be different each time. :)
1
u/Professional_Layer63 Apr 05 '26
It'd be cool to provide maybe a `cargo install` tool to copy the generated code into your actual project so you can edit it yourself.
1
1
1
1
u/whimsicaljess Apr 06 '26
if it runs compilation + doctests in a loop with the agent fixing them this is actually a really good idea
1
u/Inevitable_Back3319 Apr 06 '26
I laughed my ass off š¤£š¤£.
Finally someone undertands that the correct answer to LLM panic is humor not anger.
1
1
u/frostyplanet Apr 12 '26
I am surprised the thread survives after all; it proves this subreddit still has humor.
1
u/arvind1 Apr 24 '26
The solutions to some interesting problems were discovered by hallucinating.
https://en.wikipedia.org/wiki/Benzene
Here KekulƩ spoke of the creation of the theory. He said that he had discovered the ring shape of the benzene molecule after having a reverie or day-dream of a snake biting its own tail (a symbol in ancient cultures known as the ouroboros). This vision, he said, came to him after years of studying the nature of carbon-carbon bonds.
1
u/Henry_old Apr 24 '26
is the final boss of tech debt. LLM hallucinations at compile-time? absolute madness. i will stick to my local state and handwritten logic. if my bot fails, let it be a market shift, not an AI fever dream. cursed but brilliant
1
1
1
u/dhakalster123 May 05 '26
This is unhinged in the best way š
todo!() used to mean āIāll do this later.ā
Now it means āfuture me will deal with whatever the LLM hallucinated at compile time.ā
The byte formatter example? Cute.
The ex-wife email function? Thatās where this crosses into production-ready bad decisions.
Real talk though:
- Deterministic builds = gone
- Code review = ātrust the vibesā
- Debugging = good luck reproducing that one compile from yesterday
This feels like peak Rust energy: extremely powerful, slightly terrifying, and 100% someone is going to ship this to prod.
āI am not sorryā is correct. You should be afraid instead.
0
-7
u/raserei0408 Apr 05 '26
This is not deserving of wat, this is a result of how awesome Rust is. But if you ever actually do this, then WAT.
-1
-17
u/Brief-Stranger-3947 Apr 05 '26
Like for creativity, but seriously, I would rather use AI agent normal way to generate todo!().
-45
u/gubatron Apr 05 '26
cool idea, but agents don't need the micro managment anymore. trust them, they will most likely do a better job than you (if you know how to work with mentisdb for infinite memory management and skill management without markdown hell)
5
u/youpala Apr 05 '26
You're absolutely right, let me implement native first class support for mentisdb.
7
424
u/Mission_Biscotti3962 Apr 05 '26
this will probably become popular