minirust / minirust

A precise specification for "Rust lite / MIR plus"
Apache License 2.0
793 stars 34 forks source link

Add more intrinsics #12

Open RalfJung opened 2 years ago

RalfJung commented 2 years ago

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.

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:

essickmango commented 5 months ago

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

for i in 0..n {}
bifbof commented 3 weeks ago
  • [x] offset and wrapping_offset

Is wrapping_offset already supported? I get an error if I try to minimize the following code:

int main() {
    let _ = (&42 as *const i32).wrapping_offset(1);
}

error message:

thread 'rustc' panicked at minimize/src/bb.rs:202:25:
unsupported Rust intrinsic `arith_offset`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
RalfJung commented 3 weeks ago

It is supported in MiniRust, but not in minimize.