3 Nov 2012 10:05
more sharing in generated code
Peter Divianszky <divipp <at> gmail.com>
2012-11-03 09:05:54 GMT
2012-11-03 09:05:54 GMT
Hi,
I have a question about sharing at the Haskell run-time level.
Suppose we have a record update
r { x = f (r x)}
and suppose that most of the time f returns it's argument unchanged.
I have the following questions:
1. Does the generated code for the record update build an identical
record when f returns it's argument unchanged instead of sharing the old
one? (I guess yes.)
2. Can we prevent building identical records?
Recently I've heard about Q-combinators.
Central idea: Change (f :: a -> a) to (f' :: a -> Maybe a) returning
Nothing when the value didn't change.
Then we can replace the record update with smarter code which
preserves more sharing.
My question is: Can (or could) we enable more sharing without
changing the source code?
Ideally the compiler would generate record update code which
checks poiter-equality of the updated field value to decide
whether a copy of the original record is needed or it can be shared
(given an optimisation flag enabled).
(Continue reading)
RSS Feed