mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-23 13:23:47 +00:00
Estimated hours taken: 30
Implement builtin tuple types, similar to those in Haskell.
Tuples are constructed and deconstructed using
the syntax X = {Arg1, Arg2, ...}.
Tuples have type `{Arg1, Arg2, ...}'.
Unary tuples (X = {Arg}) do work, unlike in Haskell. The rationale
for this is that it is useful to be able to construct unary tuples
to be passed to a polymorphic predicate which uses std_util__deconstruct
to deal with a tuple of any arity. Since this is probably the only
use for unary tuples, it's not really worth the effort of treating
them as no_tag types, so we don't.
The type-infos for tuples have the same structure as for higher-order
types. There is a single type_ctor_info for tuples, and the arity
is placed before the argument type_infos.
library/parser.m:
Change the way '{}/N' terms are parsed, so that the parsed
representation is consistent with the way other functors
are represented (previously the arguments were left as
unparsed ','/2 terms). This avoids special case code
in prog_io__parse_qualified_term, term__term_to_type
and term__type_to_term.
compiler/prog_io_dcg.m:
compiler/prog_io_util.m:
Handle the new structure of '{}/N' terms when parsing DCG escapes
by converting the argument list back into a single ','/2 term.
compiler/module_qual.m:
Treat tuples as a builtin type.
compiler/typecheck.m:
Typecheck tuple constructors.
compiler/mode_util.m:
Propagate types into tuple bound insts.
compiler/type_util.m:
Add type_is_tuple/2 and type_id_is_tuple/1 to identify tuple types.
Add tuples to the list of types which are not atomic types.
Handle tuple types in `type_constructors' and
`get_cons_id_arg_types' and `switch_type_num_functors'.
compiler/tabling.m:
Handle tabling of tuples.
compiler/term_util.m:
Handle tuples in the code to compute functor norms.
compiler/magic_util.m:
compiler/rl.m:
compiler/rl_key.m:
Handle tuple types in the Aditi back end.
compiler/mercury_to_mercury.m:
library/io.m:
library/term_io.m:
Handle output of '{}/N' terms.
compiler/higher_order.m:
compiler/simplify.m:
Don't specialize complicated unifications of tuple
types into calls to a specific unification procedure --
even if the procedure were implemented, it probably
wouldn't be that much more efficient.
compiler/unify_proc.m:
Generate unification procedures for complicated unifications
of tuples (other than in-in unifications). These are generated
lazily as required.
compiler/make_hlds.m:
Export add_special_pred for use by unify_proc.m.
compiler/polymorphism.m:
Export polymorphism__process_pred for use by unify_proc.m.
compiler/bytecode_gen.m:
compiler/code_util.m:
compiler/ml_code_util.m:
Handle unify procedure names and tags for tuple types.
compiler/mlds_to_c.m:
Output tuple types as MR_Tuple.
compiler/ml_unify_gen.m:
Compute the field types for tuples.
compiler/polymorphism.m:
compiler/pseudo_type_info.m:
Treat tuple type_infos in a similar way to higher-order type_infos.
compiler/hlds_data.m:
Document how cons_ids for tuple types are represented.
compiler/switch_gen.m:
compiler/table_gen.m:
Add tuple types to switches on type_util__builtin_type.
compiler/llds_out.m:
util/mdemangle.c:
profiler/demangle.m:
Transform items named "{}" to "f_tuple" when mangling symbols.
library/builtin.m:
Define the type_ctor_info used for tuples.
library/private_builtin.m:
Add `builtin_unify_tuple/2' and `builtin_compare_tuple/3',
both of which abort. All comparisons and in-in unifications
of tuples are performed by the generic unification functions
in runtime/mercury_ho_call.c and runtime/mercury.c.
library/std_util.m:
Implement the various RTTI functions for tuples.
Encode tuple `TypeCtorDesc's in a similar way to that
used for higher-order types. This has the consequence that the limit
on the arity of higher-order types is now MAX_VIRTUAL_REG,
rather than 2*MAX_VIRTUAL_REG.
Avoid calling MR_GC_free for the type-info vector returned
from ML_expand() for tuples because unlike the vectors
for du types, it is not copied.
runtime/mercury_type_info.h:
Add macros for extracting fields from tuple type-infos.
These just call the macros for extracting fields from higher-order
type-infos.
Add a macro MR_type_ctor_rep_is_variable_arity(), which
returns TRUE for tuples and higher-order types.
The distinction between higher-order and first-order types
is now misnamed -- the distinction is really between fixed arity
types and builtin variable arity types. I'm not sure whether
it's worth renaming everything.
runtime/mercury.h:
runtime/mercury.c:
Define unification and comparison of tuples in
high-level code grades.
runtime/mercury_deep_copy_body.h:
runtime/mercury_make_type_info_body.h:
runtime/mercury_tabling.c:
runtime/mercury_unify_compare_body.h:
Handle tuple types in code which traverses data using RTTI.
tests/hard_coded/construct.{m,exp}:
tests/hard_coded/expand.{m,exp}:
Test RTTI functions from std_util.m applied to tuples.
tests/hard_coded/tuple_test.{m,exp}:
Test unification, comparison, term_to_type etc. applied to tuples.
tests/hard_coded/deep_copy.{m,exp}:
Test deep copy of tuples.
tests/hard_coded/typeclasses/tuple_instance.{m,exp}:
Test instance declarations for tuples.
tests/tabling/expand_tuple.{m,exp}:
Test tabling of tuples.
tests/hard_coded/write.m:
Add some module qualifications for code which uses
`{}/1' constructors which are not tuples.
tests/invalid/errors2.{m,err_exp,err_exp2}:
Test handling of tuples in type errors messages.
NEWS:
doc/reference_manual.texi:
w3/news/newsdb.inc:
Document tuples.
doc/transition_guide.texi:
Document the change to the parsing of '{}/N' terms.
88 lines
1.7 KiB
Mathematica
88 lines
1.7 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
|
|
:- module errors2.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred bind_type_param(TypeParam::input, TypeParam2::output).
|
|
|
|
bind_type_param(Argument) :-
|
|
Argument = 0.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% currently the compiler just gives a warning for this test case
|
|
|
|
:- pred unresolved_polymorphism.
|
|
|
|
unresolved_polymorphism :-
|
|
bind_type_param(Arg, Arg).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- pred produce_string(string).
|
|
|
|
:- pred expect_int(int).
|
|
|
|
:- pred type_error.
|
|
|
|
type_error :-
|
|
produce_string(X),
|
|
expect_int(X).
|
|
|
|
:- pred type_error_2.
|
|
type_error_2 :-
|
|
produce_string(X),
|
|
expect_int(Y),
|
|
X = Y.
|
|
|
|
:- pred type_error_3.
|
|
type_error_3 :-
|
|
X = Y,
|
|
produce_string(X),
|
|
expect_int(Y).
|
|
|
|
:- type foo_type ---> foo_functor(int, character, string).
|
|
:- type bar_1_type ---> bar_functor(int, character, string).
|
|
:- type bar_2_type ---> bar_functor(character, int, string).
|
|
|
|
:- pred type_error_4.
|
|
type_error_4 :-
|
|
Y = 0,
|
|
X = foo_functor(Y, 'x', 1.0).
|
|
|
|
:- pred type_error_5.
|
|
:- type foo ---> a ; b ; c.
|
|
|
|
type_error_5 :-
|
|
Y = 'a',
|
|
X = foo_functor(0, Y, 1.0).
|
|
|
|
:- pred type_error_6.
|
|
|
|
type_error_6 :-
|
|
Y = 'a',
|
|
X = bar_functor(0, Y, 1.0).
|
|
|
|
:- pred type_error_7.
|
|
|
|
type_error_7 :-
|
|
Y = 'a',
|
|
Z = bar_functor(A, B, C),
|
|
expect_int(C).
|
|
|
|
:- use_module list, string.
|
|
|
|
:- pred type_error_8.
|
|
type_error_8 :-
|
|
from_char_list([], Str),
|
|
string__from_char_list(list:[], Str).
|
|
|
|
:- pred type_error_9.
|
|
type_error_9 :-
|
|
X = {1, "2", '3'},
|
|
Y = {"1", '2', 3},
|
|
X = Y.
|
|
|
|
%-----------------------------------------------------------------------------%
|