Files
mercury/tests/hard_coded/require_scopes.exp
Zoltan Somogyi 3080515d3a Add require_switch_arms_{det,semidet,...} to the language.
The new construct looks like this:

    require_switch_arms_det [C] (
        (
            C = 'a',
            ... compute Out ...
        ;
            C = 'b',
            ... compute Out ...
        )
    )

If any of the goals computing Out are not det, the compiler will generate
an error message. The det at the end of the keyword can be replaced
by any of the other seven determinisms, though I don't think either
require_switch_arms_failure or require_switch_arms_erroneous will see much use.

This diff adds only the implementation. I will add the documentation
and the NEWS item after we all had a chance to install this diff and
try it out.

compiler/hlds_goal.m:
    Add a scope representing this kind of goal in the HLDS.

compiler/prog_item.m:
    Add a goal expression for this kind of goal in the parse tree.

compiler/prog_io_goal.m:
    Look for the new kind of goal expression in terms when creating
    the parse tree.

    Factor out some commonalities between the parsing of the new goal
    expression and existing types of goal expressions.

compiler/goal_expr_to_goal.m:
    Convert the new kind of goal expression to the new scope in the HLDS.

compiler/det_report.m:
    Implement the checks that the new goal type calls for.

    Factor out some commonalities between the implementation of the new goal
    type and existing goal types.

    Move the types and predicates dealing with comparisons of determinisms
    from here to prog_data.m, due to the sort-of-bugfix to modecheck_call.m.

compiler/prog_data.m:
    Move the types and predicates dealing with comparisons of determinisms
    from det_report.m to here. The old code for this was intended for only one
    requirement, and did not deal well with comparisons of two determinisms
    in which each determinism makes an assertion the other does not make.
    Create a way to represent such comparison results.

compiler/modecheck_call.m:
    When deciding which mode of a procedure to call, we prefer determinisms
    that make more assertions about solution counts. However, when comparing
    incomparable determinisms (such as semidet vs multi, each of which makes
    an assertion the other doesn't), the algorithm chose based solely
    on the ORDER of the modes. We now explicitly prefer modes that promise
    lower maximum solution counts, giving less importance to cannot_fail
    assertions.

compiler/*.m:
    Conform to the change to hlds_goal.m or prog_item.m.

library/ops.m:
    Add the new keywords as operators.

tests/hard_coded/require_scopes.{m,exp}:
    Extend this test case to test the new construct in the absence of errors.

tests/invalid/require_scopes.{m,exp}:
    Extend this test case to test the new construct in the presence of errors.
2014-11-14 12:46:46 +11:00

12 lines
407 B
Plaintext

test_detism_scope(1) = 1
test_detism_scope(11) = 1
test_detism_scope(21) = 21
test_switch_scope(f1) = []
test_switch_scope(f2) = [1, 2]
test_switch_scope(f3(10)) = [3, 10, 11]
test_switch_scope(f3(20)) = [3, 20, 21]
test_switch_arms_detism_scope(f1) = [101, 1101]
test_switch_arms_detism_scope(f1) = [101, 1101]
test_switch_arms_detism_scope(f3(10)) = [110, 1110]
test_switch_arms_detism_scope(f3(20)) = []