Proposal: Relax rules for 'pure'
sclytrack
sclytrack at fake.com
Wed Sep 22 15:36:43 PDT 2010
> > So weakly-pure should not access global stuff. But that is harder
> > to track by the compiler with mutable parameters.
> Not really. You just need to disallow shared, __gshared in pure function
> declarations.
> > Or weakly-pure is only noglobal when called in pure routines, because of the
> > immutable barrier.
> > Unwritten contract, not checked by the compiler? (Like property getters shouldn't
> > modify the "state" of the object.)
> No. The contract is, that the function only has access to the parameters
> you have given it. It depends _only_ on its parameters.
> If you've made all parameters immutable or value types, it's strongly
> pure.
> These additional contracts come automatically from the type system.
pure doStuff( [immutable] int a, [unshared] MyClass a)
{
}
1) If shared it must be immutable.
2) If mutable it must be not shared.
More information about the Digitalmars-d
mailing list