Replies: 2 comments
-
Note, in Arraymancer I use a trick with distinct type to enforce immutability even through pointers:
type
RawImmutableView*[T] = distinct ptr UncheckedArray[T]
RawMutableView*[T] = distinct ptr UncheckedArray[T] template `[]`*[T](v: RawImmutableView[T], idx: int): T =
bind distinctBase
distinctBase(type v)(v)[idx]
template `[]`*[T](v: RawMutableView[T], idx: int): var T =
bind distinctBase
distinctBase(type v)(v)[idx]
template `[]=`*[T](v: RawMutableView[T], idx: int, val: T) =
bind distinctBase
distinctBase(type v)(v)[idx] = val Though this is likely not applicable here because you need to know all the operations you need to generate the overload for, but maybe a converter .... or no, forget it. |
Beta Was this translation helpful? Give feedback.
0 replies
-
We do track
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently, after CPS transformation immutable parameters become mutable and the compiler will not help detect that:
Example
is rewritten and one of the proc becomes
or
To keep the mutability semantics, we can introduce a wrapper proc that just does unpacking instead, and the inner keep the var/non-var
And for efficiency, one of them, at least, should be tagged inline.
Beta Was this translation helpful? Give feedback.
All reactions