I’m hugely in favour of parameterized mutability.
Some pros:
- Reduced amount of physical code to maintain, less duplication of logic
- Smaller number of methods in APIs, less combinatoric explosions
- Reduced binary size (in contrast to generics in general, mutability is simply a compile time notion)
- More natural chaining of mut/immut method calls; this is harder to do with just macros
Some cons:
- more syntax and/or sigils; general increased language complexity
- potential increase in compile time from need to determine if a valid combination of mutabilities exists
Some other syntaxes to consider:
fn get <'a, "m> (foo: &'a"m Foo) -> &'a"m Bar;
Concise, matches lifetimes, sigil heavy, possibly precludes generic mutability of values, mutability is named so that it cascades in a predictable manner.
fn get <'a> (foo: &'a mut? Foo) -> &'a mut? Bar;
More verbose, matches mut’s use everywhere else, a bit sigily, permits generic mutability everywhere, mutability of one ref/value holds independent of others, potentially tricky.
Regardless of the precise syntax and implementation, I think the compiler should always try to infer immutable first, and then mutable if not possible. If neither is possible it should of course be a compilation error. Unnecessary generic mutability should also probably be a warning, if possible.