Files
mercury/tests/valid/switch_detection_bug2.m
Simon Taylor 2727699e93 Fix a bug where cse_detection failed to hoist a common deconstruction for
Estimated hours taken: 5

Fix a bug where cse_detection failed to hoist a common deconstruction for
a one-armed switch out where switch_detection expected it to, due to a
call getting in the way. This resulted in switch_detection not finding
a switch necessary to prove determinism correctness.

compiler/switch_detection.m:
compiler/cse_detection.m:
	Make both modules use the same code to find deconstructions of
	non-local variables of disjunctions.

tests/valid/switch_detection_bug2.m:
	Test case, taken from samples/diff.
1998-09-10 06:18:48 +00:00

70 lines
2.0 KiB
Mathematica

%-----------------------------------------------------------------------------%
% Fix a bug where cse_detection wasn't hoisting the common deconstruction
% for a one-arm switch on argument 2 of display_diff_side_by_side_2.
% The symptom was a determinism error.
:- module switch_detection_bug2.
:- interface.
:- import_module io, int, list, string, std_util.
%-----------------------------------------------------------------------------%
:- type pos == int.
:- type segment == pair(pos,pos).
:- type edit --->
add(pos,segment)
; delete(segment,pos)
; change(segment,segment).
:- type diff == list(edit).
:- pred display_diff_side_by_side_2(int, side_by_side_info, diff,
io__state, io__state).
:- mode display_diff_side_by_side_2(in, in, in, di, uo) is det.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module require, std_util, int, list, char, string, bool.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
% Parameters to pass around.
:- type side_by_side_info
---> side_by_side_info(
int, % Half width
int, % Column 2 offset
bool, % Left column only
bool, % Suppress common lines
bool % Help sdiff
).
display_diff_side_by_side_2(_Prev, SBS, []) -->
{ SBS = side_by_side_info(_, _, _, Suppress, _) },
( { Suppress = no } ->
[]
;
[]
).
display_diff_side_by_side_2(Prev, SBS, [Edit | Diff]) -->
{ first_mentioned_positions(Edit, _, _) },
{ SBS = side_by_side_info(_, _, _, Suppress, _) },
( { Suppress = no } ->
[]
;
[]
),
display_diff_side_by_side_2(Prev, SBS, Diff).
:- pred first_mentioned_positions(edit :: in, pos :: out, pos :: out) is det.
:- external(first_mentioned_positions/3).
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%