[m-dev.] a conditional field update operator
Zoltan Somogyi
zoltan.somogyi at runbox.com
Wed Mar 8 14:41:19 AEDT 2017
One of the changes I made to simplify_info operations was to
replace code like this:
simplify_info_set_varset(X, !Info) :-
!Info ^ simp_varset := X.
with code like this:
simplify_info_set_varset(X, !Info) :-
( if private_builtin.pointer_equal(X, !.Info ^ simp_varset) then
true
else
!Info ^ simp_varset := X
).
The two are semantically equivalent, but different in performance.
The first never pays the cost of a test, but always pays the cost of
allocating a new structure, while for the second, things are the other
way around. This means that performance-wise, which one you want
depends on the probability of the new value of the field being different
from its old value, and on the size of the structure as a whole.
In many cases, the second approach is appropriate, but at the moment,
it takes five lines of code instead of one. I was thinking that we could
have a new operator, maybe ::= or :?=, that would be like :=, but
would create a new structure only if the new value of the field was
different from the old value. Then the compiler would expand the one line
to the five lines version internally.
Do people think such an extension to field syntax would be useful
more generally than just in the Mercury compiler? If so, what should
the syntax be?
Zoltan.
More information about the developers
mailing list