mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-21 20:33:55 +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.
41 lines
803 B
Mathematica
41 lines
803 B
Mathematica
:- module intermod_test2.
|
|
|
|
:- interface.
|
|
|
|
:- import_module int.
|
|
:- pred baz(int::in) is semidet.
|
|
|
|
:- func plusone(int :: in) = (int :: out) is det.
|
|
|
|
:- implementation.
|
|
|
|
:- type t
|
|
---> f(int)
|
|
; g(int1).
|
|
|
|
% Check that local types used only in other type declarations are put
|
|
% in the `.opt' file.
|
|
:- type int1 ---> int1(int).
|
|
|
|
:- mode int_mode :: int_mode1.
|
|
:- mode int_mode1 :: in.
|
|
|
|
baz(X) :- T = f(1), bar(T, X).
|
|
|
|
:- pred bar(t::in, int::int_mode) is semidet.
|
|
|
|
bar(T, 2) :-
|
|
Pred = (pred(T1::in, Int::int_mode) is semidet :-
|
|
T1 = f(1),
|
|
Int = 2
|
|
),
|
|
Pred(T, 2).
|
|
|
|
% One version of the compiler incorrectly wrote this declaration to
|
|
% the .opt file as `:- pragma inline((intermod_test2:plusone)/2).'
|
|
% -- bromage 20 Nov 1997
|
|
:- pragma inline(plusone/1).
|
|
|
|
plusone(Int0) = Int :- Int is Int0 + 1.
|
|
|