The MLDS either module- or type-qualifies several kinds of entities.
It used to use the same qual/3 wrapper for all these entities. However,
many kinds of entities are never (and can never be) type-qualified,
because they are not defined inside a type.
This diff replaces the mlds_fully_qualified_name type, and its qual/3 wrapper,
with a separate type and a separate wrapper for each kind of entity.
For those entities that can be both module- and type-qualified, have this
wrapper continue to include a mlds_qual_kind (module_qual or type_qual) field;
for the entities that are only ever module qualified, omit this field.
compiler/mlds.m:
Make the change described above.
There are some related changes.
The first is that the argument of the ml_field_named rval specifying
the field used to be a string. Change this to be a field_var_name,
because if a field's name is given by a field_var_name in its definition,
it should be given by that same field_var_name in its uses as well.
Without this, it is unnecessarily hard to ensure that the code that
generates the target language versions of the field's name match
in definitions and uses; specification, it would be unnecessarily hard
to ensure that they do module- or type-qualification the same way.
The second is required by the first. We used to use "ptr_num"
as the name of only a compiler-generated local variable, but it is
actually the name of a field in a compiler-generated class, and the
local variable use actually refers to the field. Therefore this diff
moves the reference to this from the mlds_local_var_name type
to the mlds_field_var_name type.
The third is switching to a more consistent naming scheme:
having the unqualified name of entities of kind xxx be mlds_xxx_name
and the qualified version of those names being qual_xxx_name.
compiler/ml_accurate_gc.m:
compiler/ml_call_gen.m:
compiler/ml_code_util.m:
compiler/ml_elim_nested.m:
compiler/ml_foreign_proc_gen.m:
compiler/ml_global_data.m:
compiler/ml_optimize.m:
compiler/ml_proc_gen.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
compiler/rtti_to_mlds.m:
Conform to the changes above.
compiler/java_names.m:
Clarify a variable name.
compiler/mlds.m:
Replace the old definition of mlds_var_name, which was a string
with an optional integer. The integer was intended to be the number
of a HLDS variable, while auxiliary variables created by the compiler,
which do not correspond to a HLDS variable, would not have the optional
integer.
This design has a couple of minor problems. The first is that there is
no place in the compiler where all the variable names are visible at once,
and without such a place, we cannot be sure that two names constructed
for different purposes don't accidentally end up with the same name.
The probability of such a clash used to be astronomically small
(which is why this hasn't been a problem), but it was not zero.
The second problem is that several kinds of compiler-created MLDS variables
want to have numerical suffixes too, usually with the suffix being a
unique sequence number used as a means of disambiguation. Most of the
places where these were created put the numerical suffix into the name
string itself, while some put the sequence number as the optional integer.
As it happens, neither of those actions is good when one wants to take
the independently generated MLDS code of several procedures in an SCC
and merge them into a single piece of MLDS code. For this, we want to
rename apart both the HLDS variable numbers and the sequence numbers.
Having the sequence number baked into the strings themselves obviously
makes such renumbering unnecessarily hard, while having sequence numbers
in the slots intended for HLDS variable numbers makes the job impossible
to do safely.
This diff switches to a new representation of mlds_var_names that
has a separate function symbol for each different "origin story"
that is possible for MLDS variables. This addresses both problems.
The single predicate that converts this structured representation
to a string is the place where we can ensure that two semantically
different MLDS variables never get translated to the same string.
The current version of this predicate does *not* offer this guarantee,
but later versions could.
And having all the integers used in mlds_var_names for different purposes
stored as arguments of different function symbols (that clearly indicate
their meaning) makes it possible to rename apart different sets
of MLDS variables easily and reliably.
Move the code for converting mlds_var_names from ml_code_util.m to here,
to make it easier to maintain it together with the mlds_var_name type.
compiler/ml_code_util.m:
Conform to the above change by generating structured MLDS var names.
Delete a predicate that is not needed with structured var names.
Delete the code moved to mlds.m.
Delete a predicate that has been unused since we deleted the IL backend.
Add ml_make_boxed_type as a version of ml_make_boxed_types that returns
exactly one type. This simplifies some code elsewhere.
Add "hld" to some predicate names to make clear that they are intended
for use only with --high-level-data.
compiler/ml_type_gen.m:
Conform to the above change by generating structured MLDS var names.
Add "hld" to the names of the (many) predicates here that are used
only with --high-level-data to make clear that fact.
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
Conform to the above change by generating structured MLDS var names.
Add a "for_csharp" or "for_java" suffix to some predicate names
to avoid ambiguities.
compiler/ml_accurate_gc.m:
compiler/ml_call_gen.m:
compiler/ml_closure_gen.m:
compiler/ml_commit_gen.m:
compiler/ml_disj_gen.m:
compiler/ml_elim_nested.m:
compiler/ml_foreign_proc_gen.m:
compiler/ml_gen_info.m:
compiler/ml_global_data.m:
compiler/ml_lookup_switch.m:
compiler/ml_optimize.m:
compiler/ml_string_switch.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
Conform to the above change by generating structured MLDS var names.
compiler/prog_type.m:
Add var_to_type, as a version of var_list_to_type_list that returns
exactly one type. This simplifies some code elsewhere.
compiler/java_names.m:
Give some predicates and functions better names.
compiler/ml_code_gen.m:
Fix typo.
compiler/equiv_type.m:
Don't export a predicate that does not need to be exported.
compiler/hlds_data.m:
compiler/polymorphism.m:
mdbcomp/goal_path.m:
Put knowledge of the goal_id to hand head constraints in only one place:
mdbcomp/goal_path.m.
compiler/goal_path.m:
Allocate goal_ids using counters.
compiler/foreign.m:
Delete an unused predicate.
compiler/ite_gen.m:
Factor out some common code.
compiler/equiv_type_hlds.m:
compiler/error_util.m:
compiler/exception_analysis.m:
compiler/global_data.m:
compiler/globals.m:
compiler/goal_expr_to_goal.m:
compiler/goal_form.m:
compiler/granularity.m:
compiler/hlds_args.m:
compiler/hlds_out_util.m:
compiler/interval.m:
compiler/java_names.m:
compiler/jumpopt.m:
compiler/labelopt.m:
compiler/lambda.m:
compiler/lco.m:
compiler/live_vars.m:
compiler/livemap.m:
compiler/modecheck_conj.m:
compiler/type_constraints.m:
Minor style cleanups.
mdbcomp/sym_name.m:
New module, containing the part of the old prim_data.m that
dealt with sym_names.
mdbcomp/builtin_modules.m:
New module, containing the part of the old prim_data.m that
dealt with builtin modules.
mdbcomp/prim_data.m:
Remove the things that are now in the two new modules.
mdbcomp/mdbcomp.m:
deep_proiler/Mmakefile:
slice/Mmakefile:
Add the two new modules.
browser/*.m:
compiler/*.m:
deep_proiler/*.m:
mdbcomp/*.m:
slice/*.m:
Conform to the above changes.
Estimated hours taken: 6
Branches: main
compiler/*.m:
Convert almost all remaining modules in the compiler to use
"$module, $pred" instead of "this_file" in error messages.
In a few cases, the old error message was misleading, since it
contained an incorrect, out-of-date or cut-and-pasted predicate name.
tests/invalid/unresolved_overloading.err_exp:
Update an expected output containing an updated error message.
Estimated hours taken: 2
Branches: main, release
Make the system compiler with --warn-unused-imports.
browser/*.m:
library/*.m:
compiler/*.m:
Remove unnecesary imports as flagged by --warn-unused-imports.
In some files, do some minor cleanup along the way.
Branches: main
Start a C# backend, adapted from mlds_to_java.m.
Some `pragma foreign_*' declarations are commented out in this change because
no bootstrap compiler will yet accept "C#" in the language specification.
The compiler already supported C# foreign_procs for the IL backend, but the IL
backend and this new backend do not agree on naming and calling conventions so
the changes to the existing C# foreign_procs will further break the IL backend.
Nobody cares.
Only tested so far with Mono on Linux.
compiler/mlds_to_cs.m:
New module. In the CVS Attic there exists an obsolete file named
mlds_to_csharp.m (replaced by mlds_to_managed.m) which we don't want to
conflict with.
For C# we need to know if a `pragma foreign_type' is a value or
reference type. Currently this is done by accepting a fake keyword
`valuetype' before the type name, like for IL.
compiler/ml_backend.m:
compiler/mercury_compile.m:
compiler/mercury_compile_mlds_back_end.m:
Hook up the C# backend.
compiler/globals.m:
Add `target_csharp' as a target language.
compiler/options.m:
Add `--csharp' and `--csharp-only' options and their synonyms.
compiler/handle_options.m:
Handle `target_csharp' like `target_java', except for features which
are still to be implemented.
compiler/add_pragma.m:
Allow C# as a `pragma foreign_export' language.
Allow C# for `pragma foreign_export_enum'.
Conform to changes.
compiler/hlds_data.m:
compiler/prog_data.m:
compiler/prog_io_pragma.m:
Accept C# as a language for `pragma foreign_type'.
Accept `csharp' as the name of a grade in trace parameters.
compiler/make_hlds_passes.m:
Reuse most of the code for implementing mutables on Java for C#.
compiler/mlds.m:
Add a new MLDS target language, `ml_target_csharp'.
Conform to changes.
compiler/ml_foreign_proc_gen.m:
Generate foreign_procs for C#.
compiler/foreign.m:
Update predicates to support C# targets.
compiler/c_util.m:
Make `quote_string' use hexadecimal escapes in C# string literals.
compiler/parse_tree.m:
compiler/java_names.m:
Add C# equivalents for predicates in this module. `java_names' is a
misleading module name, but the predicates for C# and Java share some
code and may possibly be combined in the future.
compiler/rtti.m:
Add predicates to return the names of RTTI structures in C#.
compiler/simplify.m:
Handle the trace parameter `grade(csharp)'.
compiler/compile_target_code.m:
compiler/make.dependencies.m:
compiler/make.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
Add some support for building of executables and libraries with
`--target csharp'.
compiler/ml_global_data.m:
compiler/ml_optimize.m:
compiler/ml_proc_gen.m:
compiler/ml_switch_gen.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/add_pred.m:
compiler/add_type.m:
compiler/granularity.m:
compiler/inlining.m:
compiler/intermod.m:
compiler/lambda.m:
compiler/mercury_compile_middle_passes.m:
compiler/mercury_to_mercury.m:
compiler/ml_code_util.m:
compiler/ml_disj_gen.m:
compiler/mlds_to_c.m:
compiler/mlds_to_il.m:
compiler/mlds_to_java.m:
compiler/modules.m:
compiler/pragma_c_gen.m:
compiler/prog_foreign.m:
compiler/special_pred.m:
compiler/write_deps_file.m:
Conform to changes.
library/builtin.m:
library/rtti_implementation.m:
library/type_desc.m:
Implement RTTI procedures for the new backend, which uses a high-level
data representation (like the Java backend). The existing C# code was
designed for the IL backend, which used a low-level representation of
the RTTI data structures.
Most (if not all) of the the "new" code is exactly the same as the Java
versions, with only syntactic changes.
Rename the C# class `void_0' to `Void_0' to match the naming convention
used by mlds_to_cs.m.
library/array.m:
Update the existing C# code to work with the new backend.
Use `object[]' as the type of all array of non-primitive types.
The problem is one we encountered on the Java backend: when creating a
new array based on the type of a single element, we don't know whether
the new array should contain elements of the class or superclass.
library/bool.m:
Export `bool' constants to C#.
library/exception.m:
Update the existing C# code to work with the new backend.
Move the `mercury.runtime.Exception' C# class to mercury_dotnet.cs.
library/float.m:
Add C# implementations of `is_nan' and `is_inf'.
library/list.m:
Add methods for manipulating lists from hand-written C# code.
library/string.m:
Add C# implementations of string procedures which were missing.
library/dir.m:
library/io.m:
library/library.m:
Update the existing C# code to work with the new backend.
library/private_builtin.m:
Update the existing C# code to work with the new backend.
Delete the static constants which are duplicated in mercury_dotnet.cs.
The mlds_to_cs.m will emit references to the constants in the latter
only.
library/backjump.m:
library/bitmap.m:
library/mutvar.m:
library/par_builtin.m:
library/region_builtin.m:
library/store.m:
library/thread.m:
library/thread.semaphore.m:
library/time.m:
library/univ.m:
Make these modules compile with the C# backend.
runtime/mercury_dotnet.cs.in:
Add RTTI classes to the `mercury.runtime' namespace, equivalent to
those on the Java backend.
Use enumerations `MR_TYPECTOR_REP_*' and `MR_SECTAG_*' constants so we
can switch on them.
Add the `UnreachableDefault' exception class.
Hide old classes which are unused with the new backend behind
#ifdef !MR_HIGHLEVEL_DATA.
Branches: main
Mangle symbols which would begin with a digit in generated Java code.
compiler/prog_foreign.m:
Add a version of name_mangle which mangles symbols beginning with a
digit, in the same way as if it contained a character not allowed in C
identifiers.
compiler/java_names.m:
compiler/mlds_to_java.m:
Call the new function.
Don't need to mangle a string in a spot.
compiler/name_mangle.m:
Update comments the file extras/dynamic_linking/name_mangle.m
which was removed a while ago.
compiler/ml_util.m:
Unrelated: make a simple change to defns_contain_main to use less
nondet stack space. I ran out of stack space when testing this change
on a particular module. The compiler was built in a debugging grade.
Branches: main
Put all Mercury-generated Java classes into the package `jmercury' and
runtime classes into `jmercury.runtime'. The Mercury module hierarchy is
not reflected in the package name. We name sub-module classes using
their fully-qualified module names with `__' between components, e.g.
`bit_buffer.read' produces `class bit_buffer__read'.
As all generated Java code is in the same package we don't need to package
qualify identifiers, and we don't need the hack to avoid clashing package
and class names. It also makes it easier to write Java foreign code because
generated Java class names are easier to predict from Mercury module names.
The package names are not `mercury' and `mercury.runtime' because on
case-insensitive file systems we may end up with a `mercury' directory
that could be confused with the `Mercury' directory.
compiler/java_names.m:
Delete code related to mangling package names.
Remove the extra `mercury' prefix added to standard library module
names, as it is redundant with `jmercury'.
Change runtime package name.
compiler/mlds_to_java.m:
Make generated code follow the new packaging scheme.
Don't automatically import all runtime classes. It doesn't seem
necessary.
Update for new packaging scheme.
compiler/file_names.m:
Fix Java file paths for the new packaging scheme.
compiler/module_cmds.m:
compiler/rtti.m:
library/array.m:
library/backjump.m:
library/benchmarking.m:
library/bitmap.m:
library/builtin.m:
library/exception.m:
library/io.m:
library/library.m:
library/mutvar.m:
library/private_builtin.m:
library/rtti_implementation.m:
library/store.m:
library/string.m:
library/time.m:
library/type_desc.m:
java/runtime/*.java:
Rename package names.
Delete unnecessary package qualification.
compiler/mlds.m:
Add some XXXs to be fixed later.
library/Mmakefile:
Update for new packaging scheme.
Let mmake --use-mmc-make work in this directory.
Branches: main
Previously, unqualified Mercury modules would result in Java classes which
were placed in the default (unnamed) package. This is a problem as Java
doesn't allow packaged classes to import types from the unpackaged classes.
This patch gives all Java classes generated from Mercury files the "mercury."
package prefix.
mmake support for Java files is even more broken than before. It expects
Java files to be placed in the same directory but, due to the "mercury."
prefix, even classes for non-nested modules are placed in a subdirectory
called `mercury'. (The standard library can still be built with mmake using
custom rules.)
Fix creation of `.jar' files. It is not enough to package the `.class' files
that we know will be produced for each module. Nested classes generate
separate `.class' files which also need to be included.
Fix creation of the shell script that launches Java programs.
compiler/java_names.m:
Add a function to add an outermost "mercury" qualifier on module names.
Make `java_module_name' add the outermost "mercury" qualifier.
compiler/mlds_to_java.m:
Add the outermost "mercury" qualifier wherever we are writing out
a package name.
compiler/compile_target_code.m:
Fix creation of `.jar' files, as described.
Use a temporary file and @-syntax to pass the list of class files to
`jar'.
Pass `jar -C <dir> <class> -C <dir> <class> ...' as -C only affects
the argument immediately following it.
Run `jar i' to add an index to jar files.
compiler/file_names.m:
Add `get_class_dir_name' to return the directory that contains class
files.
Make `choose_file_name' work for Java files again (with package
directories) when `--use-subdirs' is disabled.
compiler/module_cmds.m:
Make `create_java_shell_script' work correctly when
`--use-grade-subdirs' is enabled, and when the main module is
packaged (as it will be).
Make Java shell scripts get the path to the class directory from $0,
and make the path to the Java interpreter overridable by an environment
variable.
Make `list_class_files_for_jar' scan the directory containing class
files, to include nested classes. Return a list of class files.
Make `list_class_files_for_jar_mmake' use `get_class_dir_name'.
library/Mmakefile:
Update hacks to build the standard library in the java grade.
mdbcomp/prim_data.m:
Delete `insert_module_qualifier' as `add_outermost_qualifier'
is equivalent.
compiler/module_qual.m:
compiler/prog_type.m:
compiler/write_deps_file.m:
Conform to changes.
Branches: main
Make `mmc --make' support submodules when compiling to Java. Java files must
be placed in subdirectories named after the package that each class belongs to.
compiler/java_names.m
compiler/parse_tree.m:
compiler/notes/compiler_design.html:
Add a new module in the parse_tree package to contain code related to
name mangling for Java.
compiler/mlds.m:
compiler/java_util.m:
Move predicates to java_names.m.
compiler/mlds_to_java.m:
Move predicates to java_names.m.
Delete an unused predicate.
compiler/file_names.m:
Rename `erlang_module_name' as it is now also used for Java.
Make `module_name_to_file_name_general' return file names for `.java'
and `.class' files that include package subdirectories.
compiler/make.program_target.m:
Clean `.class' files on make clean.
compiler/mlds_to_il.m:
mdbcomp/prim_data.m:
Move `sym_name_to_list' to mdbcomp.prim_data.
compiler/compile_target_code.m:
compiler/elds_to_erlang.m:
Conform to changes.
library/Mmakefile:
Delete hacks that work around Mercury not writing submodule .java files
in subdirectories.