mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-21 12:23:44 +00:00
The purpose of this diff is to allow Mercury programs to contain
impure Mercury code without the compiler changing its behavior
inappropriately, while still allowing the compiler to aggressively
optimize pure code. To do this, we require impure predicates to be so
declared, and calls to impure predicates to be flagged as such. We
also allow predicates implemented in terms of impure predicates to be
promised to be pure; lacking such a promise, any predicate that calls
an impure predicate is assumed to be impure.
At the moment, we don't allow impure functions (only predicates),
though some of the work necessary to support them has been done.
Note that to make the operators work properly, the precedence of the
`pred' and `func' operators has been changed from 1199 to 800.
Estimated hours taken: 150
compiler/purity.m:
New compiler pass for purity checking.
compiler/hlds_goal.m:
Add `impure' and `semipure' to the goal_feature enum.
compiler/hlds_out.m:
compiler/typecheck.m:
compiler/special_pred.m:
Fixed code that prints predicate name to write something more
helpful for special (compiler-generated) predicates. Added
code to print new markers. Added purity argument to
mercury_output_pred_type. New public predicate
special_pred_description/2 provides an english description for
each compiler-generated predicate.
compiler/hlds_pred.m:
Add `impure' and `semipure' to marker enum. Added new
public predicates to get predicate purity and whether or not
it's promised to be pure.
compiler/prog_data.m:
compiler/mercury_to_mercury.m:
compiler/prog_io.m:
compiler/prog_io_goal.m:
compiler/prog_io_pragma.m:
compiler/prog_io_dcg.m:
compiler/prog_util.m:
compiler/equiv_type.m:
compiler/intermod.m:
compiler/mercury_to_c.m:
compiler/module_qual.m:
Add purity argument to pred and func items. Add new `impure'
and `semipure' operators. Add promise_pure pragma. Add
purity/2 wrapper to goal_expr type.
compiler/make_hlds.m:
compiler/mercury_to_goedel.m:
Added purity argument to module_add_{pred,func},
clauses_info_add_pragma_c_code, and to pred and func items.
Handle promise_pure pragma. Handle purity/2 wrapper used to
handle user-written impurity annotations on goals.
compiler/mercury_compile.m:
Add purity checking pass between type and mode checking.
compiler/mode_errors.m:
Distinguish mode errors caused by impure goals preventing
goals being delayed.
compiler/modes.m:
Don't delay impure goals, and ensure before scheduling an
impure goal that no goals are delayed. Actually, we go ahead
and try to schedule goals even if impurity causes a problem,
and then if it still doesn't mode check, then we report an
ordinary mode error. Only if the clause would be mode correct
except for an impure goal do we report it as an impurity problem.
compiler/simplify.m:
Don't optimize away non-pure duplicate calls. We could do
better and still optimize duplicate semipure goals without an
intervening impure goal, but it's probably not worth the
trouble. Also don't eliminate impure goals on a failing branch.
compiler/notes/compiler_design.html:
Documented purity checking pass.
doc/reference_manual.texi:
Document purity system.
doc/transition_guide.texi:
library/nc_builtin.nl:
library/ops.m:
library/sp_builtin.nl:
New operators and new precdence for `pred' and `func'
operators.
tests/hard_coded/purity.m
tests/hard_coded/purity.exp
tests/hard_coded/Mmakefile:
tests/invalid/purity.m
tests/invalid/purity_nonsense.m
tests/invalid/purity.err_exp
tests/invalid/purity_nonsense.err_exp
tests/invalid/Mmakefile:
Test cases for purity.
47 lines
2.4 KiB
Plaintext
47 lines
2.4 KiB
Plaintext
purity.m:028: In predicate `purity:w1/0':
|
|
purity.m:028: warning: declared `impure' but actually pure.
|
|
purity.m:032: In predicate `purity:w2/0':
|
|
purity.m:032: warning: declared `semipure' but actually pure.
|
|
purity.m:036: In predicate `purity:w3/0':
|
|
purity.m:036: warning: declared `impure' but actually semipure.
|
|
purity.m:040: In predicate `purity:w4/0':
|
|
purity.m:040: warning: unnecessary `promise_pure' pragma.
|
|
purity.m:045: In predicate `purity:w5/0':
|
|
purity.m:045: warning: declared `impure' but promised pure.
|
|
purity.m:050: In predicate `purity:w6/0':
|
|
purity.m:050: warning: declared `semipure' but promised pure.
|
|
purity.m:059: In predicate `purity:e1/0':
|
|
purity.m:059: error: predicate is impure.
|
|
purity.m:059: It must be declared `impure' or promised pure.
|
|
purity.m:064: In predicate `purity:e2/0':
|
|
purity.m:064: error: predicate is semipure.
|
|
purity.m:064: It must be declared `semipure' or promised pure.
|
|
purity.m:068: In predicate `purity:e3/0':
|
|
purity.m:068: error: predicate is impure.
|
|
purity.m:068: It must be declared `impure' or promised pure.
|
|
purity.m:074: In call to impure predicate `purity:imp/0':
|
|
purity.m:074: error: call must be preceded by `impure' indicator.
|
|
purity.m:078: In call to semipure predicate `purity:semi/0':
|
|
purity.m:078: error: call must be preceded by `semipure' indicator.
|
|
purity.m:112: Error in closure: closure is impure.
|
|
purity.m:118: Error in closure: closure is semipure.
|
|
purity.m:093: In unification predicate for type (purity:e8):
|
|
purity.m:093: error: predicate is impure.
|
|
purity.m:093: It must be pure.
|
|
purity.m:101: In unification predicate for type (purity:e9):
|
|
purity.m:101: error: predicate is semipure.
|
|
purity.m:101: It must be pure.
|
|
purity.m:083: In clause for `e6':
|
|
purity.m:083: in argument 1 of call to predicate `purity:in/1':
|
|
purity.m:083: mode error: variable `X' has instantiatedness `free',
|
|
purity.m:083: expected instantiatedness was `ground'.
|
|
purity.m:083: The goal could not be reordered, because
|
|
purity.m:083: it was followed by an impure goal.
|
|
purity.m:084: This is the location of the impure goal.
|
|
purity.m:090: In clause for `e7':
|
|
purity.m:090: in argument 1 of call to predicate `purity:imp1/1':
|
|
purity.m:090: mode error: variable `X' has instantiatedness `free',
|
|
purity.m:090: expected instantiatedness was `ground'.
|
|
purity.m:090: The goal could not be reordered, because it was impure.
|
|
For more information, try recompiling with `-E'.
|