On Wednesday, 17 December 2014 at 12:29:21 UTC, Ola Fosheim
Grøstad wrote:
On Wednesday, 17 December 2014 at 11:13:02 UTC, Marc Schütz
wrote:
On Wednesday, 17 December 2014 at 07:48:52 UTC, bearophile
wrote:
Walter Bright:
I'm afraid I don't understand at all what you wrote.
Perhaps reading about linear type systems could help:
http://en.wikipedia.org/w/index.php?title=Substructural_type_system&redirect=no#Linear_type_systems
But note that we want a "relaxed" linear type system. In
general, we are fine with multiple aliases, although there are
Pointer aliasing is an optimization killer, which is why C99
added the «restrict» keyword. I think in most cases the use of
stack allocated objects tend to be alias-free, so it is
important that this knowledge is retained so that the compiler
can make use of it.
http://en.wikipedia.org/wiki/Pointer_aliasing
I know, this is one of those applications. The one I was thinking
of is const-borrowing (useful to prevent iterator invalidation
and a bunch of other things).
I think that enforcing alias-freeness by default (the way a
strict linear type system requires) doesn't fit too well into the
existing language. Some way of signalling this to the compiler
will therefore be required. It might be as simple as C's
`restrict` keyword (but it needs to be enforced!), or better yet,
an `unrestrict` keyword. Parameters would be alias-free by
default unless explicitly specified otherwise. Local aliases
(inside one function) are however ok, as long as not more than
one is passed to another function at the same time.