Files
mercury/tests/term/Mercury.options
Julien Fischer ee5e325924 Workaround a hole in exception analysis that was causing it to incorrectly
Estimated hours taken: 3.5
Branches: main, release

Workaround a hole in exception analysis that was causing it to incorrectly
conclude that polymorphic procedures that might throw an exception would not.
The problem involved types like the following:

	:- type foo
		---> 	foo1
		;	foo2(bar).

	:- type bar ... where equality is bar_equals.

	where bar_equals is a predicate that may throw an exception.

The problem was that calls to builtin.unify (and by extension all procedures
the analysis considers conditional) with arguments of type foo were not being
treated as possibly throwing an exception.  This is because exception analysis
was considering only the head of the type and not what was contained in the
body.  In particular it missed the situation above where a type with
user-defined equality was embedded in a monomorphic type.

The workaround in this diff restricts exception analysis to declaring
polmorphic procedures not to throw an exception only if the properties of the
type can be determined by examining the head of the type.  In practice this
means restricting it to enumerations and to types exported by the standard
library.  In the case of the latter, the information is hardcoded into the
analyser.  (The above is in reference to so-called type-exceptions, exceptions
that result from a call to a user-defined equality or comparison predicate
that throws an exception - the behaviour of polymorphic procedures with
user-exceptions, exceptions (ultimately) caused by a call to throw/1, is
unchanged.)

The long term fix is to add an analysis that analyses type definitions for
features of interest to other optimizations, e.g. whether they contain other
types that have user-defined equality or whether they contain existentially
quantified constructors.  (Such an analysis will also eventually be required
for things like trail-usage optimization and the experimental optimization for
removing the overhead of minimal model tabling.)

compiler/exception_analysis.m:
	Fix the handling of polymorphism so that we don't erroneously
	conclude that procedures that may throw exceptions do not.

tests/term/Makefile:
tests/term/Mercury.options:
tests/term/exception_analysis_test2.m:
tests/term/exception_analysis_test2.trans_opt_exp:
	Add a test case for the above problem and also check that
	we handle enumerations with user-defined equality correctly.
2006-05-30 03:19:40 +00:00

65 lines
2.4 KiB
Plaintext

MCFLAGS-ack=--term-norm=simple
MCFLAGS-append=--term-norm=simple
MCFLAGS-arit_exp=--term-norm=simple
MCFLAGS-associative=--term-norm=simple
MCFLAGS-dds1_2=--term-norm=simple
MCFLAGS-dds3_13=--term-norm=simple
MCFLAGS-dds3_14=--term-norm=simple
MCFLAGS-dds3_15=--term-norm=simple
MCFLAGS-dds3_17=--term-norm=simple
MCFLAGS-dds3_8=--term-norm=simple
MCFLAGS-exception_analysis_test=--analyse-exceptions --no-warn-inferred-erroneous --no-warn-simple-code
MCFLAGS-exception_analysis_test2=--analyse-exceptions --no-warn-inferred-erroneous
MCFLAGS-existential_error1=--term-norm=num-data-elems
MCFLAGS-existential_error2=--term-norm=num-data-elems
MCFLAGS-existential_error3=--term-norm=num-data-elems
MCFLAGS-fold=--term-norm=simple
MCFLAGS-generic_call=--analyse-closures
MCFLAGS-inf_const_bug=--term-norm=total
MCFLAGS-my_list=--term-norm=simple
MCFLAGS-lte=--term-norm=simple
MCFLAGS-my_map=--term-norm=simple
MCFLAGS-member=--term-norm=simple
MCFLAGS-mergesort=--term-norm=simple
MCFLAGS-mergesort_ap=--term-norm=simple
MCFLAGS-mergesort_t=--term-norm=simple
MCFLAGS-mmatrix=--term-norm=simple
MCFLAGS-money=--term-norm=simple
MCFLAGS-naive_rev=--term-norm=simple
MCFLAGS-occur=--term-norm=simple
MCFLAGS-ordered=--term-norm=simple
MCFLAGS-overlap=--term-norm=simple
MCFLAGS-permutation=--term-norm=simple
MCFLAGS-pl1_1=--term-norm=simple
MCFLAGS-pl1_2=--term-norm=simple
MCFLAGS-pl2_3_1=--term-norm=simple
MCFLAGS-pl3_1_1=--term-norm=simple
MCFLAGS-pl3_5_6=--term-norm=simple
MCFLAGS-pl3_5_6a=--term-norm=simple
MCFLAGS-pl4_01=--term-norm=simple
MCFLAGS-pl4_4_3=--term-norm=simple
MCFLAGS-pl4_4_6a=--term-norm=simple
MCFLAGS-pl4_5_2=--term-norm=simple
MCFLAGS-pl4_5_3a=--term-norm=simple
MCFLAGS-pl5_2_2=--term-norm=simple
MCFLAGS-pl6_1_1=--term-norm=simple
MCFLAGS-pl7_2_9=--term-norm=simple
MCFLAGS-pl7_6_2a=--term-norm=simple
MCFLAGS-pl7_6_2b=--term-norm=simple
MCFLAGS-pl7_6_2c=--term-norm=simple
MCFLAGS-pl8_2_1=--term-norm=simple
MCFLAGS-pl8_2_1a=--term-norm=simple
MCFLAGS-pl8_3_1=--term-norm=simple
MCFLAGS-pl8_3_1a=--term-norm=simple
MCFLAGS-pl8_4_1=--term-norm=simple
MCFLAGS-pl8_4_2=--term-norm=simple
MCFLAGS-pragma_non_term=--term-norm=simple
MCFLAGS-pragma_term=--term-norm=simple
MCFLAGS-promise_will_not_throw=--analyse-exceptions
MCFLAGS-queens=--term-norm=simple
MCFLAGS-quicksort=--term-norm=simple
MCFLAGS-select=--term-norm=simple
MCFLAGS-subset=--term-norm=simple
MCFLAGS-sum=--term-norm=simple
MCFLAGS-vangelder=--term-norm=simple