Files
mercury/tests/valid/sharing_exist.m
Peter Wang 2c16009dd7 Fix two compiler aborts in the structure sharing analysis.
Branches: main

Fix two compiler aborts in the structure sharing analysis.

compiler/ctgc.selector.m:
	Fix a problem with widening structure sharing pairs in the presence of
	existential types.  We'd try to reduce a term selector to a type
	selector of the type of the node selected by the term selector, but if
	that node would be existentially typed then the compiler would abort.
	To avoid that, we resort to reducing the selector to a type selector of
	the parent node's type instead.

	Make `type_of_node' and `select_subtype' into semidet predicates which
	fail if the selector would select an existentially typed node, rather
	than aborting.  Add det versions of the original functions.

	Make `select_subtype' able to succeed on existentially typed functors
	if the selector doesn't actually select an existentally typed
	argument.

compiler/structure_sharing.domain.m:
	Don't add a new sharing pair to a sharing set if the left and right
	hand sides of the sharing pair are the same after normalisation.  This
	avoids a different abort if such a pair needs to be removed: it tries
	to remove both (LHS - RHS) and (RHS - LHS) but since the two sides are
	equal, only one copy of the pair would exist in the sharing set to be
	removed.

tests/valid/Mercury.options:
tests/valid/Mmakefile:
tests/valid/sharing_exist.m:
	Add test case.
2008-03-17 01:56:11 +00:00

25 lines
577 B
Mathematica

% Regression test. Structure sharing widening caused compiler aborts in the
% presence of existential types.
%
% Uncaught Mercury exception:
% Software Error: ctgc.selector.m: Unexpected: get_type_of_node: existential
% type.
:- module sharing_exist.
:- interface.
:- type quux
---> some [T] quux(T, string).
:- pred replace(quux::in, T::in, quux::out) is det.
%-----------------------------------------------------------------------------%
:- implementation.
replace(Q0, X, Q) :-
Q0 = quux(_, Y),
Q = 'new quux'(X, Y).
% vi:ft=mercury:ts=8:sts=4:sw=4:et