Issue #2392 (closed) was a bug in the re-introduction of name sharing. It turns out that preventing an inlining of the generic to_ functions suffices to avoid the name clashes.
The MR also resolves a conceptual problem of uniqueness types (not just in SaC but also in Clean where this problem remains unresolved!).
The problem is that equational reasoning postulates that beta-reductions and eta-extensions can be done without changing the semantics of a program.
This implies that { a = f(); return [a,a]; }
and { return [f(), f()]; }
should both have the same semantics.
If a is of a unique type, this equality fails!
In SaC, the compiler ignores UNQ types after they have been checked and performs many optimisations that assume equational reasoning to hold (most prominently here CSE :-)
To re-enable full ER, we need to make the uniqueness explicit through a data-dependency (as we do for external states anyways).
This MR weaves the global object TheControlFlow
into all properly constructed constructors that use the generic functions to_<unq-type>
.
That way, two calls to a constructor f()
now become distinct as they operate on conceptually different states of TheControlFlow
.
This should ensure that all objects in SaC indeed cannot be shared and we should have proper uniqueness objects!