minirust icon indicating copy to clipboard operation
minirust copied to clipboard

Add more intrinsics

Open RalfJung opened this issue 2 years ago • 3 comments

Rust intrinsics are basically primitive operations of the language. So I think it makes most sense to add them as (unary or binary) operators to MiniRust, or possibly as statements of they don't return anything. The unary vs binary split is a bit annoying but maybe not too bad...

So, we should probably make a list of intrinsics that we should support. I'm just going to start writing down a few but this is surely not exhaustive yet.

  • [x] offset and wrapping_offset
  • [ ] offset_from

Other intrinsics can probably be implemented as regular MiniRust functions and don't need to be primitives -- we can define their semantics via lower-level MiniRust code:

  • [ ] unchecked_{add,sub,mul,div,shl,shr}, exact_div
  • [ ] copy, copy_nonoverlapping

RalfJung avatar Jul 11 '22 17:07 RalfJung

unchecked_add is also required for the minimizer to transpile range loops like

for i in 0..n {}

essickmango avatar Feb 15 '24 17:02 essickmango