mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-17 06:47:17 +00:00
Add impure functions to Mercury, clean up the purity module somewhat,
Estimated hours taken: 30 Add impure functions to Mercury, clean up the purity module somewhat, fix some bugs in purity, update and expand the purity documentation, and re-organize the purity checks. Impure functions can be declared just like impure preds. However, they can only be called in an explicit unification preceeded by a purity level: impure X = some_impure_func(Y, Z) The bug fixed was the fact that closures of impure predicates were only being detected when using lambda syntax. Purity information was discarded and impure closures could be created like this: Pred = some_impure_pred You could then use this predicate anywhere you like without any purity declarations. compiler/hlds_module.m: Add get_pred_id pred which will return the pred_id of a predicate matching a given type. This is like get_pred_and_proc_id, but only gets the information we are interested in, and is semidet. We need a semidet version to handle cases where type inference cannot infer a type before the limit is reached, but we try to purity check this code. (The bug mentioned above was stopping us from purity checking the test case for this before). compiler/make_hlds.m: Check for "impure" unifications with expressions that are not function calls and issue appropriate error messages. When unravelling impure function call unifications, put the input parameter unifications (if any) before the actual call. Only mark the goal_info for the function call as impure. compiler/mercury_to_goedel.m: compiler/mercury_to_mercury.m: compiler/module_qual.m: compiler/prog_data.m: compiler/prog_io.m: compiler/prog_io_dcg.m: compiler/prog_io_goal.m: compiler/prog_util.m: Add purity information to unify goals. Don't assume unify goals are pure. compiler/purity.m: Allow impure functions. Check unification goals for purity (not just lambda unification). Check unifications that are transformed into calls to make sure the call is purity correct. Put purity checking logic into separate predicates. Use an enum to return different errors and warnings. (The last two changes make it much easier to see the similarities between checking goals and checking predicates for purity correctness). Give different error messages for impure functions (highlight that you need to use them in an explicit unification). Handle unknown predicate lookups (can occur when unifying with a higher order term whose type could not be inferred). Add a few comments delineating where changes might need to be made to make foreign code impure by default in future. compiler/notes/authors.html: Add Peter Schachte to the authors list. doc/reference_manual.texi: Document impure functions. Expand more on what impure predicates/functions can do. Explain the concept of worst purity, and use it to explain the "inferred purity"/"declared purity" concepts. Make it more explicit that only impure goals obey strict-sequential like semantics. tests/invalid/type_inf_loop.err_exp2: Fix this test case to reflect the new error message new that we check the purity of this code correctly (or rather, we correctly fail to be able to purity check this code). tests/hard_coded/Mmakefile: tests/hard_coded/purity.exp: tests/hard_coded/purity.m: tests/hard_coded/purity/Mmakefile: tests/hard_coded/purity/impure_func_t1.m: tests/hard_coded/purity/purity.m: tests/hard_coded/purity/runtests: Remove purity tests from the hard_coded directory, give it a sub-directory of its own. tests/invalid/Mmakefile: tests/invalid/purity.err_exp: tests/invalid/purity.m: tests/invalid/purity_nonsense.err_exp: tests/invalid/purity_nonsense.m: tests/invalid/purity/Mmakefile: tests/invalid/purity/impure_func_t2.err_exp: tests/invalid/purity/impure_func_t2.m: tests/invalid/purity/impure_func_t3.err_exp: tests/invalid/purity/impure_func_t3.m: tests/invalid/purity/impure_func_t4.err_exp: tests/invalid/purity/impure_func_t4.m: tests/invalid/purity/impure_func_t5.err_exp: tests/invalid/purity/impure_func_t5.m: tests/invalid/purity/impure_pred_t1.err_exp: tests/invalid/purity/impure_pred_t1.m: tests/invalid/purity/impure_pred_t2.err_exp: tests/invalid/purity/impure_pred_t2.m: tests/invalid/purity/purity.err_exp: tests/invalid/purity/purity.m: tests/invalid/purity/purity_nonsense.err_exp: tests/invalid/purity/purity_nonsense.m: tests/invalid/purity/runtests: Remove purity tests from the invalid directory, give it a sub-directory of its own.
This commit is contained in:
@@ -287,8 +287,8 @@ prog_util__rename_in_goal_expr(call(SymName, Terms0, Purity), OldVar, NewVar,
|
||||
call(SymName, Terms, Purity)) :-
|
||||
term__substitute_list(Terms0, OldVar, term__variable(NewVar),
|
||||
Terms).
|
||||
prog_util__rename_in_goal_expr(unify(TermA0, TermB0), OldVar, NewVar,
|
||||
unify(TermA, TermB)) :-
|
||||
prog_util__rename_in_goal_expr(unify(TermA0, TermB0, Purity), OldVar, NewVar,
|
||||
unify(TermA, TermB, Purity)) :-
|
||||
term__substitute(TermA0, OldVar, term__variable(NewVar),
|
||||
TermA),
|
||||
term__substitute(TermB0, OldVar, term__variable(NewVar),
|
||||
|
||||
Reference in New Issue
Block a user