Add the new builtin types: int64 and uint64.
Support for these new types will need to be bootstrapped over several changes.
This is the first such change and does the following:
- Extends the compiler to recognise 'int64' and 'uint64' as builtin types.
- Extends the set of builtin arithmetic, bitwise and relational operators
to cover the new types.
- Adds the new internal option '--unboxed-int64s' to the compiler; this will be
used to control whether 64-bit integer types are boxed or not.
- Extends all of the code generators to handle the new types.
- Extends the runtimes to support the new types.
- Adds new modules to the standard library intend to contain basic operations
on the new types. (These are currently empty and not documented.)
There are bunch of limitations marks with "XXX INT64"; these will be lifted in
part 2 of this change. Also, 64-bit integer types are currently always boxed,
again this limitation will be lifted in later changes.
compiler/options.m:
Add the new option --unboxed-int64s.
compiler/prog_type.m:
compiler/prog_data.m:
compiler/builtin_lib_types.m:
Recognise int64 and uint64 as builtin types.
compiler/builtin_ops.m:
Add builtin operations for the new types.
compiler/hlds_data.m:
Add new tag types for the new types.
compiler/ctgc.selector.m:
compiler/dead_proc_elim.m:
compiler/export.m:
compiler/foreign.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/hlds_code_util.m:
compiler/hlds_dependency_graph.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/implementation_defined_literals.m:
compiler/inst_check.m:
compiler/mercury_to_mercury.m:
compiler/mode_util.m:
compiler/module_qual.qualify_items.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/parse_tree_to_term.m:
compiler/parse_type_name.m:
compiler/polymorphism.m:
compiler/prog_out.m:
compiler/prog_util.m:
compiler/rbmm.execution_path.m:
compiler/rtti.m:
compiler/table_gen.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
compiler/unused_imports.m:
compiler/xml_documentation.m:
Conform to the above changes to the parse tree and HLDS.
compiler/c_util.m:
Support writing out constants of the new types.
compiler/llds.m:
Add a representation for constants of the new types to the LLDS.
compiler/stack_layout.m:
Add a new field to the stack layout params that records whether
64-bit integers are boxed or not.
compiler/call_gen.:m
compiler/code_info.m:
compiler/disj_gen.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/jumpopt.m:
compiler/llds_out_data.m:
compiler/llds_out_instr.m:
compiler/lookup_switch.m:
compiler/mercury_compile_llds_back_end.m:
compiler/prog_rep.m:
compiler/prog_rep_tables.m:
compiler/var_locn.m b/compiler/var_locn.m:
Support the new types in the LLDS code generator.
compiler/mlds.m:
Support constants of the new types in the MLDS.
compiler/ml_call_gen.m:
compiler/ml_code_util.m:
compiler/ml_global_data.m:
compiler/ml_rename_classes.m:
compiler/ml_top_gen.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/mlds_to_target_util.m:
compiler/rtti_to_mlds.m:
Conform to the above changes to the MLDS.
compiler/mlds_to_c.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
Generate the appropriate target code for constants of the new types
and operations involving them.
compiler/bytecode.m:
compiler/bytecode_gen.m:
Handle the new types in the bytecode generator; we just abort if we
encounter them for now.
compiler/elds.m:
compiler/elds_to_erlang.m:
compiler/erl_call_gen.m:
compiler/erl_code_util.m:
compiler/erl_unify_gen.m:
Handle the new types in the Erlang code generator.
library/private_builtin.m:
Add placeholders for the builtin unify and compare operations for
the new types. Since the bootstrapping compiler will not recognise
the new types we give them polymorphic arguments. These can be
replaced after this change has bootstrapped.
Update the Java list of TypeCtorRep constants here.
library/int64.m:
library/uint64.m:
New modules that will eventually contain builtin operations on the new
types.
library/library.m:
library/MODULES_UNDOC:
Do not include the above modules in the library documentation for now.
library/construct.m:
library/erlang_rtti_implementation.m:
library/rtti_implementation.m:
library/table_statistics.m:
deep_profiler/program_representation_utils.m:
mdbcomp/program_representation.m:
Handle the new types.
configure.ac:
runtime/mercury_conf.h.in:
Define the macro MR_BOXED_INT64S. For now it is always defined, support for
unboxed 64-bit integers will be enabled in a later change.
runtime/mercury_dotnet.cs.in:
java/runtime/TypeCtorRep.java:
runtime/mercury_type_info.h:
Update the list of type_ctor reps.
runtime/mercury.h:
runtime/mercury_int.[ch]:
Add macros for int64 / uint64 -> MR_Word conversion, boxing and
unboxing.
Add functions for hashing 64-bit integer types suitable for use
with the tabling mechanism.
runtime/mercury_tabling.[ch]:
Add additional HashTableSlot structs for 64-bit integer types.
Omit the '%' character from the conversion specifiers we pass via
the 'key_format' argument to the macros that generate the table lookup
function. This is so we can use the C99 exact size integer conversion
specifiers (e.g. PRIu64 etc.) directly here.
runtime/mercury_hash_lookup_or_add_body.h:
Add the '%' character that was omitted above to the call to debug_key_msg.
runtime/mercury_memory.h:
Add new builtin allocation sites for boxed 64-bit integer types.
runtime/mercury_builtin_types.[ch]:
runtime/mercury_builitn_types_proc_layouts.h:
runtime/mercury_construct.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_ml_expand_body.h:
runtime/mercury_table_type_body.h:
runtime/mercury_tabling_macros.h:
runtime/mercury_tabling_preds.h:
runtime/mercury_term_size.c:
runtime/mercury_unify_compare_body.h:
Add the new builtin types and handle them throughout the runtime.
runtime/Mmakefile:
Add mercury_int.c to the list of .c files.
doc/reference_manual.texi:
Add the new types to the list of reserved type names.
Add the mapping from the new types to their target language types.
These are commented out for now.
In the Java grade, the type_ctor_rep constants are currently defined in the
private_builtin module of the standard library. The Java version of the
runtime currently duplicates some of these constants for its own use (since it
cannot refer to the library ones). This means changes to the set of
type_ctor_reps need to potentially occur in two places, which is a maintenance
headache.
This changes shifts the definitions of all the type_ctor_rep constants in the
Java grade into the runtime and updates the compiler to generate code that
uses these new definitions.
library/private_builtin.m:
Add a note mentioning that the type_ctor_rep constants defined here
will eventually be removed.
java/runtime/TypeCtorRep.java:
Define constants for *all* of the type_ctor_reps in this class.
library/rtti_implementation.m:
library/type_desc.m:
Update code to refer to the new version of the type_ctor_rep constants.
compiler/rtti.m:
Update the compiler to generate references to the new version of the
type_ctor_rep constants.
Add a new builtin type: uint, which is an unsigned word sized integer type.
Support for this new type will need be bootstrapped over several changes.
This is the first such change and does the following:
- Extends the compiler to recognize 'uint' as a builtin type.
- Extends the set of builtin operations to include relational and (some)
arithmetic operations on uints.
- Extends all of the code generators to handle the above. There are some
limitations currently marked by 'XXX UINT'. These will be lifted once
the compiler recognised uint and additional library support becomes
available.
- Extends the runtime to support uints.
compiler/prog_type.m:
compiler/prog_data.m:
compiler/builtin_lib_types.m:
Recognize uint as a builtin type.
Add a new alternative to the cons_id/0 type corresponding to the uint type
-- for bootstrapping purposes its argument is currently an int.
compiler/builtin_ops.m:
Add builtin relational and arithmetic operations on uints. Note that the
existing 'unsigned_le' operation is actually intended for use with signed
values. Rather than attempt to modify its meaning, I have just added new
operations specific to the uint type.
compiler/hlds_data.m:
Add a new tag type for uints.
compiler/type_ctor_info.m:
Recognise uint as a builtin.
Bump the RTTI version number here.
compiler/ctgc.selector.m:
compiler/dead_proc_elim.m:
compiler/dependency_graph.m:
compiler/export.m:
compiler/foreign.m:
compiler/goal_util.m:
compiler/higher_order.m:
compiler/hlds_code_util.m:
compiler/hlds_out_pred.m:
compiler/hlds_out_util.m:
compiler/hlds_pred.m:
compiler/implementation_defined_literals.m:
compiler/inst_check.m:
compiler/mercury_to_mercury.m:
compiler/mode_util.m:
compiler/module_qual.qualify_items.m:
compiler/parse_tree_to_term.m:
compiler/parse_type_name.m:
compiler/polymorphism.m:
compiler/prog_out.m:
compiler/prog_rep.m:
compiler/prog_rep_tables.m:
compiler/prog_util.m:
compiler/rbmm.execution_path.m:
compiler/rtti.m:
compiler/special_pred.m:
compiler/switch_gen.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/type_constraints.m:
compiler/type_util.m:
compiler/typecheck.m:
compiler/unify_gen.m:
compiler/unify_proc.m:
compiler/unused_imports.m:
compiler/write_module_interface_files.m:
compiler/xml_documentation.m:
Conform to the above changes to the parse tree and HLDS.
compiler/c_util.m:
Support generating builtin operations for uints.
compiler/llds.m:
Add a representation for uint constants to the LLDS.
Map uints onto MR_Unsigned.
compiler/call_gen.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/jumpopt.m:
compiler/llds_out_data.m:
compiler/llds_out_instr.m:
compiler/opt_debug.m:
compiler/opt_util.m:
Support uints in the LLDS code generator.
compiler/mlds.m:
Support uint constants in the MLDS.
compiler/ml_accurate_gc.m:
compiler/ml_call_gen.m:
compiler/ml_global_data.m:
compiler/ml_simplify_switch.m:
compiler/ml_switch_gen.m:
compiler/ml_tailcall.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen.m:
compiler/ml_util.m:
compiler/rtti_to_mlds.m:
Conform to the above change to the MLDS.
compiler/mlds_to_c.m:
compiler/mlds_to_java.m:
compiler/mlds_to_cs.m:
Generate the appropriate target code for uint constants and uint
relational operations.
compiler/bytecode.m:
compiler/bytecode_gen.m:
Handle uints in the bytecode generator: we just abort if we
encounter them for now.
compiler/elds.m:
compiler/elds_to_erlang.m:
compiler/erl_call_gen.m:
compiler/erl_code_util.m:
compiler/erl_rtti.m:
compiler/erl_unify_gen.m:
Handle uints in the Erlang code generator.
library/private_builtin.m:
Add placeholders for builtin_{unify,compare}_uint. Since the
bootstrapping compiler will not recognize uint as a type, we
give them polymorphic arguments. These can be replaced after
this change has bootstrapped.
Update the Java list of TypeCtorRep constants, which for some
reason is defined here.
library/uint.m:
New module that will eventually contain operations on uints.
library/MODULES_DOCS:
library/library.m:
Add the uint module.
library/construct.m:
library/erlang_rtti_implementation.m:
library/rtti_implementation.m:
mdbcomp/program_representation.m:
Handle uints.
deep_profiler/program_representation_utils.m:
Conform to the above change.
runtime/mercury_dotnet.cs.in:
Update the list of TypeCtorReps for C#
java/runtime/TypeCtorRep.java:
Update this, although the actual TypeCtorRep constants
are defined the library.
runtime/mercury_type_info.h:
Bump the RTTI version number.
Add an alternative for uints to the tyepctor rep enum.
runtime/mercury_builtin_types.{h,c}:
runtime/mercury_builtin_types_proc_layouts.h:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_table_type_body.h:
runtime/mercury_tabling.h:
runtime/mercury_tabling_macros.h:
runtime/mercury_unify_compare_body.h:
Add uint as a builtin type and handle it throughout the runtime.
runtime/mercury_grade.h:
Bump the binary compatibility version.
runtime/mercury_term_size.c:
runtime/mercury_ml_expand_body.h:
Handle uint and fix probable bugs with the handling of ints on
64-bit Windows.
I noticed this bug when accidentally throwing a Mercury exception containing
some malformed Mercury data (a Java null pointer). The Java worker thread
tried to report the exception, by calling back into Mercury but this
encountered a null pointer exception itself due to the bad data and failed
to de-register itself from the thread pool. This caused the thread pool to
mistakingly think that a thread was still alive and it failed to terminate
the program.
The solution is tu ensure that the pool knows the thread has shutdown if any
exception occurs.
This bug isn't likely to occur in practice, throwing exceptions whose
message is null is unusual.
java/runtime/MercuryWorkerThread.java:
As above.
These allow types to be defined in the following manner:
:- type job ---> job(pred(int::out, io::di, io::uo) is det).
For any construction unification using this functor the argument must
have the required higher-order inst; it is a mode error if it does not.
When terms of type job with inst ground are deconstructed, the argument
is inferred to have the given inst, allowing a higher-order call in that
mode.
The new type syntax is currently only permitted as the direct argument of
a functor in a du type definition. In future it would be meaningful to
support this syntax in other locations, but that is left for a separate
change.
In order to correctly implement the construct/3 library predicate, we
need to be able to dynamically check that arguments do not violate
any constraints on the argument insts. At the moment, we conservatively
abort if any such constraints are present irrespective of whether they
are satisfied or not. Since these constraints are a new feature, no
existing code will abort in this way.
The implementation refers to the inst information associated with types
as "subtype information". This is because, generally, we think of the
combination of a type with a fully bound inst (i.e., one that describes
terms that contain no unbound variables) describes a subtype of that type.
compiler/inst_util.m:
Ensure that arguments have the necessary insts in construction
unifications.
Where available, propagate the insts into arguments rather than
using ground(shared, none).
compiler/prog_io_type_name.m:
Parse the new form of types.
compiler/unparse.m:
Unparse the new form of types.
compiler/prog_io_type_defn.m:
Allow the new form of types in functor arguments.
compiler/prog_ctgc.m:
compiler/prog_io_item.m:
compiler/prog_io_mutable.m:
compiler/prog_io_pragma.m:
compiler/prog_io_typeclass.m:
compiler/superhomogeneous.m:
Disallow the new form of types in places other than functor
arguments.
compiler/prog_data.m:
Go back to representing function types with result type appended
to the arguments. In most case this now results in simpler code.
compiler/prog_type.m:
Abstract away the representation of predicate vs function arguments
by using a predicate to construct these types.
compiler/rtti.m:
compiler/type_ctor_info.m:
Include subtype information about the arguments of a du functor
and about the argument of a notag functor. Generate this
information from the argument types.
Currently, the information is one bit which says whether or not
any subtypes exist in the arguments.
Bump the RTTI version number from the compiler side.
compiler/rtti_out.m:
Output functor subtype information for the low-level C backend.
compiler/rtti_to_mlds.m:
Include functor subtype information in the MLDS.
compiler/mlds_to_cs.m:
Add the new runtime type to the special cases.
compiler/erl_rtti.m:
compiler/erlang_rtti.m:
library/erlang_rtti_implementation.m:
Include functor subtype info in the erlang RTTI.
java/runtime/DuFunctorDesc.java:
java/runtime/FunctorSubtypeInfo.java:
Include functor subtype information in the Java runtime.
runtime/mercury_dotnet.cs.in:
Include functor subtype information in the C# runtime.
runtime/mercury_type_info.h:
Include functor subtype information in the C runtime.
Bump the RTTI version number in the runtime.
Define macros to access the new field. These macros can correctly
handle the previous RTTI version, therefore we do not need to
change the minimum version at this time.
library/private_builtin.m:
Define constants for use by the Java backend.
library/construct.m:
library/rtti_implementation.m:
Use the new RTTI to ensure we don't attempt to construct terms
that violate the new insts.
compiler/prog_rep_tables.m:
Ignore the new inst info for now.
compiler/*.m:
Changes to conform to above.
doc/reference_manual.texi:
Document the new feature.
tests/hard_coded/functor_ho_inst.{m,exp}:
tests/hard_coded/functor_ho_inst_2.{m,exp}:
tests/hard_coded/functor_ho_inst_excp.{m,exp}:
tests/hard_coded/functor_ho_inst_excp_2.{m,exp}:
Test the new functionality.
tests/invalid/combined_ho_type_inst.{m,err_exp}:
tests/invalid/combined_ho_type_inst_2.{m,err_exp}:
Test that we don't allow the new types where they are not permitted,
or are incomplete.
tests/invalid/functor_ho_inst_bad.{m,err_exp}:
tests/invalid/functor_ho_inst_bad_2.{m,err_exp}:
tests/invalid/functor_ho_inst_bad_3.{m,err_exp}:
Test that the argument inst information is enforced as required.
tests/hard_coded/Mmakefile:
tests/invalid/Mmakefile:
Run the new test cases.
This file-specific setting will override a default setting of expandtabs
in $HOME/.vimrc.
*/Makefile:
*/Mmakefile:
As above.
tests/hard_coded/.gitignore:
Don't ignore the purity subdir. This ignore must have been left over
from when purity.m was a test in hard_coded, not hard_coded/purity,
and it ignored an executable, not a directory.
finalisers should be executed only if main/2 returns normally, it does not
throw an exception. The C backends already do this correctly but the Java
backend did not. The C# backend has the same bug, this patch does not fix
the C# backend.
java/runtime/MercuryThreadPool.java:
Add a parameter to the shutdown() method to specify whether the backend
is aborting.
In runMain(), run finalisers only if the runtime is exiting normally.
java/runtime/MercuryRuntime.java:
Add a new finalise() method that takes a parameter allowing standalone
Java applications to specify whether or not they are aborting when the
finalise the RTS.
doc/reference_manual.texi:
Specify the behaviour of finalise directives if main/2 terminates
with an uncaught exception.
samples/java_interface/standalone_java/JavaMain.java:
Conform to changes in MercuryRuntime.java.
When main/2 throws an exception we did not properly shutdown the thread pool
and therefore the JVM would not shut down. Simply calling shutdown() in a
finally block is insufficient because then the primordial thread may finish
before the worker thread is able to report the exception thrown by main/2.
This doesn't seem right because the JVM is supposed to wait for all the
non-daemon threads to finish before it exits. I suspect that the primordial
thread is closing stdout and stderr as it exits and therefore the exception
is never seen, but I don't know.
This change fixes the issue by ensuring that shutdown() is always called (in
a finally block) and that the main thread waits for the thread pool to
shutdown before it exits.
java/runtime/MercuryThreadPool.java:
runMain() will not exit until the worker threads have exited.
Create a new method waitForShutdown() that will wait for the thread pool
to shutdown.
Signal the main thread when a worker thread exits.
java/runtime/MercuryWorkerThread.java:
Worker threads now exit if their task raises an unhanded exception.
java/runtime/MercuryRuntime.java:
Allow standalone programs to have the same behavour as programs whose
entrypoint is written in Mercury.
The thread pool code used in the Java backend was tied the execution of
main/2. However if Mercury is used as a library the thread pool won't have
been started and threads created with thread.spawn would not be executed.
This patch makes it possible to start and stop the thread pool independently of
main/2 by calling startup() and shutdown(). These calls are called
implicitly by calling runMain(). The thread pool can also be started on
demand.
This patch also adds the MercuryRuntime class, which now contains methods
that may be called by users' Java code to interact with the Mercury runtime
system, including a new finalise() method.
java/runtime/MercuryThreadPool.java:
Add startup() method.
shutdown() method is now public and it's meaning has changed, it now
requests the shutdown rather than performing it.
Renamed some variables to make their meanings clearer.
java/runtime/JavaInternal.java:
Initialise the ThreadPool and MercuryOptions objects on demand.
Make all members of this class static to avoid confusion.
Add a private constructor.
java/runtime/MercuryRuntime.java:
Add methods that can be called by Mercury users to interact with the
runtime system. Including a convenient finalise() method that does all
the finalisation.
samples/java_interface/standalone_java/mercury_lib.m:
samples/java_interface/standalone_java/JavaMain.java:
Extend the standalone Java example so that it makes use of threads: Add
a fibs function in Mercury that uses concurrency and therefore starts
the thread pool; call it from the Java code.
Use the new finalise() method from the MercuryRuntime class inside of a
finally block.
samples/java_interface/standalone_java/Makefile:
Fix a minor error.
Fix a bug that made it possible that the tasks_lock could be locked but
never unlocked if an exception was thrown.
java/runtime/MercuryThreadPool.java:
As above.
If threads are blocked while there is work in the queue extra threads may be
spawned to keep the processors busy.
Beginning now, tasks created with thread.spawn are use the thread pool.
(thread.spawn_native does not use the thread pool.)
java/runtime/Semaphore.java:
Wrap Java's Semaphore class which call the current thread's blocked()
and running() methods when a thread blocks and then runs after being
blocked.
library/thread.semaphore.m:
Use our own Semaphore class.
java/runtime/MercuryThread.java:
java/runtime/MercuryWorkerThread.java:
Define blocked() and running() on our threads.
java/runtime/NativeThread.java:
This class is used by spawn_native/4 and is required to define blocked()
and running(), however it implements them as no-ops as it isn't included
in the thread pool.
java/runtime/ThreadStatus.java:
Define the BLOCKED status.
java/runtime/MercuryThreadPool.java:
Count blocked threads seperatly and allow the creation of new threads
when existing threads become blocked.
Add some tracing code to help debug the thread management code. This is
disabled by default.
library/thread.m:
Implement spawn for Java using the thread pool. This was not enabled
earlier because without using java/runtime/Semaphore.java it was
possible to deadlock the system.
java/runtime/Task.java:
Add some tracing code to debug thread state changes, this is disabled by
default.
The old version_array rewind code used linear stack space in order to
perform it's updates in the right order (newest to oldest) by following the
structure's next pointers (which are a oldest to newest list). I previously
introduced week prev pointers so that walking over this structure newest to
oldest could be done with constant stack space. However that is less
efficient than the method suggested by Peter Wang.
Peter suggested using a bitmap and traversing oldest-to-newest, marking
each update in the bitmap and checking the bitmap before making any update.
Thus preserving older values over newer ones (which is good, this code
_rewinds_ updates). This patch implements Peter's suggestion and removes
the prev pointers from the structure for C and Java backends.
Thanks to Peter Wang for giving me a hand with C#.
library/version_array.m:
As above.
runtime/mercury_bitmap.h:
Add some macros for initialising bitmaps and testing, setting and clearing
their bits.
library/bitmap.m:
java/runtime/MercuryBitmap.java:
Move the Java MercuryBitmap class into the runtime library. This makes
it easier for other standard library modules to use this Java class.
library/bitmap.m:
runtime/mercury_dotnet.cs.in:
Move C# MercuryBitmap class into runtime/mercury_dotnet.cs
library/bitmap.m:
Add extra methods to the C# MercuryBitmap class.
tests/hard_coded/version_array_test.exp:
tests/hard_coded/version_array_test.m:
Ensure that the test verifies that rolling back updates to a version
array rolls back changes in the correct order: If two updates modify the
same cell, then the older one should be visible in the result.
Use longer arrays so that the bitmap used in the rollback code is more
than one byte in length.
Thread pools are often used to reduce poor performance on embarrassingly
parallel work loads. This isn't immediately necessary on the Java backend
however I've implemented it because:
+ It will be required when we implement parallel conjunctions for the
Java backend.
+ I want to implement parallel profiling on the Java backend and don't
want to have to implement this once now, and then re-implement it after
introducing thread pools later.
We want the thread pool to generally restrict the number of threads that are
in use, this reduces overheads. However, when one or more tasks become
blocked then it can be desirable to create extra threads, this helps ensure
that all processors are kept busy and that thread pooling doesn't contribute
to any deadlocks itself. The implementation is a work in prograss and
currently does not implement this second feature.
Java's API provides several different thread pools, see
java.util.concurrent.Executors, none of which are suitable. Specifically
the fixed thread pool is unsuitable as we want to be able to temporarily
exceed the normal number of threads as explained above; and the cached
thread pools, which are also very similar to the ThreadPoolExecutor class,
do not implement the correct algorithm for determining when a new thread
should be created (they can still perform poorly for embarassingly parallel
workloads). Additionally we cannot instrument this code as easily for
parallel profiling.
These changes alter the behaviour of Mercury threads on the Java backend in
two ways, they now behave more correctly and more like threads on the C
backends.
+ If a thread throws an exception it is now reported and the program is
aborted. Previously it was ignored and let pass to the Java runtime
where I assume it was reported.
+ The program now exits only after all threads have exited.
The ThreadPool will automatically detect the number of threads to use, or if
the -P flag is given in the MERCURY_OPTIONS environment variable it will
honor that.
java/runtime/MercuryThread.java:
java/runtime/MercuryThreadPool.java:
java/runtime/MercuryWorkerThread.java:
java/runtime/Task.java:
java/runtime/ThreadStatus.java:
These new classes make up the thread pool. A MercuryThread is an
abstract class for Mercury threads, MercuryWorkerThread is a concrete
subclass of MercuryThread which includes the worker thread behaviour.
A Task is a computation/closure that has not yet been started, it
provides some methods not available in Java's generic Runnable and
Callable classes. The others should be self-explanatory and all files
contain documentation.
java/runtime/Getopt.java:
java/runtime/MercuryOptions.java:
Parse the MERCURY_OPTIONS environment variable for the -P flag.
java/runtime/JavaInternal.java:
Add support for handling Mercury exceptions, this is used in case a
worker thread's task (a Mercury thread) throws an exception.
compiler/mlds_to_java.m:
The main method of the main Java class of an application now starts and
uses the thread pool to execute main/2.
library/exception.m:
Export exception reporting code to the Java runtime system.
library/thread.m:
Use the thread pool for thread.spawn.
This change enables constant structure support for the Java backend for the
structures introduced by the polymorphism pass.
compiler/const_struct.m:
compiler/ml_unify_gen.m:
Enable constant structure support
java/runtime/TypeInfo_Struct.java:
Add a constructor to the TypeInfo structure for Java. This constructor
has the interface expected by the polymorphism code.
Never expect to be passed the arity to the varargs constructor.
compiler/polymorphism.m:
compiler/ml_unify_gen.m:
Change how we avoid creating TypeInfos with an explicit arity argument
for Java
We never specify the arity for a TypeInfo_Struct in a Java grade. There
are two reasons: this is a little difficult to handle due to overloading
rules and it is not necessary.
This is handled by removing these arguments in the MLDS backend.
However, the current solution does not work when we create TypeInfos as
constant structures. Therefore this change removes the special case
from the MLDS backend and instead never creates the arity arguments
during the polymorphism pass. rtti_to_mlds.m didn't need updating as it
already had the correct behaviour.
compiler/rtti_to_mlds.m:
Update a comment.
Delete the empty lazy_evaluation directory from extras.
*/.cvsignore:
Make this into .gitignore files.
(Update them where necessary.)
extra/lazy_evalution:
Delete this directory; its former contents were moved
elsewhere some time ago.
Branches: main, 11.07
Fix a problem that prevents Java 1.7 from compiling the Java code generated by
the Mercury compiler. Previously, the TypeInfo_Struct class in the Java
version of Mercury's runtime defined the following constructors:
public TypeInfo_Struct(TypeInfoStruct ti, int arity, Object... as)
public TypeInfo_Struct(TypeInfoStruct ti, Object... as)
Changes to the way most specific varargs method selection works in Java 1.7
means the above is now rejected by the Java compiler. (It should apparently
have never been allowed in the first place.)
The fix is to delete the first constructor above from the runtime and not
generate code that provides the arity. (The arity argument was only ever used
as a sanity check on the number of the following arguments.)
java/runtime/TypeInfo_Struct.java
Delete one of the ambiguous constructors from this class.
compiler/rtti_to_mlds.m:
Don't pass an arity argument to the constructor for TypeInfo_Struct
objects.
Branches: main
Pack consecutive enumeration arguments in discriminated union types into a
single word to reduce cell sizes. Argument packing is only enabled on C
back-ends with low-level data, and reordering arguments to improve
opportunities for packing is not yet attempted. The RTTI implementations for
other back-ends will need to be updated, but that is best left until after any
argument reordering change.
Modules which import abstract enumeration types are notified so by writing
declarations of the form:
:- type foo where type_is_abstract_enum(NumBits).
into the interface file for the module which defines the type.
compiler/prog_data.m:
Add an `arg_width' argument to constructor arguments.
Replace `is_solver_type' by `abstract_type_details', with an extra
option for abstract exported enumeration types.
compiler/handle_options.m:
compiler/options.m:
Add an internal option `--allow-argument-packing'.
compiler/make_hlds_passes.m:
Determine whether and how to pack enumeration arguments, updating the
`arg_width' fields of constructor arguments before constructors are
added to the HLDS.
compiler/mercury_to_mercury.m:
compiler/modules.m:
Write `where type_is_abstract_enum(NumBits)' to interface files
for abstract exported enumeration types.
compiler/prog_io_type_defn.m:
Parse `where type_is_abstract_enum(NumBits)' attributes on type
definitions.
compiler/arg_pack.m:
compiler/backend_libs.m:
Add a new module. This mainly contains a predicate which packs rvals
according to arg_widths, which is used by both LLDS and MLDS back-ends.
compiler/ml_unify_gen.m:
compiler/unify_gen.m:
Take argument packing into account when generating code for
constructions and deconstructions. Only a relatively small part of the
compiler actually needs to understand argument packing. The rest works
at the HLDS level with constructor arguments and variables, or at the
LLDS and MLDS levels with structure fields.
compiler/code_info.m:
compiler/var_locn.m:
Add assign_field_lval_expr_to_var and
var_locn_assign_field_lval_expr_to_var.
Allow more kinds of rvals in assign_cell_arg. I do not know why it was
previously restricted, except that the other kinds of rvals were not
encountered as cell arguments before.
compiler/mlds.m:
We can now rely on the compiler to pack arguments in the
mlds_decl_flags type instead of doing it manually. A slight downside
is that though the type is packed down to a single word cell, it will
still incur a memory allocation per cell. However, I did not notice
any difference in compiler speed.
compiler/rtti.m:
compiler/rtti_out.m:
Add and output a new field for MR_DuFunctorDesc instances, which, if
any arguments are packed, points to an array of MR_DuArgLocn. Each
array element describes the offset in the cell at which the argument's
value is held, and which bits of the word it occupies. In the more
common case where no arguments are packed, the new field is simply
null.
compiler/rtti_to_mlds.m:
Generate the new field to MR_DuFunctorDesc.
compiler/structure_reuse.direct.choose_reuse.m:
For now, prevent structure reuse reusing a dead cell which has a
different constructor to the new cell. The code to determine whether a
dead cell will hold the arguments of a new cell with a different
constructor will need to be updated to account for argument packing.
compiler/type_ctor_info.m:
Bump RTTI version number.
Conform to changes.
compiler/add_type.m:
compiler/check_typeclass.m:
compiler/equiv_type.m:
compiler/equiv_type_hlds.m:
compiler/erl_rtti.m:
compiler/hlds_data.m:
compiler/hlds_out_module.m:
compiler/intermod.m:
compiler/make_tags.m:
compiler/mlds_to_gcc.m:
compiler/opt_debug.m:
compiler/prog_type.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/special_pred.m:
compiler/type_constraints.m:
compiler/type_util.m:
compiler/unify_proc.m:
compiler/xml_documentation.m:
Conform to changes.
Reduce code duplication in classify_type_defn.
compiler/hlds_goal.m:
Clarify a comment.
library/construct.m:
Make `construct' pack arguments when necessary.
Remove an old RTTI version number check as recommended in
mercury_grade.h.
library/store.m:
Deal with packed arguments in this module.
runtime/mercury_grade.h:
Bump binary compatibility version number.
runtime/mercury_type_info.c:
runtime/mercury_type_info.h:
Bump RTTI version number.
Add MR_DuArgLocn structure definition.
Add a macro to unpack an argument as described by MR_DuArgLocn.
Add a function to determine a cell's size, since the number of
arguments is no longer correct.
runtime/mercury_deconstruct.c:
runtime/mercury_deconstruct.h:
runtime/mercury_deconstruct_macros.h:
runtime/mercury_ml_arg_body.h:
runtime/mercury_ml_expand_body.h:
Deal with packed arguments when deconstructing.
Remove an old RTTI version number check as recommended in
mercury_grade.h.
runtime/mercury_deep_copy_body.h:
Deal with packed arguments when copying.
runtime/mercury_table_type_body.h:
Deal with packed arguments in tabling.
runtime/mercury_dotnet.cs.in:
Add DuArgLocn field to DuFunctorDesc. Argument packing is not enabled
for the C# back-end yet so this is unused.
trace/mercury_trace_vars.c:
Deal with packed arguments in MR_select_specified_subterm,
use for the `hold' command.
java/runtime/DuArgLocn.java:
java/runtime/DuFunctorDesc.java:
Add DuArgLocn field to DuFunctorDesc. Argument packing is not enabled
for the Java back-end yet so this is unused.
extras/trailed_update/tr_store.m:
Deal with packed arguments in this module (untested).
extras/trailed_update/samples/interpreter.m:
extras/trailed_update/tr_array.m:
Conform to argument reordering in the array, map and other modules in
previous changes.
tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/hard_coded/lco_pack_args.exp:
tests/hard_coded/lco_pack_args.m:
tests/hard_coded/pack_args.exp:
tests/hard_coded/pack_args.m:
tests/hard_coded/pack_args_copy.exp:
tests/hard_coded/pack_args_copy.m:
tests/hard_coded/pack_args_intermod1.exp:
tests/hard_coded/pack_args_intermod1.m:
tests/hard_coded/pack_args_intermod2.m:
tests/hard_coded/pack_args_reuse.exp:
tests/hard_coded/pack_args_reuse.m:
tests/hard_coded/store_ref.exp:
tests/hard_coded/store_ref.m:
tests/invalid/Mmakefile:
tests/invalid/where_abstract_enum.err_exp:
tests/invalid/where_abstract_enum.m:
tests/tabling/Mmakefile:
tests/tabling/pack_args_memo.exp:
tests/tabling/pack_args_memo.m:
Add new test cases.
tests/hard_coded/deconstruct_arg.exp:
tests/hard_coded/deconstruct_arg.exp2:
tests/hard_coded/deconstruct_arg.m:
Add constructors with packed arguments to these cases.
tests/invalid/where_direct_arg.err_exp:
Update expected output.
Branches: main
The direct argument functor change added the constant MR_SECTAG_NONE_DIRECT_ARG
in some places but not others, breaking deconstruct on C# and Java back-ends.
compiler/mlds_to_gcc.m:
java/runtime/Sectag_Locn.java:
library/rtti_implementation.m:
runtime/mercury_dotnet.cs.in:
Add missing constants.
Branches: main
java/runtime/TypeInfo_Struct.java:
runtime/mercury_dotnet.cs.in:
Add overloads of `TypeInfo_Struct.maybe_new' so the C# and Java
compilers can pick the more appropriate version at compile time,
as they know the type of the argument.
Simplify the code.
Branches: main, 10.04
java/runtime/TypeInfo_Struct.java:
Collapse equivalences when comparing type_infos for equality.
java/runtime/TypeCtorRep.java:
Duplicate the required constants which otherwise are in
private_builtin.m. They should all be moved here but I don't want to
make that change on the 10.04 branch.
library/rtti_implementation.m:
Collapse equivalences in type_info_num_functors.
tests/hard_coded/construct_bug.m:
Use text streams in this test case, as the current hacky implementation
of `io.write_binary' doesn't work on the Java backend.
Branches: main
java/runtime/TypeInfo_Struct.java:
Make TypeInfo_Struct.unify() method compare correctly two type_infos
where one type_info has a null `args' field and another has a
zero-length `args' array.
Branches: main
Implement some RTTI procedures for Java:
get_functor_ordinal/2,
get_functor_lex/2,
type_ctor/2,
pseudo_type_ctor_and_args/3,
make_type/2
Make type_desc/type_ctor_desc/pseudo_type_desc into synonyms for type_info/etc.,
mainly to simplify the hand-written RTTI handling functions. Previously the
*_desc types were represented by *Desc wrapper classes.
compiler/mlds_to_java.m:
compiler/builtin_lib_types.m:
Map *_desc types to TypeInfo_Struct, TypeCtorInfo_Struct,
PseudoTypeInfo_Struct. We cannot simply use
`:- pragma foreign_type("Java", ...)' in the library as the compiler
will complain about missing type definitions for other language
backends.
library/construct.m:
Implement get_functor_ordinal, get_functor_lex for Java backend.
Conform to removal of *Desc classes.
library/rtti_implementation.m:
Implement get_functor_ordinal, get_functor_lex,
pseudo_type_ctor_and_args for Java backend.
Handle existentially quantified arguments in get_functor_du.
Make type_info/type_ctor_info comparison procedures compare module
names before constructor names, to match MR_compare_type_info,
MR_compare_type_ctor_info.
library/type_desc.m:
Implement type_ctor, pseudo_type_ctor_and_args, make_type on Java
backend.
Conform to removal of *Desc wrapper classes.
java/runtime/TypeCtorInfo_Struct.java:
Add constructor for variable arity type constructors.
java/runtime/TypeCtorRep.java:
Delete unused constants.
Branches: main
Add a new calling convention for Mercury procedures exported to Java with
`:- pragma foreign_export'. When the procedure has multiple output arguments,
require the caller to pass instances of a `Ref<T>' class which contain a field
to hold the output value. This is more verbose than returning an `Object[]'
array, and requires extra memory allocations, but is more type-safe. Another
advantage is that the Ref arguments will appear at the same positions as the
output arguments in the Mercury procedure.
The new convention must be enabled with `--java-export-ref-out'. The plan is
to enable it by default in the future.
compiler/options.m:
doc/reference_manual.texi:
Add the option.
compiler/ml_proc_gen.m:
When the option is set, disable `--det-copy-out' and generate the
function parameters assuming pass-by-reference for outputs.
Only use the new convention when necessary.
compiler/mlds_to_java.m:
Make the code to generate the exported forwarding methods account for
`mlds_ptr_type' parameters. These are converted to `Ref<T>' arguments.
java/runtime/Ref.java:
Add the reference class.
Estimated hours taken: 2
Branches: main
Override Object#equals for Mercury enumerations in the Java grades
and document that this should be used for equality testing in Java
code. The problem with using == is that instances might not have
the same addresses if they are serialized and then deserialized.
MercuryEnum is now a class and not an interface.
compiler/ml_type_gen.m:
Inherit the MercuryEnum class in Mercury enumerations
instead of implementing the MercuryEnum interface.
compiler/mlds_to_java.m:
Don't output the MR_value member in Java classes that correspond to
Mercury enumerations. This member is now inherited from MercuryEnum.
Don't mangle classes in the Mercury runtime.
doc/reference_manual.texi:
Document that the equals method should be used for exported
Mercury enumerations.
java/runtime/MercuryEnum.java:
Make MercuryEnum a class and implement the equals method.
Also implement the hashcode method.
Branches: main
Mark Java RTTI classes as implementing java.io.Serializable to
enable serialization of existentially typed values.
java/runtime/DuExistInfo.java:
java/runtime/DuExistLocn.java:
java/runtime/DuFunctorDesc.java:
java/runtime/DuPtagLayout.java:
java/runtime/EnumFunctorDesc.java:
java/runtime/ForeignEnumFunctorDesc.java:
java/runtime/MethodPtr.java:
java/runtime/NotagFunctorDesc.java:
java/runtime/PseudoTypeInfo.java:
java/runtime/ReservedAddrFunctorDesc.java:
java/runtime/Sectag_Locn.java:
java/runtime/TypeClassConstraint.java:
java/runtime/TypeClassDeclStruct.java:
java/runtime/TypeClassId.java:
java/runtime/TypeClassMethod.java:
java/runtime/TypeCtorInfo_Struct.java:
java/runtime/TypeCtorRep.java:
java/runtime/TypeFunctors.java:
java/runtime/TypeInfo_Struct.java:
java/runtime/TypeLayout.java:
As above.
TypeCtorInfo_Struct.unify() cannot rely on the uniqueness of
TypeCtorInfo_Struct instances, as deserialisation will create new
copies.
Branches: main
On the Java backend, use specialised MethodPtr interfaces so that when calling
a method pointer input arguments do not have to be passed via a temporary
array, for arities up to 15. For higher arities the temporary array is still
used.
java/runtime/MethodPtr.java:
java/runtime/MethodPtr1.java:
java/runtime/MethodPtr10.java:
java/runtime/MethodPtr11.java:
java/runtime/MethodPtr12.java:
java/runtime/MethodPtr13.java:
java/runtime/MethodPtr14.java:
java/runtime/MethodPtr15.java:
java/runtime/MethodPtr2.java:
java/runtime/MethodPtr3.java:
java/runtime/MethodPtr4.java:
java/runtime/MethodPtr5.java:
java/runtime/MethodPtr6.java:
java/runtime/MethodPtr7.java:
java/runtime/MethodPtr8.java:
java/runtime/MethodPtr9.java:
java/runtime/MethodPtrN.java:
Add specialised MethodPtr interfaces and MethodPtrN for any higher
arities.
compiler/mlds_to_java.m:
Make the code generator use the specialised MethodPtr interfaces.
library/Mmakefile:
Compile java/runtime/*.java files explicitly as some MethodPtr*.java
files won't be compiled implicitly when compiling the standard library.
library/exception.m:
java/runtime/Exception.java:
library/rtti_implementation.m:
Conform to changes.
Branches: main
compiler/make_hlds_passes.m:
Support `thread_local' mutables on Java backend.
Add some newlines in generated code for mutables.
compiler/prog_mutable.m:
Update documentation.
java/runtime/JavaInternal.java:
Avoid a warning.
Branches: main
Make the Java backend not use native code to implement any standard library
procedures. The only such procedures were related to benchmarking and timing,
which aren't very important so I just make a best effort using methods that
the Java standard library provides.
library/benchmarking.m:
Implement `benchmarking.report_stats' for Java as closely as possible
without native code. Add real time output.
Add `benchmarking.ML_initialise' to remember the time when the
program starts up.
compiler/mlds_to_java.m:
Make the main wrapper call `benchmarking.ML_initialise' at startup.
library/time.m:
Implement `time.clock', `time.times', `time.clocks_per_sec',
`time.clk_tck' as closely as possible without native code.
library/Mmakefile:
Comment out commands to build and install Native.so.
java/runtime/Native.c:
Even though this is not used any more, update the function names for
the "jmercury" package prefix.
README.Java:
Update section on unimplemented procedures.
Branches: main
Make the Java jmercury.runtime.Exception class implement the getMessage()
method for Throwable objects. This is useful when Mercury code is called
from Java code, without the main/2 wrapper.
java/runtime/Exception.java:
Add a method pointer as a class variable.
Implement the getMessage() method by calling the method pointer
if set.
library/exception.m:
On module initialisation set the method pointer in the
jmercury.runtime.Exception class.
Factor out code from report_uncaught_exception_2.
Branches: main
Implementation of construct and construct_tuple for Java backend.
java/runtime/TypeCtorInfo_Struct.java:
The type_ctor_num_functors field was not being initialised.
library/construct.m:
Call the predicates in rtti_implementation.m when appropriate.
library/rtti_implementation.m:
Fix get_functor_enum which was confused lexical ordering and functor
ordinals.
Implement construct and construct_tuple for Java backend.
Delete some out of date comments.
library/type_desc.m:
Add Pseudo_type_desc_0 class which mirrors the
jmercury.runtime.PseudoTypeInfo class with Type_desc_0 and
Type_ctor_desc_0 as subclasses.
Fill in stubs that work with pseudo_type_descs.
library/univ.m:
Export predicates.
README.Java:
Update readme.
Branches: main
Make Java classes corresponding to Mercury types automatically serialisable.
java/runtime/MercuryType.java:
Make MercuryType extend java.io.Serializable.
compiler/mlds_to_java.m:
java/runtime/MercuryEnum.java:
Add a MercuryEnum interface which is implemented by classes
corresponding to Mercury enumerations. Previously enumerations
didn't implement MercuryType.
compiler/ml_type_gen.m:
Make enumeration classes implement MercuryType and MercuryEnum.
library/builtin.m:
Make builtin.copy check for MercuryEnum instead of relying on
enumeration classes not to implement MercuryType. This is not
strictly necessary but avoids copying instances of enumeration
classes.
Branches: main
The Java backend was sometimes generating code like this to initialise RTTI
data structures:
foo_type_info.init(...,
/* cast */ new TypeInfo_Struct(bar_type_ctor_info), ...);
bar_type_ctor_info.init(...);
where `bar_type_ctor_info' is actually a type_info.
The problem is that the fields of the non-initialised `bar_type_ctor_info'
would be copied into the new TypeInfo_Struct object. The "cast" is of course
also unnecessary as the bar is already a TypeInfo_Struct.
This patch attempts to fix the problem in two ways:
1. Don't allocate a new TypeInfo_Struct object to emulate the "cast" unless the
value is actually a TypeCtorInfo_Struct, avoiding the problem of copying
uninitialised fields. Currently this is implemented by a runtime check because
the MLDS `cast' operation doesn't record the original type of the value being
cast.
2. Instead of relying on mlds_to_rtti.m to return a list of RTTI data
structures where sub-structures appear before the structures that reference
them, explicitly perform a topological sort. This should be more robust.
Unrelated change: use pre-allocated PseudoTypeInfo instances for common
variable numbers (1 through 5).
compiler/rtti_to_mlds.m:
Add a function to order a list of RTTI definitions as above.
Use cons instead of list.append in some places now that we can.
compiler/mlds_to_java.m:
Call the function to order RTTI definitions before outputing
the initialisations.
Call TypeInfo_Struct.maybe_new instead of allocating new
TypeInfo_Structs.
Generate code that uses pre-allocated PseudoTypeInfo instances.
java/runtime/TypeInfo_Struct.java:
Add a `maybe_new' method for "casting" TypeCtorInfo_Structs to
TypeInfos or returning the argument unchanged.
Delete a copy constructor; now unused.
Add some assertions.
java/runtime/PseudoTypeInfo.java:
Add static instances of PseudoTypeInfo.
tests/hard_coded/Mmakefile:
tests/hard_coded/java_rtti_bug.exp:
tests/hard_coded/java_rtti_bug.m:
Add test case.
Branches: main
Make `:- initialise' and `:- finalise' declarations work in Java grades.
Initialisation predicates are simply called from static initialisation blocks.
Finalisation predicates work by registering methods (objects) with the
JavaInternal runtime class. After main/2 terminates each of the registered
methods is called.
compiler/make_hlds_passes.m:
Make add_pass_3_initialise, add_pass_3_finalise generate predicates
for backends other than C.
compiler/mlds_to_java.m:
Generate code to register finalisation predicates with the runtime.
Make the generated code that calls main/2 call run the registered
finalisers as well.
java/runtime/JavaInternal.java:
Add code to register and call finalisers when main/2 terminates.
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
Work on RTTI implementation for Java.
library/construct.m:
library/type_desc.m:
Properly distinguish between type_infos and type_descs. These are not
the same in Java grades (for now, at least).
Use special purpose conversion functions instead of unsafe_casts.
Don't call erlang_rtti_implementation.m predicates in other grades.
library/rtti_implementation.m:
Properly distinguish between type_infos and type_descs.
Use special purpose conversion functions instead of unsafe_casts.
Implement some stub predicates for Java.
Fix get_arg_type_info which assumed the usual low-level type_info
representation. In Java we have a TypeInfo_Struct class with a
distinct array for type_info arguments so all the indices to access
arguments were wrong.
Try to be consistent about how variables are numbered (start from 1).
Rename some predicates to make them less ambiguous.
Don't use field access to call functions as it is confusing.
Update unsafe_get_enum_value for an earlier change where I renamed the
`value' field in enumeration classes to `MR_value'.
library/stream.string_writer.m:
library/string.m:
Convert type_infos to type_descs properly.
library/erlang_rtti_implementation.m:
Unrelated: use private_builtin.unsafe_type_cast instead of a
foreign_proc.
library/io.m:
Unrelated: add Java implementation of io.stdout_stream_2/1.
java/runtime/TypeInfo_Struct.java:
Add a copy method.
Branches: main
Fix two problems implementation of arrays for Java backend:
- array.from_list([1, 2, 3]) didn't work because it would create an Integer[]
array, but the code generated by the Mercury compiler would try to assign
it to a int[] variable. Fix this by special casing the primitive types to
create arrays with the expected types.
- We used the class of a representative element to determine the type of
an array to create. Enumeration types only have the one class
corresponding to the Mercury type, so the class of the representative
element is correct.
However, general d.u. types have subclasses for each functor, so the class
of a representative element could correspond to a functor. This meant that
arrays could only hold more elements with the same functor. What is needed
is actually the super class, corresponding to a Mercury type.
The solution adopted here is to make Java classes corresponding to Mercury
types implement an interface called `MercuryType'. Then we can tell
whether the class or the superclass of the representative element is the
one needed.
java/runtime/MercuryType.java:
Add the new interface.
compiler/ml_type_gen.m:
When the target language is Java, make d.u. parent types implement
the `MercuryType' interface.
compiler/mlds_to_java.m:
Make the `MercuryType' interface special so it is printed without an
arity suffix.
library/array.m:
Fix the problems with creating/resizing ararys.
Branches: main
The Java 5 compiler warns about a method with an array argument:
m1(Object[] args)
overriding a method declared with varargs:
m1(Object... args)
The Java 6 compiler accepts it, though I don't know if that was intended.
java/runtime/MethodPtr.java:
Don't use varargs syntax for MethodPtr.call___0_0.
library/rtti_implementation.m:
Explicitly create the Object[] arrays in foreign_procs.
Branches: main
RTTI improvements for Java backend. io.write/3 works for some simple types
(builtin types and non-existential d.u. types).
compiler/mlds_to_java.m:
Fix problem with cyclic RTTI definitions. Initialisers could refer to
other RTTI structures which weren't yet allocated, leading to fields
being null. The fix is to allocate all top-level RTTI objects first
and initialise in a second phase.
java/runtime/DuExistInfo.java:
java/runtime/DuExistLocn.java:
java/runtime/DuFunctorDesc.java:
java/runtime/EnumFunctorDesc.java:
java/runtime/ForeignEnumFunctorDesc.java:
java/runtime/TypeClassConstraint.java:
java/runtime/TypeClassDeclStruct.java:
java/runtime/TypeClassId.java:
java/runtime/TypeCtorInfo_Struct.java:
java/runtime/TypeInfo_Struct.java:
Separate constructors into constructors for the initial allocation,
and an `init' method to fill in the fields.
java/runtime/MethodPtr.java:
Use variadic method support to simplify semidet_call_* and
result_call_* in rtti_implementation.m.
library/builtin.m:
Make Java definitions of builtin.unify/2 and builtin.compare/3 call
rtti_implementation.generic_unify and generic_compare.
library/private_builtin.m:
Add missing MR_TYPECTOR_REP_FOREIGN_ENUM{,_USEREQ} constants
for C# and Java.
library/rtti_implementation.m:
Fix and add missing Java versions of many foreign_procs.
Add more attributes to foreign_procs.
Clean up the code a bit (fewer casts and ^ field access functions).
README.Java:
Bump Java version requirement to J2SE 1.5 or higher.
Branches: main
java/runtime/TypeInfo_Struct.java:
Modify this class enough so that Java code generated for the standard
library compiles with it.
library/io.m:
A few more Java foreign procs were overriding the wrong procedures.
library/type_desc.m:
Add missing class and methods.
Branches: main
compiler/rtti.m:
In RTTI data, map integers to Java `int' instead of the nonsensical
`mercury.runtime.Integer'.
java/runtime/TypeCtorInfo_Struct.java:
Conform to the change.