invariant constancy: revisited
Jakob Ovrum
jakobovrum at gmail.com
Fri Mar 14 09:16:18 PDT 2014
Here we go again.
Back in 2012, invariants were misguidedly made const by default
without going through any review whatsoever, breaking a ton of
code in the process[1]. That means bitwise constancy is enforced
for the this-reference in the body of the invariant. There is no
way to opt out of this.
The well-intentioned argument is that invariants should not have
side effects, which I wholeheartedly agree with. The problem is
measuring side effects in terms of bitwise constancy and not
logical constancy. I was using logically constant invariants at
the time, but had to abandon them because of this change (again,
no way to opt out). Also, debug code inside invariants is also
hampered by bitwise const.
Pull requests were since made to revert the change, while
allowing invariants to be type-qualified explicitly to enforce
bitwise-constancy[1][2]. They eventually rot away, and now two
years later, invariants are still artificially limited by bitwise
const; as I had stopped using invariants, I never noticed.
I think we're running out of time to fix this, if we haven't
already. Specifically, the reversion was never commented on by
Walter, though Andrei did seem supportive. Please approve the
change. Hopefully this is the time to reclaim invariants ;)
[1]
https://github.com/D-Programming-Language/dmd/commit/3c138718365541cde67abbdcfc031d755c3a7969
[2] https://github.com/D-Programming-Language/dmd/pull/1073
[3] https://github.com/D-Programming-Language/dmd/pull/1560
More information about the Digitalmars-d
mailing list