mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-22 21:03:53 +00:00
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.
70 lines
2.0 KiB
Mathematica
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).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|