mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-14 05:12:33 +00:00
77a1261d3bd0900b09d06f6d2061da9f72bf22f9
100 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
40bda1e4a0 |
Fix a bug in inst_merge when merging a ground inst with a bound inst
Estimated hours taken: 8
Branches: main
Fix a bug in inst_merge when merging a ground inst with a bound inst
containing 'any' insts. Previously,
inst_merge(ground, bound(f(..., any, ...)))
would return a result of 'any' which is not as accurate as we would
like (e.g. this problem occurs often in Mercury code generated by the
HAL compiler). To improve this, we pass the type of the variable
being merged to inst_merge and when this situation arises we expand
'ground' to 'bound(<functors of type>)' and use this inst in the
merge.
An alternative to passing the types through inst_merge would be to
reinstate the use of 'typed_inst' and 'typed_ground' which are created
by (currently commented out) code in 'propagate_types_into_insts'.
However, this has previously been found to cause performance problems
since it greatly expands the size of all insts and instmaps in the
program. The approach used here is the same as that adopted for
inst_matches_{initial,final} some time ago, where it does not appear
to have a noticeable performance impact on typical programs.
compiler/inst_util.m:
Pass types through inst_merge and implement the changes to
inst_merge(ground, bound(...)) described above.
compiler/inst_match.m:
compiler/instmap.m:
compiler/mode_util.m:
compiler/simplify.m:
Pass types to calls to inst_merge.
compiler/inst_match.m:
compiler/type_util.m:
Move 'maybe_get_cons_id_arg_types' and
'maybe_get_higher_order_arg_types' from inst_match.m to
type_util.m and export them.
compiler/mode_util.m:
Export 'constructors_to_bound_insts'.
tests/valid/Mmakefile:
tests/valid/merge_ground_any.m :
Add a regression test.
tests/invalid/Mmakefile:
tests/invalid/merge_ground_any.err_exp:
tests/invalid/merge_ground_any.m:
Add a test to make sure the ground inst is expanded out to the
full set of functors for the type.
|
||
|
|
ad0aa5b60e |
Allow user-defined types with a single constructor `{}/1'
Estimated hours taken: 1
Branches: main
compiler/type_util.m:
Allow user-defined types with a single constructor `{}/1'
to be treated as no-tag types. Unary tuples aren't treated
as no-tag types because it would significantly complicate
the implementation.
Use more descriptive variable names.
Simplify some code using std_util__map_maybe.
|
||
|
|
f21676c3a6 |
When testing for type_info types, check that the type is in
Estimated hours taken: 0.5 Branches: main compiler/type_util.m: When testing for type_info types, check that the type is in the 'private_builtin' module. This allows user-defined types to use the names 'type_info', 'type_ctor_info', etc. This change is required to allow the new module rtti_implementation.m to compile in reserved_tag grades. The compiler was assuming that the types in this module were the builtin type_info types and was not using the reserved_tag representation for them. |
||
|
|
9dd11b2fc6 |
Smart recompilation. Record version numbers for each item
Estimated hours taken: 400
Smart recompilation. Record version numbers for each item
in interface files. Record which items are used in each compilation.
Only recompile a module if the output file does not exist or
nothing has changed.
There is still some work to do on this:
- it doesn't work with inter-module optimization.
- it doesn't work when the module name doesn't match the file name.
(this problem will go away when mmake functionality is moved into
the compiler.
I'll hold off documenting this change in the NEWS file and
on the web page for a month or so, until I've had a bit more
experience using it.
compiler/options.m:
compiler/handle_options.m:
doc/user_guide.texi:
Add an option `--smart-recompilation', currently off by default.
Add an internal option `--generate-version-numbers' to control
whether version numbers are written to the interface files. If
`--smart-recompilation' is disabled because the module
is being compiled with `--intermodule-optimization' (e.g. in the
standard library), we still want to write the version numbers
to the interface files.
Add an option `--verbose-recompilation' (default off)
to write messages describing why recompilation is needed.
Add an option `--warn-smart-recompilation' (default on)
to control warnings relating to the smart recompilation
system. Warn if smart recompilation will not work with
the output and inter-module optimization options given.
compiler/recompilation.m:
Type declarations for smart recompilation.
Predicates to record program items used by compilation.
compiler/recompilation_version.m:
Compute version numbers for program items in interface files.
compiler/recompilation_usage.m:
Find all items used by a compilation.
compiler/recompilation_check.m:
Check whether recompilation is necessary.
compiler/timestamp.m:
Timestamp ADT for smart recompilation.
compiler/mercury_compile.m:
Invoke the smart recompilation passes.
compiler/modules.m:
compiler/prog_io.m:
Return timestamps for modules read.
When reading a module make sure the current input stream
is reset to its old value, not stdin.
Handle version number items in interface files.
compiler/module_qual.m:
compiler/unify_proc.m:
compiler/make_hlds.m:
Record all items used by local items.
compiler/make_hlds.m:
Process `:- pragma type_spec' declarations in
add_item_list_clauses. The qual_info is needed
when processing `:- pragma type_spec' declarations
so that any equivalence types used by the declaration
can be recorded as used by the predicate or function to
which the `:- pragma type_spec' applies.
compiler/equiv_type.m:
For each imported item, record which equivalence types
are used by that item.
compiler/hlds_module.m:
Add a field to the module_info to store information about
items used during compilation of a module.
compiler/check_typeclass.m:
Make sure any items used in clauses for typeclass method
implementations are recorded in the `.used' file.
compiler/prog_data.m:
compiler/*.m:
Factor out some duplicated code by combining the
pred and func, and pred_mode and func_mode items.
Make it easier to extract the name of a type, inst or mode
from its declaration.
Add an item type to hold the version numbers for an interface file.
Allow warnings to be reported for `nothing' items (used for
reporting when version numbers are written using an
obsolete format).
compiler/prog_io.m:
compiler/prog_io_util.m:
compiler/typecheck.m:
compiler/type_util.m:
compiler/*.m:
Strip contexts from all types, not just those in class constraints.
This makes it possible to use ordinary unification to check
whether items have changed (with the exception of clauses).
Remove code to create types with contexts in typechecking.
Remove code scattered through the compiler to remove contexts
from types in class constraints.
compiler/hlds_pred.m:
compiler/prog_util.m:
Move hlds_pred__adjust_func_arity to prog_util, so that it
can be used by the pre-hlds passes.
compiler/typecheck.m:
compiler/hlds_module.m:
Move typecheck__visible_modules to hlds_module.m, so it can
be used by recompilation_usage.m.
compiler/typecheck.m:
Add a comment telling where updates may be required if the
code to typecheck a var-functor unification changes.
compiler/error_util.m:
Allow writing messages without contexts (used for the verbose
recompilation messages).
Add functions to format sym_name and sym_name_and_arity,
and to add punctuation to the end of an error message
without unwanted line breaks before the punctuation.
scripts/Mmake.rules:
compiler/modules.m:
Don't remove the output file before running the compiler. We need
to leave the old output file intact if smart recompilation detects
that recompilation is not needed.
compiler/notes/compiler_design.html:
Document the new modules.
library/io.m:
NEWS:
Add predicates to find the modification time of files
and input_streams.
library/set.m:
NEWS:
Add a predicate version of set__fold
Don't sort the output of set__filter, it's already sorted.
library/std_util.m:
NEWS:
Add a predicate `std_util__map_maybe/3' and a function
`std_util__map_maybe/2' to apply a predicate or a function to
a value stored in a term of type `std_util__maybe'.
configure.in:
runtime/mercury_conf.h.in:
runtime/RESERVED_MACRO_NAMES:
When checking whether the compiler is recent enough, check for
the --warn-smart-recompilation option.
Check for stat().
library/Mmakefile:
Disable warnings about smart recompilation not working with
`--intermodule-optimization'.
browser/Mmakefile:
Disable warnings about smart recompilation not working when
the module name doesn't match the file name.
runtime/mercury_string.h:
Add a macro MR_make_string_const() which automates computation
of the length of string argument to MR_string_const().
tests/recompilation/Mmakefile:
tests/recompilation/runtests:
tests/recompilation/test_functions:
tests/recompilation/TESTS:
tests/recompilation/README:
A framework for testing smart recompilation.
The option currently only works for the recompilation directory.
tests/recompilation/TEST.m.{1,2}:
tests/recompilation/TEST_2.m.{1,2}:
tests/recompilation/TEST.exp.{1,2}:
tests/recompilation/TEST.err_exp.2:
Test cases, where TEST is one of add_constructor_r, add_instance_r,
add_instance_2_r, add_type_nr, change_class_r, change_instance_r,
change_mode_r, field_r, func_overloading_nr, func_overloading_r,
lambda_mode_r, nested_module_r, no_version_numbers_r,
pragma_type_spec_r, pred_ctor_ambiguity_r, pred_overloading_r,
add_type_re, remove_type_re, type_qual_re.
tests/handle_options:
Add an option `-e' to generate any missing expected output files.
|
||
|
|
04e614485d |
Implement deep profiling; merge the changes on the deep2 branch back
Estimated hours taken: 500 Branches: main Implement deep profiling; merge the changes on the deep2 branch back onto the trunk. The main documentation on the general architecture of the deep profiler is the deep profiling paper. doc/user_guide.texi: Document how to use the deep profiler. deep_profiler: deep_profiler/Mmakefile: A new directory holding the deep profiler and its mmakefile. Mmakefile: Add targets for the new directory. Add support for removing inappropriate files from directories. deep_profiler/interface.m: The deep profiler consists of two programs: mdprof_cgi.m, which acts as a CGI "script", and mdprof_server.m, which implements the server process that the CGI script talks to. Interface.m defines the interface between them. script/mdprof.in: A shell script template. ../configure uses it to generate mdprof, which is a wrapper around mdprof_cgi that tells it how to find mdprof_server. deep_profiler/mdprof_cgi.m: The CGI "script" program. deep_profiler/mdprof_server.m: The top level predicates of the server. deep_profiler/profile.m: The main data structures of the server and their operations. deep_profiler/read_profile.m: Code for reading in profiling data files. deep_profiler/startup.m: Code for post-processing the information in profiling data files, propagating costs from procedures to their ancestors and performing various kinds of summaries. deep_profiler/server.m: Code for responding to requests from the CGI script. deep_profiler/cliques.m: Code to find cliques in graphs. deep_profiler/array_util.m: deep_profiler/util.m: Utility predicates. deep_profiler/dense_bitset.m: An implementation of (part of) the set ADT with dense bit vectors. deep_profiler/measurements.m: Operations on profiling measurements. deep_profiler/timeout.m: An implementation of a timeout facility. deep_profiler/conf.m: Functions that depend on autoconfigured settings. configure.in: Find out what command to use to find the name of the local host. Install deep profiling versions of the standard library along with the other profiling versions. runtime/mercury_conf.h.in: Add some macros for deep_profiler/conf.m to use. library/profiling_builtin.m: runtime/mercury_deep_call_port_body.h: runtime/mercury_deep_leave_port_body.h: runtime/mercury_deep_redo_port_body.h: A new library module that implements deep profiling primitives. Some of these primitives have many versions, whose common code is factor is factored out in three new include files in the runtime. compiler/deep_profiling.m: New module to perform the program transformations described in the paper. compiler/notes/compiler_design.html: Document the new compiler module. compiler/mercury_compiler.m: Invoke the new module in deep profiling grades. Allow global static data to be generated by deep_profiling.m. compiler/options.m: Add options to turn on deep profiling and (for benchmarking purposes) control its implementation. Add an optiooption disable tailcall optimization in the LLDS backend, to help benchmarking deep profiling. compiler/jumpopt.m: compiler/optimize.m: Obey the option to disable tailcalls. compiler/handle_options.m: Handle the implications of deep profiling. compiler/modules.m: In deep profiling grades, automatically import profiling_builtin.m. compiler/prog_util.m: doc/Makefile: library/library.m: Handle the new builtin module. compiler/export.m: In deep profiling grades, wrap deep profiling code around exported procedures to handle the "unscheduled call" aspects of callbacks to Mercury from the foreign language. compiler/higher_order.m: profiler/demangle.m: util/demangle.c: When creating a name for a higher-order-specialized predicate, include the mode number in the name. compiler/add_trail_ops.m: compiler/type_util.m: Move c_pointer_type from add_trail_ops to type_util, so it can also be used by deep_profiling.m. compiler/hlds_goal.m: Add a new goal feature that marks a tail call, for use by deep_profiling.m. compiler/hlds_pred.m: Add a new field to proc_info structures for use by deep_profiling.m. Add a mechanism for getting proc_ids for procedure clones. Remove next_proc_id, an obsolete and unused predicate. compiler/hlds_data.m: Add a new cons_id to refer to the proc_static structure of a procedure. compiler/bytecode_gen.m: compiler/code_util.m: compiler/dependency_graph.m: compiler/hlds_out.m: compiler/mercury_to_mercury.m: compiler/ml_unify_gen.m: compiler/opt_debug.m: compiler/prog_rep.m: compiler/rl_exprn.m: compiler/switch_util.m: compiler/unify_gen.m: Trivial changes to handle the new cons_id, goal feature and/or proc_info argument. compiler/rtti.m: Add a utility predicate for extracting pred_id and proc_id from an rtti_proc_label, for use by hlds_out.m compiler/layout.m: compiler/layout_out.m: compiler/llds.m: compiler/llds_common.m: Add support for proc_static and call_site_static structures. compiler/layout_out.m: compiler/llds_out.m: Add code for the output of proc_static structures. compiler/code_util.m: Make code_util__make_proc_label_from_rtti a function, and export it. util/mkinit.c: compiler/llds_out.m: compiler/layout.m: compiler/modules.m: Add support for a fourth per-module C function, for writing out proc_static structures (and the call_site_static structures they contains). Since proc_static structures can be referred to from LLDS code (and not just from other static structures and compiler-generated C code), reorganize the declarations of static structures slightly. Change the schema for the name of the first per-module C function slightly, to make it the addition of the fourth function easier. The scheme now is: mercury__<modulename>__init mercury__<modulename>__init_type_tables mercury__<modulename>__init_debugger mercury__<modulename>__write_out_proc_statics Improve formatting of the generated C code. library/*.m: runtime/mercury.c: runtime/mercury_context.c: runtime/mercury_engine.c: runtime/mercury_ho_call.c: runtime/mercury_tabling.c: runtime/mercury_trace_base.c: runtime/mercury_wrapper.c: trace/mercrury_trace.[ch]: trace/mercrury_trace_declarative.c: trace/mercrury_trace_external.c: trace/mercrury_trace_internal.c: Conform to the new scheme for initialization functions for hand-written modules. compiler/mercury_compile.m: library/benchmarking.m: runtime/mercury_conf_param.h: runtime/mercury.h: runtime/mercury_engine.c: runtime/mercury_goto.c: runtime/mercury_grade.h: runtime/mercury_ho_call.c: runtime/mercury_label.[ch]: runtime/mercury_prof.[ch]: Add an MR_MPROF_ prefix in front of the C macros used to control the old profiler. compiler/handle_options.m: runtime/mercury_grade.h: scripts/canonical_grade.sh-subr: scripts/init_grade_options.sh-subr: scripts/parse_grade_options.sh-subr: Make deep profiling completely separate from the old profiling system, by making the deep profiling grade independent of MR_MPROF_PROFILE_TIME and the compiler option --profile-time. library/array.m: library/builtin.m: library/std_util.m: runtime/mercury_hand_unify_body.h: runtime/mercury_hand_compare_body.h: In deep profiling grades, wrap the deep profiling call, exit, fail and redo codes around the bodies of hand-written unification and comparison procedures. Make the reporting of array bounds violations switchable between making them fatal errors, as we currently, and reporting them by throwing an exception. Throwing an exception makes debugging code using arrays easier, but since exceptions aren't (yet) propagated across engine boundaries, we keep the old behaviour as the default; the new behaviour is for implementors. runtime/mercury_deep_profiling_hand.h: New file that defines macros for use in Mercury predicates whose definition is in hand-written C code. library/exception.m: runtime/mercury_exception_catch_body.h: runtime/mercury_stacks.h: In deep profiling grades, wrap the deep profiling call, exit, fail and redo codes around the bodies of the various modes of builtin_catch. Provide a function that C code can use to throw exceptions. library/benchmarking.m: library/exception.m: library/gc.m: library/std_util.m: runtime/mercury_context.[ch]: runtime/mercury_engine.[ch]: runtime/mercury_debug.c: runtime/mercury_deep_copy.c: runtime/mercury_overflow.h: runtime/mercury_regs.h: runtime/mercury_stacks.h: runtime/mercury_thread.c: runtime/mercury_wrapper.c: Add prefixes to the names of the fields in the engine and context structures, to make code using them easier to understand and modify. runtime/mercury_deep_profiling.[ch]: New module containing support functions for deep profiling and functions for writing out a deep profiling data file at the end of execution. runtime/mercury_debug.[ch]: Add support for debugging deep profiling. Add support for watching the value at a given address. Make the buffered/unbuffered nature of debugging output controllable via the -du option. Print register contents only if -dr is specified. runtime/mercury_goto.h: runtime/mercury_std.h: Use the macros in mercury_std.h instead of defining local variants. runtime/mercury_goto.h: runtime/mercury_stack_layout.h: runtime/mercury_stack_trace.c: runtime/mercury_tabling.c: trace/mercury_trace.c: trace/mercury_trace_declarative.c: trace/mercury_trace_external.c: trace/mercury_trace_vars.c: Standardize some of the macro names with those used in the debugger paper. runtime/mercury_heap.h: Add support for memory profiling with the deep profiler. runtime/mercury_prof.[ch]: runtime/mercury_prof_time.[ch]: Move the functionality that both the old profiler and the deep profiler need into the new module mercury_prof_time. Leave mercury_prof containing stuff that is only relevant to the old profiler. runtime/mercury_prof.[ch]: runtime/mercury_strerror.[ch]: Move the definition of strerror from mercury_prof to its own file. runtime/mercury_wrapper.[ch]: Add support for deep profiling. Add suppory for controlling whether debugging output is buffered or not. Add support for watching the value at a given address. runtime/Mmakefile: Mention all the added files. scripts/mgnuc.in: Add an option for turning on deep profiling. Add options for controlling the details of deep profiling. These are not documented because they are intended only for benchmarking the deep profiler itself, for the paper; they are not for general use. tools/bootcheck: Compile the deep_profiler directory as well as the other directories containing Mercury code. Turn off the creation of deep profiling data files during bootcheck, since all but one of these in each directory will be overwritten anyway. Add support for turning on --keep-objs by default in a workspace. tools/speedtest: Preserve any deep profiling data files created by the tests. trace/mercury_trace.c: Trap attempts to perform retries in deep profiling grades, since they would lead to core dumps otherwise. util/Mmakefile: Avoid compile-time warnings when compiling getopt. tests/*/Mmakefile: tests/*/*/Mmakefile: In deep profiling grades, switch off the tests that test features that don't work with deep profiling, either by design or because the combination hasn't been implemented yet. |
||
|
|
19f6ca24e0 |
Add arity when outputting types. This lets us distinguish types that
Estimated hours taken: 0.5 Branches: main, dotnet-foreign Add arity when outputting types. This lets us distinguish types that have the same name but different arity, which is a bit of a problem in high-level data grades. Also add a minor fix for mapping Mercury arrays into System.Array. compiler/mlds_to_il.m: Append _arity to the type name. Translate arrays into System.Array. Re-use a little duplicated code. compiler/type_util.m: Add type_id_is_array for detecting arrays. |
||
|
|
19ceeaf30f |
Merge the changes from the HAL branch onto the main branch.
Estimated hours taken: 40
(to do this merge... 100s of hours on the HAL branch
itself by myself and Warwick Harvey though).
Merge the changes from the HAL branch onto the main branch. With the recent
changes made to the HAL implementation, this means adding just one grade,
`.rt' or --reserve-tag, which reserves one tag (zero) in each type for
use by HAL's Herbrand constraint solver. This disables no-tag types and
enumerations.
This grade will now bootstrap, and passes all tests, except for a few failing
cases in the debugger and tabling directories.
compiler/options.m:
compiler/handle_options.m:
Add the `.rt' or --reserve-tag grade option.
runtime/mercury_conf_param.h:
Document the macro MR_RESERVE_TAG
doc/user_guide.texi:
Document the `.rt' grade.
compiler/make_hlds.m:
Don't record any types as no-tag types if we are in a .rt grade.
compiler/make_tags.m:
compiler/type_ctor_info.m:
Allocate tags starting from `1' in .rt grades.
compiler/rtti_out.m:
In .rt grades, output a dummy ptag definition for tag `0'.
compiler/type_util.m:
Add predicates `type_util__constructors_are_dummy_argument_type' and
`type_constructors_are_type_info' for use when allocating tags to
ensure that type infos and dummy types (io__state/0 and store__store/1)
are still treated as no-tag types in .rt grades.
library/sparse_bitset.m:
When allocating a sparse bitset element, use tag `1' if we are in a
.rt grade.
runtime/mercury_tags.h:
Define a macro `MR_UNIV_TAG' which is `1' is we in a .rt grade and
`0' otherwise. (Now that univ is a user defined type, it is a also
assigned a `var' tag).
Also make the definitions of MR_RAW_TAG_NIL and MR_RAW_TAG_CONS take the
.rt grade into account.
runtime/mercury_type_info.h:
Define `MR_unravel_univ' and
`MR_initialise_univ' for taking apart and putting together univs.
Add a new secondary tag alternative: MR_SECTAG_VARIABLE, used to
represent Herbrand variables.
library/std_util.m:
Use MR_UNIV_TAG, MR_unravel_univ and MR_initialise_univ when
manipulating univs.
Handle the new MR_SECTAG_VARIABLE secondary tag by aborting.
runtime/mercury_deep_copy_body.h:
runtime/mercury_tabling.c:
runtime/mercury_unify_compare_body.h:
Handle the new MR_SECTAG_VARIABLE secondary tag by aborting.
library/std_util.m:
Add a constant for MR_SECTAG_VARIABLE in the MC++ back end.
scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/mgnuc.in:
scripts/parse_grade_options.sh-subr:
Process the new grade.
scripts/mmake.in:
Add an option `--include-makefile', which includes a Makefile given
as a command line argument into the Makefile generated by mmake.
This is used to implement `halmake', a make program for HAL which
just passes a bunch of extra rules and variable definitions onto
mmake.
tests/debugger/existential_type_classes.m:
tests/hard_coded/existential_types_test.m:
trace/mercury_trace_declarative.c:
trace/mercury_trace_external.c:
trace/mercury_trace_internal.c:
Use MR_UNIV_TAG.
TODO:
- The declarative debugger falls over in .rt grades. This is possibly
because compiler/static_term.m assumes that the generated code uses
the same data representation as the compiler itself. This should be
fixed, although it is not critical; the declarative debugger won't
work with trailing as is, and the .rt grade is only ever used in
conjunction with trailing (.tr) at this stage.
|
||
|
|
50f1674dd5 |
In mdb's print and browse commands, allow the field to be printed to be
Estimated hours taken: 8
In mdb's print and browse commands, allow the field to be printed to be
specified by name as well as by number. This required extending the RTTI
for notag types to record field names.
trace/mercury_trace_vars.m:
Allow the field to be printed to be specified by name as well as by
number.
library/std_util.m:
Add code to find out whether a term has a field with a given name,
and if yes, which field that is. At the moment, this functionality
is accessible only from C. (There is no point to adding to the
user-visible interface before a redesign of that interface.)
Fix an old bug: ML_arg() was not compensating for the extra type_info
and/or typeclass_info arguments inserted at the start of a cell for
functors with existentially typed arguments. Document the ML_expand
data structure better to make that bug less likely in the future.
runtime/mercury_type_info.h:
Add an extra field to the type for notag type functors, recording
the field name of the argument, if it has one.
compiler/rtti.m:
Add a maybe-argument-name field to the record for notag types.
compiler/type_ctor_info.m:
Record the name of the single argument of the single functor of a
notag type, if it has one.
compiler/type_util.m:
Make that argument name available.
compiler/rtti_out.m:
Print out that argument name.
compiler/make_tags.m:
compiler/make_hlds.m:
compiler/rtti_to_mlds.m:
Ignore that argument name.
tests/debugger/field_names.{m,inp,exp}:
A new test case to test the printing of subterms specified by field
numbers and/or names.
tests/debugger/Mmakefile:
Enable the new test case.
|
||
|
|
b251a990aa |
Improve the efficiency of type_util__type_is_no_tag_type.
Estimated hours taken: 1 Improve the efficiency of type_util__type_is_no_tag_type. This change reduces the time taken by `mmc -C make_hlds' by about 2%. compiler/hlds_data.m: compiler/hlds_module.m: compiler/make_hlds.m: Add a field to the module_info to hold information about no-tag types to avoid searching the entire type table. compiler/type_util.m: Look up the no-tag type table rather than the type table in type_is_no_tag_type. Minor efficiency improvements for type_to_type_id. Avoid unnecessary calls to type_to_type_id. |
||
|
|
82378c381b |
Allow polymorphic ground insts. This change assumes that all inst
Estimated hours taken: 80 Allow polymorphic ground insts. This change assumes that all inst parameters in the mode declaration for a predicate or function are constrained to be ground-shared. This is a temporary measure until we work out a nice syntax to allow the programmer to tell the compiler that certain inst parameters may be treated as ground insts. Since we don't currently support unconstrained inst parameters anyway, this shouldn't cause a problem. TODO: - Add syntax, something like `:- mode p(in(I)) <= ground(I).', to specify that an inst parameter represents a ground inst. - Allow abstract ground insts that are treated in a similar way to what we've done here with ground inst parameters. - Make mode checking more efficient (i.e. rewrite the mode system). compiler/inst.m: Add a new alternative for ground insts: `constrained_inst_var(inst_var)'. Define the type `inst_var_sub'. compiler/inst_match.m: Change inst_matches_initial so that it: - handles constrained_inst_vars correctly; - returns the inst_var substitutions necessary for the call; - handles inst_matches_initial(ground(...), bound(...), ...) properly (this requires knowing the type of the variable). The last change has also been made for inst_matches_final and inst_matches_binding. However, the check is disabled for now because, without alias tracking, the mode checker becomes too conservative. compiler/hlds_pred.m: compiler/mode_info.m: compiler/simplify.m: compiler/det_util.m: Include the inst_varset in the proc_info, mode_info and simplify_info. Add a vartypes field to the det_info. Remove the vartypes field from the simplify_info since it is now in the det_info. Use record syntax for these data structures and their access predicates to make future changes easier. compiler/prog_io.m: When processing pred and func mode declarations, convert all inst_var(V) insts to ground(shared, constrained_inst_var(V)). compiler/prog_data.m: compiler/hlds_data.m: compiler/make_hlds.m: compiler/mode_util.m: Use inst_vars instead of inst_params. compiler/modes.m: compiler/modecheck_call.m: compiler/unique_modes.m: compiler/mode_util.m: When checking or recomputing initial insts of a call, build up an inst_var substitution (using the modified inst_matches_initial) and apply this to the final insts of the called procedure before checking/recomputing them. compiler/mode_util.m: Make sure that recompute_instmap_delta recomputes the instmap_deltas for lambda_goals even when RecomputeAtomic = no. compiler/type_util.m: Add a new predicate, type_util__cons_id_arg_types which nondeterministically returns the cons_ids and argument types for a given type. Add a new predicate type_util__get_consid_non_existential_arg_types which is the same as type_util__get_existential_arg_types except that it fails rather than aborting for existenially typed arguments. compiler/accumulator.m: compiler/check_typeclass.m: compiler/clause_to_proc.m: compiler/common.m: compiler/continuation_info.m: compiler/deforest.m: compiler/det_analysis.m: compiler/det_report.m: compiler/det_util.m: compiler/dnf.m: compiler/follow_code.m: compiler/goal_store.m: compiler/goal_util.m: compiler/higher_order.m: compiler/inst_util.m: compiler/instmap.m: compiler/lambda.m: compiler/magic.m: compiler/magic_util.m: compiler/mercury_to_mercury.m: compiler/modecheck_unify.m: compiler/module_qual.m: compiler/pd_info.m: compiler/pd_util.m: compiler/polymorphism.m: compiler/post_typecheck.m: compiler/prog_io_util.m: compiler/prog_rep.m: compiler/saved_vars.m: compiler/stack_layout.m: compiler/table_gen.m: compiler/unify_proc.m: compiler/unneeded_code.m: compiler/unused_args.m: Pass inst_varsets and types where needed. Changes to reflect change in definition of the inst data type. compiler/inlining.m: Recompute the instmap deltas for a procedure after inlining. This bug showed up compiling tests/hard_coded/lp.m with inlining and deforestation turned on: deforestation was getting incorrect instmap deltas from inlining, causing the transformation to break mode-correctness. It has only just shown up because of the added call to `inst_matches_initial' from within `recompute_instmap_delta'. tests/invalid/Mmakefile: tests/invalid/unbound_inst_var.m: tests/invalid/unbound_inst_var.err_exp: tests/valid/Mmakefile: tests/valid/unbound_inst_var.m: Move the `unbound_inst_var' test case from `invalid' to `valid' and extend its coverage a bit. |
||
|
|
3cf329a739 |
Fix bugs in explicit type qualification.
Estimated hours taken: 4
Fix bugs in explicit type qualification.
compiler/make_hlds.m:
Make the code to handle type qualification expressions match
the documentation. Variables occurring in type qualifications
but not in the predicate's argument types are local to the
clause in which they occur.
Don't export clauses_info_init -- it's not used anywhere else.
Add field labels to the qual_info type.
compiler/hlds_pred.m:
compiler/*.m:
Add a field to the clauses_info to contain the mapping from
type variable names to type variables for the head types.
This needs to be maintained because type variables added
while processing type qualifications in a clause should
not be added to the map used for other clauses.
compiler/typecheck.m:
Apply substitutions to the explicit vartypes at the end
of each pass of typechecking to keep them in sync with
the type variables in the argument types.
compiler/type_util.m:
Add a predicate type_util__apply_variable_renaming_to_type_map
for use by typecheck.m.
doc/reference_manual.texi:
Add some more comments about the handling of explicit type
qualifications to the documentation about valid type assignments.
Change references to existential type _qualifiers_ to consistently
refer to existential type _quantifiers_.
tests/hard_coded/type_qual.{m,exp}:
Add some more tests.
tests/hard_coded/Mmakefile:
Pass `--infer-all' to mmc when compiling type_qual.m.
|
||
|
|
46a8da81cb |
Implement builtin tuple types, similar to those in Haskell.
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.
|
||
|
|
2490aac4dd |
Generate declarations and clauses for the compiler-generated
Estimated hours taken: 10 Generate declarations and clauses for the compiler-generated unification and comparison procedures only when they are needed. The vast majority of these procedures are never used. This change speeds up `mmc -C make_hlds' by about 5%. compiler/make_hlds.m: Export add_special_pred_for_real and add_special_pred_decl_for_real for use by unify_proc.m. Don't generate declarations or clauses for unification or comparison predicates for imported types immediately unless the predicate needs to be typechecked. Don't generate clauses for comparison predicates for imported types -- they will never be used because the predicate has import_status `imported'. compiler/special_pred.m: compiler/typecheck.m: Add predicate special_pred_for_type_needs_typecheck, which succeeds for types with user-defined equality and types with existentially typed constructors. compiler/unify_proc.m: Make sure the declarations and clauses for the unification predicate for a type have been generated before processing a unify_request for that type. Add predicates for use by higher_order.m to force generation of a special predicate when required for specialization of a call to unify/2 or compare/3. Simplify the code for unification predicates for enumeration types. The code that was being generated cast the arguments to int, then called unify/2 on the ints. The simpler version just creates a unify goal. Enumerations are atomic types, so modecheck_unify.m will treat the unification as a simple_test. compiler/polymorphism.m: Add a predicate polymorphism__process_generated_pred to be used by unify_proc.m to process the bodies of the generated unification predicates. compiler/post_typecheck.m: Add versions of post_typecheck__finish_pred and post_typecheck__finish_imported_pred which don't require an io__state, for use by unify_proc.m. Errors should never be reported in post_typecheck.m for unification or comparison predicates. compiler/simplify.m: Don't generate calls to the type-specific predicate for an in-in complicated unification if the predicate is generated lazily. higher_order.m will handle the specialization in that case. compiler/higher_order.m: Call unify_proc.m to generate the declarations for a special pred when there is a call to that special pred which could be specialized. Add field labels to the higher_order_info type. compiler/type_util.m: Add predicates type_id_is_atomic and classify_type_id, which are similar to type_is_atomic and classify_type, for use by special_pred.m. |
||
|
|
19bcf11e7a |
Fix a bug in the handling of instances with unconstrained type
Estimated hours taken: 1 Fix a bug in the handling of instances with unconstrained type variables where a type variable occurs multiple times in the instance declaration. The compiler was adding multiple copies of the type_info for such variables to the typeclass_info. compiler/type_util.m: Remove duplicates in the list of variables returned by `get_unconstrained_tvars/3'. tests/hard_coded/Mmakefile: tests/hard_coded/instance_unconstrained_tvar_dup.m: tests/hard_coded/instance_unconstrained_tvar_dup.exp: Test case. |
||
|
|
791ec10d1e |
Add options for
Estimated hours taken: 1 Add options for unboxed_enums - turns on unboxed enums (default is yes) unboxed_no_tag_types - turns on unboxed no-tag-types (default is yes) Currently every grade uses these representations. We will set these to `no' on the IL backend (and probably the Java backend) if using a simple implementation of the the Array of Object representation for Mercury data structures. compiler/make_tags.m: Check for these options when creating representations. compiler/options.m: Add the new options. compiler/type_util.m: Make sure type_is_no_tag_type checks the appropriate option. Add a new predicate type_constructors_are_no_tag_type which just does a check of the structure of the constructors (you have to do the option checking yourself). compiler/higher_order.m: compiler/mode_util.m: Use the new type_is_no_tag_type (this actually simplifies the code). compiler/type_ctor_info.m: Use type_constructors_are_no_tag_type and check the globals. |
||
|
|
9dcab9bee2 |
Add a new optimization, enabled by the option --unneeded-code.
Estimated hours taken: 40 Add a new optimization, enabled by the option --unneeded-code. This optimization removes goals whose outputs are not used at all, and moves goals whose outputs are only used on some computation branches to the starts of those branches, so they do not need to be executed on other branches. Such deletions/movements are done only when the semantic switches and the properties of the relevant goal together permit it. compiler/unneeded_code.m: A new module to perform the goal rearrangement. compiler/hlds_goal.m: The new optimization needs to know how many functors the switched-on variable can be bound to, so it can check whether a given number of switch arms covers all alternatives or not. To make access to this information convenient, we add a field to the goal_path_step alternative for switch arm entry that records this number. compiler/goal_path.m: Fill in this number. To make this possible, we thread the necessary information through the predicates in this module. compiler/type_util.m: Add a utility predicate type_util__switch_type_num_functors, for use by the new code in goal_path.m. compiler/switch_detection.m: Avoid duplicated code by using type_util__switch_type_num_functors where relevant. compiler/code_aux.m: Add three new auxiliary predicate, code_aux__goal_cannot_loop_or_throw, code_aux__goal_can_loop_or_throw and code_aux__goal_can_loop, to the existing code_aux__goal_cannot_loop. code_aux__goal_cannot_loop now checks only what its name says. compiler/trace.m: Ignore the new field when generating goal paths strings. compiler/mercury_compile.m: Invoke unneeded_code.m if required. compiler/hlds_pred.m: Add some utility predicates for use by unneeded_code.m. compiler/unused_args.m: Use the new utility predicates instead of reimplementing them. compiler/options.m: Define the --unneeded-code option, and its auxiliary, --unneeded-code-copy-limit. doc/user_guide.texi: Document the new options. |
||
|
|
3ed3421f49 |
Fix a bug reported by Peter Ross <peter.ross@miscrit.be>:
Estimated hours taken: 3 Fix a bug reported by Peter Ross <peter.ross@miscrit.be>: check that type, mode, and determinism of main/2 conform to what the Mercury language reference manual requires. compiler/post_typecheck.m: Check that the arguments of main/2 have type `io__state'. compiler/type_util.m: Add predicate `type_is_io_state', for use by post_typecheck.m. compiler/modes.m: Check the the arguments of main/2 have mode `di, uo'. Also split some of the code in proc_check_eval_methods out into separate procedures. compiler/det_report.m: Check that main/2 has determinism `det' or `cc_multi', rather than just checking that it doesn't fail. (We don't want to allow main/2 to have determinism `multi', since that doesn't work in MLDS grades, for which `multi' procedures have a different calling convention than `det' or `cc_multi' procedures. Similarly we don't want to allow main/2 to have determinism `erroneous', since a future back-end might use a different calling convention for that.) tests/general/partition.m: Change the declared determinism of main/2 from `multi' to `det', to make this test case conform to the language reference manual. This is needed now that the compiler checks the determinism of main/2 properly. tests/invalid/Mmakefile: tests/invalid/invalid_main.m: tests/invalid/invalid_main.err_exp: A regression test. |
||
|
|
8c62fcec99 |
For --high-level-data, use field names rather than offsets
Estimated hours taken: 12 For --high-level-data, use field names rather than offsets when accessing fields. compiler/hlds_data.m: Include the field names in the hlds_cons_defn, for use by ml_unify_gen.m. compiler/make_hlds.m: compiler/typecheck.m: compiler/post_typecheck.m: compiler/type_util.m: Minor changes to handle the change to hlds_cons_defn. compiler/ml_type_gen.m: For fields of certain types, such as `float', etc., generate the field type as a boxed type (mlds__generic_type). Don't generate a field for the secondary tag if it isn't needed. If none of the ctors need a secondary tag, then skip it entirely. If some but not all ctors need a secondary tag, then put the secondary tag field in a separate class derived fom the base class for this type, and have the classes for the ctors that need it derived from that class rather than from the base class. compiler/ml_unify_gen.m: For --high-level-data, use field names rather than offsets when accessing data fields and secondary tags. (XXX the code for closures still uses offsets.) compiler/ml_code_util.m: Add two new routines for dealing with fields, `ml_gen_field_name' and `ml_must_box_field_type', for use by ml_type_gen.m and ml_unify_gen.m. compiler/mlds.m: Change the documentation for the ClassType field in `field' lvals: rename it as `PtrType', and make it clear that this is the type of the pointer, not the type of the class pointed to. Also add a new CtorType field to the `named_field' field_id. compiler/ml_elim_nested.m: Minor changes to handle the modifications to mlds.m. compiler/mlds_to_c.m: Ensure that we name-mangle struct names and field names. For named_field field accesses, cast the pointer to the type specified by the new CtorType field before dereferencing it. |
||
|
|
957c54c0b2 |
My previous bug fix for overloading resolution of field access functions
Estimated hours taken: 1 My previous bug fix for overloading resolution of field access functions and constructors didn't work for existentially typed constructors. compiler/post_typecheck.m: When checking whether a constructor matches a cons_id and argument types, make sure the actual argument types don't bind any of the existentially quantified type variables of the constructor. compiler/typecheck.m: compiler/type_util.m: Factor out the code to check whether the argument types of a call subsume the actual argument types into a new predicate, `type_util__arg_type_list_subsumes'. tests/valid/Mmakefile: tests/valid/record_syntax_bug_2.m: Test case. |
||
|
|
281796aa9a |
Make an addition to the type class info structure; add type infos for
Estimated hours taken: 10
Make an addition to the type class info structure; add type infos for
any type variables from the head of the instance declaration which are
unconstrained, and make the class method call mechanism insert these as
arguments to method calls. The implementations of methods expect to be passed
a type info for each unconstrained type variable and a type class info for
each constraint. Previously we were not passing the appropriate type infos.
Also move the documentation about the type class transformation from
polymorphism.m to a new file, compiler/notes/type_class_transformation.html.
compiler/base_typeclass_info.m:
Generate the appropriate part of the new structure in the
base_typeclass_info.
compiler/polymorphism.m:
Add the appropriate type infos to the typeclass_info.
compiler/type_util.m:
Add a new predicate `get_unconstrained_tvars'.
runtime/mercury_deep_copy_body.h:
Update copy_typeclass_info to reflect the new structure.
runtime/mercury_ho_call.c:
Copy the extra type infos to the beginning of the arguments when
doing a class method call.
runtime/mercury_type_info.h:
Update the macros used to access the type class info.
compiler/notes/type_class_transformation.html:
The documentation about the type class transformation has been
moved from polymorphism.m to here. This change corrects that
documentation in several places and updates that documentation to
reflect the changes to the typeclass_info structure from this diff.
tests/hard_coded/typeclasses/instance_unconstrained_tvar.exp:
tests/hard_coded/typeclasses/instance_unconstrained_tvar.m:
A test case for this change.
tests/hard_coded/typeclasses/Mmakefile:
Turn this test case on. For the moment, type specialisation is
turned off for this test case as the specialiser does not insert the
extra type infos that are needed.
|
||
|
|
d0e7584c8e |
Add a new predicate, type_util__real_vars, which is the same
Estimated hours taken: 8
(including a few misguided tries...)
compiler/type_util.m:
Add a new predicate, type_util__real_vars, which is the same
as type_util__vars except it doesn't count type-info variables.
compiler/{continuation_info.m, hlds_pred.m, trace.m}:
Use type_util__real_vars rather than type_util__vars since the
latter was causing problems when calculating the live type-infos,
and causing the failure of the test case
tests/hard_coded/existential_rtti.m in debug grade.
|
||
|
|
736424a5e6 |
Remove type_id_is_hand_defined, because it makes bootstrapping hard.
Estimated hours taken: 1 Remove type_id_is_hand_defined, because it makes bootstrapping hard. Instead, consider that a type is hand defined if it is abstract even in the module that defines it, or if it appears on a short list of types which have hand-defined RTTI even though they have (incorrect) Mercury definitions as well. The list contains private_builtin's type_info, type_ctor_info, typeclass_info and base_typeclass_info. compiler/base_type_info.m: compiler/base_type_layout.m: compiler/make_hlds.m: compiler/unify_proc.m: Remove references to type_id_is_hand_defined. compiler/type_util.m: Replace replace type_id_is_hand_defined with type_id_has_hand_defined_rtti. |
||
|
|
89d56f909e |
Update some obsolete comments.
Estimated hours taken: 0.5 compiler/type_util.m: Update some obsolete comments. (The typevarset syncronization problem that the comment was referring to has been fixed long ago. Also there should be no need to rename apart when substituting equivalence types.) |
||
|
|
cc8ecc43f1 |
Prepare for the breakup of std_util.m.
Estimated hours taken: 0.1 Prepare for the breakup of std_util.m. |
||
|
|
5940825cdb |
Implement syntax for getting and setting fields of constructors.
Estimated hours taken: 70 Implement syntax for getting and setting fields of constructors. compiler/make_hlds.m: Add information about field definitions to the module_info. Check that user-defined field access functions for exported fields are also exported, otherwise predicates in other modules could use a different method to access a field than predicates in module defining the field. Add a `predicate preds_add_implicit_report_error' to allow that check to be performed for functions which are added to the module_info by some means other than a `:- func' declaration. Parse field access goals and expressions. Add predicates `insert_arg_unifications_with_supplied_contexts', and `append_arg_unification', which allow more control over the contexts given to the added unifications. These are useful because the field value for an update is really an argument of the inner-most update function call, while the input term is an argument of the outer-most function call. compiler/prog_io_dcg.m: Allow DCG goals of the form `:=(DCGArg)', which unifies `DCGArg' with the output DCG argument, ignoring the input DCG argument. The rationale for this change is that if we have convenient syntax for updating parts of a DCG argument, we should also have convenient syntax for updating the whole DCG argument. compiler/typecheck.m: Add a default clause for field access functions for which the user has supplied type and mode declarations but no clauses. Typecheck field access function calls. Use `io__write_list' to remove some duplication of code to write out comma separated lists of error descriptions. compiler/post_typecheck.m: Expand field accessor goals into the equivalent unifications. They are expanded inline rather than generating new get and set predicates for field name to avoid having to work out how to mode the generated predicates. Remove an unnecessary goal traversal to qualify function calls and constructors. That code is now called from purity.m. compiler/prog_data.m: compiler/prog_io.m: compiler/mercury_to_goedel.m: compiler/mercury_to_mercury.m: Store field names as `sym_name's rather than strings. Use a `maybe' type rather than an empty string to designate an unlabelled field. compiler/hlds_data.m: Define data structures to hold information about the field names visible in a module. compiler/hlds_module.m: Add a field to type module_info to hold information about the fields visible in a module. compiler/hlds_pred.m: Add predicates to identify field access function names, and to handle the arguments of field access functions. compiler/make_hlds.m: compiler/hlds_goal.m: compiler/modecheck_call.m: compiler/higher_order.m: compiler/purity.m: compiler/polymorphism.m: compiler/dnf.m: compiler/cse_detection.m: compiler/lambda.m: Move `create_atomic_unification' from make_hlds.m to hlds_goal.m because it is used by several other modules. compiler/hlds_goal.m: Add a version of goal_info_init which takes the context of the goal, for use by make_hlds.m. compiler/type_util.m: Add a predicate `type_util__get_type_and_cons_defn' to get the hlds_type_defn and hlds_cons_defn for a user-defined constructor. compiler/prog_util.m: Add predicates to add and remove prefixes or suffixes from the unqualified part of a sym_name. compiler/prog_out.m: Add a predicate to convert a `sym_name/arity' to a string. compiler/hlds_out.m: Add `hlds_out__simple_call_id_to_string' to convert a `pred_or_func - sym_name/arity' to a string for use in error messages. compiler/purity.m: Thread through the pred_info so that the expansion of field accessor goals can add new variables. compiler/mercury_to_mercury.m: library/ops.m: Reduce precedence of `^/2' for use as a field name separator. Add operator `^'/1 to designate which side of the `:=' is the field name in a DCG field access goal. Add operator `:=/2' for field update expressions. doc/reference_manual.texi: Document the new syntax. doc/transition_guide.texi: Document the new operators. tests/hard_coded/Mmakefile: tests/hard_coded/record_syntax.m: tests/hard_coded/record_syntax.exp: tests/invalid/Mmakefile: tests/invalid/record_syntax_errors.m: tests/invalid/record_syntax_errors.err_exp: Test cases. |
||
|
|
8a074ac664 |
Remove unnecessary explicit quantification goals before working
Estimated hours taken: 2
compiler/simplify.m:
Remove unnecessary explicit quantification goals before working
out whether a goal can cause a stack flush.
Don't increase the non-locals set of an explicit quantification
goal through common structure elimination because that could change
the determinism.
Don't optimize a singleton switch into a test followed
by the case goal if the constructor being tested against
is existentially quantified. This is necessary because
the code to produce the test uses type_util__get_cons_id_arg_types,
which does not correctly handle the existentially quantified
type variables or the type-infos for those type variables.
compiler/type_util.m:
Add type_util__is_existq_cons, which succeeds if a constructor
is existentially typed.
type_util__get_cons_id_arg_types now aborts if the cons_id
is existentially typed rather than silently giving wrong answers.
compiler/goal_util.m:
Add a comment that goal_util__switch_to_disjunction and
goal_util__case_to_disjunct abort on existentially typed constructors.
compiler/magic.m:
Add an XXX comment that we should check for existentially
typed constructors before calling goal_util__switch_to_disjunction.
tests/hard_coded/Mmakefile:
tests/hard_coded/existential_type_switch_opt.{m,exp}:
Test case.
|
||
|
|
34d52a4091 |
Fix a bug with switches on existential types.
Estimated hours taken: 12 Fix a bug with switches on existential types. This bug meant that existential types with two or more functors did not work at all, due to internal compiler errors when compiling the unification and comparison predicates for those types. compiler/type_util.m: Add new function cons_id_adjusted_arity, which computes the arity _including_ the extra typeinfo and typeclassinfo arguments inserted for existential data types. compiler/type_util.m: compiler/polymorphism.m: Move the predicates constraint_list_get_tvars and constraint_get_tvars from polymorphism.m into type_util.m, for use in cons_id_adjusted_arity. compiler/modes.m: compiler/unique_modes.m: When modechecking the functor test in switch statements, use cons_id_adjusted_arity to compute the arity of the inst, compiler/instmap.m: In instmap__bind_var_to_functor (and the instmap_delta version), use cons_id_adjusted_arity to compute the arity of the inst. compiler/goal_util.m: compiler/pd_info.m: compiler/pd_util.m: compiler/saved_vars.m: compiler/mode_util.m: compiler/deforest.m: compiler/follow_code.m: compiler/higher_order.m: compiler/simplify.m: Pass the type(s) down to recompute_instmap_delta and instmap__bind_var_to_functor, since cons_id_adjusted_arity needs to know the type. compiler/hlds_pred.m: compiler/hlds_out.m: Add a `vartypes' typedef, defined by `:- type vartypes == map(prog_var, type)', and make use of it. Rename the `vartypes' type in hlds_out as `maybe_vartypes'. tests/hard_coded/Mmakefile: tests/hard_coded/existential_type_switch.m: tests/hard_coded/existential_type_switch.exp: Add a regression test. tests/hard_coded/Mmakefile: Enable the existential_types_test.m test case, which should have been enabled previously. (The reason that it wasn't seems to be that I made a mistake when merging in the changes from the existential types branch.) |
||
|
|
00df2750bd |
Remove the limitation of user-guided type specialization that
Estimated hours taken: 50 Remove the limitation of user-guided type specialization that the replacement types must be ground. compiler/higher_order.m: Only add extra type-infos, not typeclass-infos when --typeinfo-liveness is set, extracting type-infos from typeclass-infos where necessary. The arguments of the specialized version are now independent of the class context of the requesting procedure, which maximises the chance of multiple specialized calls to the same procedure being able to use the same code. The code to specialize calls is now slightly simpler because it does not have to work out how to order extra typeclass-info arguments. Specialize special preds for no-tag types where the wrapped type is an atomic type and the no-tag type does not have a user-defined equality pred. This will be useful for specializations involving type `term__var/1'. Make sure the proc_infos for specialized procedures are valid before reanalyzing the goals requesting the specializations. Rework the handling of branched goals to ensure that pred_infos and proc_infos are single threaded through branched goals - when higher_order.m was first written they were constant. Always go over all procedures for every predicate to make sure unifications are specialized in all procedures. compiler/make_hlds.m: Check for type variables substituted multiple times or occurring on both sides of the substitution. Adjust the arity for specializations of functions. compiler/polymorphism.m: Make sure the vartypes field for imported procedures is valid by copying it from the clauses_info to the proc_info. compiler/polymorphism.m: compiler/simplify.m: compiler/table_gen.m: compiler/magic.m: Remove an unused argument from polymorphism__make_type_info_vars. compiler/type_util.m: compiler/det_analysis.m: Add a predicate `type_util__type_has_user_defined_equality_pred' replacing similar code in det_analysis.m. compiler/post_typecheck: Don't overwrite the vartypes field in the pred_info for automatically generated unification procedures for imported types. library/varset.m: Add predicates `varset__merge_without_names' and `varset__merge_subst_without_names'. compiler/equiv_type.m: Use the new predicates in varset.m to avoid adding the variable names from the declarations of equivalence types into the tvarsets of declarations which use those types. This is needed so that `varset__create_name_var_map' (used by make_hlds.m for `:- pragma type_spec' declarations and explicit type qualifications) is not confused by multiple occurrences of a variable name. doc/reference_manual.texi: Remove documentation of the limitation that the substituted types must be ground. tests/hard_coded/type_spec.m: tests/hard_coded/type_spec.err_exp: Tests for non-ground substitutions and specialization of unification of no-tag types. tests/invalid/type_spec.err_exp: Remove the error for a non-ground substitution. Add tests for recursive type substitutions and type variables with multiple replacement types. |
||
|
|
396fb9edcf |
Strip away io__state' (and store__store') arguments
Estimated hours taken: 1 Strip away `io__state' (and `store__store') arguments in the MLDS code generator. compiler/export.m: compiler/type_util.m: compiler/make_hlds.m: Move export__exclude_argument_type to type_util.m and rename it as type_util__is_dummy_argument_type. compiler/ml_code_gen.m: Omit arguments for which type_util__is_dummy_argument_type is true. compiler/mlds_to_c.m: Output `Bar foo(void)' rather than `Bar foo()' for functions with no parameters. |
||
|
|
b845fcb08f |
Fix a bug that was causing the compiler to fail the debugger
Estimated hours taken: 4 Fix a bug that was causing the compiler to fail the debugger tests with an unknown layout error. std_util:type_info/0 needs to be defined by hand so we can tell the RTTI system that it is a type_info. This change breaks bootstrapping with earlier compilers. Use the CVS tag bootstrap_19990719_handdefine_typeinfo to bootstrap this change. compiler/type_util.m: Add std_util:type_info/0 to the hand defined types. This is different to private_builtin:type_info/1 which was already there. It was type_info/0 that the debugger was failing on. library/builtin.m: Move the type_ctor_info for c_pointer back into this module. It should have finished bootstrapping by now. library/std_util.m: Define type_ctor_info as (abstractly) equivalent to a type_info instead of equivalent to a c_pointer. This will allow this type to be handled by the garbage collector or debugger. runtime/mercury_bootstrap.c: Move the RTTI info for c_pointer out of this module. Add the type_ctor_info for type_info/0 as it is now a hand defined type. tests/hard_coded/higher_order_type_manip.exp: Fix expected test results not that type_ctor_info is equivalent to type_info/0. Estimated hours taken: _____ <overview or general description of changes> <directory>/<file>: <detailed description of changes> |
||
|
|
2725b1a331 |
Aditi update syntax, type and mode checking.
Estimated hours taken: 220
Aditi update syntax, type and mode checking.
Change the hlds_goal for constructions in preparation for
structure reuse to avoid making multiple conflicting changes.
compiler/hlds_goal.m:
Merge `higher_order_call' and `class_method_call' into a single
`generic_call' goal type. This also has alternatives for the
various Aditi builtins for which type declarations can't
be written.
Remove the argument types field from higher-order/class method calls.
It wasn't used often, and wasn't updated by optimizations
such as inlining. The types can be obtained from the vartypes
field of the proc_info.
Add a `lambda_eval_method' field to lambda_goals.
Add a field to constructions to identify which RL code fragment should
be used for an top-down Aditi closure.
Add fields to constructions to hold structure reuse information.
This is currently ignored -- the changes to implement structure
reuse will be committed to the alias branch.
This is included here to avoid lots of CVS conflicts caused by
changing the definition of `hlds_goal' twice.
Add a field to `some' goals to specify whether the quantification
can be removed. This is used to make it easier to ensure that
indexes are used for updates.
Add a field to lambda_goals to describe whether the modes were
guessed by the compiler and may need fixing up after typechecking
works out the argument types.
Add predicate `hlds_goal__generic_call_id' to work out a call_id
for a generic call for use in error messages.
compiler/purity.m:
compiler/post_typecheck.m:
Fill in the modes of Aditi builtin calls and closure constructions.
This needs to know which are the `aditi__state' arguments, so
it must be done after typechecking.
compiler/prog_data.m:
Added `:- type sym_name_and_arity ---> sym_name/arity'.
Add a type `lambda_eval_method', which describes how a closure
is to be executed. The alternatives are normal Mercury execution,
bottom-up execution by Aditi and top-down execution by Aditi.
compiler/prog_out.m:
Add predicate `prog_out__write_sym_name_and_arity', which
replaces duplicated inline code in a few places.
compiler/hlds_data.m:
Add a `lambda_eval_method' field to `pred_const' cons_ids and
`pred_closure_tag' cons_tags.
compiler/hlds_pred.m:
Remove type `pred_call_id', replace it with type `simple_call_id',
which combines a `pred_or_func' and a `sym_name_and_arity'.
Add a type `call_id' which describes all the different types of call,
including normal calls, higher-order and class-method calls
and Aditi builtins.
Add `aditi_top_down' to the type `marker'.
Remove `aditi_interface' from type `marker'. Interfacing to
Aditi predicates is now handled by `generic_call' hlds_goals.
Add a type `rl_exprn_id' which identifies a predicate to
be executed top-down by Aditi.
Add a `maybe(rl_exprn_id)' field to type `proc_info'.
Add predicate `adjust_func_arity' to convert between the arity
of a function to its arity as a predicate.
Add predicates `get_state_args' and `get_state_args_det' to
extract the DCG state arguments from an argument list.
Add predicate `pred_info_get_call_id' to get a `simple_call_id'
for a predicate for use in error messages.
compiler/hlds_out.m:
Write the new representation for call_ids.
Add a predicate `hlds_out__write_call_arg_id' which
replaces similar code in mode_errors.m and typecheck.m.
compiler/prog_io_goal.m:
Add support for `aditi_bottom_up' and `aditi_top_down' annotations
on pred expressions.
compiler/prog_io_util.m:
compiler/prog_io_pragma.m:
Add predicates
- `prog_io_util:parse_name_and_arity' to parse `SymName/Arity'
(moved from prog_io_pragma.m).
- `prog_io_util:parse_pred_or_func_name_and_arity to parse
`pred SymName/Arity' or `func SymName/Arity'.
- `prog_io_util:parse_pred_or_func_and_args' to parse terms resembling
a clause head (moved from prog_io_pragma.m).
compiler/type_util.m:
Add support for `aditi_bottom_up' and `aditi_top_down' annotations
on higher-order types.
Add predicates `construct_higher_order_type',
`construct_higher_order_pred_type' and
`construct_higher_order_func_type' to avoid some code duplication.
compiler/mode_util.m:
Add predicate `unused_mode/1', which returns `builtin:unused'.
Add functions `aditi_di_mode/0', `aditi_ui_mode/0' and
`aditi_uo_mode/0' which return `in', `in', and `out', but will
be changed to return `di', `ui' and `uo' when alias tracking
is implemented.
compiler/goal_util.m:
Add predicate `goal_util__generic_call_vars' which returns
any arguments to a generic_call which are not in the argument list,
for example the closure passed to a higher-order call or
the typeclass_info for a class method call.
compiler/llds.m:
compiler/exprn_aux.m:
compiler/dupelim.m:
compiler/llds_out.m:
compiler/opt_debug.m:
Add builtin labels for the Aditi update operations.
compiler/hlds_module.m:
Add predicate predicate_table_search_pf_sym, used for finding
possible matches for a call with the wrong number of arguments.
compiler/intermod.m:
Don't write predicates which build `aditi_top_down' goals,
because there is currently no way to tell importing modules
which RL code fragment to use.
compiler/simplify.m:
Obey the `cannot_remove' field of explicit quantification goals.
compiler/make_hlds.m:
Parse Aditi updates.
Don't typecheck clauses for which syntax errors in Aditi updates
are found - this avoids spurious "undefined predicate `aditi_insert/3'"
errors.
Factor out some common code to handle terms of the form `Head :- Body'.
Factor out common code in the handling of pred and func expressions.
compiler/typecheck.m:
Typecheck Aditi builtins.
Allow the argument types of matching predicates to be adjusted
when typechecking the higher-order arguments of Aditi builtins.
Change `typecheck__resolve_pred_overloading' to take a list of
argument types rather than a `map(var, type)' and a list of
arguments to allow a transformation to be performed on the
argument types before passing them.
compiler/error_util.m:
Move the part of `report_error_num_args' which writes
"wrong number of arguments (<x>; expected <y>)" from
typecheck.m for use by make_hlds.m when reporting errors
for Aditi builtins.
compiler/modes.m:
compiler/unique_modes.m:
compiler/modecheck_call.m:
Modecheck Aditi builtins.
compiler/lambda.m:
Handle the markers for predicates introduced for
`aditi_top_down' and `aditi_bottom_up' lambda expressions.
compiler/polymorphism.m:
Add extra type_infos to `aditi_insert' calls
describing the tuple to insert.
compiler/call_gen.m:
Generate code for Aditi builtins.
compiler/unify_gen.m:
compiler/bytecode_gen.m:
Abort on `aditi_top_down' and `aditi_bottom_up' lambda
expressions - code generation for them is not yet implemented.
compiler/magic.m:
Use the `aditi_call' generic_call rather than create
a new procedure for each Aditi predicate called from C.
compiler/rl_out.pp:
compiler/rl_gen.m:
compiler/rl.m:
Move some utility code used by magic.m and call_gen.m into rl.m.
Remove an XXX comment about reference counting being not yet
implemented - Evan has fixed that.
library/ops.m:
compiler/mercury_to_mercury.m:
doc/transition_guide.texi:
Add unary prefix operators `aditi_bottom_up' and `aditi_top_down',
used as qualifiers on lambda expressions.
Add infix operator `==>' to separate the tuples in an
`aditi_modify' call.
compiler/follow_vars.m:
Thread a `map(prog_var, type)' through, needed because
type information is no longer held in higher-order call goals.
compiler/table_gen.m:
Use the `make_*_construction' predicates in hlds_goal.m
to construct constants.
compiler/*.m:
Trivial changes to add extra fields to hlds_goal structures.
doc/reference_manual.texi:
Document Aditi updates.
Use @samp{pragma base_relation} instead of
@samp{:- pragma base_relation} throughout the Aditi documentation
to be consistent with other parts of the reference manual.
tests/valid/Mmakefile:
tests/valid/aditi_update.m:
tests/valid/aditi.m:
Test case.
tests/valid/Mmakefile:
Remove some hard-coded --intermodule-optimization rules which are
no longer needed because `mmake depend' is now run in this directory.
tests/invalid/*.err_exp:
Fix expected output for changes in reporting of call_ids
in typecheck.m.
tests/invalid/Mmakefile
tests/invalid/aditi_update_errors.{m,err_exp}:
tests/invalid/aditi_update_mode_errors.{m,err_exp}:
Test error messages for Aditi updates.
tests/valid/aditi.m:
tests/invalid/aditi.m:
Cut down version of extras/aditi/aditi.m to provide basic declarations
for Aditi compilation such as `aditi__state' and the modes
`aditi_di', `aditi_uo' and `aditi_ui'. Installing extras/aditi/aditi.m
somewhere would remove the need for these.
|
||
|
|
8c97633e71 |
Allow construction unifications for existentially typed functors,
Estimated hours taken: 6 Allow construction unifications for existentially typed functors, using the syntax "X = 'new foo'(Y)" rather than the usual "X = foo(Y)". We need to use a special syntax for exisentially typed constructions because type analysis and polymorphism need to know which occurrences of existentially typed functors are constructors and which are deconstructors. Note that we still don't yet support RTTI for existentially typed data types. compiler/typecheck.m: For existentially typed functors, allow the functor to have a "new " prefix, and if so, make the quantifiers and constraints universal rather than existential. compiler/polymorphism.m: For unifications with existentially typed functors, check for a "new " prefix on the functor. If the functor has such a prefix, strip off the prefix, and treat the unification as a construction rather than treating it as a deconstruction. compiler/type_util.m: Define a new predicate `remove_new_prefix', for use by typecheck.m and polymorphism.m. compiler/modecheck_unify.m: For construction unifications, check that all the type_info and typeclass_info arguments introduced by polymorphism.m are ground. tests/hard_coded/typeclasses/existential_data_types.m: Change the test case to use this new feature, rather than hacking it using the C interface. doc/reference_manual.texi: Document the new features. |
||
|
|
ec86c88404 |
Merge in the changes from the existential_types_2 branch.
Estimated hours taken: 4 Merge in the changes from the existential_types_2 branch. This change adds support for mode re-ordering of code involving existential types. The change required modifying the order of the compiler passes so that polymorphism comes before mode analysis, so that mode analysis can check the modes of the `type_info' or `typeclass_info' variables that polymorphism introduces, so that it can thus re-order the code accordingly. This change also includes some more steps towards making existential data types work. In particular, you should be able to declare existentially typed data types, the compiler will generate appropriate unification and compare/3 routines for them, and deconstruction unifications for them should work OK. However, currently there's no way to construct them except via `pragam c_code', and we don't generate correct RTTI for them, so you can't use `io__write' etc. on them. library/private_builtin.m: compiler/accumulator.m: compiler/bytecode_gen.m: compiler/check_typeclass.m: compiler/clause_to_proc.m: compiler/code_util.m: compiler/common.m: compiler/dead_proc_elim.m: compiler/dependency_graph.m: compiler/det_analysis.m: compiler/det_report.m: compiler/follow_code.m: compiler/follow_vars.m: compiler/goal_util.m: compiler/higher_order.m: compiler/hlds_goal.m: compiler/hlds_out.m: compiler/hlds_pred.m: compiler/intermod.m: compiler/lambda.m: compiler/live_vars.m: compiler/magic.m: compiler/make_hlds.m: compiler/mercury_compile.m: compiler/mercury_to_c.m: compiler/mode_errors.m: compiler/mode_info.m: compiler/mode_util.m: compiler/modecheck_call.m: compiler/modecheck_unify.m: compiler/modes.m: compiler/pd_cost.m: compiler/polymorphism.m: compiler/post_typecheck.m: compiler/purity.m: compiler/quantification.m: compiler/rl_exprn.m: compiler/rl_key.m: compiler/simplify.m: compiler/table_gen.m: compiler/term_traversal.m: compiler/type_util.m: compiler/typecheck.m: compiler/unify_gen.m: compiler/unify_proc.m: compiler/unique_modes.m: compiler/unused_args.m: compiler/notes/compiler_design.html: doc/reference_manual.texi: tests/hard_coded/typeclasses/Mmakefile: tests/hard_coded/typeclasses/existential_data_types.m: tests/hard_coded/typeclasses/existential_data_types.exp: tests/warnings/simple_code.exp: tests/hard_coded/Mmakefile: tests/term/arit_exp.trans_opt_exp: tests/term/associative.trans_opt_exp: tests/term/pl5_2_2.trans_opt_exp: tests/term/vangelder.trans_opt_exp: tests/term/arit_exp.trans_opt_exp: tests/term/associative.trans_opt_exp: tests/term/pl5_2_2.trans_opt_exp: tests/term/vangelder.trans_opt_exp: tests/invalid/errors2.err_exp2: tests/invalid/prog_io_erroneous.err_exp2: tests/invalid/type_inf_loop.err_exp2: tests/invalid/types.err_exp2: tests/invalid/polymorphic_unification.err_exp: tests/invalid/Mmakefile: tests/warnings/simple_code.exp: tests/debugger/queens.exp: tests/hard_coded/Mmakefile: tests/hard_coded/existential_reordering.m: tests/hard_coded/existential_reordering.exp: Merge in the changes from the existential_types_2 branch. |
||
|
|
2eb7e77257 |
c_pointer needs to be a hand defined type -- up until now everything but
Estimated hours taken: 0.5 c_pointer needs to be a hand defined type -- up until now everything but the type_ctor_info is hand defined. We need to be able to change the contents of the type_ctor_info, however. compiler/type_util.m: library/builtin.m: runtime/mercury_bootstrap.c: Make builtin:c_pointer a hand-defined type, doing the usual bootstrapping trick. |
||
|
|
354ba90db6 |
Making changes to type_ctor_infos for the builtin types array and univ
Estimated hours taken: 2 Making changes to type_ctor_infos for the builtin types array and univ is much easier if we can simply change their type_ctor_info by hand rather than detecting them as simple cases. They already have their type_ctor_functors and layouts defined by hand anyway. compiler/type_util.m: Turn off the generation of type_ctor_info for the types array:array and std_util:univ. runtime/mercury_bootstrap.c: Put type_ctor_infos for these types into the bootstrapping file. They are not needed (or wanted) for stage 1, but needed for stage 2. We rename the functors and layouts slightly so that the stage 2 linking doesn't have them multiply defined. |
||
|
|
79dcbbef15 |
User-guided type specialization.
Estimated hours taken: 60 User-guided type specialization. compiler/prog_data.m: compiler/prog_io_pragma.m: compiler/modules.m: compiler/module_qual.m: compiler/mercury_to_mercury.m: Handle `:- pragma type_spec'. compiler/prog_io_pragma.m: Factor out some common code to parse predicate names with arguments. compiler/hlds_module.m: Added a field to the module_sub_info to hold information about user-requested type specializations, filled in by make_hlds.m and not used by anything after higher_order.m. compiler/make_hlds.m: For each `:- pragma type_spec' declaration, introduce a new predicate which just calls the predicate to be specialized with the specified argument types. This forces higher_order.m to produce the specialized versions. compiler/higher_order.m: Process the user-requested type specializations first to ensure that they get the correct names. Allow partial matches against user-specified versions, e.g. map__lookup(map(int, list(int)), int, list(int)) matches map__lookup(map(int, V), int, V). Perform specialization where a typeclass constraint matches a known instance, but the construction of the typeclass_info is done in the calling module. Give slightly more informative progress messages. compiler/dead_proc_elim.m: Remove specializations for dead procedures. compiler/prog_io_util.m: Change the definition of the `maybe1' and `maybe_functor' types to avoid the need for copying to convert between `maybe1' and `maybe1(generic)'. Changed the interface of `make_pred_name_with_context' to allow creation of predicate names for type specializations which describe the type substitution. compiler/make_hlds.m: compiler/prog_io_pragma.m: Make the specification of pragma declarations in error messages consistent. (There are probably some more to be fixed elsewhere for termination and tabling). compiler/intermod.m: Write type specialization pragmas for predicates declared in `.opt' files. compiler/mercury_to_mercury.m: Export `mercury_output_item' for use by intermod.m. compiler/options.m: Add an option `--user-guided-type-specialization' enabled with `-O2' or higher. compiler/handle_options.m: `--type-specialization' implies `--user-guided-type-specialization'. compiler/hlds_goal.m: Add predicates to construct constants. These are duplicated in several other places, I'll fix that as a separate change. compiler/type_util.m: Added functions `int_type/0', `string_type/0', `float_type/0' and `char_type/0' which return the builtin types. These are duplicated in several other places, I'll fix that as a separate change. library/private_builtin.m: Added `instance_constraint_from_typeclass_info/3' to extract the typeclass_infos for a constraint on an instance declaration. This is useful for specializing class method calls. Added `thread_safe' to various `:- pragma c_code's. Added `:- pragma inline' declarations for `builtin_compare_*', which are important for user-guided type specialization. (`builtin_unify_*' are simple enough to go in the `.opt' files automatically). compiler/polymorphism.m: `instance_constraint_from_typeclass_info/3' does not need type_infos. Add `instance_constraint_from_typeclass_info/3' to the list of `typeclass_info_manipulator's which higher_order.m can interpret. NEWS: doc/reference_manual.texi: doc/user_guide.texi Document the new pragma and option. tests/invalid/Mmakefile: tests/invalid/type_spec.m: tests/invalid/type_spec.err_exp: Test error reporting for invalid type specializations. tests/hard_coded/Mmakefile: tests/invalid/type_spec.m: tests/invalid/type_spec.exp: Test type specialization. |
||
|
|
ec5cfac2e8 |
Rename some missed references to base_type_* as type_ctor_* in
Estimated hours taken: 0.1 compiler/base_type_layout.m: compiler/polymorphism.m: compiler/type_util.m: Rename some missed references to base_type_* as type_ctor_* in some comments and an error message. |
||
|
|
1f312b45e9 |
During the writing of the RTTI paper, we decided that type_ctor_info
Estimated hours taken: 8
During the writing of the RTTI paper, we decided that type_ctor_info
was a much better name than base_type_info.
Rename base_type* as type_ctor*, except we don't rename the modules
base_type_info and base_type_layout just yet.
Most of these changes were made using the following sed patterns:
s/base_type_info/type_ctor_info/g
s/base_type_layout/type_ctor_layout/g
s/base_type_functors/type_ctor_functors/g
s/BASETYPE_INFO/TYPE_CTOR_INFO/g
s/TYPEFUNCTORS/TYPE_CTOR_FUNCTORS/g
s/TYPELAYOUT/TYPE_CTOR_LAYOUT/g
s/BASE_TYPEINFO/TYPE_CTOR_INFO/g
s/BASE_TYPE_INFO/TYPE_CTOR_INFO/g
s/BaseTypeInfo/TypeCtorInfo/g
s/BaseTypeLayout/TypeCtorLayout/g
s/base_type(/type_ctor(/g
s/:- module type_ctor_info/:- module base_type_info/g
s/:- module type_ctor_layout/:- module base_type_layout/g
s/type_ctor_info__/base_type_info__/g
s/type_ctor_layout__/base_type_layout__/g
/import_module/s/type_ctor_info/base_type_info/g
/import_module/s/type_ctor_layout/base_type_layout/g
compiler/*.m:
library/*.m:
runtime/*.{c,h}:
profiler/demangle.m:
util/mdemangle.c:
Applied the above sed commands.
runtime/mercury_bootstrap.h:
Add bootstrapping #defines so the type_ctor_* substitutions in
the library don't cause link problems.
Delete some redundant bootstrapping definitions.
|
||
|
|
18430aaef1 |
Aditi compilation.
Estimated hours taken: 1200
Aditi compilation.
compiler/options.m:
The documentation for these is commented out because the Aditi
system is not currently useful to the general public.
--aditi: enable Aditi compilation.
--dump-rl: write the intermediate RL to `<module>.rl_dump'.
--dump-rl-bytecode: write a text version of the bytecodes
to `<module>.rla'
--aditi-only: don't produce a `.c' file.
--filenames-from-stdin: accept a list of filenames to compile
from stdin. This is used by the query shell.
--optimize-rl, --optimize-rl-cse, --optimize-rl-invariants,
--optimize-rl-index, --detect-rl-streams:
Options to control RL optimization passes.
--aditi-user:
Default owner of any Aditi procedures,
defaults to $USER or "guest".
--generate-schemas:
write schemas for base relations to `<module>'.base_schema
and schemas for derived relations to `<module>'.derived_schema.
This is used by the query shell.
compiler/handle_options.m:
Handle the default for --aditi-user.
compiler/hlds_pred.m:
compiler/prog_data.m:
compiler/prog_io_pragma.m:
compiler/make_hlds.m:
Add some Aditi pragma declarations - `aditi', `supp_magic', `context',
`naive', `psn' (predicate semi-naive), `aditi_memo', `aditi_no_memo',
`base_relation', `owner' and `index'.
Separate out code to parse a predicate name and arity.
compiler/hlds_pred.m:
Add predicates to identify Aditi procedures.
Added markers `generate_inline' and `aditi_interface', which
are used internally for Aditi code generation.
Add an `owner' field to pred_infos, which is used for database
security checks.
Add a field to pred_infos to hold the list of indexes for a base
relation.
compiler/make_hlds.m:
Some pragmas must be exported if the corresponding predicates
are exported, check this.
Make sure stratification of Aditi procedures is checked.
Predicates with a mode declaration but no type declaration
are no longer assumed to be local.
Set the `do_aditi_compilation' field of the module_info if there
are any local Aditi procedures or base relations.
Check that `--aditi' is set if Aditi compilation is required.
compiler/post_typecheck.m:
Check that every Aditi predicate has an `aditi__state' argument,
which is used to ensure sequencing of updates and that Aditi
procedures are only called within transactions.
compiler/dnf.m:
Changed the definition of disjunctive normal form slightly
so that a call followed by some atomic goals not including
any database calls is considered atomic. magic.m can handle
this kind of goal, and it results in more efficient RL code.
compiler/hlds_module.m:
compiler/dependency_graph.m:
Added dependency_graph__get_scc_entry_points which finds
the procedures in an SCC which could be called from outside.
Added a new field to the dependency_info, the
aditi_dependency_ordering. This contains all Aditi SCCs of
the original program, with multiple SCCs merged where
possible to improve the effectiveness of differential evaluation
and the low level RL optimizations.
compiler/hlds_module.m:
Add a field to record whether there are any local Aditi procedures
in the current module.
Added versions of module_info_pred_proc_info and
module_info_set_pred_proc_info which take a pred_proc_id,
not a separate pred_id and proc_id.
compiler/polymorphism.m:
compiler/lambda.m:
Make sure that predicates created for closures in Aditi procedures
have the correct markers.
compiler/goal_util.m:
Added goal_util__switch_to_disjunction,
goal_util__case_to_disjunct (factored out from simplify.m)
and goal_util__if_then_else_to_disjunction. These are
require because supplementary magic sets can't handle
if-then-elses or switches.
compiler/type_util.m:
Added type_is_aditi_state/1.
compiler/mode_util.m:
Added partition_args/5 which partitions a list of arguments
into inputs and others.
compiler/inlining.m:
Don't inline memoed procedures.
Don't inline Aditi procedures into non-Aditi procedures.
compiler/intermod.m:
Handle Aditi markers.
Clean up handling of markers which should not appear in `.opt' files.
compiler/simplify.m:
Export a slightly different interface for use by magic.m.
Remove explicit quantifications where possible.
Merge multiple nested quantifications.
Don't report infinite recursion warnings for Aditi procedures.
compiler/prog_out.m:
Generalised the code to output a module list to write any list.
compiler/code_gen.m:
compiler/arg_info.m:
Don't process Aditi procedures.
compiler/mercury_compile.m:
Call magic.m and rl_gen.m.
Don't perform the low-level annotation passes on Aditi procedures.
Remove calls to constraint.m - sometime soon a rewritten version
will be called directly from deforestation.
compiler/passes_aux.m:
Add predicates to process only non-Aditi procedures.
compiler/llds.m:
compiler/llds_out.m:
Added new `code_addr' enum members, do_{det,semidet,nondet}_aditi_call,
which are defined in extras/aditi/aditi.m.
compiler/call_gen.m:
Handle generation of do_*_aditi_call.
compiler/llds_out.m:
Write the RL code for the module as a constant char array
in the `.c' file.
compiler/term_errors.m:
compiler/error_util.m:
Move code to describe predicates into error_util.m
Allow the caller to explicitly add line breaks.
Added error_util:list_to_pieces to format a list of
strings.
Reordered some arguments for currying.
compiler/hlds_out.m:
Don't try to print clauses if there are none.
runtime/mercury_init.h:
util/mkinit.c:
scripts/c2init.in:
Added a function `mercury__load_aditi_rl_code()' to the generated
`<module>_init.c' file which throws all the RL code for the program
at the database. This should be called at connection time by
`aditi__connect'.
Added an option `--aditi' which controls the output
`mercury__load_aditi_rl_code()'.
compiler/notes/compiler_design.html:
Document the new files.
Mmakefile:
bindist/Mmakefile:
Don't distribute extras/aditi yet.
New files:
compiler/magic.m:
compiler/magic_util.m:
Supplementary magic sets transformation. Report errors
for constructs that Aditi can't handle.
compiler/context.m:
Supplementary context transformation.
compiler/rl_gen.m:
compiler/rl_relops.m:
Aditi code generation.
compiler/rl_info.m:
Code generator state.
compiler/rl.m:
Intermediate RL representation.
compiler/rl_util:
Predicates to collect information about RL instructions.
compiler/rl_dump.m:
Print out the representation in rl.m.
compiler/rl_opt.m:
Control low-level RL optimizations.
compiler/rl_block.m:
Break a procedure into basic blocks.
compiler/rl_analyse.m:
Generic dataflow analysis for RL procedures.
compiler/rl_liveness.m:
Make sure all relations are initialised before used, clear
references to relations that are no longer required.
compiler/rl_loop.m:
Loop invariant removal.
compiler/rl_block_opt.m:
CSE and instruction merging on basic blocks.
compiler/rl_key.m:
Detect upper/lower bounds for which a goal could succeed.
compiler/rl_sort.m:
Use indexing for joins and projections.
Optimize away unnecessary sorting and indexing.
compiler/rl_stream.m:
Detect relations which don't need to be materialised.
compiler/rl_code.m:
RL bytecode definitions. Automatically generated from the Aditi
header files.
compiler/rl_out.m:
compiler/rl_file.m:
Output the RL bytecodes in binary to <module>.rlo (for use by Aditi)
and in text to <module>.rla (for use by the RL interpreter).
Also output the schema information if --generate-schemas is set.
compiler/rl_exprn.m:
Generate bytecodes for join conditions.
extras/aditi/Mmakefile:
extras/aditi/aditi.m:
Definitions of some Aditi library predicates and the
interfacing and transaction processing code.
|
||
|
|
5c955626f2 |
These changes make var' and term' polymorphic.
Estimated hours taken: 20 These changes make `var' and `term' polymorphic. This allows us to make variables and terms representing types of a different type to those representing program terms and those representing insts. These changes do not *fix* any existing problems (for instance there was a messy conflation of program variables and inst variables, and where necessary I've just called varset__init(InstVarSet) with an XXX comment). NEWS: Mention the changes to the standard library. library/term.m: Make term, var and var_supply polymorphic. Add new predicates: term__generic_term/1 term__coerce/2 term__coerce_var/2 term__coerce_var_supply/2 library/varset.m: Make varset polymorphic. Add the new predicate: varset__coerce/2 compiler/prog_data.m: Introduce type equivalences for the different kinds of vars, terms, and varsets that we use (tvar and tvarset were already there but have been changed to use the polymorphic var and term). Also change the various kinds of items to use the appropriate kinds of var/varset. compiler/*.m: Thousands of boring changes to make the compiler type correct with the different types for type, program and inst vars and varsets. |
||
|
|
3447bf5083 |
Define the types typeclass_info and base_typeclass_info by hand,
Estimated hours taken: 3 Define the types typeclass_info and base_typeclass_info by hand, so that they can be recognized as special cases in the runtime system. At the same time, move the definitions of type_info and base_type_info back into private_builtin.m. They had been placed in runtime/mercury_bootstrap for bootstrapping purposes, but have now been bootstrapped (and will be replaced by typeclass_info which will undergo the same process). compiler/base_type_layout.m: Add typeclass_info to the special cases. compiler/type_util.m: Turn off base_type_info generation for typeclass_info and base_typeclass_info. library/private_builtin.m: Move the definitions of type_info and base_type_info to here. runtime/mercury_bootstrap.c: Add handwritten definitions of the typeclass_info and base_typeclass_info types. runtime/mercury_type_info.c: runtime/mercury_type_info.h: Rename all the TYPELAYOUT_*_VALUE #defines as MR_TYPELAYOUT_*_VALUE enum values. Leave forwarding definitions for backwards compatability (temporary). Add MR_TYPELAYOUT_TYPECLASSINFO_VALUE to the MR_TypeLayoutValue. Add MR_DATAREP_TYPECLASSINFO. |
||
|
|
f05dc52d86 |
Fix a bug in the renaming of tvars in type class constraint proofs, and
Estimated hours taken: 20
Fix a bug in the renaming of tvars in type class constraint proofs, and
generally clean up the handling of variable renaming in polymorphism.m.
Change the representation of constraint_proofs to only hold the number of an
instance declaration and not the hlds_instance_defn itself. This means that
polymorphism must look up the instance table to get at hlds_instance_defn,
then calculate the appropriate renamings and substitutions. The rationale
behind this is that the proofs for the superclasses, stored in the
hlds_instance_defn, also need to be renamed. However, we can't just rename
them during typecheck.m because they may not contain proofs for *all* their
ancestors --- that would require topologically sorting the instance defns
before check_typeclass.m.
Also delete the code which attempts to specialise class method calls because
Simon's recent change does this anyway.
hlds_data.m:
Change the constraint_proof representation to only hold instance
numbers, not definitions.
polymorphism.m:
When applying an instance decl, look it up in the instance table
rather than trying to use the half-renamed one in the proof.
Also, rather than trying to pass down a renaming substution into
polymorphism__make_typeclass_info_var, rename everything before
calling it.
type_util.m:
Add two new predicates: apply_subst_to_constraint_proofs and
apply_rec_subst_to_constraint_proofs.
typecheck.m:
Only store the instance number in the proof.
|
||
|
|
3e244090d7 |
Rework the handling of types in higher_order.m.
Estimated hours taken: 50 Rework the handling of types in higher_order.m. - Fix bugs in higher_order.m that stopped it working with --typeinfo-liveness. - Perform type and typeclass specialisation. compiler/polymorphism.m: Previously the type of typeclass_infos variables did not contain any information about the constraint about which the variable contains information. Now the type of a typeclass_info is `private_builtin:typeclass_info( private_builtin:constraint([ClassName, ConstrainedTypes]))'. This allows predicates such as type_list_subsumes to check that the class constraints match. Note that `private_builtin:constraint' has no declaration, so a lookup in the type definition map will fail. That's OK, because type_to_type_id will fail on it, so it will be treated as a type variable by any code which doesn't manipulate types directly. Added polymorphism__typeclass_info_class_constraint to get the class_constraint from a typeclass_info's type. This isn't used yet. Also, fix a bug in extract_type_info: an entry in the typeinfo_var_map was being overwritten using an entry from a dummy typevarset. Actually the optimization to overwrite the location of the type_info after extracting it from a typeclass_info was wrong because the type_info won't be in that location in other branches. compiler/higher_order.m: Rework the handling of type substitutions. Now the types of the called procedure are `inlined' into the calling procedure, rather than building up the types of the specialised version using the higher-order arguments. The advantage of this is that the code is a bit simpler and handles extra type_infos properly. The disadvantage is that the argument types for specialised versions may be more specific than they need to be, so in some cases more specialised versions will be created than before. Also, don't actually rebuild the higher-order terms in the specialised versions - just pass the terms through in case they are needed. Handle the extra typeinfos required for --typeinfo-liveness. Specialize calls to unify/2, index/2 and compare/3. Specialize class_method_calls. Specialize calls to the predicates in private_builtin.m which manipulate typeclass_infos. compiler/type_util.m: type_to_type_id now fails on the dummy `constraint' type. Remove typeinfos for non-variable types from the typeinfo_varmap after inlining and higher-order specialisation. compiler/inlining.m: Factor out some common code to handle type substitutions for use by higher_order.m. compiler/hlds_pred.m: Return the list of extra type_info variables added to the argument list. compiler/goal_util.m: Take a set of non-locals as an argument to goal_util__extra_nonlocal_typeinfos rather than extracting them from a goal. compiler/special_pred.m: Handle unmangled unify/compare/index in special_pred_get_type. compiler/base_type_layout.m: Don't generate references to the typeinfo for `private_builtin:constraint' - it doesn't exist. compiler/unused_args.m: Don't barf on specialised unification predicate names. compiler/options.m: Added options: `--type-specialization' (default off). `--higher-order-size-limit' - restrict the size of specialized versions produced by higher_order.m. `--disable-opt-for-trace' (default on) - where possible don't change the options to make the trace match the source code. compiler/handle_options.m: Don't disable higher_order.m when --typeinfo-liveness is set. Handle `--disable-opt-for-trace'. compiler/hlds_data.m: compiler/*.m: Add the instance number to `base_typeclass_info_const' cons_ids, so that higher_order.m can easily index into the list of instances for a class to find the methods. compiler/hlds_out.m: Use the correct varset when printing out the constraint proofs. Write the typeclass_info_varmap for each procedure. compiler/mercury_to_mercury.m: Print type variables with variable numbers. library/private_builtin.m: Add the argument to the typeclass_info type to hold the representation of the constraint. runtime/mercury_ho_call.c: Semidet and nondet class_method_calls where (0 < num_arg_typeclass_infos < 4) were aborting at runtime because arguments were being placed starting at r1 rather than at r(1 + num_arg_typeclass_infos). doc/user_guide.texi Document the new options. compiler/notes/compiler_design.html: Update the role of higher_order.m. tests/hard_coded/typeclasses/extra_typeinfo.m: Test case for the mercury_ho_call.c bug and the polymorphism.m extract_typeinfo bug and for updating the typeclass_info_varmap for specialised versions. |
||
|
|
01e0972fcd |
Don't generate base_type_* structures or special preds for
Estimated hours taken: 5 Don't generate base_type_* structures or special preds for private_builtin:type_info/1 and private_builtin:base_type_info/1. This allows us to write definitions for it by hand. compiler/base_type_info.m: compiler/base_type_layout.m: Don't generate structures if type_id_is_hand_defined for that type_id. compiler/make_hlds.m: compiler/unify_proc.m: Don't generate special preds if type_id_is_hand_defined for that type_id. compiler/type_util.m: Define type_id_is_hand_defined. |
||
|
|
6455e041cb |
Merge in the changes from the existential types branch,
Estimated hours taken: 6
(plus another 80 or so already recorded for
my commits on the existential_types branch)
Merge in the changes from the existential types branch,
and make some modifications to address dgj's code review comments.
These changes add support for existentially quantified type variables
and type class constraints on functions and predicates.
(Existential data types, however, are not supported -- see below.)
Existentially quantified type variables are introduced with
an explicit `some [T]', e.g. `:- some [T] pred foo(T)'.
Existentially quantified type class constraints are introduced
with `&' instead of `<=', e.g. `:- some [T] (pred foo(T) & ord(T))'.
There's still several limitations:
0. XXX It's not yet documented in the language reference manual.
1. XXX It doesn't do any mode checking or mode reordering.
If you write code that uses existentially typed procedures in the
wrong order, then you'll get an internal error in polymorphism.m
or in the code generator. (Cases where a type_info has no
producer at all are caught by the check for unbound type
variables in post_typecheck.m.)
To support this, we need to change things so that polymorphism.m
gets invoked before mode checking.
2. Using `in' modes on arguments of existential type won't work.
If you try, you will get a compile error.
It would be nice to extend things to allow this kind of
"implied mode" for type_infos, where an existential type
becomes a universal type if some value of that type is
input. Supporting this would require first fixing
limitation 1 (described above) and then
3. There's no support for `pragma c_code' for procedures
with existential type class constraints.
(In fact, there's not really any support for `pragma c_code'
for procedures with universal type class constraints either --
the C code has no way of getting access to the type class info.)
4. XXX Taking the address of something which is existentially typed
should be illegal, but we don't check this.
In addition, these changes in this batch make a start towards allowing
existentially typed data types. The compiler now accepts existential
quantifiers and type class constraints on type definitions, and type
checks them accordingly (assuming all functor occurrences are
deconstructors, not constructors -- see limitation 2 above). But
there's no special handling for them in polymorphism.m, so if you try
to use them, it will abort with an internal error.
The changes also includes fixes for a couple of bugs in typechecking
and polymorphism that I discovered while making the above changes,
and an improvement to the error reporting from typecheck.m in one case.
Those changes are listed separately below.
compiler/prog_data.m:
Add a new type `class_constraints', which holds two different
lists of constraints, namely the existentially quantified constraints
and the universally quantified ones.
Add a new field to the parse tree representation of pred and
func declarations to hold a list of the existentially quantified
type variables, and change the `list(class_constraint)' into
`class_constraints' so that we can store existential constraints too.
Add new fields to the `constructor' data type (formerly just a pair)
to hold the existentially quantified type variables and
type class constraints.
compiler/hlds_pred.m:
Add several new fields to the pred_info:
- a list of the existentially quantified type variables;
- a list of the "HeadTypeParams": type variables which
cannot be bound by this predicate (i.e. those whose type_infos
come from this pred's caller or are returned from
other preds called by this one);
- and a list of unsatisfied type class constraints.
Add a predicate pred_info_get_univ_quant_tvars to compute the
universally quantified type variables.
Change the pred constraints field from `list(class_constraint)'
to `class_constraints' so that it can hold existential constraints too.
compiler/hlds_data.m:
Add new fields to hlds_cons_defn to hold the existentially
quantified type variables and type class constraints.
compiler/*.m:
Minor changes to reflect the above-mentioned data structure
changes in prog_data.m, hlds_pred.m, and hlds_data.m.
compiler/prog_io.m:
Add code to parse the new constructs.
Also rewrite the code for parsing purity specifiers,
type quantifiers and type class constraints, using basically
the method suggested by Peter Schachte: treat these as
"declaration attributes", and have parse_decl strip off
all the declaration attributes into a seperate list and
then pass that list to process_decl, which for each different
kind of declaration processes the attributes which are
appropriate for that declaration and then calls check_no_attributes
to ensure that there were no inappropriate attributes.
The purpose of this rewrite was to allow it to handle the new
constructs properly, and to avoid unnecessary code duplication.
compiler/mercury_to_mercury.m:
Add code to pretty-print the new constructs.
compiler/make_hlds.m:
Copy the new fields in the parse tree into the
corresponding new fields in the pred_info.
Add code to check for various misuses of quantifiers.
compiler/hlds_out.m:
Print out the new fields in the pred_info (except the
unsatisfied type class constraints -- if these are non-empty,
post_typecheck.m will print them out in the error message).
When printing out types, pass the AppendVarNums parameter down,
so that HLDS dumps will distinguish between different type
variables that have the same name.
Delete hlds_out__write_constructor, since it was doing exactly
the same thing as mercury__output_ctor.
compiler/typecheck.m:
Lots of changes to handle existential types and existential
type class constraints.
compiler/post_typecheck.m:
When checking for unbound type variables,
use the value of HeadTypeParams from the pred_info.
compiler/type_util.m:
Delete `type_and_constraint_list_matches_exactly', since it was not
used. Add various `apply_variable_renaming_to_*' predicates for
renaming constraints.
compiler/polymorphism.m:
Lots of changes to handle existential types and existential
type class constraints.
Also some changes to make the code more maintainable:
compiler/prog_data.m:
compiler/hlds_goal.m:
compiler/mercury_to_mercury.m:
Put curly braces around the definitions of 'some'/2 and '&'/2 functors
in `:- type' definitions, to avoid them being misinterpreted as
existential type constraints.
compiler/goal_util.m:
compiler/polymorphism.m:
compiler/hlds_pred.m:
compiler/lambda.m:
Include type_infos for existentially quantified type variables
and type_class_infos for existential constraints
in the set of extra variables computed by
goal_util__extra_type_info_vars.
compiler/inlining.m:
Change inlining__do_goal to handle inlining of calls to
existentially typed predicates -- for them, instead of not
binding any type variables at all in the caller, it allows the
call to bind any type variables in the caller except for those
that are universally quantified.
compiler/inlining.m:
compiler/deforest.m:
Call pred_info_get_univ_quant_tvars and pass the
result to inlining__do_inline_goal.
tests/hard_coded/Mmakefile:
tests/hard_coded/existential_types_test.{m,exp}:
tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/existential_type_classes.{m,exp}:
Test cases for the use of existential types and
existential type class constraints.
----------
Improve an error message.
compiler/typecheck.m:
Improve error reporting by checking type class constraints for
satisfiability as we go and thus reporting unsatisfiable constraints
as soon as possible, rather than only at the end of the clause.
Previously we already did that for the case of ground constraints,
but they are not the only unsatsfiable constraints: constraints
on head type params (type variables which cannot be bound) are
also unsatisfiable if they can't be eliminated straight away
by context reduction.
tests/invalid/Mmakefile:
tests/invalid/typeclass_test_7.{m,err_exp}:
Regression test for the above change.
----------
Avoid problems where type inference was reporting some
spurious errors for predicates using type classes,
because the check for unsatisfied type class constraints
was being done before the final pass of type inference
had finished.
compiler/hlds_pred.m:
Add new field to the pred_info containing the unproven
type class constraints.
compiler/typecheck.m:
When inferring type class constraints, make sure that before
we save the results back in the pred_info, we restrict the
constraints to the head type variables. Constraints
on other type variables should be treated as
unsatisfied constraints.
Don't check for unsatisfied type class constraints at the
end of each pass; instead, just save the unproven type class
constraints in the pred_info.
compiler/post_typecheck.m:
Check for unsatisfied type class constraints, using
the new field in the pred_info.
tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/inference_test_2.{m,exp}:
tests/invalid/Mmakefile:
tests/invalid/typeclass_test_8.{m,err_exp}:
Add regression tests for this change.
----------
Fix a bug with the computation of the non-locals for
predicates with more than one constraint on the same type variable --
it was only including one of the type-class-infos, rather than all of them.
compiler/goal_util.m:
Change `goal_util__extra_nonlocal_typeinfos' so that it gets
passed the TypeClassInfoVarMap and uses this to include all
the appropriate typeclass infos in the extra nonlocals.
compiler/hlds_pred.m:
compiler/lambda.m:
compiler/polymorphism.m:
Pass the TypeClassInfoVarMap to `goal_util__extra_nonlocal_typeinfos'.
tests/hard_coded/typeclasses/Mmakefile:
tests/hard_coded/typeclasses/lambda_multi_constraint_same_tvar.{m,exp}:
Regression test for the above-mentioned bug.
|
||
|
|
fd691889bf |
Get rid of unnecessary type variables when creating the auxiliary predicate
Estimated hours taken: 3
Get rid of unnecessary type variables when creating the auxiliary predicate
for an instance method. This will hopefully be a little more robust than
the current approach since typecheck.m is now able to get rid of any unused
tvars... they *must* have been introduced by type inference.
library/varset.m:
Add a predicate varset__squash which gets rid of unused variables.
compiler/check_typeclass.m:
Call varset__squash to get rid of the unnecessary tvars.
compiler/typecheck.m:
Call varset__squash to get rid of the unnecessary tvars, rather than
doing it "manually".
compiler/type_util.m:
Add a new pred apply_variable_renaming_to_constraint.
|
||
|
|
247b1c24b9 |
Fix various invasions of the user's namespace by `mercury_builtin.m',
Estimated hours taken: 6
Fix various invasions of the user's namespace by `mercury_builtin.m',
by splitting mercury_builtin.m into two modules, called builtin.m and
private_builtin.m, and ensuring that the latter is imported as if
by `:- use_module' rather than `:- import_module'.
library/builtin.m:
library/private_builtin.m:
Split mercury_builtin.m into two modules, builtin.m,
which contains stuff intended to be public,
and private_builtin.m, which contains implementation
details that are not supposed to be public.
library/mercury_builtin.m:
Add a comment saying that this module is no longer used, and
should eventually be removed. I have not removed it yet, since
that would prevent bootstrapping with the current compiler. It
will be removed as a seperate change later, once all the
changes have propagated.
compiler/prog_util.m:
Change the definition of mercury_private_builtin_module/1 and
mercury_public_builtin_module so that instead of automatically
importing mercury_builtin.m as if by `import_module', the
copiler will now automatically import builtin.m as if by
`import_module' and private_builtin.m as if by `use_module'.
compiler/polymorphism.m:
Change a call to mercury_private_builtin_module/1 for
unsafe_promise_unique to instead call mercury_public_builtin_module/1.
compiler/unify_proc.m:
Avoid hard-coding "mercury_builtin" by instead
calling one of mercury_{private,public}_builtin_module/1.
runtime/mercury_type_info.[ch]:
library/term.m:
library/std_util.m:
compiler/code_util.m:
Change a few hard-coded instances of "mercury_builtin"
to "builtin" or "private_builtin" as appropriate.
runtime/mercury_trace_util.c:
runtime/mercury_trace_internal.c:
library/prolog.m:
compiler/*.m:
Update comments that refer to "mercury_builtin" to instead
refer to either "builtin" or "private_builtin".
doc/Mmakefile:
Don't include the interface to private_builtin.m in the
library reference manual.
tools/bootcheck:
Add `-p'/`--copy-profiler' option. This is needed to get
the above changes to bootstrap.
tools/test_mercury:
Pass `-p' to tools/bootcheck.
tests/term/*.trans_opt_exp:
s/mercury_builtin/builtin/g
|
||
|
|
c273ecdbcc |
A re-work of check_typeclass.m. Now, rather than the ad-hoc approach of
Estimated hours taken: 25 A re-work of check_typeclass.m. Now, rather than the ad-hoc approach of checking each method of each instance declaration for *exact* type and mode correctness, we generate a new predicate that gets inserted into the HLDS. This predicate is checked for type, mode, uniqueness and determinism correctness in the appropriate compiler pass. As a consequence, the check_typeclass pass now has to come before typecheck.m. Previously, it was the final semantic analysis pass because it had to use type, mode, uniqueness and determinism information. The new approach does not need that information to be available. This has the following user-visible improvements: - constraints on class methods are now checked properly. An instance's implementation of a method may be less constrained. (Previously, these constraints weren't even checked at all. Oops). - a method implementation may be more polymorphic than expected - implied modes will be used for methods if necessary This is a much more robust approach (and it co-incides with the typeclass paper ;-) ). compiler/check_typeclass.m: Introduce the auxiliary predicate for the instance method. As an optimisation, do not introduce the predicate if the implementation given is an *exact* match (in terms of types, modes and determinism). compiler/mercury_compile.m: Put the check_typeclass pass before typechecking. compiler/type_util.m: Change type_list_matches_exactly to type_and_constraint_list_matches_exactly since check_typeclass is also responsible for checking constraints on method implementations. (This is only used in the optimisation mentioned above). |
||
|
|
5e86fb5715 |
Fix some bugs in the handling of "non-simple" type class constraints
Estimated hours taken: 12 Fix some bugs in the handling of "non-simple" type class constraints (ones for which the types being constrained are not just type variables). compiler/prog_io_typeclass.m: Ensure that constraints on type class declarations must be "simple". This is needed the ensure termination of type checking. (We already did this for instance declarations, but not for superclass constraints on type class declarations.) compiler/prog_data.m: Document the invariant that the types in a type class constraint must not contain any information in their term__context fields. compiler/type_util.m: compiler/equiv_type.m: compiler/polymorphism.m: compiler/prog_io_typeclass.m: Enforce the above-mentioned invariant. compiler/typecheck.m: Allow the declared constraints to be a superset of the inferred constraints. When performing context reduction, eliminate declared constraints at each step rather than only at the end. Remove declared constraints and apply superclass rules before applying instance rules. When applying instance rules, make sure that it is a type error if there is no matching instance rule for a ground constraint. If context reduction results in an error, restore the original type assign set, to avoid repeating the same error message at every subsequent call to perform_context_reduction. compiler/check_typeclass.m: Change the way we superclass conformance for instance declarations to take advantage of the new "DeclaredConstraints" argument to typecheck__reduce_context_by_rule_application. |
||
|
|
11d8161692 |
Add support for nested modules.
Estimated hours taken: 50
Add support for nested modules.
- module names may themselves be module-qualified
- modules may contain `:- include_module' declarations
which name sub-modules
- a sub-module has access to all the declarations in the
parent module (including its implementation section).
This support is not yet complete; see the BUGS and LIMITATIONS below.
LIMITATIONS
- source file names must match module names
(just as they did previously)
- mmc doesn't allow path names on the command line any more
(e.g. `mmc --make-int ../library/foo.m').
- import_module declarations must use the fully-qualified module name
- module qualifiers must use the fully-qualified module name
- no support for root-qualified module names
(e.g. `:parent:child' instead of `parent:child').
- modules may not be physically nested (only logical nesting, via
`include_module').
BUGS
- doesn't check that the parent module is imported/used before allowing
import/use of its sub-modules.
- doesn't check that there is an include_module declaration in the
parent for each module claiming to be a child of that parent
- privacy of private modules is not enforced
-------------------
NEWS:
Mention that we support nested modules.
library/ops.m:
library/nc_builtin.nl:
library/sp_builtin.nl:
compiler/mercury_to_mercury.m:
Add `include_module' as a new prefix operator.
Change the associativity of `:' from xfy to yfx
(since this made parsing module qualifiers slightly easier).
compiler/prog_data.m:
Add new `include_module' declaration.
Change the `module_name' and `module_specifier' types
from strings to sym_names, so that module names can
themselves be module qualified.
compiler/modules.m:
Add predicates module_name_to_file_name/2 and
file_name_to_module_name/2.
Lots of changes to handle parent module dependencies,
to create parent interface (`.int0') files, to read them in,
to output correct dependencies information for them to the
`.d' and `.dep' files, etc.
Rewrite a lot of the code to improve the readability
(add comments, use subroutines, better variable names).
Also fix a couple of bugs:
- generate_dependencies was using the transitive implementation
dependencies rather than the transitive interface dependencies
to compute the `.int3' dependencies when writing `.d' files
(this bug was introduced during crs's changes to support
`.trans_opt' files)
- when creating the `.int' file, it was reading in the
interfaces for modules imported in the implementation section,
not just those in the interface section.
This meant that the compiler missed a lot of errors.
library/graph.m:
library/lexer.m:
library/term.m:
library/term_io.m:
library/varset.m:
compiler/*.m:
Add `:- import_module' declarations to the interface needed
by declarations in the interface. (The previous version
of the compiler did not detect these missing interface imports,
due to the above-mentioned bug in modules.m.)
compiler/mercury_compile.m:
compiler/intermod.m:
Change mercury_compile__maybe_grab_optfiles and
intermod__grab_optfiles so that they grab the opt files for
parent modules as well as the ones for imported modules.
compiler/mercury_compile.m:
Minor changes to handle parent module dependencies.
(Also improve the wording of the warning about trans-opt
dependencies.)
compiler/make_hlds.m:
compiler/module_qual.m:
Ignore `:- include_module' declarations.
compiler/module_qual.m:
A couple of small changes to handle nested module names.
compiler/prog_out.m:
compiler/prog_util.m:
Add new predicates string_to_sym_name/3 (prog_util.m) and
sym_name_to_string/{2,3} (prog_out.m).
compiler/*.m:
Replace many occurrences of `string' with `module_name'.
Change code that prints out module names or converts
them to strings or filenames to handle the fact that
module names are now sym_names intead of strings.
Also change a few places (e.g. in intermod.m, hlds_module.m)
where the code assumed that any qualified symbol was
fully-qualified.
compiler/prog_io.m:
compiler/prog_io_goal.m:
Move sym_name_and_args/3, parse_qualified_term/4 and
parse_qualified_term/5 preds from prog_io_goal.m to prog_io.m,
since they are very similar to the parse_symbol_name/2 predicate
already in prog_io.m. Rewrite these predicates, both
to improve maintainability, and to handle the newly
allowed syntax (module-qualified module names).
Rename parse_qualified_term/5 as `parse_implicit_qualified_term'.
compiler/prog_io.m:
Rewrite the handling of `:- module' and `:- end_module'
declarations, so that it can handle nested modules.
Add code to parse `include_module' declarations.
compiler/prog_util.m:
compiler/*.m:
Add new predicates mercury_public_builtin_module/1 and
mercury_private_builtin_module/1 in prog_util.m.
Change most of the hard-coded occurrences of "mercury_builtin"
to call mercury_private_builtin_module/1 or
mercury_public_builtin_module/1 or both.
compiler/llds_out.m:
Add llds_out__sym_name_mangle/2, for mangling module names.
compiler/special_pred.m:
compiler/mode_util.m:
compiler/clause_to_proc.m:
compiler/prog_io_goal.m:
compiler/lambda.m:
compiler/polymorphism.m:
Move the predicates in_mode/1, out_mode/1, and uo_mode/1
from special_pred.m to mode_util.m, and change various
hard-coded definitions to instead call these predicates.
compiler/polymorphism.m:
Ensure that the type names `type_info' and `typeclass_info' are
module-qualified in the generated code. This avoids a problem
where the code generated by polymorphism.m was not considered
type-correct, due to the type `type_info' not matching
`mercury_builtin:type_info'.
compiler/check_typeclass.m:
Simplify the code for check_instance_pred and
get_matching_instance_pred_ids.
compiler/mercury_compile.m:
compiler/modules.m:
Disallow directory names in command-line arguments.
compiler/options.m:
compiler/handle_options.m:
compiler/mercury_compile.m:
compiler/modules.m:
Add a `--make-private-interface' option.
The private interface file `<module>.int0' contains
all the declarations in the module; it is used for
compiling sub-modules.
scripts/Mmake.rules:
scripts/Mmake.vars.in:
Add support for creating `.int0' and `.date0' files
by invoking mmc with `--make-private-interface'.
doc/user_guide.texi:
Document `--make-private-interface' and the `.int0'
and `.date0' file extensions.
doc/reference_manual.texi:
Document nested modules.
util/mdemangle.c:
profiler/demangle.m:
Demangle names with multiple module qualifiers.
tests/general/Mmakefile:
tests/general/string_format_test.m:
tests/general/string_format_test.exp:
tests/general/string__format_test.m:
tests/general/string__format_test.exp:
tests/general/.cvsignore:
Change the `:- module string__format_test' declaration in
`string__format_test.m' to `:- module string_format_test',
because with the original declaration the `__' was taken
as a module qualifier, which lead to an error message.
Hence rename the file accordingly, to avoid the warning
about file name not matching module name.
tests/invalid/Mmakefile:
tests/invalid/missing_interface_import.m:
tests/invalid/missing_interface_import.err_exp:
Regression test to check that the compiler reports
errors for missing `import_module' in the interface section.
tests/invalid/*.err_exp:
tests/warnings/unused_args_test.exp:
tests/warnings/unused_import.exp:
Update the expected diagnostics output for the test cases to
reflect a few minor changes to the warning messages.
tests/hard_coded/Mmakefile:
tests/hard_coded/parent.m:
tests/hard_coded/parent.child.m:
tests/hard_coded/parent.exp:
tests/hard_coded/parent2.m:
tests/hard_coded/parent2.child.m:
tests/hard_coded/parent2.exp:
Two simple tests case for the use of nested modules with
separate compilation.
|