mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-18 15:26:31 +00:00
c745c93c1da4f53b4772bee4cc8e187ddae3e6da
71 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
b2012c0c0e |
Rename the types 'type', 'inst' and 'mode' to 'mer_type', 'mer_inst'
Estimated hours taken: 8 Branches: main compiler/*.m: Rename the types 'type', 'inst' and 'mode' to 'mer_type', 'mer_inst' and 'mer_mode'. This is to avoid the need to parenthesize these type names in some contexts, and to prepare for the possibility of a parser that considers those words to be reserved words. Rename some other uses of those names (e.g. as item types in recompilation.m). Delete some redundant synonyms (prog_type, mercury_type) for mer_type. Change some type names (e.g. mlds__type) and predicate names (e.g. deforest__goal) to make them unique even without module qualification. Rename the function symbols (e.g. pure, &) that need to be renamed to avoid the need to parenthesize them. Make their replacement names more expressive. Convert some more modules to four space indentation. Avoid excessively long lines, such as those resulting from the automatic substitution of 'mer_type' for 'type'. |
||
|
|
d609181cb9 |
Consider types of the form
Estimated hours taken: 30
Branches: main
Consider types of the form
:- type x ---> f.
to be dummy types, since they contain no information. Optimize them the same
way we currently optimize io.state and store.store.
runtime/mercury_type_info.h:
Add a new type_ctor_rep for dummy types.
runtime/mercury_tabling.h:
Add a representation for "tabled" dummy types, which don't actually
have a level in the trie, so that the runtime system can handle that
fact.
runtime/mercury_ml_expand_body.h:
When deconstructing a value of a dummy type, ignore the actual value
(since it will contain garbage) and instead return the only possible
value of the type.
runtime/mercury_construct.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_copy_body.c:
runtime/mercury_tabling.c:
runtime/mercury_unify_compare_body.h:
library/rtti_implementation.m:
Handle the type_ctor_rep of dummy types.
runtime/mercury_builtin_types.c:
Provide a place to record profiling information about unifications and
comparisons for dummy types.
runtime/mercury_mcpp.h:
java/runtime/TypeCtorRep.java:
library/private_builtin.m:
Add a new type_ctor_rep for dummy types, and fix some previous
discrepancies in type_ctor_reps.
mdbcomp/prim_data.m:
Move a bunch of predicates for manipulating special_pred_ids here from
the browser and compiler directories.
Rename the function symbols of the special_pred_id type to avoid the
need to parenthesize the old `initialise' function symbol.
Convert to four-space indentation.
mdbcomp/rtti_access.m:
Don't hardcode the names of special preds: use the predicates in
prim_data.m.
Convert to four-space indentation.
browser/declarative_execution.m:
Delete some predicates whose functionality is now in
mdbcomp/prim_data.m.
compiler/hlds_data.m:
Replace the part of du type that says whether a type an enum, which
used to be a bool, with something that also says whether the type is a
dummy type.
Convert to four-space indentation.
compiler/make_tags.m:
Compute the value for the new field of du type definitions.
compiler/hlds_out.m:
Write out the new field of du type definitions.
compiler/rtti.m:
Modify the data structures we use to create type_ctor_infos to allow
for dummy types.
Convert to four-space indentation.
compiler/type_ctor_info.m:
Modify the code that generates type_ctor_infos to handle dummy types.
compiler/type_util.m:
Provide predicates for recognizing dummy types.
Convert to four-space indentation.
compiler/unify_proc.m:
Generate the unify and compare predicates of dummy types using a new
code scheme that avoids referencing arguments that contain garbage.
When generating code for unifying or comparing other types, ignore
any arguments of function symbols that are dummy types.
Don't use DCG style access predicates.
compiler/higher_order.m:
Specialize the unification and comparison of values of dummy types.
Break up an excessively large predicate, and factor out common code
from the conditions of a chain of if-then-elses.
compiler/llds.m:
For each input and output of a foreign_proc, include a field saying
whether the value is of a dummy type.
compiler/pragma_c_gen.m:
Fill in the new fields in foreign_proc arguments.
compiler/hlds_goal.m:
Rename some predicates for constructing unifications to avoid
unnecessary ad-hoc overloading. Clarify their documentation.
Rename a predicate to make clear the restriction on its use,
and document the restriction.
Add a predicate for creating simple tests.
Add a utility predicate for setting the context of a goal directly.
compiler/modules.m:
Include dummy types interface files, even if they are private to the
module. This is necessary because with the MLDS backend, the generated
code inside the module and outside the module must agree whether a
function returning a value of the type returns a real value or a void
value, and this requires them to agree on whether the type is dummy
or not.
The impact on interface files is minimal, since very few types are
dummy types, and changing a type from a dummy type to a non-dummy type
or vice versa is an ever rarer change.
compiler/hlds_pred.m:
Provide a representation in the compiler of the trie step for dummy
types.
compiler/layout_out.m:
Print the trie step for dummy types.
compiler/table_gen.m:
Don't table values of dummy types, and record the fact that we don't
by including a dummy trie step in the list of trie steps.
compiler/add_pragma.m:
compiler/add_special_pred.m:
compiler/add_type.m:
compiler/aditi_builtin_ops.m:
compiler/bytecode.m:
compiler/bytecode_gen.m:
compiler/code_gen.m:
compiler/code_info.m:
compiler/continuation_info.m:
compiler/cse_detection.m:
compiler/det_report.m:
compiler/exception_analysis.m:
compiler/inst_match.m:
compiler/livemap.m:
compiler/llds_out.m:
compiler/llds_out.m:
compiler/middle_rec.m:
compiler/ml_call_gen.m:
compiler/ml_closure_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_il.m:
compiler/modecheck_unify.m:
compiler/modes.m:
compiler/opt_util.m:
compiler/post_term_analysis.m:
compiler/post_typecheck.m:
compiler/qual_info.m:
compiler/rl.m:
compiler/rl_exprn.m:
compiler/rl_key.m:
compiler/rtti_out.m:
compiler/simplify.m:
compiler/size_prof.m:
compiler/term_constr_initial.m:
compiler/term_constr_util.m:
compiler/term_norm.m:
compiler/termination.m:
compiler/trace.m:
compiler/typecheck.m:
compiler/unify_gen.m:
Conform to the changes above.
compiler/export.m:
compiler/exprn_aux.m:
compiler/foreign.m:
compiler/polymorphism.m:
compiler/proc_label.m:
compiler/rtti_to_mlds.m:
compiler/special_pred.m:
compiler/stack_alloc.m:
compiler/stack_layout.m:
compiler/state_var.m:
compiler/switch_util.m:
compiler/trace_params.m:
Conform to the changes above.
Convert to four-space indentation.
compiler/mlds_to_java.m:
compiler/var_locn.m:
Conform to the changes above, which requires threading the module_info
through the module.
Convert to four-space indentation.
compiler/mercury_compile.m:
Pass the module_info to mlds_to_java.m.
compiler/ml_util.m:
compiler/polymorphism.m:
compiler/type_ctor_info.m:
compiler/type_util.m:
Delete some previously missed references to the temporary types used
to bootstrap the change to the type_info type's arity.
compiler/polymorphism.m:
Turn back on an optimization that avoids passing parameters (such as
type_infos) to foreign_procs if they are not actually referred to.
compiler/prog_data.m:
Convert to four-space indentation.
library/svvarset.m:
Add a missing predicate.
trace/mercury_trace.c:
Delete the unused function that used to check for dummy types.
tests/debugger/field_names.{m,inp,exp}:
Add to this test case a test of the handling of dummy types. Check that
their values can be printed out during normal execution, and that the
debugger doesn't consider them live nondummy variables, just as it
doesn't consider I/O states live nondummy variables.
|
||
|
|
f57fe1b7df |
Add language and compiler support for finalise declarations.
Estimated hours taken: 8
Branches: main
Add language and compiler support for finalise declarations.
NEWS:
Mention finalise declarations.
compiler/prog_data.m:
Add a new item type for finalise declarations.
Add a new kind of item origin - items can now be introduced as part of
the source-to-source transformation that implements finalise
declarations.
compiler/prog_io.m:
Parse finalise declarations.
compiler/modules.m:
Don't write out finalise declarations in private interfaces.
compiler/hlds_module.m:
Add a slot to the HLDS that stores the names of the predicates in
finalise declarations.
Add access predicates for the above.
compiler/add_pragma.m:
compiler/make_hlds_passes.m:
Fix in incorrect comment: we add initialise declarations on third, not
second, pass.
Restore the code that use the enhanced switch detection capability.
Implement the source-to-source transformation that implements finalise
declarations. This is almost identical to that for intitialise
declarations.
compiler/llds.m:
compiler/llds_out.m:
compiler/transform_llds.m:
Add a slot to the LLDS to hold the name of the predicates specified in
the finalise declarations.
Emit the necessary code to call these predicates after main has finished.
compiler/mlds.m:
compiler/ml_code_gen.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_ilasm.m:
compiler/mlds_to_java.m:
compiler/mlds_to_managed.m:
As above, but for the MLDS.
compiler/mercury_compile.m:
Conform to changes in the MLDS.
XXX This module probably shouldn't manipulating the MLDS directly.
compiler/module_qual.m:
compiler/mercury_to_mercury.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
Conform to the above changes.
library/ops.m:
Add `finalise' as an operator.
runtime/mercury_wrapper.c:
Call any user specified finalise predicates from
mercury_runtime_terminate.
doc/reference_manual.texi:
Document finalise declarations.
tests/hard_coded/Mmakefile:
tests/hard_coded/finalise_decl.m:
tests/hard_coded/finalise_decl.exp:
Tests finalise declarations.
tests/hard_coded/sub-modules/Mmakefile:
tests/hard_coded/sub-modules/finalise_child.m:
tests/hard_coded/sub-modules/finalise_parent.m:
tests/hard_coded/sub-modules/finalise_parent.{exp,exp2}:
Test finalise declarations and sub-modules. There are two expected
outputs because the order of execution between a parent module and its
children of any finalisers is arbitrary.
tests/invalid/Mmakefile:
tests/invalid/bad_finalise_decl.m:
tests/invalid/bad_finalise_decl.err_exp:
Test error messages associated with finalise declarations.
|
||
|
|
3fc6b3f128 |
Change the representation of types in the compiler.
Estimated hours taken: 30 Branches: main Change the representation of types in the compiler. We also add some support for handling kinds, which will be used later when we have a kind system. There are a number of places where kinds are not yet handled correctly -- we assume that all kinds will be `star'. Each of these locations is flagged with a comment that contains "XXX kind inference:". compiler/prog_data.m: Implement the new version of type (type). Change the definition of type_param to be a variable instead of a term, since all parameters must be variables anyway. Implement versions of varset.merge_* which work with tvarsets and produce renamings instead of substitutions. Renamings are more convenient than substitutions because we don't need to know the kinds of type variables in order to build the renaming, and in any case the substitutions shouldn't have anything other than variables in the range so renamings will be more efficient and safe. Define the type of kinds, and provide a couple of utility predicates to operate on them. compiler/prog_io.m: Parse type definition heads as a sym_name and list of type_params, rather than a functor. Handle this change in other predicates. Allow parse errors to be returned by get_with_type/3, and handle these errors. Remove parse_type/2. This predicate didn't do any processing, it just forwarded handling to convert_type/2. compiler/prog_io_typeclass.m: Change type_is_functor_and_vars to handle the new representation of types. In doing so, we retain the old behaviour that pure predicates pass this test, but no other pred or func types. This behaviour is arguably incorrect, but there is little point changing the behaviour at the moment. Instead we should remove these kind of restrictions entirely, but that should be done later. compiler/prog_io_util.m: Provide predicates to both parse and unparse types. We need to unparse types before printing them out, since we do a lot of special case handling when printing out terms and we don't want to duplicate this functionality for types. compiler/module_qual.m: Remove report_invalid_type. We now report ill-formed types during parsing. compiler/superhomogeneous.m: Handle errors from the parsing of type expressions. compiler/prog_out.m: Provide a predicate to convert builtin_types to their string names, and vice-versa. compiler/prog_type.m: Add a bunch of simple tests to use on types which may have kind annotations present. In such cases, types do not have a canonical representation so the simple handling of these tests is not what we want. (Note that these are only required in early phases. The kind annotations -- when they are implemented -- will be removed before type checking.) Consistently handle the application of renamings, substitutions and recursive substitutions to various data structures. compiler/mercury_to_mercury.m: Implement mercury_output_type, mercury_format_type and mercury_type_to_string. These convert the type to a term before formatting -- the reason for this is so that appropriate parentheses are used when formatting operators. This results in some slight changes to error messages, which are reflected in changes to the expected output files in the tests. Remove the old version of mercury_type_to_string. Change the argument ordering of mercury_format_var to be consistent with mercury_format_type. (Other predicates in this module should probably be changed in a similar way, since this argument ordering is more amenable to higher-order programming. But that can be left for another change.) compiler/type_util.m: Implement type unification. The behaviour is much the same as the previous behaviour, except that we now handle apply/N types properly, and we also allow for kind annotations. Implement an occurs check for types. Remove the example definition of replace_eqv_type. It isn't used and would no longer work anyway even if it would have worked before. Add a tvar_kind_map field to ctor_defn. The functions type_info_type and type_ctor_info_type now return types with `void' as their argument, rather than the type that the type_info or type_ctor_info was for. Remove type_util.real_vars/2, since it no longer does anything different from prog_type.vars/2. Remove the commented out implementation of type_to_ctor_and_args/3. Its implementation is in prog_type.m, and has changed significantly in any case. compiler/add_clause.m: Move parse_purity_annotation/3 to prog_io_util.m. compiler/check_typeclass.m: Remove apply_substitution_to_var_list/3, since we now have predicates in prog_type.m to handle such things. compiler/continuation_info.m: compiler/trace.m: Use prog_type.vars/2 instead of type_util.real_vars/2. The two predicates have the same meaning now since type_infos don't contain any type variables. compiler/hlds_data.m: Add tvar_kind_map fields to hlds_type_defn and hlds_class_defn. compiler/hlds_pred.m: Add a tvar_kind_map field to pred_info. compiler/polymorphism.m: Add a tvar_kind_map field to poly_info. Remove unify_corresponding_types, which is no longer used. compiler/hlds_out.m: Use mercury_output_type/5 instead of term_io__write_term/4 and mercury_output_term/5. compiler/post_typecheck.m: Build the void substitution directly rather than building intermediate lists. compiler/recompilation.version.m: Use term__list_subsumes instead of type_list_subsumes, which now operates only on types. This follows up on what was suggested in an XXX comment. compiler/typecheck_errors.m: Use unparse_type/2 to format error messages. compiler/typecheck_info.m: Don't export write_type_with_bindings/5. It is no longer used outside of this module. compiler/*.m: Conform to the above changes. library/rtti_implementation.m: Fix a syntax error that went undetected in our previous implementation, and amazingly enough was compiled correctly anyway. library/term.m: Move the versions of term__unify, term__unify_list and term__list_subsumes that were implemented specifically for types to here. The version of term_unify that takes a list of bound variables (i.e., variables that should not be bound any further) is used by the subsumption check, which in turn is used by recompilation.version.m. tests/invalid/kind.err_exp: tests/invalid/tc_err1.err_exp: tests/invalid/tc_err2.err_exp: tests/misc_tests/pretty_print_test.exp: Update the expected output of these tests to match what we now do. |
||
|
|
6634a3dfc2 |
Implement initialise declarations for the high-level C backend.
Estimated hours taken: 1.5 Branches: main Implement initialise declarations for the high-level C backend. compiler/mlds.m: Add a slot to the MLDS to hold the name of module intialisation predicates. XXX We should use a higher level representation of the names here in case we need to treat them differently in the other target languages. compiler/mlds_to_c.m: Output the necessary INIT and REQUIRED_INIT comments. compiler/mercury_compile.m: compiler/ml_code_gen.m: compiler/ml_elim_nested.m: compiler/ml_optimize.m: compiler/ml_tailcall.m: Handle the extra field in the MLDS. compiler/mlds_to_il.m: compiler/mlds_to_ilasm.m: compiler/mlds_to_java.m: compiler/mlds_to_managed.m: compiler/mlds_to_gcc.m: Handle the extra field in the MLDS. We don't yet support initialise declarations on these backends. |
||
|
|
3c60c0e485 |
Change a bunch of modules to import only one module per line, even
Estimated hours taken: 4 Branches: main compiler/*.m: Change a bunch of modules to import only one module per line, even from the library. compiler/mlds_to_il.m: compiler/mlds_to_managed.m: Convert these modules to our current coding style. Use state variables where appropriate. Use predmode declarations where possible. |
||
|
|
601fe20aba |
Simplify the structure of the compiler by removing the cycle
Estimated hours taken: 3.5 Branches: main Simplify the structure of the compiler by removing the cycle parse_tree -> backend_libs -> check_hlds -> parse_tree from the package dependency graph. I've done this by factoring out the code in backend_libs.foreign and backend_libs.name_mangle that is needed by the frontend of the compiler and putting it in a new module, parse_tree.prog_foreign. This removes the dependency between the parse_tree and backend_libs packages. The obvious downside to this is that the name mangler is now split in two, although such a division was always in implicit in the predicates of the name_mangle module anyway, ie. between those bits that operate on the HLDS/MLDS/LLDS level data structures and those that don't. compiler/name_mangle.m: compiler/foreign.m: compiler/prog_foreign.m: Move code for dealing with foreign language procedures that is required by the parse_tree package into a new module, prog_foreign. Update the formatting in some of these modules so that they match our current coding standard. compiler/*.m: Update to reflect the above change. compiler/notes/compiler_design.html: Include the new module. Fix some spelling errors. |
||
|
|
4970242093 |
Use proc_label data structure defined in mdbcomp.prim_data instead of proc_id
Estimated hours taken: 4 Branches: main Use proc_label data structure defined in mdbcomp.prim_data instead of proc_id defined in mdb.declarative_execution and delete proc_id, since these data structures are almost identical. browser/declarative_execution.m Remove proc_id and flat_module_name types. Use mdbcomp.prim_data.proc_label and mdbcomp.prim_data.module_name instead. browser/declarative_debugger.m browser/declarative_oracle.m browser/declarative_tree.m browser/declarative_user.m Use mdbcomp.prim_data.proc_label and mdbcomp.prim_data.module_name instead of mdb.declarative_execution.proc_id and mdb.declarative_execution.module_name. mdbcomp/prim_data.m compiler/prog_out.m Move sym_name_to_string from prog_out to prim_data. Fix comment for prog_out.sym_name_and_arity_to_string. compiler/bytecode.m compiler/check_typeclass.m compiler/code_gen.m compiler/deforest.m compiler/higher_order.m compiler/hlds_code_util.m compiler/hlds_error_util.m compiler/hlds_module.m compiler/hlds_out.m compiler/intermod.m compiler/layout_out.m compiler/make.module_target.m compiler/make_hlds.m compiler/mercury_compile.m compiler/mercury_to_mercury.m compiler/ml_elim_nested.m compiler/mlds_to_c.m compiler/mlds_to_gcc.m compiler/mlds_to_il.m compiler/mlds_to_java.m compiler/mlds_to_managed.m compiler/modes.m compiler/modules.m compiler/opt_debug.m compiler/options_file.m compiler/polymorphism.m compiler/prog_io.m compiler/prog_rep.m compiler/rl.m compiler/rl_exprn.m compiler/rl_gen.m compiler/rl_info.m compiler/rl_out.pp compiler/rtti.m compiler/rtti_out.m compiler/rtti_to_mlds.m compiler/source_file_map.m compiler/table_gen.m compiler/trans_opt.m compiler/unify_gen.m compiler/unique_modes.m compiler/unused_args.m Use mdbcomp.prim_data.sym_name_to_string instead of prog_out.sym_name_to_string. |
||
|
|
a3352a6e5d |
Do not include :- import_module' and :- use_module' declarations
Estimated hours taken: 22 Branches: main Do not include `:- import_module' and `:- use_module' declarations in the implementation section of .int and .int2 files unless the types that they export are required by the definition of an equivalence type. This should help prevent unnecessary recompilations when new imports are made in the implementation of modules. Break up check_hlds.type_util so that predicates that do not require access to the HLDS are placed in a new module, parse_tree.prog_type. The above change requires some of these predicates. This also removes one of the dependencies between the parse_tree package on modules of the check_hlds package. Remove the remaining such dependency by moving inst_constrains_unconstrained_var/1 from check_hlds.inst_util to parse_tree.prog_mode. None of the modules in parse_tree now depend upon modules in check_hlds. Modify the parser so that import_module declarations that specify more than one module are replaced by multiple import_module declarations, with one module per declaration. This makes the above change easier to implement and is in any case required by the upcoming diff for canonicalizing module interfaces. We also do the same for use_module and include_module declarations. compiler/modules.m: Don't import modules in the implementation section of interface files unless they are required by the definition of equivalence types. compiler/prog_type.m: New module. Move procedures from type_util that do not depend on the HLDS to here so that we can use them when generating interface files. XXX There are probably others that could be moved as well - I only moved those that were immediately useful. compiler/type_util.m: Delete the procedures that have been moved to the new prog_type module. compiler/prog_io.m: Remove the dependency on check_hlds.inst_util. compiler/prog_io_typeclass.m: compiler/equiv_type.m: Remove dependencies on check_hlds.type_util. compiler/prog_util.m: Add a predicate sym_name_get_module_name/2 that is similar to sym_name_get_module_name/3 except that it fails if the input is an unqualified sym_name. compiler/inst_util.m: Delete inst_contains_unconstrained_var/1 from this module and copy it to prog_mode.m. compiler/parse_tree.m: Include the new module. Do not import the check_hlds package as all dependencies on this package have been removed. compiler/*.m: Minor changes to conform to the above. compiler/notes/compiler_design.html: Mention the new module. |
||
|
|
59d2d4a573 |
This adds a module mdbcomp__trace_counts that reads in the
Estimated hours taken: 17 Branches: main This adds a module mdbcomp__trace_counts that reads in the .mercury_trace_counts files produced by the compiler's trace mechanism. The format of said files was slightly changed. As the new module is to be used by the compiler and the debugger, it is placed in the mdbcomp module. This required bringing some types from the compiler into a new module within mdbcomp. browser/trace_counts.m: New module for reading execution trace summaries. browser/prim_data.m: New module holding types and predicates moved in from the compiler. Types: pred_or_func, sym_name, module_name, proc_label, special_pred_id, trace_port Predicates: string_to_sym_name, insert_module_qualifier The mode field of proc_label is now an int instead of a proc_id to avoid pulling proc_id into mdbcomp. browser/mdbcomp.m: Add trace_counts and prim_data to the mdbcomp module. browser/declarative_execution.m: Renamed mdb's definition of module_name to flat_module_name to avoid conflicts with the definition in mdbcomp__prim_data. runtime/mercury_trace_base.c: In the format of .mercury_trace_counts, write module and predicate names now use quoted atom syntax so that names with spaces and non-printable characters can be machine-parsed. browser/: compiler/: Many changes to account for movement of types, and the change to proc_label. |
||
|
|
d0228c4489 |
Some work towards getting the "browser" directory to build in grade java.
Estimated hours taken: 24 Branches: main Some work towards getting the "browser" directory to build in grade java. In particular, this is a step towards fixing a problem in the Java back-end with sub-modules. When compiling code that uses sub-modules, we run up against a Java restriction that a class which is in a package is not allowed to have the same name as the package. The work-around is to use names starting with an uppercase letter for Java class names, and names starting with a lower-case letter for Java package names. XXX This diff is a partial step: it uses names starting with an uppercase letter for Java class names that correspond to Mercury types. It does not yet use an uppercase letter for Java classes that correspond to Mercury modules. XXX With this diff, we just flip the case of the initial letter, which just works around the problem by avoiding the clashing cases, rather than eliminating them. We should use a more complicated mangling that eliminates the problem completely, e.g. map lowercase Mercury names to uppercase, map uppercase Mercury names to "U_" followed by the name. compiler/mlds_to_java.m: Output type names with an initial uppercase letter. compiler/mlds.m: Add a new enumeration type qual_kind, with values type_qual and module_qual. Add a qual_kind field to the fully_qualified_type type. Add a qual_kind argument to the append_class_qualifier function, and if the qual_kind is module_qual, adjust the case of the qualifier appropriately for the back-end. compiler/ml*.m: compiler/rtti_to_mlds.m: Fill in the new qual_kind field, and pass qual_kind to append_class_qualifier. library/builtin.m: library/private_builtin.m: library/type_desc.m: library/io.m: library/rtti_implementation.m: Use type names with an initial uppercase letter. browser/Mmakefile: Work around problems where Java compilers don't like the file names generated by mmc for code using sub-modules. For IL and Java, build with --allow-stubs --no-warn-stubs. browser/declarative_execution.m: Give a Java definition for the "proc_layout" type. This is needed to avoid compilation errors in grade java. |
||
|
|
885fd4a387 |
Remove almost all dependencies by the modules of parse_tree.m on the modules
Estimated hours taken: 12 Branches: main Remove almost all dependencies by the modules of parse_tree.m on the modules of hlds.m. The only such dependencies remaining now are on type_util.m. compiler/hlds_data.m: compiler/prog_data.m: Move the cons_id type from hlds_data to prog_data, since several parts of the parse tree data structure depend on it (particularly insts). Remove the need to import HLDS modules in prog_data.m by making the cons_ids that refer to procedure ids refer to them via a new type that contains shrouded pred_ids and proc_ids. Since pred_ids and proc_ids are abstract types in hlds_data, add predicates to hlds_data to shroud and unshroud them. Also move some other types, e.g. mode_id and class_id, from hlds_data to prog_data. compiler/hlds_data.m: compiler/prog_util.m: Move predicates for manipulating cons_ids from hlds_data to prog_util. compiler/inst.m: compiler/prog_data.m: Move the contents of inst.m to prog_data.m, since that is where it belongs, and since doing so eliminates a circular dependency. The separation doesn't serve any purpose any more, since we don't need to import hlds_data.m anymore to get access to the cons_id type. compiler/mode_util.m: compiler/prog_mode.m: compiler/parse_tree.m: Move the predicates in mode_util that don't depend on the HLDS to a new module prog_mode, which is part of parse_tree.m. compiler/notes/compiler_design.m: Mention prog_mode.m, and delete the mention of inst.m. compiler/mercury_to_mercury.m: compiler/hlds_out.m: Move the predicates that depend on HLDS out of mercury_to_mercury.m to hlds_out.m. Export from mercury_to_mercury.m the predicates needed by the moved predicates. compiler/hlds_out.m: compiler/prog_out.m: Move predicates for printing parts of the parse tree out of hlds_out.m to prog_out.m, since mercury_to_mercury.m needs to use them. compiler/purity.m: compiler/prog_out.m: Move predicates for printing purities from purity.m, which is part of check_hlds.m, to prog_out.m, since mercury_to_mercury.m needs to use them. compiler/passes_aux.m: compiler/prog_out.m: Move some utility predicates (e.g. for printing progress messages) from passes_aux.m to prog_out.m, since some predicates in submodules of parse_tree.m need to use them. compiler/foreign.m: compiler/prog_data.m: Move some types from foreign.m to prog_data.m to allow the elimination of some dependencies on foreign.m from submodules of parse_tree.m. compiler/*.m: Conform to the changes above, mostly by updating lists of imported modules and module qualifications. In some cases, also do some local cleanups such as converting predicate declarations to predmode syntax and fixing white space. |
||
|
|
27d766c073 |
Add a mechanism that allows foreign_decl pieces of code to remain local
Estimated hours taken: 4 Branches: main Add a mechanism that allows foreign_decl pieces of code to remain local to the module. This is needed by the robdd module, which I want to add to the library. doc/reference_manual.texi: Document the new mechanism, which is an optional field in foreign_decl pragmas. compiler/foreign.m: Add a flag to foreign_decls that says whether they are local to their defining module, or exported to other modules. compiler/prog_data.m: Add a field to the foreign_decl item to hold this flag. compiler/prog_io_pragm.m: Parse the optional field in foreign_decl pragmas that specifies this flag. compiler/mercury_to_mercury.m: Print the field in foreign_decl items. compiler/make_hlds.m: Transmit the field from the item to the HLDS. compiler/mercury_compile.m: When generating the list of foreign_decls to put at the start of a C file, do not enclose the local declarations in the usual guards. These guards are defined by the header file, but having seen the header file doesn't guarantee any more that we have seen all the foreign_decls of the module we are compiling. compiler/export.m: compiler/mlds_to_c.m: When generating header files, only include a foreign_decl if it is not marked as local. compiler/mlds_to_java.m: compiler/mlds_to_managed.m: Ignore the local/exported distinction for foreign_decls for now. Implementing it for these languages may be nontrivial, and we don't yet need the capability. compiler/hlds_module.m: compiler/llds_out.m: compiler/recompilation.version.m: compiler/module_qual.m: compiler/modules.m: Conform to the changes above. |
||
|
|
8d878c9172 |
Break some lines that are > 79 chars and fix some indentation.
Estimated hours taken: 0.5 Branches: main compiler/mlds_to_java.m: Break some lines that are > 79 chars and fix some indentation. |
||
|
|
c91313b32f |
Bring these modules up to date with our current coding style.
Estimated hours taken: 8
Branches: main
compiler/modules.m:
compiler/compile_target_code.m:
compiler/handle_options.m:
compiler/bytecode_data.m:
compiler/prog_io_util.m:
Bring these modules up to date with our current coding style. Use
predmode declarations and state variable syntax where appropriate.
Fix inconsistent indentation. Print more error messages using
error_util.m for printing error messages.
compiler/trace_param.m:
Add a new predicate for use by the updated code in handle_options.m.
compiler/error_util.m:
compiler/hlds_error_util.m:
Make error_util.m to be a submodule of parse_tree.m, not hlds.m.
Most of its predicates are not dependent on HLDS data structures.
Move the ones that are into a new module, hlds_error_util, that
is a submodule of hlds.m. Overall, this reduces the dependence
of submodules of parse_tree.m, including modules.m, on submodules
of hlds.m.
compiler/notes/compiler_design.html:
Update the documentation of compiler modes to account for
hlds_error_util.m.
compiler/hlds.m:
compiler/parse_tree.m:
Update the list of included submodules.
compiler/*.m:
Update module imports and module qualifications as needed for the
change above.
tests/invalid/*.{exp,exp2}:
Update the expected outputs of a bunch of test cases to reflect the new
format of some warning messages due to the user error_util; they now
observe line length limits, and print contexts in some cases where they
were previously missing.
|
||
|
|
f108a25591 |
This diff partially cleans up the Java backend.
Estimated hours taken: 4 Branches: main This diff partially cleans up the Java backend. There are only two changes to actual algorithms, although neither of these affect the generated Java code. The first is just to replace calls to error/1 with calls to unexpected/2. The second change is to make the compiler abort while accumulating information about method pointers if it encounters a construct in the MLDS that should have been transformed away before the Java backend was invoked. compiler/mlds_to_java.m: Use predmode syntax throughout. Use state variables in the appropriate spots. Fix some minor indentation and layout problems. Group clauses of the same predicate together. Arrange code so that procedure are listed in a top-down order - (XXX I didn't do this for all the procedures). Add some section headings. Fix some minor errors in comments. Replace calls to error/1 with calls to unexpected/2. Abort execution if we encounter features in the MLDS that cannot be converted to Java, e.g. labels, gotos etc. |
||
|
|
7af03bf50d |
Bug fix for Java grade RTTI definitions.
Estimated hours taken: 6 Branches: main Bug fix for Java grade RTTI definitions. compiler/rtti_to_mlds.m: Re-ordered the output of definitions so that subdefinitions always appear before the definition which uses them. This is neccessary because in Java, static initializers are performed at runtime in textual order, and if a definition relies on another static variable for its constructor but said variable has not been initialized, then it is treated as `null' by the JVM with no warning. This change should not effect the other back-ends. Also added an XXX comment about this invariant. compiler/mlds_to_java.m: compiler/mlds.m: Document the invariant above. |
||
|
|
19b8f361ea |
Mention improvements in the Java back-end.
Estimated hours taken: 0.5 Branches: main NEWS: Mention improvements in the Java back-end. compiler/mlds_to_java.m: Update the Java TODO list. |
||
|
|
b61cb1adea |
Bug fix for casting enumerated types.
Estimated hours taken: 2 Branches: main Bug fix for casting enumerated types. compiler/mlds_to_java.m: Removed the ".value" suffix for expressions of the form: (Type) Thing.value except for the case where Type is int, since this is the only case for which the expression makes sense. |
||
|
|
356a427125 |
Bug fix for importing modules in the Java grade.
Estimated hours taken: 0.1 Branches: main Bug fix for importing modules in the Java grade. compiler/mlds_to_java.m: Output all import statements as comments. This is necessary because they are currently being used incorrectly (eg to import classes in a flat file structure) and safe because we always use fully qualified names anyway. |
||
|
|
9d892fbada |
Augment the descriptors of du functors with information about the type class
Estimated hours taken: 8 Branches: main Augment the descriptors of du functors with information about the type class constraints on their existentially typed arguments (if any). This is not yet used, but will be needed to perform type class membership tests (as we discussed on wednesday). We will need to bump the binary compatibility version number when we start relying on the newly generated data. Turn on the generation of the new type class descriptor data structures, since we now need them to describe functors with type class constraints. This in turn required making the generation of those data structures work for the MLDS backends as well as the LLDS backend. (The original diff that added those data structures updated only the LLDS backend.) compiler/mercury_compile.m: Always generate descriptors for type class declarations in both LLDS and MLDS backends. Generate descriptors for type class instances (which are not referred to from functor descriptors) only if --new-type-class-rtti is given. compiler/rtti.m: Instead of recording just the number of constraints on existentially typed arguments of functors, record the constraints themselves. Add new rtti_ids to describe (arrays of) constraints in DuExistInfos. Add predicates to look up the types of not just the data structures denoted by rtti_ids, but also their element types if they are arrays. This is needed because functor desciptors may now contain arrays of MR_TypeClassConstraints, even though we generate no data structure of that type; we generate structures of type MR_TypeClassConstraintN for various values of N, and cast them to MR_TypeClassConstraint. Factor out some common code. compiler/rtti_out.m: Implement the new field of DuExistInfos, and comment out the code needed to generate type class instances' method descriptors. Comment out the code for generating method addresses. (See the comment on mercury_typeclass_info.h below.) Fix a misleading variable name. compiler/rtti_to_mlds.m: Replace "not yet implemented" aborts when translating the new style type class decl and instance structures with actual translation code. Implement the new field of DuExistInfos. Factor out common code for making arrays of pseudo-typeinfos. compiler/mlds_to_gcc.m: Factor out the code for turning the type of an rtti data structure into the type of an array of them, to allow the latter step not to be done if we are want the type of the array elements. Add code for defining the types of type class declaration and instance descriptors. Implement the new field of DuExistInfos. compiler/type_ctor_info.m: Instead of recording just the number of constraints on existentially typed arguments of functors, record the constraints themselves. compiler/type_class_info.m: Generate instance descriptors only if requested. Export a function now needed by type_ctor_info.m. compiler/mlds.m: Allow mlds__rtti_type to refer to the types of elements of the arrays we generate, even if there is no rtti_id that has that type. compiler/mlds_to_c.m: Module qualify type class declaration and instance descriptors, at least for now; it is only base_typeclass_infos for which we need to detect duplicate definitions in different modules. Modify the types of du functor descriptors to include type class constraint information. compiler/ml_closure_gen.m: compiler/ml_util.m: compiler/mlds_to_c.m: compiler/mlds_to_java.m: compiler/opt_debug.m: Trivial changes to conform to the changes above. runtime/mercury_type_info.h: Add a field giving a list of type class constraints to MR_DuExistInfo. Move the definitions of the types describing type class constraints here from mercury_typeclass_info.h, since MR_DuExistInfo now refers to it. mercury_type_info.h cannot include mercury_typeclass_info.h without causing a circularity problem. runtime/mercury_types.h: Move a bunch of typedefs of structs here from mercury_typeclass_info.h, again to avoid circularity problems. runtime/mercury_typeclass_info.h: Remove the stuff moved to mercury_type_info.h and mercury_types.h. For now, do not include the code addresses of the procedure's representing an instance's methods in the instance structure, since the MLDS backend doesn't really have a notion of a generic code address, and even if it did it doesn't have an equivalent of the LLDS backend's code address to proc layout structure mapping, so the code addresses by themselves would be useless. (The code addresses needed for method calls are stored in the base_typeclass_info, not the instance structure.) When we want to start using information about instance methods in ways beyond what is afforded by the dictionary in the base_typeclass_info, we will need to revisit this decision, and will probably have to include the necessary information about the instance methods in the instance's data structure directly instead of via a pointer to the instance method implementations themselves. runtime/mercury_type_info.h: runtime/mercury_tags.h: Move a macro used to define enum constants that compiler generated code can refer to from mercury_type_info.h to mercury_tags.h (which already contains a similar macro whose definition is also dependent on --reserve-tag), since it is now also needed in mercury_proc_id.h. runtime/mercury_proc_id.h: Use that macro define MR_PREDICATE and MR_FUNCTION, since the compiler now generates references to them. |
||
|
|
eef98d77fa |
Bug fix for enumerated type switch statements in Java.
Estimated hours taken: 9 Branches: main Bug fix for enumerated type switch statements in Java. compiler/mlds_to_java.m: Modified rval_is_enum_object/1 so that it considers field selections as well as vars. This fixes a problem that arose in producing the switch statement for fold_bits/7 in library/sparse_bitset, where the enumerated type was not detected, so it was trying to switch on an Object: (mercury.sparse_bitset.fold_bits_7_p_3_env_0) env_ptr).Dir_8 as opposed to: (mercury.sparse_bitset.fold_bits_7_p_3_env_0) env_ptr).Dir_8.value which is what it should have. After making this change, it was also necessary to correct a call in output_initializer_body from output_rval_maybe_with_enum to just plain output_rval, since at that point it is known that the Rval is not an enum object. The standard library will now compile without error in grade java. |
||
|
|
7c8066732a |
Added support for progname and exit status in grade Java.
Estimated hours taken: 3 Branches: main Added support for progname and exit status in grade Java. compiler/mlds_to_java.m: Added code to maybe_write_main_driver/5 to store the main class's name and exit status in mercury.runtime.JavaInternal's static variables. Also, main() now calls java.lang.System.exit() instead of returning, since Java insists that main must have void return type. java/runtime/JavaInternal.java: Added static variables "progname" and "exit_status". |
||
|
|
425287b6e0 |
More work on the Java back-end. The standard library now compiles
Estimated hours taken: 6
Branches: main
More work on the Java back-end. The standard library now compiles
in grade `java', and hello world (the version using io__write_string,
and linked against the standard library in library/*.m, not the
hand-coded one in java/library/*.java) now works!
compiler/make_hlds.m:
Ignore `pragma type_spec' declarations for the Java back-end.
This works around a problem where javac was failing to compile
some of our generated code due to it overflowing limits on
file name length for the names of the .class files for some
nested classes.
compiler/mlds_to_java.m:
Add some comments. Add myself to the "main authors" list.
library/string.m:
Provide Java definitions of string__first_char and
string__unsafe_index. (These are needed for string.append,
which is used by private_builtin.sorry.)
library/io.m:
Provide Java definitions of io__write_{string,int,char,float}/3.
java/runtime/TypeCtorInfo_Struct.java:
Fix a cut-and-paste error.
java/runtime/TypeInfo_Struct.java:
Improve the implementation of the TypeInfo_Struct(Object)
constructor so that it doesn't throw exceptions during
the initialization of the standard library.
java/runtime/FA_TypeInfo_Struct1.java:
Make this type inherit from TypeInfo_Struct.
|
||
|
|
b50430e8b9 |
Bug fixes for the Java back-end.
Estimated hours taken: 2 Branches: main Bug fixes for the Java back-end. The standard library now almost compiles in grade java. compiler/mlds_to_java.m: Output Java foreign declarations before any other code, to fix a problem with references to the TYPE_CTOR_REP constants in library/private_builtin.m. Fix some bugs where we were not being consistent about mangling the module name when naming the classes used to simulate taking procedure addresses. This bug broke Java compilation of library/char.m. Fix some bugs where the compiler was getting confused about which types map to array types in Java. For MLDS casts that cast to type_info or pseudo_type_info, generate Java constructor calls, not Java casts. This fixes type errors in the generated Java code. Simplify the code for hand_defined_type. compiler/rtti.m: Fix a bug in tc_rtti_name_java_type: map typeclass_infos to the Java type "java.lang.Object[]", not "java.lang.Integer[]". The latter didn't work because the elements which hold the method addresses do not have type java.lang.Integer. java/runtime/DuExistInfo.java: java/runtime/NotagFunctorDesc.java: Define constructors for these types. java/runtime/TypeInfo_Struct.java: Define some additional constructors for this type. library/builtin.m: Provide Java stub definitions of - classes for the types func/0 and c_pointer/0; - unify/compare preds for func, c_pointer, tuple, and void; Define Java definitions for the additional modes of compare/3 (they just call the first mode). library/exception.m: Define Java versions of make_io_state and consume_io_state, and Java stubs for throw_impl and catch_impl. Change try_all so that it calls catch_impl, like try does, rather than calling builtin_catch directly. This is needed since the .NET and Java back-ends only define catch_impl, not builtin_catch. library/io.m: Provide Java `pragma foreign_type' declarations for the types array.array(T) and io.system_error. This is needed to avoid compilation errors when building in grade `java'. library/private_builtin.m: Delete the Java definition of the type_info for type_info/1, because that is generated automatically now, after petdr's recent bug fix. Provide Java stubs definitions of the unify/compare preds for ref/1, heap_pointer/0, type_ctor_info, type_info, base_typeclass_info, and typeclass_info. Provide Java definition of dummy_var. library/type_desc.m: Provide Java stub definitions of - classes for type_desc/0 and type_ctor_desc/0 - unify/compare preds for those types library/store.m: Define unification and comparison predicates for the store(S) type. This is needed because the automatically generated ones might not have the right semantics, but also because the Java back-end generates some invalid code for the automatically generated unification and compare predicates (the generated code has some invalid references to "dummy_var"). |
||
|
|
12418653ee |
Bug fixes for the Java back-end.
Estimated hours taken: 12 Branches: main Bug fixes for the Java back-end. compiler/mlds_to_java.m: Fix a bug where we were outputting an incorrect type for nested structure initializers Fix a bug where we were outputting invalid syntax for some array initializers. Fix a bug where the code output for string comparisons was not properly parenthesized. compiler/mlds.m: Add a new argument to init_struct that specifies the type of the structure being initialized. This is needed to handled nested structure initializers for the Java back-end. compiler/rtti.m: Add new alternatives to ctor_rtti_name for all the types which are used as nested components of RTTI structures. This is needed in order to have appropriate RTTI types to use in rtti_to_mlds.m for the new field of init_struct. compiler/rtti_to_mlds.m: Substantial changes to fill in the new field of init_struct in all the generated initializers. compiler/ml_elim_nested.m: compiler/ml_optimize.m: compiler/ml_unify_gen.m: compiler/ml_util.m: compiler/mlds_to_c.m: compiler/mlds_to_gcc.m: compiler/mlds_to_il.m: Minor changes to handle the new argument to init_struct. compiler/mlds_to_gcc.m: compiler/opt_debug.m: Minor changes to handle the new alternatives for ctor_rtti_name. compiler/mlds_to_gcc.m: Fix a bug where it was generating a structure type, rather than an array thereof, for res_name_ordered_table. |
||
|
|
8693e293a2 |
This diff makes hlds_pred.m and many callers of its predicates easier to read
Estimated hours taken: 4 Branches: main This diff makes hlds_pred.m and many callers of its predicates easier to read and to maintain, but contains no changes in algorithms whatsoever. compiler/hlds_pred.m: Bring this module into line with our current coding standards. Use predmode declarations, functions, and state variable syntax when appropriate. Reorder arguments of predicates where necessary for the use of state variable syntax, and where this improves readability. Replace old-style lambdas with new-style lambdas or with partially applied named procedures. Standardize indentation. compiler/*.m: Conform to the changes in hlds_pred.m. This mostly means using the new argument orders of predicates exported by hlds_pred.m. Where this is now conveniently possible, change predicates to use state variable notation. In some modules, using state variable notation required changing the orders of arguments in the module's top predicate. compiler/passes_aux.m: Change the order of arguments in the calls this module makes to allow the callees to use state variable notation. Convert this module to state variable notation too. |
||
|
|
f007b45df8 |
Implement the infrastructure for term size profiling.
Estimated hours taken: 400
Branches: main
Implement the infrastructure for term size profiling. This means adding two
new grade components, tsw and tsc, and implementing them in the LLDS code
generator. In grades including tsw (term size words), each term is augmented
with an extra word giving the number of heap words it contains; in grades
including tsc (term size cells), each term is augmented with an extra word
giving the number of heap cells it contains. The extra word is at the start,
at offset -1, to leave almost all of the machinery for accessing the heap
unchanged.
For now, the only way to access term sizes is with a new mdb command,
"term_size <varspec>". Later, we will use term sizes in conjunction with
deep profiling to do experimental complexity analysis, but that requires
a lot more research. This diff is a necessary first step.
The implementation of term size profiling consists of three main parts:
- a source-to-source transform that computes the size of each heap cell
when it is constructed (and increments it in the rare cases when a free
argument of an existing heap cell is bound),
- a relatively small change to the code generator that reserves the extra
slot in new heap cells, and
- extensions to the facilities for creating cells from C code to record
the extra information we now need.
The diff overhauls polymorphism.m to make the source-to-source transform
possible. This overhaul includes separating type_ctor_infos and type_infos
as strictly as possible from each other, converting type_ctor_infos into
type_infos only as necessary. It also includes separating type_ctor_infos,
type_infos, base_typeclass_infos and typeclass_infos (as well as voids,
for clarity) from plain user-defined type constructors in type categorizations.
This change needs this separation because values of those four types do not
have size slots, but they ought to be treated specially in other situations
as well (e.g. by tabling).
The diff adds a new mdb command, term_size. It also replaces the proc_body
mdb command with new ways of using the existing print and browse commands
("print proc_body" and "browse proc_body") in order to make looking at
procedure bodies more controllable. This was useful in debugging the effect
of term size profiling on some test case outputs. It is not strictly tied
to term size profiling, but turns out to be difficult to disentangle.
compiler/size_prof.m:
A new module implementing the source-to-source transform.
compiler/notes/compiler_design.html:
Mention the new module.
compiler/transform_hlds.m:
Include size_prof as a submodule of transform_hlds.
compiler/mercury_compile.m:
If term size profiling is enabled, invoke its source-to-source
transform.
compiler/hlds_goal.m:
Extend construction unifications with an optional slot for recording
the size of the term if the size is a constant, or the identity of the
variable holding the size, if the size is not constant. This is
needed by the source-to-source transform.
compiler/quantification.m:
Treat the variable reference that may be in this slot as a nonlocal
variable of construction unifications, since the code generator needs
this.
compiler/compile_target_code.m:
Handle the new grade components.
compiler/options.m:
Implement the options that control term size profiling.
doc/user_guide.texi:
Document the options and grade components that control term size
profiling, and the term_size mdb command. The documentation is
commented out for now.
Modify the wording of the 'u' HLDS dump flag to include other details
of unifications (e.g. term size info) rather than just unification
categories.
Document the new alternatives of the print and browse commands. Since
they are for developers only, the documentation is commented out.
compiler/handle_options.m:
Handle the implications of term size profiling grades.
Add a -D flag value to print HLDS components relevant to HLDS
transformations.
compiler/modules.m:
Import the new builtin library module that implements the operations
needed by term size profiling automatically in term size profiling
grades.
Switch the predicate involved to use state var syntax.
compiler/prog_util.m:
Add predicates and functions that return the sym_names of the modules
needed by term size profiling.
compiler/code_info.m:
compiler/unify_gen.m:
compiler/var_locn.m:
Reserve an extra slot in heap cells and fill them in in unifications
marked by size_prof.
compiler/builtin_ops.m:
Add term_size_prof_builtin.term_size_plus as a builtin, with the same
implementation as int.+.
compiler/make_hlds.m:
Disable warnings about clauses for builtins while the change to
builtin_ops is bootstrapped.
compiler/polymorphism.m:
Export predicates that generate goals to create type_infos and
type_ctor_infos to add_to_construct.m. Rewrite their documentation
to make it more detailed.
Make orders of arguments amenable to the use of state variable syntax.
Consolidate knowledge of which type categories have builtin unify and
compare predicates in one place.
Add code to leave the types of type_ctor_infos alone: instead of
changing their types to type_info when used as arguments of other
type_infos, create a new variable of type type_info instead, and
use an unsafe_cast. This would make the HLDS closer to being type
correct, but this new code is currently commented out, for two
reasons. First, common.m is currently not smart enough to figure out
that if X and Y are equal, then similar unsafe_casts of X and Y
are also equal, and this causes the compiler do not detect some
duplicate calls it used to detect. Second, the code generators
are also not smart enough to know that if Z is an unsafe_cast of X,
then X and Z do not need separate stack slots, but can use the same
slot.
compiler/type_util.m:
Add utility predicates for returning the types of type_infos and
type_ctor_infos, for use by new code in polymorphism.m.
Move some utility predicates here from other modules, since they
are now used by more than one module.
Rename the type `builtin_type' as `type_category', to better reflect
what it does. Extend it to put the type_info, type_ctor_info,
typeclass_info, base_typeclass_info and void types into categories
of their own: treating these types as if they were a user-defined
type (which is how they used to be classified) is not always correct.
Rename the functor polymorphic_type to variable_type, since types
such as list(T) are polymorphic, but they fall into the user-defined
category. Rename user_type as user_ctor_type, since list(int) is not
wholly user-defined but falls into this category. Rename pred_type
as higher_order_type, since it also encompasses functions.
Replace code that used to check for a few of the alternatives
of this type with code that does a full switch on the type,
to ensure that they are updated if the type definition ever
changes again.
compiler/pseudo_type_info.m:
Delete a predicate whose updated implementation is now in type_util.m.
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
Still treat type_infos, type_ctor_infos, typeclass_infos and
base_typeclass_infos as user-defined types, but prepare for when
they won't be.
compiler/hlds_pred.m:
Require interface typeinfo liveness when term size profiling is
enabled.
Add term_size_profiling_builtin.increase_size as a
no_type_info_builtin.
compiler/hlds_out.m:
Print the size annotations on unifications if HLDS dump flags call
for unification details. (The flag test is in the caller of the
modified predicate.)
compiler/llds.m:
Extend incr_hp instructions and data_addr_consts with optional fields
that allow the code generator to refer to N words past the start of
a static or dynamic cell. Term size profiling uses this with N=1.
compiler/llds_out.m:
When allocating memory on the heap, use the macro variants that
specify an optional offset, and specify the offset when required.
compiler/bytecode_gen.m:
compiler/dense_switch.m:
compiler/dupelim.m:
compiler/exprn_aux.m:
compiler/goal_form.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/inst_match.m:
compiler/intermod.m:
compiler/jumpopt.m:
compiler/lambda.m:
compiler/livemap.m:
compiler/ll_pseudo_type_info.m:
compiler/lookup_switch.m:
compiler/magic_util.m:
compiler/middle_rec.m:
compiler/ml_code_util.m:
compiler/ml_switch_gen.m:
compiler/ml_unify_gen.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/modecheck_unify.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/par_conj_gen.m:
compiler/post_typecheck.m:
compiler/reassign.m:
compiler/rl.m:
compiler/rl_key.m:
compiler/special_pred.m:
compiler/stack_layout.m:
compiler/static_term.m:
compiler/string_switch.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unused_args.m:
compiler/use_local_vars.m:
Minor updates to conform to the changes above.
library/term_size_prof_builtin.m:
New module containing helper predicates for term size profiling.
size_prof.m generates call to these predicates.
library/library.m:
Include the new module in the library.
doc/Mmakefile:
Do not include the term_size_prof_builtin module in the library
documentation.
library/array.m:
library/benchmarking.m:
library/construct.m:
library/deconstruct.m:
library/io.m:
library/sparse_bitset.m:
library/store.m:
library/string.m:
Replace all uses of MR_incr_hp with MR_offset_incr_hp, to ensure
that we haven't overlooked any places where offsets may need to be
specified.
Fix formatting of foreign_procs.
Use new macros defined by the runtime system when constructing
terms (which all happen to be lists) in C code. These new macros
specify the types of the cell arguments, allowing the implementation
to figure out the size of the new cell based on the sizes of its
fields.
library/private_builtin.m:
Define some constant type_info structures for use by these macros.
They cannot be defined in the runtime, since they refer to types
defined in the library (list.list and std_util.univ).
util/mkinit.c:
Make the addresses of these type_info structures available to the
runtime.
runtime/mercury_init.h:
Declare these type_info structures, for use in mkinit-generated
*_init.c files.
runtime/mercury_wrapper.[ch]:
Declare and define the variables that hold these addresses, for use
in the new macros for constructing typed lists.
Since term size profiling can refer to a memory cell by a pointer
that is offset by one word, register the extra offsets with the Boehm
collector if is being used.
Document the incompatibility of MR_HIGHTAGS and the Boehm collector.
runtime/mercury_tags.h:
Define new macros for constructing typed lists.
Provide macros for preserving the old interface presented by this file
to the extent possible. Uses of the old MR_list_cons macro will
continue to work in grades without term size profiling. In term
size profiling grades, their use will get a C compiler error.
Fix a bug caused by a missing backslash.
runtime/mercury_heap.h:
Change the basic macros for allocating new heap cells to take
an optional offset argument. If this is nonzero, the macros
increment the returned address by the given number of words.
Term size profiling specifies offset=1, reserving the extra
word at the start (which is ignored by all components of the
system except term size profiling) for holding the size of the term.
Provide macros for preserving the old interface presented by this file
to the extent possible. Since the old MR_create[123] and MR_list_cons
macros did not specify type information, they had to be changed
to take additional arguments. This affects only hand-written C code.
Call new diagnostic macros that can help debug heap allocations.
Document why the macros in this files must expand to expressions
instead of statements, evn though the latter would be preferable
(e.g. by allowing them to declare and use local variables without
depending on gcc extensions).
runtime/mercury_debug.[ch]:
Add diagnostic macros to debug heap allocations, and the functions
behind them if MR_DEBUG_HEAP_ALLOC is defined.
Update the debugging routines for hand-allocated cells to print the
values of the term size slot as well as the other slots in the relevant
grades.
runtime/mercury_string.h:
Provide some needed variants of the macro for copying strings.
runtime/mercury_deconstruct_macros.h:
runtime/mercury_type_info.c:
Supply type information when constructing terms.
runtime/mercury_deep_copy_body.h:
Preserve the term size slot when copying terms.
runtime/mercury_deep_copy_body.h:
runtime/mercury_ho_call.c:
runtime/mercury_ml_expand_body.h:
Use MR_offset_incr_hp instead of MR_incr_hp to ensure that all places
that allocate cells also allocate space for the term size slot if
necessary.
Reduce code duplication by using a now standard macro for copying
strings.
runtime/mercury_grade.h:
Handle the two new grade components.
runtime/mercury_conf_param.h:
Document the C macros used to control the two new grade components,
as well as MR_DEBUG_HEAP_ALLOC.
Detect incompatibilities between high level code and profiling.
runtime/mercury_term_size.[ch]:
A new module to house a function to find and return term sizes
stored in heap cells.
runtime/mercury_proc_id.h:
runtime/mercury_univ.h:
New header files. mercury_proc_id.h contains the (unchanged)
definition of MR_Proc_Id, while mercury_univ.h contains the
definitions of the macros for manipulating univs that used to be
in mercury_type_info.h, updated to use the new macros for allocating
memory.
In the absence of these header files, the following circularity
would ensue:
mercury_deep_profiling.h includes mercury_stack_layout.h
- needs definition of MR_Proc_Id
mercury_stack_layout.h needs mercury_type_info.h
- needs definition of MR_PseudoTypeInfo
mercury_type_info.h needs mercury_heap.h
- needs heap allocation macros for MR_new_univ_on_hp
mercury_heap.h includes mercury_deep_profiling.h
- needs MR_current_call_site_dynamic for recording allocations
Breaking the circular dependency in two places, not just one, is to
minimize similar problems in the future.
runtime/mercury_stack_layout.h:
Delete the definition of MR_Proc_Id, which is now in mercury_proc_id.h.
runtime/mercury_type_info.h:
Delete the macros for manipulating univs, which are now in
mercury_univ.h.
runtime/Mmakefile:
Mention the new files.
runtime/mercury_imp.h:
runtime/mercury.h:
runtime/mercury_construct.c:
runtime/mercury_deep_profiling.h:
Include the new files at appropriate points.
runtime/mercury.c:
Change the names of the functions that create heap cells for
hand-written code, since the interface to hand-written code has
changed to include type information.
runtime/mercury_tabling.h:
Delete some unused macros.
runtime/mercury_trace_base.c:
runtime/mercury_type_info.c:
Use the new macros supplying type information when constructing lists.
scripts/canonical_grade_options.sh-subr:
Fix an undefined sh variable bug that could cause error messages
to come out without identifying the program they were from.
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/canonical_grade_options.sh-subr:
scripts/mgnuc.in:
Handle the new grade components and the options controlling them.
trace/mercury_trace_internal.c:
Implement the mdb command "term_size <varspec>", which is like
"print <varspec>", but prints the size of a term instead of its value.
In non-term-size-profiling grades, it prints an error message.
Replace the "proc_body" command with optional arguments to the "print"
and "browse" commands.
doc/user_guide.tex:
Add documentation of the term_size mdb command. Since the command is
for implementors only, and works only in grades that are not yet ready
for public consumption, the documentation is commented out.
Add documentation of the new arguments of the print and browse mdb
commands. Since they are for implementors only, the documentation
is commented out.
trace/mercury_trace_vars.[ch]:
Add the functions needed to implement the term_size command, and
factor out the code common to the "size" and "print"/"browse" commands.
Decide whether to print the name of a variable before invoking the
supplied print or browse predicate on it based on a flag design for
this purpose, instead of overloading the meaning of the output FILE *
variable. This arrangement is much clearer.
trace/mercury_trace_browse.c:
trace/mercury_trace_external.c:
trace/mercury_trace_help.c:
Supply type information when constructing terms.
browser/program_representation.m:
Since the new library module term_size_prof_builtin never generates
any events, mark it as such, so that the declarative debugger doesn't
expect it to generate any.
Do the same for the deep profiling builtin module.
tests/debugger/term_size_words.{m,inp,exp}:
tests/debugger/term_size_cells.{m,inp,exp}:
Two new test cases, each testing one of the new grades.
tests/debugger/Mmakefile:
Enable the two new test cases in their grades.
Disable the tests sensitive to stack frame sizes in term size profiling
grades.
tests/debugger/completion.exp:
Add the new "term_size" mdb command to the list of command completions,
and delete "proc_body".
tests/debugger/declarative/dependency.{inp,exp}:
Use "print proc_body" instead of "proc_body".
tests/hard_coded/nondet_c.m:
tests/hard_coded/pragma_inline.m:
Use MR_offset_incr_hp instead of MR_incr_hp to ensure that all places
that allocate cells also allocate space for the term size slot if
necessary.
tests/valid/Mmakefile:
Disable the IL tests in term size profiling grades, since the term size
profiling primitives haven't been (and probably won't be) implemented
for the MLDS backends, and handle_options causes a compiler abort
for grades that combine term size profiling and any one of IL, Java
and high level C.
|
||
|
|
31a4f2d85e |
Some fixes to the Java back-end to make it support RTTI
Estimated hours taken: 18 Branches: main Some fixes to the Java back-end to make it support RTTI better. The aim is to at least be able to *compile* code that makes use of polymorphism (e.g. the Mercury standard library!), although that aim is not yet achieved with this diff. Getting code which actually *uses* the RTTI to work is still a long way off... compiler/rtti.m: compiler/mlds_to_java.m: Fix some bugs in the code to output RTTI type names. compiler/mlds_to_java.m: Output the RTTI definitions. This is needed to avoid errors in code which references them. Handle initializers better; in particular deal with nested initializers properly. Pass the current module name down to output_lval, so that we can module-qualify data names only if they occur in a different module. This is needed to ensure that static data defined in other modules gets module-qualified, but local variables don't. This also required change some places which were incorrectly calling output_fully_qualified_name to instead call output_name. Add comments in the generated output code when generating "java.lang.Object", so that it is clearer what kind of object is involved. Add some special treatment for the types with hand-defined RTTI. java/runtime/*.java: Add some definitions of RTTI types, and some new constructors for the RTTI types that were already defined. These are currently all just stubs. |
||
|
|
599ef915d9 |
Instead of being relied on all over the place, centralize the compiler's
Estimated hours taken: 16 Branches: main Instead of being relied on all over the place, centralize the compiler's knowledge of the names of unify, compare and index predicates in one place, special_pred.m. This should make it easy to change the naming scheme once we switch over to compiler-generated type_ctor_infos for builtin types, which will eliminate the runtime system's knowledge of the naming scheme. compiler/hlds_pred.m: Add a field to pred_infos that says whether the predicate is a unify, compare or index predicate, and if so, for which type constructor. Code that used to test the predicate's name for __Unify__ etc now tests this field instead. Similarly the code that used to employ devious tricks to find out the type the unify/compare/index predicate is for. compiler/rtti.m: Include this field in rtti_proc_labels as well as pred_infos. compiler/make_hlds.m: Fill in this field as appropriate. compiler/proc_label.m: Replace the predicate name with special_pred_id in the proc_labels of unify, index and compare preds. compiler/special_pred.m: Narrow the interface to prevent reliance on the naming scheme for compiler-generated unify, compare and index predicates, except when absolutely necessary, i.e. when creating names for them. Narrow the mechanism required to reverse-engineer the type constructor a unify/compare/index predicate is for from the types to the functionality required by higher_order.m. compiler/code_gen.m: compiler/det_report.m: compiler/higher_order.m: compiler/intermod.m: compiler/layout_out.m: compiler/magic_util.m: compiler/ml_code_util.m: compiler/name_mangle.m: compiler/opt_debug.m: compiler/opt_util.m: compiler/optimize.m: compiler/polymorphism.m: compiler/post_typecheck.m: compiler/proc_label.m: compiler/rl_exprn.m: compiler/rl_key.m: compiler/simplify.m: compiler/termination.m: compiler/typecheck.m: compiler/unify_proc.m: compiler/unused_args.m: Update code and comments to conform to the changes above. compiler/hlds_out.m: Don't refer to the 'type' that a unify, compare or index predicate is for; refer to the type *constructor*. compiler/mlds_to_java.m: Delete an unused predicate. tests/invalid/purity/purity.err_exp: Update this expected output for the change in hlds_out.m. |
||
|
|
9e6462b383 |
More fixes to make the Java back-end work better.
Estimated hours taken: 4 Branches: main More fixes to make the Java back-end work better. compiler/mlds_to_java.m: Fix a bug in the name mangling, where we were adding an "mr_" prefix to uses (but not definitions) of types whose name happens to be a Java keyword. We don't need to add an "mr_" prefix for those cases, since the "_0" appended for the arity will already ensure that the name is not a Java keyword. Fix a bug where we were not outputting the correct Java type for Mercury types of the form array(T) where T is a type variable. For those types, we need to output "java.lang.Object", not "java.lang.Object[]", since the type needs to be able to hold arrays of any type, e.g. "int[]". Simplify the handling of procedures declared `external': rather than defining foo() as a forwarding procedure that calls extern_foo(), just leave foo() undefined, and assume that the `pragma java_code' for this module defineds foo(). |
||
|
|
8e9c813e37 |
Various fixes to make the Java back-end work better.
Estimated hours taken: 24 Branches: main Various fixes to make the Java back-end work better. compiler/ml_code_gen.m: Make sure that no module in the generated MLDS tries to import itself. Also, add some XXX comments about the handling of model_semi foreign_procs for Java and IL. compiler/ml_code_util.m: Fix a bug with the handling of `top_unused' modes with `--det-copy-out'. compiler/mlds_to_java.m: Add an XXX comment about the problem with type names clashing with constructor names. Add an XXX comment about ignoring `pragma foreign_import' and `pragma export' for Java. Fix the code so that we handle `foreign_decl' and `foreign_code' for Java properly -- previously, we were generating code for `foreign_decl' in the wrong place, and `foreign_code' was just ignored. Handle procedures defined as `external' by calling `extern_Foo', rather than generating a declaration with no body, because Java syntax doesn't allow that. Fix a bug where some names weren't getting mangled properly. Fix some bugs where it was not generating correct package names or module qualifiers for modules in the Mercury standard library. library/Mmakefile: Add support for the `java' grade. This involved adding new targets `javas' and `classes', and making the main `library' target depend on these if the grade is `java'. library/builtin.m: Add (stub) Java implementations of various builtins: - the type_ctor_infos for the builtin types int, string, character - builtin.unify/2 and builtin.compare/3 library/private_builtin.m: Add (stub) Java implementations of various builtins: - the type_ctor_info for private_builtin.type_info/1 - builtin_compare_int/3, builtin_compare_string/3, builtin_strcmp/3 library/math.m: - Fix a couple of bugs in the Mercury code for "log" and "log2". library/std_util.m: Provide a Java implementation for cc_multi_equal/2. Avoid a compiler warning for the Mercury implementation of semidet_succeed and semidet_fail. library/store.m: Rename the constructor for the `store/1' type, to work around a bug in the Java back-end. library/string.m: Fix bugs in the Mercury implementation of string__contains_char and string__split. Provide a Java implementation of string__length. library/type_desc.m: Provide Java implementations of type_of/1 and has_type/2. Provide (stub) implementations of the builtin types type_desc/0 and type_ctor_desc/0. |
||
|
|
66eb5b46e4 |
Fix two related anomalies. One was that base_typeclass_infos were being
Estimated hours taken: 6 Branches: main Fix two related anomalies. One was that base_typeclass_infos were being created using the fcailities of rtti.m, but they were being referred to using data_addr, not rtti_addr, in the LLDS backend, and they had similar special treatment in the MLDS backend. The second is the special treatment of base_typeclass_infos within rtti.m, rtti_out.m and rtti_to_mlds.m, due to the fact that unlike the other data structures defined in rtti.m, their id does not include an rtti_type_ctor. When we move over to the proposed data structures for representing type class and instance information, base_typeclass_infos won't be alone in not including an rtti_type_ctor in their id. compiler/rtti.m: Introduce the notion of an rtti_id, which includes an rtti_type_ctor only for references to data structures for which that is appropriate. compiler/llds.m: compiler/mlds.m: Delete the redundant data_name base_typeclass_info. Use rtti_ids where appropriate. compiler/llds_out.m: Delete the code handling the deleted data_name base_typeclass_info. Conform to the changes to rtti.m and llds.m. compiler/ll_pseudo_type_info.m: compiler/ml_closure_gen.m: compiler/ml_unify_gen.m: compiler/ml_util.m: compiler/mlds_to_c.m: compiler/mlds_to_gcc.m: compiler/mlds_to_il.m: compiler/mlds_to_il.m: compiler/mlds_to_java.m: compiler/opt_debug.m: compiler/rtti_out.m: compiler/rtti_to_mlds.m: compiler/stack_layout.m: compiler/unify_gen.m: Conform to the changes above, which in several cases allows us to eliminate the special handling of base_typeclass_infos. compiler/base_typeclass_info.m: Follow up on an old XXX, and make a predicate tail recursive. |
||
|
|
1cb657b998 |
Reduce inappropriate dependencies on ll_backend modules.
Estimated hours taken: 3 Branches: main Reduce inappropriate dependencies on ll_backend modules. Except for simplification of unnecessarily complicated logic in dependency_graph.m, this change only moves functionality around. compiler/llds_out.m: compiler/c_util.m: compiler/name_mangle.m: Move predicates that are used by multiple backends from ll_backend__llds_out to backend_libs__c_util and to a new module backend_libs__name_mangle. Make the relevant ones functions, and give some of them more meaningful names. compiler/trace.m: compiler/hlds_goal.m: Move a backend-independent predicate from ll_backend__trace to hlds__hlds_goal. compiler/llds.m: compiler/trace_params.m: Move the definition of the trace_port type from ll_backend__llds to libs__trace_params to avoid having libs__trace_params depend on ll_backend. compiler/exprn_aux.m: compiler/globals.m: Move the definition of the imported_is_constant from ll_backend__exprn_aux to libs__globals to avoid having libs__globals depend on ll_backend. compiler/*.m: Conform to the above changes. This removes many inappropriate dependencies on the LLDS backend. |
||
|
|
9551640f55 |
Import only one compiler module per line. Sort the blocks of imports.
Estimated hours taken: 2 Branches: main compiler/*.m: Import only one compiler module per line. Sort the blocks of imports. This makes it easier to merge in changes. In a couple of places, remove unnecessary imports. |
||
|
|
cdca9fed0a |
Add Java support to the foreign language interface.
Estimated hours taken: 70 Branches: main Add Java support to the foreign language interface. mercury/compiler/compile_target_code.m: mercury/compiler/make.module_target.m: mercury/compiler/mercury_compile.m: Pass `compile_java_file' a Java filename rather than a module name. mercury/compiler/globals.m: Add `java' as a `foreign_language'. mercury/compiler/handle_options.m: Allow Java as a back-end foreign language if the target language is Java. mercury/compiler/hlds_data.m: Allow Java foreign_types. mercury/compiler/intermod.m: mercury/compiler/foreign.m: mercury/compiler/make.util.m: mercury/compiler/make_hlds.m: mercury/compiler/mercury_compile.m: mercury/compiler/mercury_to_mercury.m: mercury/compiler/ml_code_gen.m: mercury/compiler/mlds.m: mercury/compiler/mlds_to_c.m: mercury/compiler/mlds_to_il.m: mercury/compiler/mlds_to_ilasm.m: mercury/compiler/mlds_to_java.m: mercury/compiler/pragma_c_gen.m: mercury/compiler/prog_data.m: mercury/compiler/prog_io_pragma.m: Add or modify existing code to support `java' as a `foreign_language' and Java `foreign_type's. mercury/compiler/mlds_to_java.m: Nicely indent the generated code that unboxes arguments from return-argument arrays which are used for methods with multiple return arguments. |
||
|
|
9d003b8546 |
Fix a bug where dummy arguments were not being recognised by the
Estimated hours taken: 0.25 Branches: main mercury/compiler/mlds_to_java.m: Fix a bug where dummy arguments were not being recognised by the Java back-end due to the addition of `.' as a module seperator. |
||
|
|
8b728691f3 |
Fix a bug in the Java back-end where incorrect code was being
Estimated hours taken: 2
Branches: main
mercury/compiler/mlds_to_java.m:
Fix a bug in the Java back-end where incorrect code was being
generated for assignments if the Lval was a field with type
enum_type.
Add a new function `mlds_lval_type' that returns the type of an
lval.
|
||
|
|
0c07d69c89 |
Reorganize the code in the compiler to centralize the code which handles
Estimated hours taken: Branches: main, release Reorganize the code in the compiler to centralize the code which handles output of floating point literals. compiler/c_util.m: Add new routines make_float_literal and output_float_literal. These output to 17 digits precision. Also add some comments. compiler/mlds_to_c.m: compiler/llds_out.m: compiler/mlds_to_java.m: compiler/ilasm.m: Use the new routines. Also add some comments. tests/hard_coded/Mmakefile: tests/hard_coded/float_consistency.m: tests/hard_coded/float_consistency.exp: A regression test. |
||
|
|
404abb0c57 |
Another step towards RTTI in Mercury.
Estimated hours taken: 32
Branches: main
Another step towards RTTI in Mercury.
This step redefines the representation of type_ctor_infos inside the compiler
to be identical to the representation we will need for efficient interpretation
of RTTI data structures in Mercury, following on from an earlier step which
did the same for (pseudo)typeinfos.
Instead of the type_ctor_info being broken down into its components in
type_ctor_info.m, the breakdown process is now performed in rtti_out.m (for the
LLDS backend) and rtti_to_mlds.m (for the MLDS backend). Eventually, the IL and
Java backends will stop using rtti_to_mlds.m for this purpose, and will instead
write out the type_ctor_data structures as static data to be interpreted
directly.
We now predefine the C types representing type_info and pseudo_type_infos
for types of arity up to 20 for the LLDS C backend as well as for the
MLDS C backend. The LLDS backend can define them for higher arities
on demand; the MLDS backend (for now) still cannot.
runtime/mercury_type_info.h:
To be able to represent all the kinds of types we now support
- add a data structure for converting values of reserved_addr types
from their printable representation to their internal representation
(it was previously missing), and
- add a type_ctor_rep to represent foreign types.
Add missing MR_ prefixes on some field names.
Add typedefs for all the types that the rtti_names can refer to.
There were already such typedefs in runtime/mercury.h for the MLDS
grades, we now have them for the LLDS grades too.
Predefine the C types representing type_info and pseudo_type_infos
for types of arity up to 20. There were already such typedefs in
runtime/mercury.h for the MLDS grades, we now have them for the
LLDS grades too.
runtime/mercury.h:
Delete the typedefs that are now in mercury_type_info.h.
runtime/mercury.h:
Delete the definitions of the C types representing type_info and
pseudo_type_infos, since these are now in mercury_type_info.h.
#include mercury_type_info.h.
compiler/rtti.m:
Add new, purely Mercury data structures for representing
type_ctor_infos and their components, designed both for efficient
interpretation and as a source for the generation of static data
structures in C.
This entailed deleting most of the alternatives of the rtti_data type
while preserving their rtti_name equivalents; the deleted alternatives
represent tables are no longer created in type_ctor_info.m but which
are created dynamically in rtti_out.m and rtti_to_mlds.m (which need
a way for one table to refer to another).
Centralize the correspondence between rtti_names and the C and Java
types of the corresponding structures (the C and Java names differ in
prefixes only). Among other things, this remove the double maintenance
problem we have previously with the LLDS and MLDS backends maintaining
their own maps of the correspondence.
Add utility predicates on the new data structures for use by both
rtti_out.m and rtti_to_mlds.m.
compiler/hlds_module.m:
Always store the ids of unification and comparison procedures in
type_ctor_gen_infos, to simplify their handling.
compiler/type_ctor_info.m:
Generate the new data structures for representing type_ctor_infos.
Conform to the changed data structures for type_ctor_gen_infos.
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
Rewrite substantial parts of these modules to convert the new data
structures for representing type_ctor_infos to sets of discrete
structures dynamically.
Most of the dynamically created structures are unique by construction,
but this is not true for typeinfos and pseudo-typeinfos. Therefore
add mechanisms to ensure that we don't generate redundant structures
representing typeinfos and pseudo-typeinfos.
compiler/mlds_to_c.m:
compiler/mlds_to_java.m:
Use the standard mechanisms for creating C and Java type names.
compiler/mlds_to_gcc.m:
Conform to the changed data structures in rtti.m and
mercury_type_info.h.
compiler/opt_debug.m:
Conform to the changed data structures in rtti.m.
compiler/dead_proc_elim.m:
Conform to the changed data structures for type_ctor_gen_infos.
compiler/pseudo_type_info.m:
Add a predicate to construct a representation of a type that may or may
not be ground.
compiler/mlds_to_gcc.m:
java/runtime/TypeCtorRep.java:
library/private_builtin.m:
library/rtti_implemenation.m:
runtime/mercury_mcpp.{cpp,h}:
Add the type_ctor_rep for foreign types to the lists of type_ctor_reps.
library/construct.m:
library/deconstruct.m:
Add missing MR_ prefixes on field names.
runtime/mercury_construct.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_ml_expand_body.h:
runtime/mercury_tabling.c:
runtime/mercury_type_info.c:
runtime/mercury_unify_compare_body.h:
Handle the type_ctor_rep for foreign types.
Add missing MR_ prefixes on field names.
library/list.m:
Add two utility predicates, is_empty and is_not_empty, for use with
higher order code.
NEWS:
Mention the new predicates in list.m. Delete a duplicate entry.
|
||
|
|
26e14009d2 |
Output Managed C++ code using the same mechanisms as we do for C#
Estimated hours taken: 40 Branches: main Output Managed C++ code using the same mechanisms as we do for C# code, rather than using pragma_c_gen to generate MC++ code. This fixes the problem that functions couldn't be defined in MC++, and also should make the code more maintainable in the future as MC++ is much more similar to C# than to C. compiler/mlds.m: Add a new field to outline_foreign_proc. This field has information which links the mlds variables with the variable names used in the foreign code. compiler/ml_code_gen.m: Generate a foreign proc for MC++ the same way we generate a foreign proc for C#. Generate the data for the new field in outline_foreign_proc. Use the context of the string which contains the pragma foreign proc body for the context of the foreign proc. This ensures that error messages refer to the correct line number. compiler/mlds_to_il.m: Add to the list of foreign languages defined in the module to include those which don't have a foreign_proc defined in them. Move the relevant code from atomic_statement_to_il to generate_method so that we handle external procedures correctly. compiler/mlds_to_ilasm.m: Call mlds_to_managed. compiler/ml_backend.m: Add the new module and remove mlds_to_mcpp and mlds_to_csharp. compiler/ml_elim_nested.m: compiler/ml_optimize.m: compiler/ml_util.m: compiler/mlds_to_c.m: compiler/mlds_to_gcc.m: compiler/mlds_to_java.m: Minor changes to handling the new field in outline_foreign_proc. compiler/mlds_to_csharp.m: compiler/mlds_to_mcpp.m: Removed files whose functionality has been subsumed by mlds_to_managed. library/construct.m: library/float.m: library/io.m: library/std_util.m: library/type_desc.m: Changes required to get the library to be able compile in the ilc grade. |
||
|
|
ac5c98bdaf |
Fix problems with the compiler-generated header files:
Estimated hours taken: 25 Branches: main Fix problems with the compiler-generated header files: 1. the header files are grade dependent, but the header files can only be installed for one grade. 2. the generated header files can clash with system headers. To solve these problems, the compiler now generates a grade dependent `.mih' file containing the declarations needed when a module is imported in a high-level C code grade, and a grade independent `.mh' file, which contains the prototypes for `:- pragma export' declarations. compiler/export.m: Generate a `.mh' rather than a `.h' file for the `:- pragma export' declarations. Allow the header file generated by export.m to be used with `--high-level-code'. compiler/modules.m: library/Mmakefile: Add a module.install_grade_hdrs target to install the `.mih' files in a grade-dependent directory. compiler/arg_info.m: compiler/hlds_out.m: compiler/hlds_pred.m: Make it easier to tell if the arg_info field of the proc_info has been set. compiler/mlds_to_c.m: Include both the `.mh' and `.mih' files for imported modules. The type used as the return value for a semidet procedure exported to C is `MR_bool', not `MR_Word'. compiler/mlds_to_c.m: compiler/modules.m: Don't add a `mercury.' prefix to the standard library header file names. They can't clash with the system headers any more. compiler/mercury_compile.m: compiler/mlds_to_c.m: Use export.m to generate the header file for `:- pragma export' declarations even in hlc grades. compiler/mlds.m: compiler/ml*.m: Distinguish between the `.mh' and `.mih' files in `mlds__import's. compiler/handle_options.m: scripts/Mmake.vars.in: scripts/mgnuc.in: Add C include directory options for the installed grade dependent `.mih' files. Mmakefile: scripts/Mmake.rules: s/h/mih/ in the commands to save the grade dependent files when installing the library grades. compiler/make.m: compiler/make.dependencies.m: compiler/make.module_target.m: compiler/make.util.m: Handle dependencies on `.mh' and `.mih' files. NEWS: doc/user_guide.texi: Document the change. |
||
|
|
ddd77f6f0e |
Get pragma foreign_type working for the C backend.
Estimated hours taken: 16
Branches: main
Get pragma foreign_type working for the C backend.
doc/reference_manual.texi:
Document C pragma foreign_types.
compiler/prog_data.m:
Add il_foreign_type and c_foreign_type which contain all the
necessary data to output a foreign_type on the respective backends.
Change foreign_language_type to refer to these new types.
compiler/prog_io_pragma.m:
Handle the changes to foreign_language_type, and parse C
foreign_type declarations.
compiler/hlds_data.m:
Change the hlds_data__foreign_type type so that it records both the
C and IL foreign types. This will allow one to output both foreign
type declarations when doing intermodule optimization.
compiler/make_hlds.m:
Changes so that we store both the IL and C foreign types in
hlds_data__foreign_type.
Also add an error checking pass where we check that there is a
foreign type for the back-end we are currently compiling to.
compiler/foreign.m:
Change to_exported_type so that it works for both the C and IL
backends by getting either the C or IL foreign_type definition.
compiler/llds.m:
compiler/pragma_c_gen.m:
Change pragma_c_input and pragma_c_output so that they record
whether or not a type is a foreign_type and if so what is the string
which represents that foreign_type.
compiler/llds_out.m:
When outputting pragma c_code variables that represent foreign_types
get the casts correct. Note that this adds the constraint on C
foreign types that they are word sized, as all we are doing is
casts, not boxing and unboxing.
compiler/mlds.m:
Change mlds__foreign_type so that we store whether a type is an IL
type or a C type. It is the responsibility of the code generator
that we never create a reference to a IL foreign type when on the C
back-end, and vice versa.
compiler/mercury_to_mercury.m:
Handle changes to prog_data__foreign_type.
compiler/hlds_out.m:
compiler/intermod.m:
compiler/magic_util.m:
compiler/ml_code_gen.m:
compiler/ml_type_gen.m:
compiler/recompilation_usage.m:
compiler/term_util.m:
compiler/type_ctor_info.m:
compiler/unify_proc.m:
Handle changes to hlds_data__foreign_type.
compiler/exprn_aux.m:
compiler/livemap.m:
compiler/middle_rec.m:
compiler/opt_util.m:
Handle changes to the pragma_c_input and pragma_c_output types.
compiler/ml_code_util.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/mlds_to_c.m:
Handle changes to mlds__foreign_type.
|
||
|
|
43fbf4b956 |
A step towards RTTI in Mercury.
Estimated hours taken: 40 Branches: main A step towards RTTI in Mercury. This step redefines the representation of pseudo-typeinfos inside the compiler to be identical to the representation we will need for efficient interpretation of RTTI data structures in Mercury. Later steps will do likewise for typectorinfos. In the end, we will have two implementations of RTTI: the current low-level, very efficient one written in C, which will be used by the C backends (both LLDS and MLDS), and a new, higher-level one which will use Mercury data structures and Mercury predicates for interpretation (along the lines of library/rtti_implementation.m) for the Java and IL backends. A large part of this change concerns the fact that pseudo-typeinfos can now contain typeinfos as well as other pseudo-typeinfos, and they do in the frequent case that the type of an argument is ground. Given that typeinfos are just special cases of pseudo-typeinfos, the code for handling the two types is usually similar, with common code factored out when relevant. In the process of redesigning the data structures concerning (pseudo-) typeinfos, I also fixed an old naming scheme that has become misleading. The representation of a (pseudo-) typeinfo depends on whether the principal type constructor is fixed arity or not. We used to denote this distinction with the phrases first-order vs higher-order, since at first the only variable arity type constructors were pred and func. However, this hasn't been true since we added tuples. I have changed the naming scheme to be fixed-arity vs variable-arity. compiler/rtti.m: Add new, purely Mercury data structures for representing typeinfos and pseudo-typeinfos, designed both for efficient interpretation and as a source for the generation of static data structures in C. compiler/pseudo_type_info.m: Delete the type definitions here, since they are superseded by the new definitions in rtti.m. Add predicates for constructing typeinfos as well as pseudo-typeinfos, since now we need those too. Conform to the changed data structures for (pseudo-) typeinfos. compiler/ll_pseudo_type_info.m: compiler/ml_closure_gen.m: compiler/rtti_out.m: compiler/rtti_to_mlds.m: compiler/opt_debug.m: compiler/type_ctor_info.m: Conform to the changed data structures for (pseudo-) typeinfos. compiler/mlds.m: Since the MLDS now refers to type_infos, add their type (mlds__type_info_type) to the list of types the MLDS knows about. compiler/ml_code_util.m: compiler/mlds_to_c.m: compiler/mlds_to_il.m: compiler/mlds_to_java.m: Handle mlds__type_info_type. compiler/mlds_to_gcc.m: Conform to the changed data structures for (pseudo-) typeinfos, and handle mlds__type_info_type. runtime/mercury_bootstrap.h: Override the compiler-generated names of the type_ctor_infos of the variable arity type constructors. The MLDS backend requires these to be module qualified; the LLDS backend requires them to be unqualified. This is a problem because the same code now generates the compiler's internal representation of pseudo-typeinfos for both backends. The temporary solution is to have the compiler generate these names module qualified, and have these macros convert them to the unqualified form. (The long term solution should be to always module qualify everything, but doing that is for another change.) runtime/mercury_type_info.h: Change the naming scheme from first order vs higher order to fixed arity vs variable arity. library/construct.m: library/deconstruct.m: runtime/mercury.c: runtime/mercury_construct.c: runtime/mercury_deconstruct.c: runtime/mercury_deep_copy_body.h: runtime/mercury_make_type_info_body.h: runtime/mercury_ml_expand_body.h: runtime/mercury_tabling.c: runtime/mercury_type_desc.c: runtime/mercury_type_info.c: runtime/mercury_unify_compare_body.h: Conform to the new naming scheme. runtime/mercury.h: Conform to the new naming scheme. Declare fixed and variable arity types for typeinfos as well as pseudo-typeinfos, since pseudo-typeinfos can now refer to typeinfos. |
||
|
|
6fe4a40db9 |
Fix a bug with accurate GC.
Estimated hours taken: 4 Branches: main Fix a bug with accurate GC. compiler/mlds.m: Rename the `is_tail_call' enumeration as `call_kind', rename the `call' alternative as `ordinary_call', and and add a new alternative `no_return_call'. compiler/ml_call_gen.m: Use `no_return_call' rather than `tail_call' for calls to procecures with determinism `erroneous'. compiler/ml_elim_nested.m: Fix a bug: when adding code to unchain the stack frame before tail calls, add a `return' statement after each tail call, to ensure that we don't try to unchain the stack frame twice. But don't do this for calls marked `no_return_call', since it's not needed in that case. (This is mandatory, not just an optimization: we can't construct a proper return statement for no_return_calls, since the return values in a `no_return_call' might not match the return types of the caller.) compiler/mlds_to_c.m: compiler/mlds_to_gcc.m: compiler/mlds_to_il.m: compiler/mlds_to_java.m: compiler/ml_util.m: compiler/ml_tailcall.m: compiler/ml_code_gen.m: compiler/ml_code_util.m: Minor changes to handle the new `no_return_call' alternative and the renaming of `call' as `ordinary_call'. |
||
|
|
7597790760 |
Use sub-modules to structure the modules in the Mercury compiler directory.
The main aim of this change is to make the overall, high-level structure of the compiler clearer, and to encourage better encapsulation of the major components. compiler/libs.m: compiler/backend_libs.m: compiler/parse_tree.m: compiler/hlds.m: compiler/check_hlds.m: compiler/transform_hlds.m: compiler/bytecode_backend.m: compiler/aditi_backend.m: compiler/ml_backend.m: compiler/ll_backend.m: compiler/top_level.m: New files. One module for each of the major components of the Mercury compiler. These modules contain (as separate sub-modules) all the other modules in the Mercury compiler, except gcc.m and mlds_to_gcc.m. Mmakefile: compiler/Mmakefile: Handle the fact that the top-level module is now `top_level', not `mercury_compile' (since `mercury_compile' is a sub-module of `top_level'). compiler/Mmakefile: Update settings of *FLAGS-<modulename> to use the appropriate nested module names. compiler/recompilation_check.m: compiler/recompilation_version.m: compiler/recompilation_usage.m: compiler/recompilation.check.m: compiler/recompilation.version.m: compiler/recompilation.version.m: Convert the `recompilation_*' modules into sub-modules of the `recompilation' module. compiler/*.m: compiler/*.pp: Module-qualify the module names in `:- module', `:- import_module', and `:- use_module' declarations. compiler/base_type_info.m: compiler/base_type_layout.m: Deleted these unused empty modules. compiler/prog_data.m: compiler/globals.m: Move the `foreign_language' type from prog_data to globals. compiler/mlds.m: compiler/ml_util.m: compiler/mlds_to_il.m: Import `globals', for `foreign_language'. Mmake.common.in: trace/Mmakefile: runtime/Mmakefile: Rename the %.check.c targets as %.check_hdr.c, to avoid conflicts with compiler/recompilation.check.c. |
||
|
|
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. |
||
|
|
c693347fca |
Do not generate unreachable code in the Java back-end, and re-enable
=================================================================== Estimated hours taken: 32 Branches: main Do not generate unreachable code in the Java back-end, and re-enable optimized tailcalls which were previously generating unreachable code. mercury/compiler/handle_options.m: Enable optimized tailcalls when compiling to Java. mercury/compiler/mlds_to_java.m: Prevent generation of unreachable code when compiling to Java. |
||
|
|
6d80ea9207 |
Add more whitespace in the output generated for class definitions:
Estimated hours taken: 0.25 Branches: main compiler/mlds_to_java.m: Add more whitespace in the output generated for class definitions: put the `extends ...' and `implements ...' parts on lines of their own. |
||
|
|
efdf4d4aea |
Implement tail call optimization for the Java back-end.
Estimated hours taken: 2 Branches: main Implement tail call optimization for the Java back-end. compiler/mlds.m: Add support for C-style `break' and `continue' statements: change the argument of the MLDS `goto' statement from a label to a new type `goto_target' which is either `break', `continue', or a label. compiler/ml_optimize.m: Add a new predicate `target_supports_break_and_continue', and for targets where this predicate succeeds, generate tail recursion using while/break/continue rather than label/goto. compiler/ml_simplify_switch.m: compiler/ml_string_switch.m: compiler/mlds_to_c.m: compiler/mlds_to_gcc.m: compiler/mlds_to_il.m: compiler/mlds_to_java.m: Minor changes to handle the new type for the argument of the `goto' statement. |