Could we have Odin-style Assembly checking in Rust?

87 points tialaramex 27 comments

The programming language Odin recently got what its creator calls "Assembly templates". Bill is very proud of this feature and although it currently only works for x86-64 I was impressed by the diagnostics this can do.

For example if you cpuid it knows that EAX and ECX should have values (but you needn't worry about EBX and EDX), if you forgot to pick a value you get a compiler diagnostic, much as you'd get a diagnostic in pure Rust if you just forget to initialize a variable you use.

Rust is rightly famous for excellent diagnostics when you make inevitable mistakes writing the Rust language. Whether that's a stray semi-colon turning your intended function value into () a typo in the name of an identifier, missing the ! from a macro invocation or myriad other mistakes, Rust will help you. But if you write any of the three forms of assembler in Rust the diagnostics are pretty poor, presumably because they're from a separate assembler and Rust just polished them up and presented them to you.

So two questions: 1. Could we provide similar functionality (to Odin's new "templates") in Rust or is there some reason I'm missing for why we just can't / shouldn't try to do so? 2. Can somebody else plausibly do this, e.g. via a proc macro, or does it require such intimate connection to the compiler innards that it's only really viable if the compiler team themselves designed any new asm macro replacement ?