News for hackers. Stuff that matters.
Re:Why Cargo Check Is So Slow by piinbinary on Saturday August 09, 2025 @10:53AM (#44846972)
I wonder why procmacros are slow. Can the compiler interpret them or does it have to go to all the work of compiling them before they can run?
Re:Why Cargo Check Is So Slow by Philpax on Saturday August 09, 2025 @10:56AM (#44847006)
It has to compile them; you can see the compiled binaries in your `target` directory. Rust doesn't have an interpreter for the full language, only for the `const` subset, so it can't interpret them.

There have been some proposals to compile the proc-macros to WASM and share those alongside the code in crates.io, but nothing substantial has come of it.

Re:Why Cargo Check Is So Slow by LegionMammal978 on Saturday August 09, 2025 @11:04AM (#44847077)
It does have an interpreter for the full language, that's what Miri uses [0]. In fact, Miri doesn't even have its own evaluator, it just adds additional features to the rustc const-evaluation. The big limitations are that it doesn't have much support for syscalls or other calls into non-Rust code, and it emulates all multithreaded code on a single thread.

[0] https://github.com/rust-lang/miri

Re:Why Cargo Check Is So Slow by Philpax on Saturday August 09, 2025 @02:30PM (#44848884)
Fair enough!
Re:Why Cargo Check Is So Slow by pjmlp on Saturday August 09, 2025 @11:15AM (#44847186)
That is an implementation detail, but yeah so far other areas have been given more priority.
Re:Why Cargo Check Is So Slow by LoganDark on Saturday August 09, 2025 @11:01AM (#44847047)
> Rust doesn't have an interpreter for the full language

Ever since a while ago, rustc uses Miri for const evaluation. So there are a lot of things it can do that it used to not be able to do. But, yes, const evaluation is limited to things that are part of the `const` subset.

Re:Why Cargo Check Is So Slow by LegionMammal978 on Saturday August 09, 2025 @11:07AM (#44847107)
As far as I'm aware, it's always been the other way around: Miri adds some features on top of rustc's const-evaluation code. The limitations of the latter are mainly self-imposed, due to the issues of exposing the different runtime models to programs. (E.g., you don't want to create allocations in const code that get deallocated at runtime.) Indeed, since 2019, the full functionality can be exposed with the unstable -Zunleash-the-miri-inside-of-you flag [0].

[0] https://github.com/rust-lang/rust/pull/56123

Re:Why Cargo Check Is So Slow by LoganDark on Saturday August 09, 2025 @03:50PM (#44849540)
I'm pretty sure we're in agreement? Miri is capable of a lot more but there are self-imposed limitations on what you're allowed to do in const.