mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-18 15:26:31 +00:00
41a27af86219d5ad8fb951794ad322d66659eb5d
80 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
41a27af862 |
Change type_id to the more descriptive type_ctor everywhere.
Estimated hours taken: 6 Branches: main compiler/*.m: Change type_id to the more descriptive type_ctor everywhere. |
||
|
|
7fbb09dc04 |
Delete the code "handling" undiscrimited unions.
Estimated hours taken: 1 Branches: main compiler/*.m: Delete the code "handling" undiscrimited unions. Their presence slows things down, the error messages they lead to can confuse users, and we are unlikely to ever implement them in the form now assumed by the code. tests/invalid/bigtest.err_exp: tests/invalid/uu_type.err_exp: Update these expected error messages. |
||
|
|
13f0e7610a |
A large step towards declarative debugging of goals that do I/O.
Estimated hours taken: 40
Branches: main
A large step towards declarative debugging of goals that do I/O. This step
does everything needed for that except modify the declarative debugger itself;
that is for Mark to do.
If you give the new option --trace-table-io-decl, the transformation performed
by the compiler on I/O primitives will preserve not just the output arguments
of the primitive, so that the primitive can be "reexecuted" without performing
any side-effects, but also the input arguments and the identity of the I/O
primitive itself. The I/O table therefore will contain a list of the I/O
primitives executed by the program after I/O tabling is started.
You can test this via the new debugger commands "print action <action-number>"
and "browse action <action-number>".
The new option is currently not documented, because the declarative debugger
does not yet use the information it provides. The new debugger commands are
not documented because they are meant only for implementors, at least for
now.
Since this change adds a field to proc_layout structures, any workspaces
compiled with debugging enabled will need to do a cvs update when this change
is installed.
compiler/options.m:
Add the option --trace-table-io-decl. When set, this causes the
compiler to transform I/O action primitives to allow declarative
debugging of I/O actions.
compiler/handle_options.m:
Make --trace-table-io-decl imply --trace-table-io.
compiler/table_gen.m:
Perform the transformation, which is similar to the existing
--trace-table-io transformation, but preserves the identity of all
non-io-state arguments (not just the outputs) and the identity
of the I/O primitive itself.
Provide better names for variables generated by tabling
transformations.
compiler/hlds_goal.m:
Add extra parameters to procedures whose job it is to create new
goals to name the variables in those goals.
compiler/layout.m:
Add a new layout structure to contain the information the runtime
system needs to interpret the information saved by the new
transformation.
compiler/layout_out.m:
Output the new layout structure.
compiler/continuation_info.m:
Add a field to proc_layouts to point to the declarative I/O tabling
structure, and another to identify the proc_layout without using LLDS
types.
compiler/code_gen.m:
Provide the definition of this field when appropriate.
compiler/hlds_pred.m:
Add a field to proc_infos to store the information from the tabling
transformation until code generation.
compiler/stack_layout.m:
Add a mechanism for transforming the high level description of I/O
action tabling data in proc_infos to the low level description we need
to generate C data structures.
compiler/hlds_data.m:
Add a new cons_id and a new cons_tag; they are used to refer to I/O
tabling structures in code generated by the new transformation.
compiler/*.m:
Handle the updates to global data types above.
library/table_builtin.m:
Modernize some old code.
Fix an old off-by-one error: make I/O tabling use the first slot
in the I/O action table.
library/varset.m:
Add a mechanism for creating a variable that is named iff the caller
has a name for it.
runtime/mercury_layout_util.[ch]:
Add a function for materializing type parameters from an answer block,
not from registers or a closure.
runtime/mercury_stack_layout.h:
Declare a C type for the data structure holding information about
I/O primitives transformed by --trace-table-io-decl, and add a field
to proc_layout structures to point to these new structures.
Add a new evaluation method for --trace-table-io-decl.
runtime/mercury_tabling_macros.h:
Add some conditionally-compiled debugging code to the primitive for
saving answers.
trace/mercury_trace_vars.[ch]:
Add functions for printing I/O action goals.
trace/mercury_trace_internal.c:
Add code for recognizing and implementing commands to print I/O
action goals.
trace/mercury_trace.c:
Add code for handling the new eval method.
tests/debugger/tabled_read.{m,inp,exp*}:
Add a polymorphic I/O action primitive, add calls to it, and test
the printing of both monomorphic and polymorphic action goals.
tests/debugger/tabled_read_decl.{m,inp,exp*,data}:
A new test case. It does the same things as the new version of
tabled_read, but it is compiled with --trace-table-io-decl, not
just --trace-table-io. It therefore can (and does) test the printing
of tabled I/O actions.
tests/debugger/Mmakefile:
Add the new test case.
|
||
|
|
cca3d674e1 |
Added parsing and pretty printing of new promise ex declarations, and
Estimated hours taken: 50 Branches: main Added parsing and pretty printing of new promise ex declarations, and appropriate documentation. library/ops.m: Added the new operators to op_table. compiler/prog_io.m: Added clauses to enter promise ex declarations into the parse tree. compiler/prog_out.m: Added predicates useful in outputting promise declarations. compiler/prog_data.m: Changed assertion constructor in type item to a more gereral promise constructor to be used for assertions and promise ex declarations. Added the type promise_type to differentiate between different promise declarations. compiler/mercury_to_mercury.m: Added clauses to output promise items, including assertions and promise ex declarations. compiler/make_hlds.m: compiler/module_qual.m: compiler/modules.m: compiler/recompilation_check.m: compiler/recompilation_version.m: Updated to reflect change in item type. compiler/notes/glossary.html: Added new terminology, updated use of `promise'. compiler/notes/todo.html: Added todo list for promise ex declarations. compiler/notes/promise_ex.html: A new file documenting development of promise ex declarations. |
||
|
|
a800e84609 |
Make foreign_proc impure by default.
Estimated hours taken: 12 Branches: main Make foreign_proc impure by default. The majority of this change is to correctly handle older pragma c_code and import declarations, which are assumed to have the the purity of their declaration. The declared purity is not known at the time we parse the pragma c_code, so we need to handle these cases at purity checking time by setting the purity attribute on the procedure to the declared purity. We can then continue with normal purity checking. compiler/make_hlds.m: Make fact table implementations pure. (no need to mess around with legacy purity behaviour here as we know for fact tables what the purity is declared to be). compiler/prog_data.m: Set the default purity to impure. Add a new attribute on foreign_procs, indicating whether the foreign_proc should have legacy purity behaviour (because it was written using pragma c_code or pragma import) or whether it should use the new purity behaviour. compiler/prog_io_pragma.m: Set the legacy_purity_behaviour attribute depending upon the c_code and import behaviour. compiler/purity.m: Handle legacy_purity_behaviour attributes. Change an XXX about assuming foreign_procs to be pure -- the code near there seems to be correct in either case, we still don't assume that a foreign_proc is impure simply because it has multiple modes. doc/reference_manual.texi: Document that pragma foreign_proc is now impure by default. |
||
|
|
aa23ac1b26 |
A few minor fixes promped by petdr's addition of support for value types
Estimated hours taken: 0.5 Branches: main A few minor fixes promped by petdr's addition of support for value types for foreign_type. compiler/ilasm.m: compiler/ilds.m: compiler/mlds_to_csharp.m: compiler/mlds_to_il.m: compiler/mlds_to_mcpp.m: Mirror the IL syntax more closely, use valuetype instead of value_class. compiler/prog_data.m: Add some comments and improve formatting of type declarations for pragma foreign_type. doc/reference_manual.texi: Improve the documentation wording for pragma foreign_type, and remove the XXX saying that we should accept value types, because we now accept value types. |
||
|
|
dffdb3fd0b |
Allow the foreign_type declaration to accept value types.
Estimated hours taken: 4
Branches: main
Allow the foreign_type declaration to accept value types.
compiler/prog_data.m:
Add an indicator to il foreign types whether or not they are
reference or value types.
compiler/prog_io_pragma.m:
Parse whether or not the foreign type is a reference or a value type.
compiler/make_hlds.m:
Decide whether or not a foreign_type is already boxed.
compiler/hlds_data.m:
compiler/mlds.m:
Add to the foreign_type an indicator of whether or not it is already
boxed.
compiler/mlds_to_il.m:
Remove code which attempted to determine when a value type was
incorrectly defined as a reference type.
Unboxed types on the .NET backend are value types.
Fix a bug where converting a value_class to a value_class was
failing.
compiler/ilasm.m:
Remove name_to_simple_type from the interface as it is no longer
needed in mlds_to_il.
compiler/mercury_to_mercury.m:
Output the new foreign_type format.
compiler/foreign.m:
compiler/hlds_out.m:
compiler/intermod.m:
compiler/magic_util.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_type_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_java.m:
compiler/recompilation_usage.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unify_proc.m:
Changes to handle the boxed indicator.
doc/reference_manual.texi:
Document how to specify a value type.
|
||
|
|
70eb377888 |
Fix and enable the new foreign_type syntax.
Estimated hours taken: 10 Branches: main Fix and enable the new foreign_type syntax. We now accept declarations such as: :- pragma foreign_type(il, xmldoc, "class [System.Xml]System.Xml.XmlDocument"). compiler/prog_data.m: Remove the foreign type location from the foreign_type pragma, it is better to make this part of the foreign_language_type. Rename backend as foreign_language_type as it specifies a type in a particular language. compiler/prog_io_pragma.m: Uncomment the foreign_type parsing code, change the syntax. Write some simple code to parse CIL type names. compiler/make_hlds.m: Check that there is a :- type declaration, and that it has the same visibility as the pragma foreign_type. compiler/mercury_to_mercury.m: compiler/module_qual.m: compiler/modules.m: compiler/recompilation_version.m: Handle changes to backend_type and the foreign_type pragma. doc/reference_manual.texi: Document the new syntax. |
||
|
|
c79a467975 |
Accept promise_pure and promise_semipure as foreign proc attributes.
Estimated hours taken: 6 Branches: main Accept promise_pure and promise_semipure as foreign proc attributes. Make changes required to make pragma foreign_proc impure by default, but leave the actual default setting commented out for now. (next step is to fix the purity of the preds/funcs in the library). compiler/prog_data.m: Add purity to the pragma_foreign_proc_attributes. We keep the default purity pure, but we have a commented out default of impure that can be switched on later. compiler/prog_io_pragma.m: Parse the new promise_pure and promise_semipure declarations. Add a promise_pure for :- pragma c_code and :- pragma import so that it is backwards compatible. Improve the code used to process the list of attributes. compiler/purity.m: Mark the code that needs to be removed once we have bootstrapped this change and fixed the library. Calculate expression purity from foreign_proc from the attributes rather than looking up the declared purity. doc/reference_manual.texi: Document the new syntax, and add commented out comments to indicate the intended change to make the default purity for foreign_proc pure. |
||
|
|
5de7305cfe |
Implement `:- pragma foreign_import_module(Lang, Module)', which tells
Estimated hours taken: 10
Implement `:- pragma foreign_import_module(Lang, Module)', which tells
the compiler that the foreign code in the module containing the
declaration uses `:- pragma export'ed procedures from module `Module'.
This information is needed for mmake to build things in the right order.
Currently programmers can hand code the required mmake rules, but
`mmc --make' will have no mechanism for doing this.
`:- pragma c_import_module(Module)' is a synonym for
`:- pragma foreign_import_module("C", Module)'.
compiler/prog_io_pragma.m:
Parse the new pragmas.
compiler/prog_data.m:
compiler/foreign.m:
compiler/hlds_module.m:
compiler/mlds.m:
compiler/modules.m:
Add the `:- pragma foreign_import_module' to the
compiler's datastructures.
compiler/make_hlds.m:
Insert `:- pragma foreign_import_module' declarations
into the HLDS.
compiler/modules.m:
Add the extra dependency information from
`:- pragma foreign_import_module' declarations
to the `.d' files.
compiler/llds.m:
compiler/foreign.m:
Move some non-backend-specific types describing the foreign
language interface from llds.m to foreign.m.
compiler/intermod.m:
Write `:- pragma foreign_import_module' declarations
to `.opt' files. XXX mmake doesn't support this properly yet.
compiler/mercury_compile.m:
compiler/foreign.m:
compiler/ml_code_gen.m:
compiler/ml_code_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_mcpp.m:
Convert `:- pragma foreign_import_module' to `#include'
statements where appropriate depending on the target
language.
compiler/*.m:
Handle `:- pragma foreign_import_module'.
Import foreign.m rather than llds.m for the foreign
interface types.
doc/reference_manual.texi:
NEWS:
Document the new pragmas.
Minor fixes for the foreign code documentation.
tests/hard_coded/Mmakefile:
tests/hard_coded/foreign_import_module.m:
tests/hard_coded/foreign_import_module_2.m:
tests/hard_coded/foreign_import_module.exp:
Test case.
|
||
|
|
77a1261d3b |
Merge the foreign_type pragma changes from the dotnet branch to the main
Estimated hours taken: 10
Branches: main
Merge the foreign_type pragma changes from the dotnet branch to the main
branch, plus do some more development work to generalise the change.
compiler/prog_data.m:
Add a type to hold the data from parsing a pragma foreign_type decl.
compiler/prog_io_pragma.m:
Parse the pragma foreign_type. This code is currently commented
out, while we decide on the syntax.
compiler/hlds_data.m:
Add a new alternative to hlds_type_body where the body of the type
is a foreign type.
compiler/make_hlds.m:
Place the foreign_type pragmas into the HLDS.
compiler/foreign.m:
Implement to_type_string which replaces export__type_to_type_string,
unlike export__type_to_type_string foreign__to_type_string takes an
argument specifying which language the representation is meant to be
in. to_type_string also needs to take a module_info to handle
foreign_types correctly. To avoid the need for the module_info to
be passed around the MLDS backend we provide a new type
exported_type which provides enough information for an alternate
version of to_type_string to be called.
compiler/export.m:
Delete export__type_to_type_string.
compiler/llds.m:
Since foreign__to_type_string needs a module_info, we add a new
field to pragma_c_arg_decl which is the result of calling
foreign__to_type_string. This avoids threading the module_info
around various llds passes.
compiler/mlds.m:
Record with in the mercury_type the exported_type, this avoids
passing the module_info around the MLDS backend.
Also add the foreign_type alternative to mlds__type.
Update mercury_type_to_mlds_type so that it handles types which are
foreign types.
compiler/mlds_to_il.m:
Convert a mlds__foreign_type into an ilds__type.
compiler/ilds.m:
The CLR spec requires that System.Object and System.String be
treated specially in the IL assembly so add them as simple types.
compiler/ilasm.m:
Before outputting a class name into the IL assembly check whether it
it can be simplified to a builtin type, and if so output that name
instead as required by the ECMA spec.
Changes for the addition of string and object as simple types.
doc/reference_manual.texi:
Document the new pragma, this is currently commented out because it
refers to syntax that has not yet been finalised.
compiler/fact_table.m:
compiler/llds_out.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_simplify_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
compiler/pragma_c_gen.m:
compiler/rtti_to_mlds.m:
Changes to handle using foreign__to_type_string.
compiler/hlds_out.m:
compiler/intermod.m:
compiler/magic_util.m:
compiler/ml_type_gen.m:
compiler/recompilation_usage.m:
compiler/recompilation_version.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unify_proc.m:
Changes to handle the new hlds_type_body.
compiler/mercury_to_mercury.m:
Output the pragma foreign_type declaration.
compiler/module_qual.m:
Qualify the pragma foreign_type declarations.
compiler/modules.m:
Pragma foreign_type is allowed in the interface.
|
||
|
|
b994075a22 |
Add support for foreign_proc("il", ....)
Estimated hours taken: 50
Branches: main
Add support for foreign_proc("il", ....)
To use it, you need to give the options
--use-foreign-language il
--backend-foreign-language il
Begin documenting foreign_proc.
compiler/foreign.m:
compiler/globals.m:
Handle the addition of il as a language option.
compiler/inlining.m:
Mention that we don't allow il code to be inlined yet and give a
pointer into ml_code_gen.m which has the reason along with the
offending code.
compiler/il_peephole.m:
compiler/ilasm.m:
Handle the addition of il_asm_code as inlineable code.
compiler/ilds.m:
Add a handwritten scope to the different scope types.
compiler/ml_code_gen.m:
Handle the generation of code for IL foreign language interfacing.
Put the max_stack_size attribute into IL foreign language code.
Document the problem with inlining.
compiler/ml_elim_nested.m:
Handle the new field in blocks indicating whether the block contains
handwritten code.
compiler/mlds.m:
Add lang_il as a possible target language.
Add attributes to target code (max_stack_size is the only one so far).
compiler/mlds_to_c.m:
compiler/mlds_to_csharp.m:
compiler/mlds_to_java.m:
compiler/mlds_to_mcpp.m:
Handle the addition of il as a language option.
compiler/mlds_to_il.m:
compiler/mlds_to_ilasm.m:
Generate inline code for foreign_proc using IL.
compiler/prog_data.m:
Add il as a language option.
Add extra attributes to the pragma_foreign_proc_attributes.
Currently there is just one extra attribute, max_stack_size.
compiler/prog_io_pragma.m:
Parse max_stack_size as an attribute on foreign_proc.
Improve error message output: previously we tried to parse the
third term of a foreign_proc, and then tried to parse the second term
(which we will accept for "c_code" but not foreign_proc).
But we should give the error message as if the "c_code" handling is
not present, as this will eventually go away.
Check for foreign_language attributes such as max_stack_size.
doc/reference_manual.texi:
Add a section for foreign_proc (and other multi-language foreign
language interfacing pragmas).
At the moment we have some reasonable documentation for "C" and
"IL" foreign_proc, and some documentation on foreign_decl and
foreign_code for C.
doc/user_guide.texi:
The language and implementation specific documentation of
the foreign language interface.
|
||
|
|
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.
|
||
|
|
d74eb22905 |
Fix a bug in the module import mechanism -- use_module should
Estimated hours taken: 8
Fix a bug in the module import mechanism -- use_module should
not be transitive. This change is needed for smart recompilation
to avoid needing to check whether the removal of a transitive
import could cause compilation errors -- it never should.
Also fix some bugs in the handling of type class declarations.
compiler/prog_data.m:
Add a `transitively_imported' pseudo-declaration, which
is placed before the items from `.int2' files and `.opt'
files.
Fix the representation of type class bodies.
`:- typeclass foo where [].' declares a typeclass with no
methods. `:- typeclass foo.' declares an abstract typeclass.
The old representation made no distinction between these cases.
compiler/hlds_data.m:
compiler/prog_data.m:
compiler/module_qual.m:
Move the declaration of type type_id from hlds_data.m to prog_data.m.
This avoids a duplicate declaration in module_qual.m.
compiler/modules.m:
Add a `transitively_imported' pseudo-declaration before the
items from `.int2' files.
Remove the bodies of typeclass declarations placed in `.int2'
files -- the methods should not be available unless the module
is explicitly imported.
compiler/module_qual.m:
Items after the `transitively_imported' pseudo-declaration
should not be considered when module qualifying locally
declared items.
compiler/equiv_type.m:
compiler/mercury_to_mercury.m:
compiler/prog_io_typeclass.m:
Handle the change to the representation of typeclass bodies.
compiler/prog_io_typeclass.m:
Check that the arguments of a typeclass declaration
are distinct variables.
compiler/make_hlds.m:
Handle abstract typeclass declarations.
compiler/check_typeclass.m:
Check that all typeclasses have a definition somewhere.
compiler/intermod.m:
Write abstract_exported typeclasses to the `.opt' file.
compiler/add_trail_ops.m:
compiler/context.m:
compiler/llds.m:
compiler/vn_type.m:
Add missing imports.
compiler/magic_util.m:
compiler/ml_type_gen.m:
Remove unnecessary imports.
NEWS:
Note that this change may break existing programs.
compiler/notes/todo.html:
Remove the item relating to this change.
tests/invalid/transitive_import.{m,err_exp}:
Add some tests for uses of transitively imported items.
tests/invalid/transitive_import_class.m:
tests/invalid/transitive_import_class2.m:
tests/invalid/transitive_import_class3.m:
tests/invalid/transitive_import_class.err_exp:
Add a test for use of transitively imported class methods.
tests/invalid/invalid_typeclass.{m,err_exp}:
Add some tests for invalid typeclass declarations.
tests/invalid/Mmakefile:
Add the new tests.
|
||
|
|
76ac44335d |
Implement a C# interface for the .NET backend.
Estimated hours taken: 45 Branches: main Implement a C# interface for the .NET backend. To use it, you currently need to set --backend-foreign-language csharp --use-foreign-language csharp in your MCFLAGS. The C# foreign language interface works by introducing a new sort of MLDS statement called outline_foreign_proc. outline_foreign_proc is expected to be turned into a separate procedure in a separate file. This is quite different to normal foreign code which has been renamed as inline target code, as it is really intended to be generated inline, inside the generated code. Because outline_foreign_proc is expected to be generated outside the normal code, we don't need to generate variable renamings, initializations, casts and other complicated interfacing code. Any marshalling is done by the backend, which knows how to marshall arguments across the boundary into the outline code and back. In the case of marshalling to C# from the .NET backend, we currently don't do anything special (part of the point of .NET is that data representation don't have to change very often just because you are using different languages, so this is a property we should try to preserve). The actual implementation of the foreign code is therefore very simple. Simply generate an appropriate procedure, and insert the user's code in the middle. The bulk of this change to delay the mangling of MLDS var names, so we can still use the original user's var name when we output the outline procedure (since the user's foreign code will refer to these var names, it's important to keep them around). compiler/foreign.m: Handle the csharp foreign language. compiler/globals.m: Fix an XXX about converting to lowercase to do language name comparisons. Add new predicates to make conversion of foreign languages to strings more uniform. compiler/handle_options.m: Don't set backend_foreign_language to the default if it has already been set by hand. compiler/ml_call_gen.m: compiler/ml_code_gen.m: compiler/ml_code_util.m: Delay the mangling of MLDS var names by keeping the variable number around until the output phase. Slightly generalize the handling of foreign language interfacing. Handle C# foreign language interfacing. Add value_output_vars to the ml_gen_info, which are the variables returned rather than passed by reference. We need to know these variables for C# interfacing so that we can handle the return value of the forwarding function. Mark the beginning and end of the MLDS foreign language processing as a "sub-module" (in comments at least). Later I may put this code into a separate module. Rename some predicates from c_code to foreign_code. compiler/ml_elim_nested.m: compiler/ml_optimize.m: compiler/ml_string_switch.m: compiler/ml_type_gen.m: compiler/ml_unify_gen.m: compiler/ml_util.m: compiler/rtti_to_mlds.m: Handle the new var_name type, and the new target_code constructors. compiler/mlds.m: Add outline_foreign_proc which is handled differently to the old target_code (which has been renamed inline_target_code). Change the definiton for mlds__var_name. compiler/mlds_to_c.m: Factor out mlds_output_to_file. Handle the new var_name type, and the new target_code constructors. compiler/mlds_to_csharp.m: A new module to generate C# code suitable for foreign language interfacing. This is largely lifted from the MC++ code, with a few changes to the output syntax. compiler/mlds_to_il.m: Return the set of foreign languages processed instead of a bool saying wither MC++ was present. This is so we can generate the appropriate output .cs or .cpp files, and because we need to keep track of all the external assembly references we need to put in the .il file. Handle the inline_target_code and mlds__var_name changes. compiler/mlds_to_ilasm.m: Output .cpp and .cs files conditionally. Factor out output_to_file. Move MC++ output code to mlds_to_mcpp.m compiler/mlds_to_java.m: Factor out output_to_file. Handle the new var_name type, and the new target_code constructors. compiler/mlds_to_mcpp.m: New file to handle generating MC++ code suitable for foreign language interfacing. compiler/options.m: Add a way of setting the backend-foreign-language option. compiler/passes_aux.m: Add output_to_file which is used by the MLDS backend to generate output files. compiler/prog_data.m: Uncomment csharp as a foreign language. |
||
|
|
711da78188 |
Rename foreign_code as foreign_proc where appropriate in the compiler.
Estimated hours taken: 4.0 Branches: main Rename foreign_code as foreign_proc where appropriate in the compiler. The rationale for this change is that it makes maintaining the code much simpler because it is clear whether `foreign' refers to a slab of code (foreign_code) or a procedure (foreign_proc). :- type pragma_foreign_code_attributes :- type pragma_foreign_proc_attributes The functors for pragma_type foreign(Lang, BodyCode) foreign(Attributes, Name, PredOrFunc, Vars, Varset, Impl) become foreign_code(Lang, BodyCode) foreign_proc(Attributes, Name, PredOrFunc, Vars, Varset, Impl) And the HLDS goal `pragma_foreign_code' becomes `foreign_proc'. compiler/*.m: Update the compiler to use the new names. |
||
|
|
a3819d359c |
Fix the handling of purity in the optimization and tabling passes.
Estimated hours taken: 15 Branches: main Fix the handling of purity in the optimization and tabling passes. Without this change tests/tabling/unused_args.m fails with inter-module optimization. compiler/purity.m: compiler/post_typecheck.m: Allow purity checking to be rerun on a single procedure without requiring an io__state. If the purity is worse (due to inlining a predicate with a `:- pragma promise_pure' declaration), add `promised_pure' or `promised_semipure' to the pred_info. compiler/hlds_out.m: compiler/hlds_pred.m: compiler/intermod.m: compiler/make_hlds.m: compiler/mercury_to_mercury.m: compiler/module_qual.m: compiler/modules.m: compiler/prog_data.m: compiler/prog_io_pragma.m: compiler/purity.m: doc/reference_manual.texi: NEWS: Implement `:- pragma promise_semipure'. This is needed if an predicate marked `promised_pure' which calls impure predicates is inlined into a semipure predicate. compiler/inlining.m: Make sure the purity markers on the goal_infos are correct after inlining predicates which are promised pure. Export a predicate inlining__can_inline_proc which is used by deforestation to determine whether inlining a procedure will change the semantics or will break code generator invariants. compiler/deforest.m: Use the same method as inlining.m to work out whether a procedure can be inlined. Don't inline predicates which are promised pure because the extra impurity which will be propagated through the goal will stop deforestation working on the goal. compiler/simplify.m: Make sure the goal_info resulting from converting a singleton switch into a conjunction has the correct purity. compiler/table_gen.m: Make sure the purity markers on the generated goal_infos are correct. Make sure that call_table_gen goal features cannot be removed by optimization passes. Don't put unnecessary `impure' markers on calls to error/1. tests/debugger/loopcheck.exp: tests/debugger/retry.exp: Adjust the expected output. The change to ensure that `call_table_gen' goal features can't be removed alters the goal paths slightly. tests/invalid/impure_method_impl.m: Adjust the expected output now that predicates can be promised semipure. |
||
|
|
ebe9f9a3ec |
Add tabling of I/O actions for the debugger.
Estimated hours taken: 80
Add tabling of I/O actions for the debugger.
compiler/options.m:
Add a new option, --trace-table-io, that enables the tabling of I/O
actions, and another, --trace-table-io-states, that governs whether the
tabling includes the I/O state variables themselves. (You want to table
these variables iff they contain meaningful information that is not
stored in global variables.) These options are for developers only
for now.
compiler/modules.m:
Implicitly import table_builtin if --trace-table-io is specified.
compiler/prog_data.m:
Add eval_table_io as a new eval method.
compiler/hlds_pred.m:
Add a mechanism for checking whether a predicate has an input/output
pair of io__state args.
Extend the tables indexed by eval_method to handle eval_table_io.
compiler/hlds_out.m:
Print the eval method in HLDS dumps.
compiler/table_gen.m:
If a procedure has a pair of I/O state args and is defined using pragma
C code that has the tabled_for_io marker, and --trace-table-io is
specified, then perform I/O tabling on it and mark it as tabled.
compiler/notes/compiler_design.m:
Document that table_gen.m can now change the evaluation methods of
procedures (to eval_table_io).
compiler/stack_layout.m:
runtime/mercury_stack_layout.h:
Add an extra field to proc layouts. If debugging is enabled and a
procedure has I/O state arguments, this field gives the number of the
stack slot which will be filled with the I/O action counter at the
time of the call, so that on retry the debugger can reset the I/O
action counter to this value.
compiler/trace.m:
Add code to reserve and fill this stack slot.
Make the order of fields in the trace_slots structure match the order
in proc layouts.
compiler/code_info.m:
compiler/live_vars.m:
Pass a module_info to trace__setup and trace__reserved_slots.
library/io.m:
Mark the I/O primitives (i.e. procedures that are defined by pragma C
code and do I/O) with the tabled_for_io feature. (See the discussion
of I/O primitives in compiler/table_gen.m.)
Standardize the formatting of predicates defined by pragma C codes.
library/table_builtin.m:
Define the predicates that perform I/O tabling, to which calls are
inserted in I/O tabled predicates. These depend on knowing what the
maximum MR_Unsigned value is.
library/table_builtin.m:
runtime/mercury_tabling_macros.h:
Table nodes implementing a simple kind of trie, which can also be
viewed as a hash table with the hash function hash(n) = hash - start
were already supported by mercury_tabling.c. They are used to
implement I/O tabling, since I/O the tabled action numbers form a
contiguous sequence. Now allow that functionality to be accessed
from the library through macros.
runtime/mercury_trace_base.[ch]:
Add the global variables required by I/O tabling.
trace/mercury_trace.c:
Implement retry across I/O by resetting the I/O counter to the value
it had on entry to the retried call. However, since this is not safe
in general, ask the user for permission first.
trace/mercury_trace.h:
Add two extra arguments to MR_trace_retry to specify the input and
output streams on which to ask permission.
trace/mercury_trace_internal.c:
Add commands to start and stop I/O tabling. For now, they are for use
by developers only and are undocumented; I expect they will change
significantly before being let loose on users.
trace/mercury_trace_external.c:
trace/mercury_trace_declarative.c:
Pass extra arguments to MR_trace_retry to indicate that these modules
are not interested (at least for now) in retry across I/O, since they
do not (yet) have mechanisms for asking the user for permission.
tests/debugger/tabled_read.{m,inp,exp,data}:
A new test case to check retry across tabled and non-tabled I/O.
tests/debugger/Mmakefile:
Enable the new test case.
|
||
|
|
477ecb18f6 |
Implement pragma foreign_code for Managed C++.
Estimated hours taken: 60 Implement pragma foreign_code for Managed C++. Currently you can only write MC++ code if your backend is capable of generating use MC++ as its "native" foreign language. The IL backend is the only backend that does this at the moment (the other backends have C as their "native" foreign language). Most of the machinery is in place to call from C to (normal) C++ but there is little work done on actually spitting out the C++ code into a separate file. The IL backend does this step already with managed C++. The intention is to turn foreign_code for C++ into a pragma import (which imports the C++ function from a separate file) and foreign_code for C (which calls the imported function). The C++ code will be inserted into a separate file that is compiled using C linkage. The important improvement this change gives is that you can write a module with a C and a MC++ implementations side-by-side. The target backend will select the most appropriate foreign language to use. You can override its choice using --use-foreign-language. Later on we will probably want more flexibility than just a single language selection option). This change also implements :- pragma foreign_decl, which allows header file style declarations to be written in languages other than C. compiler/code_gen.m: Reject code that is not C when generating LLDS. compiler/export.m: Start renaming C as foreign. Reject code that is not C when generating exports. compiler/foreign.m: A new module to handle foreign language interfacing. The bulk of the code for pragma import has been moved here from make_hlds. compiler/globals.m: Convert foreign language names to foreign_language. This code has been moved closer to the similar conversion we do for target language names. Add globals__io_lookup_foreign_language_option to make it easier to deterministically lookup the options relating to foreign languages. compiler/hlds_module.m: Move module_add_foreign_decl and module_add_foreign_body_code from make_hlds.m (where they were called module_add_c_header and module_add_c_code). compiler/hlds_out.m: Write the foreign language out in HLDS dumps. compiler/llds.m: Change foreign_header_info to foreign_decl_info. Change definitions of foreign_decl_code and foreign_body_code to include the language. compiler/llds_out.m: Reject code that is not C when writing out LLDS. compiler/make_hlds.m: Add foreign language information to the bodys and decls when creating them. Update error messages to refer to foreign code instead of C code. Use foreign.m to generate interfaces from the backend language to the foreign language. Hardcode C as the language for fact tables. compiler/mercury_compile.m: Collect the appropriate foreign language code together for output to the backend. compiler/intermod.m: compiler/mercury_to_mercury.m: Output the foreign language string. Change a few names to foreign_code instead of c_code. compiler/ml_code_gen.m: Filter the foreign language bodys and decls so that we only get the ones we are in (given by the use-foreign-language option). compiler/mlds_to_c.m: Abort if we are given non C foreign language code to output (we might handle it here in future, or we might handle it elsewhere). compiler/mlds_to_ilasm.m: Abort if we are given non MC++ foreign language code to output (we might handle it here in future, or we might handle it elsewhere). compiler/options.m: compiler/handle_options.m: Add --use-foreign-language as a user option to control the preferred foreign language to use as the implementation of this module. Add backend_foreign_language as an internal option which stores the foreign language that the compiler will use as a default (e.g. the natural foreign language for the backend to use). Set the preferred backend foreign language depending on the target. compiler/prog_data.m: Add managedcplusplus as a new alternative for the foreign_language type. Make c_header_code into foreign_decl. Give the foreign language for foreign_code as an attribute of the code. Write code to turn attributes into a list of strings (suitable for writing out by mercury_to_mercury). This fixes what appears to be a bug in tabled_for_io -- the tabled_for_io attribute was not being written out. Structure the code so this bug is difficult to repeat in future. compiler/prog_io_pragma.m: Parse foreign_decl. Turn c_header_code into a special case of foreign_decl. compiler/*.m: Remove the language field from pragma_foreign_code, it is now an attribute of the code. Various type and variable renamings. tests/invalid/pragma_c_code_and_clauses1.err_exp: tests/invalid/pragma_c_code_dup_var.err_exp: tests/warnings/singleton_test.exp: Update the tests to reflect the new error messages talking about :- pragma foreign_code rather than :- pragma c_code. |
||
|
|
e6769ef622 |
Record the module that each instance declaration came from.
Estimated hours taken: 8 Record the module that each instance declaration came from. This is needed for the IL back-end, which includes that module name in the symbol name that it generates for each instance declaration. compiler/prog_data.m: Add a module_name field to the `instance' item. compiler/prog_io_typeclass.m: When parsing `instance' declarations, store the module name that they came from in the module_name field of the `instance' item. compiler/hlds_data.m: Add a module_name field to the `hlds_instance_defn' structure. compiler/make_hlds.m: Copy the module_name field from the `instance' item to the `hlds_instance_defn' structure. compiler/polymorphism.m: Fix an old XXX: when constructing `base_typeclass_info_const's, use the module name from the `hlds_instance_defn', rather than hard-coding the invalid value "some bogus module name". compiler/rtti.m: Add a module_name field to the `base_typeclass_info' rtti_name and rtti_data. compiler/base_typeclass_info.m: Copy the module_name field in the `hlds_instance_defn' to the module_name field in the `base_typeclass_info' rtti_data and rtti_name. compiler/rtti_to_mlds.m: When constructing mlds `data_addr's, use the module_name from the `base_typeclass_info' rtti_name, rather than assuming that such references always refer to instance declarations in the current module. (That assumption would be a safe one currently, but doing it this way is probably a bit more robust against future changes.) compiler/*.m: Trivial changes to reflect the above data structure changes. |
||
|
|
702b512aaf |
Add a new type of annotation on procedures defined by pragma foreign
Estimated hours taken: 1 compiler/prog_data.m: Add a new type of annotation on procedures defined by pragma foreign code. For now the annotation is ignored. When I/O tabling is implemented (soon), this annotation will ask for the procedure to be considered an I/O predicate and tabled accordingly. compiler/prog_io_pragma.m: Parse the new annotation. tests/valid/tabled_for_io.m: Test case to check that the compiler accepts the new annotation. tests/valid/Mmakefile: Enable the test case. |
||
|
|
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. |
||
|
|
4d0dff1860 |
Allow typeclass instance declarations to contain clauses, as an
Estimated hours taken: 10 Allow typeclass instance declarations to contain clauses, as an alternative to the current `pred(<MethodName>) is <ImplName>)' syntax. This avoids the need for the user to explicitly define names for procedures that just implement type class methods. XXX Note that currently we only permit one clause per method. compiler/prog_data.m: Change the second `sym_name' field of `instance_method' into a new type `instance_proc_def', which has two alternatives. The first, `name(sym_name)', is for the old syntax. The second, `clauses(list(item))', is for the new syntax. compiler/prog_io_typeclass.m: Parse the new syntax. compiler/make_hlds.m: Add new predicate `produce_instance_method_clauses', for use by check_typeclass.m. This handles the generation of HLDS clauses_infos for both the old and new syntax for instance method definitions. Return the qual_info produced by `parse_tree_to_hlds', so that it can be passed to `produce_instance_method_clauses'. compiler/mercury_compile.m: Pass the qual_info returned by make_hlds.m to check_typeclass.m. compiler/check_typeclass.m: Move the code which produces HLDS definitions for instance methods into `produce_instance_method_clauses' in make_hlds.m. Thread the io__state and qual_info throughout most of the code, since this they are needed to process the new syntax. (The io__state is needed so we can spit out warnings about singleton variables in clauses in type class methods, and the qual_info is needed to handle explicit type qualifiers in such clauses.) compiler/mercury_to_mercury.m: Output the new syntax. tests/hard_coded/typeclasses/Mmakefile: tests/hard_coded/typeclasses/instance_clauses.m: tests/hard_coded/typeclasses/instance_clauses.exp: A test case for the new feature. doc/reference_manual.texi: Document the new feature. |
||
|
|
c192d50143 |
Add preliminary support for a new pragma:
Estimated hours taken: 15 Add preliminary support for a new pragma: :- pragma foreign_code(LanguageString, .... <same args as c_code>). This is intended to be the eventual replacement of pragma c_code. Presently the only valid language is "C". The existing pragma c_code is simply turned into pragma foreign_code. pragma foreign_code is not a supported pragma at the moment. There are several other changes that are intended (for example, foreign_code will be impure by default). This change also changes the HLDS goal pragma_c_code/7 to pragma_foreign_code/8 where the extra argument is the foreign language. Any code currently generating output for pragma C code simply checks that the foreign language is set to "c". Since this is the only alternative of the type foreign_language, it will always succeed. However when new alternatives are added it should be fairly easy to find where the changes need to be made. Some type names and predicate names have also been updated, however there are many more that haven't yet been touched. compiler/prog_io_pragma.m: Accept the new syntax. Turn the old syntax into the new item. compiler/hlds_goal.m: Change pragma_c_code/7 to pragma_foreign_code/8. Define the foreign_language type. compiler/llds.m: Change user_c_code/2 to user_foreign_code/3. compiler/*.m: Update the rest of the compiler to handle these types. Make a few small changes to update variable names, predicate names and type names. |
||
|
|
a48beedc9d |
Fix a bug where pragma imports of polymorphic predicates where not
Estimated hours taken: 16
Fix a bug where pragma imports of polymorphic predicates where not
having typeinfos prepended to the call.
compiler/prog_data.m:
Add a the new functor import/4 to pragma_c_code impl.
The functor stores all the information needed to constuct a C code
fragment a pragma import.
compiler/make_hlds.m:
Rather then constructing the C code fragment immediately, construct
the sub-parts and store them in import/4.
compiler/polymorphism.m:
Prepend the typeinfos to the list of variables passed to the
imported C function.
compiler/ml_code_gen.m:
compiler/pragma_c_gen.m:
Construct the C code fragment then call the routine which handles
`ordinary' pragma c_code.
compiler/hlds_out.m:
compiler/mercury_to_mercury.m:
Add code to recognise the import/4 functor.
|
||
|
|
a033b2e748 |
Fix a bug which caused intermod.m to abort when a type class
Estimated hours taken: 2 Fix a bug which caused intermod.m to abort when a type class contained a predicate or function with more than one mode. compiler/check_typeclass.m: Reorder the method declarations in each instance so that they match the order of the list of pred_proc_ids for the instance implementation. compiler/intermod.m: Remove duplicate pred_ids from the list of methods in an instance declaration when module qualifying the original instance declaration before writing it to the `.opt' file. Make sure that predicates referred to by an instance declaration in a `.opt' file are made exported. compiler/prog_data.m: Simplify the code by replacing the `pred_instance' and `func_instance' constructors of the `instance_method/0' type with a single constructor with a `pred_or_func' argument. compiler/mercury_to_mercury.m: compiler/check_typeclass.m: compiler/prog_io_typeclass.m: compiler/intermod.m: Handle the change to the `instance_method/0' type. tests/hard_coded/typeclasses/Mmakefile: tests/hard_coded/typeclasses/intermod_typeclass_bug.m: tests/hard_coded/typeclasses/intermod_typeclass_bug2.m: tests/hard_coded/typeclasses/intermod_typeclass_bug.exp: Test case. |
||
|
|
79d75acdb0 |
Add impure functions to Mercury, clean up the purity module somewhat,
Estimated hours taken: 30 Add impure functions to Mercury, clean up the purity module somewhat, fix some bugs in purity, update and expand the purity documentation, and re-organize the purity checks. Impure functions can be declared just like impure preds. However, they can only be called in an explicit unification preceeded by a purity level: impure X = some_impure_func(Y, Z) The bug fixed was the fact that closures of impure predicates were only being detected when using lambda syntax. Purity information was discarded and impure closures could be created like this: Pred = some_impure_pred You could then use this predicate anywhere you like without any purity declarations. compiler/hlds_module.m: Add get_pred_id pred which will return the pred_id of a predicate matching a given type. This is like get_pred_and_proc_id, but only gets the information we are interested in, and is semidet. We need a semidet version to handle cases where type inference cannot infer a type before the limit is reached, but we try to purity check this code. (The bug mentioned above was stopping us from purity checking the test case for this before). compiler/make_hlds.m: Check for "impure" unifications with expressions that are not function calls and issue appropriate error messages. When unravelling impure function call unifications, put the input parameter unifications (if any) before the actual call. Only mark the goal_info for the function call as impure. compiler/mercury_to_goedel.m: compiler/mercury_to_mercury.m: compiler/module_qual.m: compiler/prog_data.m: compiler/prog_io.m: compiler/prog_io_dcg.m: compiler/prog_io_goal.m: compiler/prog_util.m: Add purity information to unify goals. Don't assume unify goals are pure. compiler/purity.m: Allow impure functions. Check unification goals for purity (not just lambda unification). Check unifications that are transformed into calls to make sure the call is purity correct. Put purity checking logic into separate predicates. Use an enum to return different errors and warnings. (The last two changes make it much easier to see the similarities between checking goals and checking predicates for purity correctness). Give different error messages for impure functions (highlight that you need to use them in an explicit unification). Handle unknown predicate lookups (can occur when unifying with a higher order term whose type could not be inferred). Add a few comments delineating where changes might need to be made to make foreign code impure by default in future. compiler/notes/authors.html: Add Peter Schachte to the authors list. doc/reference_manual.texi: Document impure functions. Expand more on what impure predicates/functions can do. Explain the concept of worst purity, and use it to explain the "inferred purity"/"declared purity" concepts. Make it more explicit that only impure goals obey strict-sequential like semantics. tests/invalid/type_inf_loop.err_exp2: Fix this test case to reflect the new error message new that we check the purity of this code correctly (or rather, we correctly fail to be able to purity check this code). tests/hard_coded/Mmakefile: tests/hard_coded/purity.exp: tests/hard_coded/purity.m: tests/hard_coded/purity/Mmakefile: tests/hard_coded/purity/impure_func_t1.m: tests/hard_coded/purity/purity.m: tests/hard_coded/purity/runtests: Remove purity tests from the hard_coded directory, give it a sub-directory of its own. tests/invalid/Mmakefile: tests/invalid/purity.err_exp: tests/invalid/purity.m: tests/invalid/purity_nonsense.err_exp: tests/invalid/purity_nonsense.m: tests/invalid/purity/Mmakefile: tests/invalid/purity/impure_func_t2.err_exp: tests/invalid/purity/impure_func_t2.m: tests/invalid/purity/impure_func_t3.err_exp: tests/invalid/purity/impure_func_t3.m: tests/invalid/purity/impure_func_t4.err_exp: tests/invalid/purity/impure_func_t4.m: tests/invalid/purity/impure_func_t5.err_exp: tests/invalid/purity/impure_func_t5.m: tests/invalid/purity/impure_pred_t1.err_exp: tests/invalid/purity/impure_pred_t1.m: tests/invalid/purity/impure_pred_t2.err_exp: tests/invalid/purity/impure_pred_t2.m: tests/invalid/purity/purity.err_exp: tests/invalid/purity/purity.m: tests/invalid/purity/purity_nonsense.err_exp: tests/invalid/purity/purity_nonsense.m: tests/invalid/purity/runtests: Remove purity tests from the invalid directory, give it a sub-directory of its own. |
||
|
|
0dab66d926 |
Allow class methods to be impure or semipure.
Estimated hours taken: 6
Allow class methods to be impure or semipure. Previously any purity annotation
on a class method was ignored, and the method assumed to be pure. (We have
for some time caught the case of providing an impure implementation for
a (pure) class method, though).
compiler/prog_data.m:
Add purity to the information we store about each method.
compiler/prog_io_typeclass.m:
Record the declared purity of each method.
compiler/make_hlds.m:
For the predicate we generate corresponding to a method, add any
purity annotations that the method has.
compiler/check_typeclass.m:
Add the appropriate impurity marker to the predicate we generate for
each instance method.
compiler/purity.m:
Be careful not to spit out spurious purity warnings:
- Never warn about excessive impurity for a class methods.
(The body of the method is just class_method_call, which
never looks impure as far as it is concerned).
- Never warn about excessive impurity for class instance
method. The fact that a method is impure doesn't mean that
its instances need to be impure, and it would be excessive
to warn about it, seeing that there is no way for the user
to avoid it (other than actually making their implementation
impure...).
compiler/mercury_to_mercury.m:
Print out method purity in interface files.
compiler/module_qual.m:
compiler/equiv_type.m:
Handle the fact that we now store purity info for class methods.
tests/hard_coded/typeclasses/impure_methods.{m,exp}:
A test case for this change.
tests/hard_coded/typeclasses/Mmakefile:
Turn this change on.
tests/invalid/impure_methods.{m,err_exp}:
A test case for invalid use of impurity and class methods
tests/invalid/Mmakefile:
Turn this change on.
|
||
|
|
b2282718cb |
improve a comment
Estimated hours taken: 0.01 prog_data.m: improve a comment |
||
|
|
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. |
||
|
|
1ffa21f5bf |
Assertion declarations in the interface must not contain any symbols from
Estimated hours taken: 26
Assertion declarations in the interface must not contain any symbols from
modules imported only in the implementation. This constraint requires
that each imported symbol be annotated with whether it is imported from
the interface or implementation.
compiler/prog_data.m:
Update the pseudo declaration `:- imported' to include which section
(either implementation or interface) the items following it were
imported from.
compiler/modules.m:
Add a new version of get_dependencies, which divides the modules up
into those imported in the interface and implementation.
Use the new version of get_dependencies to place the new form of
`:- imported' declarations at the start of items from different
sections.
compiler/hlds_pred.m:
Add a new field to the imported data constructor in the type
import_status, which records in which section the symbol was
imported in.
compiler/make_hlds.m:
Modify module_defn_update_import_status so that it now records from
which section a symbol is imported.
compiler/module_qual.m:
Any unqualified symbol in an assertion might come from *any*
of the imported modules, so turn off the warning about modules which
are imported in the interface but not used, if an unqualified symbol
appears in the assertion.
compiler/assertion.m:
Use where a symbol is imported from when deciding whether an
assertion in the interface is valid.
Call module_info_incr_errors whenever an error message is written.
compiler/post_typecheck.m:
Add the extra module_info arg to assertion__in_interface_check, so
that module_info_incr_errors can be called.
compiler/dead_proc_elim.m:
compiler/higher_order.m:
compiler/hlds_out.m:
compiler/intermod.m:
compiler/unused_args.m:
Updates to use the new form of the data constructor imported.
|
||
|
|
63983a9128 |
Fix confusion over whether attributes are numbered starting from
Estimated hours taken: 3 Fix confusion over whether attributes are numbered starting from zero or one. compiler/prog_data.m: compiler/rl.m: compiler/rl_key.m: compiler/rl_sort.m: Attributes in sort and index specifications are now numbered starting from 1, to be consistent with argument numbering in the rest of the compiler, and for error messages. compiler/rl_exprn.m: compiler/rl_out.pp: Aditi numbers arguments starting from 0, so convert the numbers here. |
||
|
|
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.
|
||
|
|
a5f5c63a3a |
Add the infrastructure for assertions into the compiler.
Estimated hours taken: 50
Add the infrastructure for assertions into the compiler.
compiler/error_util.m:
Output the correct pred name for assertions.
compiler/hlds_data.m:
Add the assertion_table structure.
compiler/hlds_module.m:
Get/set the assertion_table from the module_info.
compiler/hlds_out.m:
Modify hlds_out__write_pred_id to identify assertions.
compiler/hlds_pred.m:
Add the goal_type assertion.
compiler/make_hlds.m:
Transform the assertion to a HLDS data structure that can be
typechecked.
compiler/mercury_to_goedel.m:
compiler/module_qual.m:
Handle the assertion structure.
compiler/mercury_to_mercury.m:
Output assertions.
compiler/post_typecheck.m:
Add a predicate which must be called after typechecking of
assertions has been finished. Also document some possible problems
with typechecking assertions.
compiler/prog_data.m:
Add assertion to the type item.
compiler/prog_io.m:
Add the ability to parse assertions.
compiler/purity.m:
After finished typechecking assertions call
post_typecheck__finish_assertion.
compiler/typecheck.m:
Don't output inference messages for assertions.
compiler/notes/compiler_design.html:
Update documentation about exactly where quantification is done.
compiler/notes/glossary.html:
Define what an assertion is.
|
||
|
|
6af76f74ea |
Move some declarations around and make some other minor changes in order
Estimated hours taken: 4
Move some declarations around and make some other minor changes in order
to reduce the number and complexity of the intermodule dependencies.
In particular, ensure that prog_data.m does not need to import
hlds*.m, purity.m, rl.m, or term_util.m.
Since we expect to have only one input language, but potentially many
different target languages, the general design principle that we have adopted
in order to minimize the number of dependencies, particularly cyclic ones,
is that modules which belong to an earlier stage of compilation should
not depend on modules which belong to a later stage of compilation.
However, that design principle has not been adhered to in many cases.
This change reduces the number of such cases.
compiler/prog_data.m:
compiler/hlds_pred.m:
Move definition of the types `eval_method' and `pred_or_func'
from hlds_pred.m to prog_data.m.
Add new type `mode_num' to prog_data.m, defined by
`type mode_num == int', and change the proc_id argument of
the `unused_args' pragma to instead use this type instead of proc_id.
Delete the import of module hlds_pred from prog_data.m.
compiler/prog_data.m:
compiler/hlds_data.m:
Move the definition of the type `determinism' from hlds_data.m to
prog_data.m. Delete the import of module hlds_data from prog_data.m.
compiler/prog_data.m:
compiler/purity.m:
Move the definition of the type `purity' from purity.m to prog_data.m.
Add import of module prog_data to purity.m.
Delete the import of module purity from prog_data.m.
This is needed because purity.m imports hlds*.m and so by
importing purity.m, prog_data.m was indirectly importing hlds*.m.
(An possible alternative here would be to split purity.m into two
parts, called say purity.m and check_purity.m; of these, only the
second would import hlds*.m. But that would be a significantly
more complicated change.)
compiler/prog_data.m:
compiler/rl.m:
Move the definition of the `index_spec' and `index_type' types from
rl.m to prog_data.m. Delete the import of module rl from prog_data.m.
compiler/prog_data.m:
Add new types `pragma_arg_size_info' and `pragma_termination_info'
to prog_data.m. These are similar to the existing types
`arg_size_info' and `termination_info' defined in term_util.m,
except that they correspond more directly to what is actually
used in `pragma termination_info' declarations.
compiler/term_util.m:
Add new predicates `add_context_to_arg_size_info' and
`add_context_to_pragma_termination_info' for converting
the prog_data types to their corresponding term_util types.
compiler/make_hlds.m:
compiler/mercury_to_mercury.m:
compiler/prog_io_pragma.m:
compiler/unused_args.m:
Minor modifications to handle the change in the type of the
mode number argument in `unused_args' pragmas, and in the types
of the arg_size_info and termination_info arguments in
`termination_info' pragmas.
compiler/mercury_to_mercury.m:
compiler/prog_io_pragma.m:
compiler/inst.m:
compiler/make_hlds.m:
compiler/call_gen.m:
compiler/common.m:
compiler/continuation_info.m:
compiler/det_report.m:
compiler/hlds_pred.m:
compiler/lambda.m:
compiler/magic_util.m:
compiler/modecheck_call.m:
compiler/prog_io_goal.m:
compiler/prog_io_util.m:
compiler/prog_util.m:
compiler/termination.m:
Delete imports of modules purity, rl, and hlds_pred, or
move them from the interface section to the implementation section.
compiler/inst.m:
compiler/prog_io_util.m:
Add an XXX comment explaining why we need to import hlds_data.m.
|
||
|
|
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. |
||
|
|
59fda6bfdf |
Implement abstract instance declarations.
Estimated hours taken: 9 Implement abstract instance declarations. compiler/prog_data.m: Rename the `instance_interface' type as `instance_body', and make it a discriminated union: either `abstract', or `concrete(Methods)'. compiler/prog_io_typeclass.m: compiler/hlds_data.m: compiler/hlds_out.m: compiler/equiv_type.m: compiler/check_typeclass.m: Change the code to reflect the new name and representation of `instance_interface'. compiler/prog_io_typeclass.m: Parse abstract instance declarations. compiler/make_hlds.m: Clean up the code a bit, and make sure that it detects some errors which previously we didn't detect: duplicate or overlapping instance declarations, and instance declarations with methods for classes with no methods. compiler/check_typeclass.m: If an instance is abstract, then we don't need to check that the methods in the instance body match those in the class. compiler/base_typeclass_info.m: Only generate base_typeclass_infos for concrete instance declarations, not for abstract ones. doc/reference_manual.texi: Document the change. tests/hard_coded/typeclasses/Mmakefile: tests/hard_coded/typeclasses/abstract_instance.m: tests/hard_coded/typeclasses/use_abstract_instance.m: tests/hard_coded/typeclasses/use_abstract_instance.exp: tests/invalid/Mmakefile: tests/invalid/typeclass_test_9.m: tests/invalid/typeclass_test_9.err_exp: Some test cases. tests/hard_coded/typeclasses/Mmakefile: Uncomment typeclass_test_5.m, since we pass that now (and have done so for quite some time). tests/invalid/typeclass_test_[3-5].err_exp: Update to reflect additional error messages produced by the improved error checking in compiler/make_hlds.m. |
||
|
|
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. |
||
|
|
ecb6edb717 |
Fix a bug with intermodule optimization of nested modules.
Estimated hours taken: 20 Fix a bug with intermodule optimization of nested modules. Previously, the compiler used to just label any predicates defined in a module containing sub-modules as `exported', since they may be needed by the separately-compiled sub-modules. However, this is a little bit of a lie, and it turns out that it doesn't work. The fix is to use a new status `exported_to_submodules' for this case. compiler/prog_data.m: Add a new pseudo-declaration ":- private_interface", used to mark items in an ":- implementation" section that will be exported to submodules. compiler/modules.m: Put declarations from modules containing sub-modules into `private_interface' sections rather than into `interface' sections. compiler/hlds_pred.m: Add a new alternative `exported_to_submodules' to the `import_status' data type. Add several new procedures for testing particular aspects of this type. compiler/module_qual.m: Set the import_status of items in a `private_interface' section to `exported_to_submodules'. compiler/intermod.m: Handle procedures with status `exported_to_submodules' specially. Also reorganize the code here a bit to make it more maintainable. compiler/base_type_info.m: compiler/base_type_info.m: compiler/base_typeclass_info.m: compiler/code_util.m: compiler/dead_proc_elim.m: compiler/hlds_out.m: compiler/make_hlds.m: compiler/termination.m: compiler/unused_args.m: Minor changes to reflect the above changes to data-structures; in particular, use the new procedures defined in hlds_pred.m instead of hard-coded tests. In termination.m, the changes included deleting some error-checking code that didn't make much sense anymore when using the new procedures rather than using hard-coded tests. tests/hard_coded/Mmakefile: tests/hard_coded/nested_intermod.m: tests/hard_coded/nested_intermod_main.m: tests/hard_coded/nested_intermod_main.exp: Add a regression test for the bug mentioned above. |
||
|
|
9deab471f0 |
Use a more SICStus- and programmer-friendly data structure for
Estimated hours taken: 0.5 compiler/prog_data.m: Use a more SICStus- and programmer-friendly data structure for pragma C code attributes. |
||
|
|
7d0e4822d1 |
Fix several bugs in the runtime engine to do with thread-safe execution.
Estimated hours taken: 15
Fix several bugs in the runtime engine to do with thread-safe execution.
Add a new flag to pragma c_code/import to allow programmers to specify
whether or not the C code is thread-safe or not, and modify code generation
to put a lock around C code that isn't thread_safe.
runtime/mercury_thread.{c,h}:
Add a global lock.
Change the handling of thread creation. create_thread now takes
a "closure" (a C struct with a fn pointer and an argument to pass
the function) which it calls in the new thread. (The same mechanism
is used in the Boehm collector), or NULL which causes the thread
to wait for work to appear in the Mercury runqueue.
runtime/mercury_context.c:
initialize the global lock.
runtime/mercury_engine.{c,h}:
Add a new field to the MercuryEngine structre which is used to
store a list of saved thread ids. These were being saved in a
local variable in call_engine_inner which was a bug because
call_engine_inner's (C) stack frame gets scribbled on by Mercury
execution. For more detail see the comments in mercury_engine.h
runtime/mercury_wrapper.c:
Use the new interface to create_thread.
compiler/prog_io_pragma.m:
Parse either a single attribute or a list of attributes instead
of just 'may_call_mercury' in pragma c code and pragma import.
These are stored in an abstract type 'pragma_c_code_attributes'
that uses a bit array (aka int) to store the attributes.
compiler/pragma_c_gen.m:
Get the code generator to emit c code to obtain and release the
global lock for pragma c code that isn't thread_safe.
compiler/<various>.m:
Change may_call_mercury to pragma_c_code_attributes.
doc/reference_manual.m:
Document the change to pragma c code.
scripts/mgnuc.in:
Pass some extra C flags for thread-safe compilation for Linux.
|
||
|
|
4556cccae8 |
Remember the term__context of where we read an instance method from so that
Estimated hours taken: 2
Remember the term__context of where we read an instance method from so that
we can give more accurate error messages. Also (slightly) improve the text of
the error message for instance methods.
check_typeclass.m:
Use the term__context of the instance method declaration as the
term__context for the introduced pred.
hlds_out.m:
If the pred is one introduced as an instance method, give a
(slightly) better error message.
mercury_to_mercury.m:
Ignore the term context.
module_qual.m:
Pass along the term context.
prog_data.m:
Add a term__context to the instance_method
prog_io_typeclass.m:
Store the term__context in the instance_method
|
||
|
|
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.
|
||
|
|
a70b59e83c |
Add a test to find the number of words needed to represent a
configure.in:
Add a test to find the number of words needed to represent a
synchronization term.
boehm_gc/gc.h:
fix a declaration by replacing the args () with (void).
boehm_gc/solaris_pthreads.c:
add a missing include
check the return values of pthread calls.
compiler/*.m:
Add handling for the new HLDS goal type par_conj.
Add handling for the four new LLDS instructions:
init_sync_term
fork
join_and_terminate
join_and_continue
compiler/code_info.m:
add a new alternative for slot_contents - sync_term.
compiler/handle_options.m:
add .par as part of the grade
compiler/hlds_goal.m:
add the new goal type par_conj.
compiler/instmap.m:
add instmap__unify which takes a list of instmaps
and abstractly unifies them.
add unify_instmap_delta which tajes two instmap deltas
and abstractly unifies them.
compiler/llds.m:
add the new llds instructions.
compiler/mode_info.m:
add par_conj as a lock reason.
library/Makefile:
work around a bug in the solaris version pthread.h
library/benchmarking.m:
reference the stack zones from the engine structure
rather than from global variables.
library/{nc,sp}_builtin.nl:
add an op declaration for &.
library/std_util.m:
change references to global variables to references inside
the engine structure.
runtime/Mmakefile:
add mercury_thread.{c,h}
add THREADLIBS to the libraries
runtime/*.{c,h}
Remove some old junk from the previous processes/shrd-mem
changes that found their way into the repository.
Add MR_ prefixes to lots of names.
runtime/mercury_context.c:
Add init_thread_stuff for creating and initializing a
context structure for the current thread.
runtime/mercury_context.h:
add a field to the mercury context which stores the thread id
of the thread where this context originated.
add various macros for implementing the new llds instructions.
runtime/mercury_engine.c:
initialize the engine structure, rather than a bunch of globals.
runtime/mercury_engine.h:
declare the mercury_engine structure.
runtime/mercury_regorder.h:
if MR_THREAD_SAFE, and there is at least one global register
then use mr0 as a pointer to the mercury engine structure.
scripts/init_grade_options.sh-subr
add thread_safe
scripts/mgnuc.in
add THREAD_OPTS
scripts/ml.in:
add THREAD_LIBS
|
||
|
|
bcf7dbf9f8 |
Add support for tabling.
Estimated hours taken: 250 Add support for tabling. This change allows for model_det, model_semidet and model_non memoing, minimal model and loop detection tabling. compiler/base_type_layout.m: Update comments to reflect new runtime naming standard. compiler/det_analysis.m: Allow tabling to change the result of det analysis. This is necessary in the case of minimal model tabling which can turn a det procedure into a semidet one. compiler/det_report.m: compiler/hlds_data.m: Add code to report error messages for various non compatible tabling methods and determinism. compiler/hlds_out.m: compiler/modules.m: Remove reference to the old memo marker. compiler/hlds_pred.m: Create new type (eval_method) to define which of the available evaluation methods should be used each procedure. Add new field to the proc_info structure. Add several new predicates relating to the new eval_method type. compiler/inlining.m: compiler/intermod.m: Make sure only procedures with normal evaluation are inlined. compiler/make_hlds.m: Add code to process new tabling pragmas. compiler/mercury_compile.m: Call the tabling transformation code. compiler/modes.m: Make sure that all procedures with non normal evaluation have no unique/partially instantiated modes. Produce error messages if they do. Support for partially instantiated modes is currently missing as it represents a large amount of work for a case that is currently not used. compiler/module_qual.m: compile/prog_data.m: compiler/prog_io_pragma.m: Add three new pragma types: `memo' `loop_check' `minimal_model' and code to support them. compiler/simplify.m: Don't report infinite recursion warning if a procedure has minimal model evaluation. compiler/stratify.m: Change the stratification analyser so that it reports cases of definite non-stratification. Rather than reporting warnings for any code that is not definitely stratified. Remove reference to the old memo marker. compiler/switch_detection.m: Fix a small bug where goal were being placed in reverse order. Call list__reverse on the list of goals. compiler/table_gen.m: New module to do the actual tabling transformation. compiler/notes/compiler_design.html: Document addition of new tabling pass to the compiler. doc/reference_manual.texi: Fix mistake in example. library/mercury_builtin.m: Add many new predicates for support of tabling. library/std_util.m: library/store.m: Move the functions : ML_compare_type_info ML_collapse_equivalences ML_create_type_info to the runtime. runtime/mercury_deep_copy.c: runtime/mercury_type_info.h: runtime/mercury_type_info.c: Move the make_type_info function into the mercury_type_info module and make it public. runtime/Mmakefile: runtime/mercury_imp.h: Add references to new files added for tabling support. runtime/mercury_string.h: Change hash macro so it does not cause a name clash with any variable called "hash". runtime/mercury_type_info.c: runtime/mercury_type_info.h: Add three new functions taken from the library : MR_compare_type_info MR_collapse_equivalences MR_create_type_info. runtime/mercury_table_any.c: runtime/mercury_table_any.h: runtime/mercury_table_enum.c: runtime/mercury_table_enum.h: runtime/mercury_table_int_float_string.c: runtime/mercury_table_int_float_string.h: runtime/mercury_table_type_info.c: runtime/mercury_table_type_info.h: runtime/mercury_tabling.h: New modules for the support of tabling. |
||
|
|
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. |
||
|
|
b5dfd26ebd |
Miscellaneous small changes.
Estimated hours taken: 1.5 Miscellaneous small changes. compiler/modes.m: Fix a couple of mode errors which were caught by the new mode checker: use of clobbered mode_infos. compiler/simplify.m: Optimise away unifications of the form X = X. (These can be created by excess assignment elimination.) compiler/follow_vars.m: compiler/hlds_goal.m: compiler/inst_match.m: compiler/prog_data.m: compiler/store_alloc.m: Minor documentation fixes. |
||
|
|
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.
|
||
|
|
5013dd9c76 |
Implement nondet pragma C codes.
Estimated hours taken: 40
Implement nondet pragma C codes.
runtime/mercury_stacks.h:
Define a new macro, mkpragmaframe, for use in the implementation
of nondet pragma C codes. This new macro includes space for a
struct with a given sruct tag in the nondet stack frame being created.
compiler/{prog_data.m,hlds_goal.m}:
Revise the representation of pragma C codes, both as the item and
in the HLDS.
compiler/prog_io_pragma.m:
Parse nondet pragma C declarations.
Fix the indentation in some places.
compiler/llds.m:
Include an extra argument in mkframe instructions. This extra argument
gives the details of the C structure (if any) to be included in the
nondet stack frame to be created.
Generalize the LLDS representation of pragma C codes. Instead of a
fixed sequence of <assign from inputs, user c code, assign to outputs>,
let the sequence contain these elements, as well as arbitrary
compiler-generated C code, in any order and possibly with repetitions.
This flexibility is needed for nondet pragma C codes.
Add a field to pragma C codes to say whether they can call Mercury.
Some optimizations can do a better job if they know that a pragma C
code cannot call Mercury.
Add another field to pragma C codes to give the name of the label
they refer to (if any). This is needed to prevent labelopt from
incorrectly optimizing away the label definition.
Add a new alternative to the type pragma_c_decl, to describe the
declaration of the local variable that points to the save struct.
compiler/llds_out.m:
Output mkframe instructions that specify a struct as invoking the new
mkpragmaframe macro, and make sure that the struct is declared just
before the procedure that uses it.
Other minor changes to keep up with the changes to the representation
of pragma C code in the LLDS, and to make the output look a bit nicer.
compiler/pragma_c_gen.m:
Add code to generate code for nondet pragma C codes. Revise the utility
predicates and their data structures a bit to make this possible.
compiler/code_gen.m:
Add code for the necessary special handling of prologs and epilogs
of procedures defined by nondet pragma C codes. The prologs need
to be modified to include a programmer-defined C structure in the
nondet stack frame and to communicate the location of this structure
to the pragma C code, whereas the functionality of the epilog is
taken care of by the pragma C code itself.
compiler/make_hlds.m:
When creating a proc_info for a procedure defined by a pragma C code,
we used to insert unifications between the headvars and the vars of
the pragma C code into the body goal. We now perform substitutions
instead. This removes a factor that would complicate the generation
of code for nondet pragma C codes.
Pass a moduleinfo down the procedures that warn about singletons
(and other basic scope errors). When checking whether to warn about
an argument of a pragma C code not being mentioned in the C code
fragment, we need to know whether the argument is input or output,
since input variables should appear in some code fragments in a
nondet pragma C code and must not appear in others. The
mode_is_{in,out}put checks need the moduleinfo.
(We do not need to check for any variables being mentioned where
they shouldn't be. The C compiler will fail in the presence of any
errors of that type, and since those variables could be referred
to via macros whose definitions we do not see, we couldn't implement
a reliable test anyway.)
compiler/opt_util.m:
Recognize that some sorts of pragma_c codes cannot affect the data
structures that control backtracking. This allows peepholing to
do a better job on code sequences produced for nondet pragma C codes.
Recognize that the C code strings inside some pragma_c codes refer to
other labels in the procedure. This prevents labelopt from incorrectly
optimizing away these labels.
compiler/dupelim.m:
If a label is referred to from within a C code string, then do not
attempt to optimize it away.
compiler/det_analysis.m:
Remove a now incorrect part of an error message.
compiler/*.m:
Minor changes to conform to changes to the HLDS and LLDS data
structures.
|