Files
mercury/tests/valid/github_50.m
Zoltan Somogyi c4dce74bb4 Improve the treatment of promises.
compiler/check_promise.m:
    Fix github issue #50. If a promise is imported from another module,
    do not process it. Processing would require the pred_id/proc_id slots
    in plain_calls to have been filled in by typechecking, but we don't
    invoke the typechecker on imported code.

compiler/assertion.m:
    Improve the documentation of the predicates that test whether
    an assertion falls into a given category of assertion. Provide variants
    of those predicates that work on goals as well as on assert_ids, so later
    we can test whether assertions fall into any of those categories.

    Add an XXX for what I am pretty sure is a bug.

compiler/hlds_module.m:
compiler/make_hlds_passes.m:
compiler/prog_data.m:
compiler/typecheck.m:
    Improve some comments.

tests/valid/github_50.m:
tests/valid/github_50.submodule.m:
    The two-module test case from github, changed to reflect our coding
    standards.

tests/valid/Mmakefile:
    Test that compiling the new test case does not cause a compiler abort.
2018-10-01 06:54:00 +10:00

75 lines
2.2 KiB
Mathematica

%---------------------------------------------------------------------------%
% vim: ft=mercury ts=4 sw=4 et
%---------------------------------------------------------------------------%
%
% Any copyright is dedicated to the Public Domain.
% http://creativecommons.org/publicdomain/zero/1.0/
%
% Released by Transnat Games for testing purposes.
%
% Causes an assert in the Mercury compiler:
% Software Error: hlds.assertion:
% predicate `hlds.assertion.record_preds_used_in'/4:
% Unexpected: invalid pred_id ** Error making `Mercury\cs\test.test.c'.
%
% This appears to be triggered by a typeclass instance in a submodule
% and the promise. It is strange, however, that the promise is NOT about
% the predicate that is used in the typeclass.
%
%---------------------------------------------------------------------------%
:- module github_50.
:- interface.
:- include_module github_50.submodule.
:- type rectangle
---> rectangle(x :: float, y :: float, w :: float, h :: float).
:- typeclass intersect_typeclass(T) where [
pred intersects(T::in, T::in) is semidet
].
:- pred rectangle_intersection(rectangle::in, rectangle::in,
rectangle::out) is semidet.
:- pred rectangles_intersect(rectangle::in, rectangle::in) is semidet.
%---------------------------------------------------------------------------%
%---------------------------------------------------------------------------%
:- implementation.
:- import_module float.
:- promise all [Rectangle] (
rectangle_intersection(Rectangle, Rectangle, Rectangle)
).
%---------------------------------------------------------------------------%
rectangle_intersection(RectangleA, RectangleB, Rectangle) :-
RectangleA = rectangle(XA, YA, WA, HA),
RectangleB = rectangle(XB, YB, WB, HB),
X = max(XA, XB),
Y = max(YA, YB),
Xmax = min(XA + WA, XB + WB),
Ymax = min(YA + HA, YB + HB),
W = Xmax - X,
H = Ymax - Y,
% Logically required for an intersection to have occurred.
Xmax >= X,
Ymax >= Y,
Rectangle = rectangle(X, Y, W, H).
rectangles_intersect(R1, R2) :-
rectangle_intersection(R1, R2, _).
%---------------------------------------------------------------------------%