Files
mercury/tests/general/ho_spec_branch_bug.exp
Ian MacLarty 6538244691 Fix a bug in higher order specialization where it incorrectly specialized a
Branches: main

Fix a bug in higher order specialization where it incorrectly specialized a
call to a variable after a branch if the variable was constructed in the branch
and its value was known in one branch arm, but not the others.

higher_order.m uses a map to track the possible values of higher order
variables.  The map maps variables to either a constant value, or a
'multiple_values' functor to indicate that the variable can contain multiple
values (and is therefore not specializable).  The problem was there was
some confusion about what it meant if a variable did not appear in this map.

merge_post_branch_infos was expecting the post_branch_info maps it was merging
to contain all the higher order variables in the arms, when in fact it only
contained variables that the goal traversal routines had deemed specializable.
Any entries it found in one post_branch_info but not the other, would be
copied to the resulting post_branch_info.  This was incorrect, because if a
variable did not occur in one post_branch_info its value might simply be
unknown in that arm (in which case is should not be specializable after
the branch).

The fix is to remove the multiple_values functor altogether.  A variable now
only appears in the post_branch_info if its value is known and unique.
merge_post_branch_infos has been changed so that it drops variables that
don't appear in both post_branch_infos.

There is one exception to the above where one switch arm is reachable and the
others are unreachable.  In this case we can copy any variables with unique
known values in the reachable arm's post_branch_info to the merged
post_branch_info.  The reachablility of each arm is therefore now also included
in the post_branch_infos.

compiler/higher_order.m:
    As above.

    Also remove some comments about the complexity of the
    merge_post_branch_infos algorithm, as the current algorithm is the obvious
    one given the new meaning of the post_branch_info maps.

tests/general/Mercury.options:
tests/general/Mmakefile:
tests/general/ho_spec_branch_bug.exp:
tests/general/ho_spec_branch_bug.m:
    Add a regression test.
2011-10-19 04:55:18 +00:00

2 lines
4 B
Plaintext