Prior work on capabilities?

Has anyone tried an RFC on adding capabilities to Rust? BTW, not sure if I'm using the right PL term. By capabilities, I mean the ability to explicitly allow or deny certain "capabilities" such as allocating, panicking, etc. Basically something along the lines of:

fn foo() -> Vec<u32> without alloc {
  Vec::new()
}

fn foo() -> Vec<u32> without alloc {
  let v = Vec::new();
  v.push(0); // Compiler error because `push` is marked as `with alloc`
  v
}
3 Likes

I think the PL term for this is "effect". The difficulty there is threading this information through closures and generic code using them.

6 Likes

CC @tmandry

1 Like

Thanks! Searching for "Rust language effects" brings up a ton of results. Most of them seem to be focused on control flow rather than don't panic/allocate though which is a bit of a bummer.

Yup, I saw that but it's more focused on threading contexts through the call stack (aka DI). Then again, if allocating or panicking were only accessible via a context, I think that's the same as having an effect that allows or denies allocation/panics.

2 Likes