Estimated hours taken: 100
Branches: main
Implement higher-order `any' insts. Pred or func expressions with an `any'
inst may bind non-local solver variables, but themselves must not be
called in a negated context. (The existing ground pred and func expressions
may not bind non-local solver variables, but may be called in a negated
context.)
Higher-order `any' insts are specified by using `any_pred' and `any_func'
in place of `pred' and `func', respectively.
We implement these insts by adding a new field to the any/1 constructor of
mer_inst, which is identical to the ground_inst_info field of the ground/2
constructor. Both are given the new type `ho_inst_info'. We then relax the
locking of non-local variables in these pred and func expressions, and extend
call/N and apply/N to also accept the new insts (provided the variables are
not locked).
We also store the groundness (ho_ground or ho_any) of each lambda expression
in a unification, in a new field in the rhs_lambda_goal constructor.
NEWS:
Mention the new feature.
compiler/prog_data.m:
Rename the ground_inst_info type ho_inst_info, and update its
documentation.
Add the ho_inst_info field to the any constructor in mer_inst.
compiler/hlds_goal.m:
Add the rhs_groundness field to rhs_lambda_goal in unify_rhs.
compiler/inst_match.m:
Propagate inst matching into the pred_inst_infos of any insts,
if they exist.
compiler/inst_util.m:
Propagate abstract unification and inst merging into the
pred_inst_infos of any insts, if they exist. May use of this
information when building ground, any, shared and mostly_unique
versions of insts.
compiler/modecheck_call.m:
Allow an `any' inst as the pred (func) argument to call/N (apply/N),
but check that the variable is not locked. If the variable is
locked, report a mode error which suggests using the ground inst.
(We could also suggest that the goal be made impure, but it is
best to point users towards the pure approach.)
compiler/modecheck_unify.m:
Relax the locking of non-locals when processing non-ground lambda
goals.
Update documentation.
compiler/mode_util.m:
Propagate type information into the pred_inst_infos of any insts.
compiler/mode_errors.m:
Change the purity error "lambda should be impure" to "lambda
should be any", since this is better advice. Also provide an
example of correct syntax if the verbose errors option is given.
compiler/prog_io_goal.m:
Parse the new kinds of expressions, returning the groundness along
with the existing information about lambda expressions.
compiler/superhomogeneous.m:
Use the above groundness when building the lambda unification.
compiler/prog_io_util.m:
Parse the new kind of insts, filling in the new ho_inst_info field
where appropriate.
compiler/polymorphism.m:
Handle the new fields. Assume that the shorthand form of lambda
expressions always defines a ground inst -- if users want non-ground
higher-order expressions they will need to use an explicit any_pred
or any_func expression.
compiler/equiv_type_hlds.m:
Replace equivalent types in the pred_inst_infos of `any' insts.
compiler/module_qual.m:
Module qualify the pred_inst_infos of `any' insts.
compiler/recompilation.usage.m:
compiler/unused_imports.m:
Look for items or imports used by insts in the pred_inst_infos of
`any' insts.
compiler/hlds_out.m:
compiler/mercury_to_mercury.m:
Output the new lambda expressions and insts in the correct format.
compiler/type_util.m:
Treat all pred and func types as solver types. (Effectively they
are, since all such types can now have non-ground values, with
call/N and apply/N acting as constraints.)
compiler/lambda.m:
Pass the groundness value when building procedures for lambda
expressions. This is not currently required for anything.
doc/reference_manual.texi:
Document the new feature, and update existing documentation on
solver types and negated contexts.
tests/valid/Mmakefile:
tests/valid/ho_any_inst.m:
New test case for some valid code using higher-order any insts.
tests/invalid/Mmakefile:
tests/invalid/ho_any_inst.err_exp:
tests/invalid/ho_any_inst.m:
New test case for some illegal code.
tests/invalid/anys_in_negated_contexts.err_exp:
Update expected error message for this test case. We now report
that the expression should be `any', rather than impure.
compiler/*.m:
Handle the new fields.