Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds the
mut
keyword, used in a fashion similar to rust (with some differences caused by the fact that we don't yet have explicit references in fe).For example:
This is an important language feature, and this pr is a "better than nothing" (I hope) implementation, which should ultimately be replaced or improved. There are some problems caused by the fact that all compound types are implicitly references, and this pr doesn't really attempt to solve them.
Consider:
Does
X::get_array
return a (non-mut) reference to themy_array
field? Or does it return a new array? The return type in the current fe syntax is ambiguous, so there's no way to tell from that. We could attempt to answer this question by doing some dataflow analysis on the body offoo
to figure out the actual return type and represent it as aType::Ref { inner: Type::Array { .. }}
or whatever, but this pr does no such thing. Instead, mutability is sort of tacked onto the side, in a way that mostly works, but can't possibly be perfect.The correct solution is probably to copy rust (of course), where the return type would be either
&Array<u8, 3>
orArray<u8, 3>
and would thus be unambiguous. Alternatively, if we want to keep the all-compound-types-are-implicit-references thing (like in python&co), we could use-> mut Array<u8, 3>
to signify that the returned array can be mutated by the recipient. If the body of foo wasreturn self.my_array
, it would be an obvious error. I prefer the ownership semantics of rust, where-> Array<u8, 3>
unambiguously means that the recipient is getting its own array that isn't shared with anyone else, but of course that brings with it a pile of complexity around references.Note that this pr also definitely doesn't do anything about aliasing. There can be multiple mutable references to the same thing. It shouldn't, however, be possible to create a mutable reference to a thing that's declared as immutable.
Because I was in there messing withI did! #703mut ctx
stuff, I changed howctx
works in a couple cases. I could split this out into a separate pr, but knowing me I probably won't.To-Do
OPTIONAL: Update Spec if applicable
Add entry to the release notes (may forgo for trivial changes)
Clean up commit history