mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-12 12:26:29 +00:00
Estimated hours taken: 15 Implement handling of typeclasses for inter-module optimization. compiler/hlds_data.m: compiler/*.m: Add fields to type hlds_class_defn for use by intermod.m - the import_status of the `:- typeclass' declaration. - the original class interface from the `:- typeclass' declaration. compiler/intermod.m: Write all local typeclasses, instances, types, insts and modes to the `.opt' file, instead of trying to work out which are needed. The old code to do this missed some types, insts and modes (test case tests/valid/intermod_test.m). compiler/polymorphism.m: Expand class method bodies for imported predicates so that method lookups for those classes can be optimized. compiler/hlds_pred.m: compiler/check_typeclass.m: compiler/higher_order.m: compiler/hlds_out.m: Add a marker `class_instance_method', used to identify predicates introduced by check_typeclass.m to call the methods for each instance. Don't export `check_typeclass__introduced_pred_name_prefix/0' - higher_order.m now checks for a `class_instance_method' marker instead. compiler/dead_proc_elim.m: Analyse all instance declarations, not just those defined in the current module, so that declarations for imported instance methods are not removed before method lookups have been specialized. tests/valid/Mmakefile: tests/valid/intermod_test.m: tests/valid/intermod_test2.m: Check that nested types and modes are written to the `.opt' file. tests/valid/intermod_typeclass.m: tests/valid/intermod_typeclass2.m: Check that local typeclass and instance declarations are written to the `.opt' file.
37 lines
667 B
Mathematica
37 lines
667 B
Mathematica
% Test overloading resolution for cross-module optimization.
|
|
:- module intermod_test.
|
|
:- interface.
|
|
|
|
:- import_module int.
|
|
|
|
:- pred p(int::out) is semidet.
|
|
|
|
:- type t
|
|
---> f(int)
|
|
; g.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module intermod_test2.
|
|
|
|
:- pragma inline(p/1).
|
|
p(X) :-
|
|
Y = f(1),
|
|
Y = f(_),
|
|
Lambda = lambda([Z::int_mode] is det, Z = 2),
|
|
local(Lambda, X),
|
|
intermod_test2__baz(X).
|
|
|
|
:- mode int_mode :: out.
|
|
|
|
:- pred local(pred(int), int).
|
|
:- mode local(pred(int_mode) is det, out) is det.
|
|
|
|
local(Pred, Int) :- call(Pred, Int).
|
|
|
|
:- pred local_2(pred(int), int).
|
|
:- mode local_2(pred(int_mode) is det, out) is det.
|
|
|
|
local_2(Pred, plusone(Int)) :- call(Pred, Int).
|
|
|