Commit Graph

2324 Commits

Author SHA1 Message Date
Julien Fischer
db05403325 Writing 16- and 32-bit integers to binary file streams.
Add predicates for writing 16- and 32-bit integers to binary file streams in
native, little and big endian byte order to the standard library.

library/io.m:
    Add the new predicates.

library/uint16.m:
library/uint32.m:
    Add a functions for casting from the signed to unsigned versions
    of these types.

runtime/mercury_int.h:
    New header intended to hold things related to the implementation
    of the integer types in C grades.  Currently it contains the
    macros defining the byte reverse operations for 16- and 32-bit
    types.   (It will eventually contain macros for (un)boxing 64-bit
    integer types on 32-bit platforms as well.)

runtime/mercury_imp.h:
runtime/Mmakefile:
     Add the new header.

tests/hard_coded/Mmakefile:
tests/write_binary_multibyte_int.{m,exp}:
     Add a test for the new predicates.
2017-09-25 06:50:42 -04:00
Zoltan Somogyi
f4e0059a49 Eliminate hlc_nest and hl_nest grades ...
... by eliminating the grade component that calls for the use of gcc nested
functions.

runtime/mercury_grade.h:
compiler/compute_grade.m:
    Delete the gcc_nested_functions grade component, and the C macro
    that specifies its presence, MR_USE_GCC_NESTED_FUNCTIONS.

scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/mgnuc.in:
scripts/parse_grade_options.sh-subr:
    Delete the code that parses the deleted grade component,
    and delete the code that signals its absence in other grades.

compiler/options.m:
    Delete the gcc_nested_functions grade option.

    Delete also the gcc_local_labels option, since it was useful
    only if gcc_nested_functions was set.

configure.ac:
    Delete the code that sometimes added hl*_nest grades to the list of grades
    to be installed.

    Fix a bunch of comments.

compiler/compile_target_code.m:
compiler/handle_options.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/ml_args_util.m:
compiler/ml_call_gen.m:
compiler/ml_code_util.m:
compiler/ml_commit_gen.m:
compiler/ml_gen_info.m:
compiler/mlds_to_c.m:
library/backjump.m:
library/exception.m:
runtime/mercury_hlc_types.h:
runtime/mercury_tabling.c:
runtime/mercury_tabling.h:
    Delete code that was active only in grades with the deleted grade
    component.

compiler/ml_accurate_gc.m:
compiler/notes/grade_library.html:
runtime/mercury_conf_param.h:
    Delete mentions of the deleted grade component.

compiler/ml_code_gen.m:
    Delete mentions of the deleted grade component, and a bunch of other
    obsolete comments.

doc/user_guide.texi:
    Fix a line break.
2017-09-07 03:01:55 +10:00
Julien Fischer
e4d03b0372 Support tabling of predicates with fixed size integer arguments.
library/table_builtin.m:
    Add the various tabling primitives -- they could not previously
    be added until part 1 of the fixed size integer change had
    bootstrapped.

library/table_statistics.m:
runtime/mercury_tabling.h:
    Update the table_step_kind/0 type and its C version to cover the fixed
    size integer types.   (The corresponding type in compiler/hlds_pred.m
    has already been updated.)

tests/tabling/Mmakefile:
tests/tabling/fib_int{8,16,32}.{m,exp}:
tests/tabling/fib_uint{8,16,32}.{m,exp}:
     Test tabling for each of the fixed size integer types.
2017-08-28 16:07:13 +10:00
Julien Fischer
e7b8045a98 Avoid warnings from GCC.
runtime/mercury_builtin_types.c:
    Avoid warnings about casting from a pointer to an integer of a different
    size from GCC when casting from MR_Box to one of the C99 fixed size
    integer types.   Cast these values to MR_Word first to avoid the warning.
2017-08-02 14:23:38 +10:00
Julien Fischer
4ba54a4fba Fix a typo.
runtime/mercury_dotnet.cs.in:
    s/UINT43/UINT32/
2017-07-18 10:32:43 +10:00
Julien Fischer
8a240ba3f0 Add builtin 8, 16 and 32 bit integer types -- Part 1.
Add the new builtin types: int8, uint8, int16, uint16, int32 and uint32.
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 'int8', 'uint8', 'int16', 'uint16', 'int32'
  and 'uint32' as builtin types.
- Extends the set of builtin arithmetic, bitwise and relational operators to
  cover the new types.
- Extends all of the code generators to handle new types.  There currently lots
  of limitations and placeholders marked by 'XXX FIXED SIZE INT'.  These will
  be lifted in later changes.
- Extends the runtimes to support the new types.
- Adds new modules to the standard library intended to hold the basic
  operations on the new types.  (These are currently empty and not documented.)

This change does not introduce the two 64-bit types, 'int64' and 'uint64'.
Their implementation is more complicated and is best left to a separate change.

compiler/prog_type.m:
compiler/prog_data.m:
compiler/builtin_lib_types.m:
    Recognise int8, uint8, int16, uint16, int32 and uint32 as builtin types.

    Add new type, int_type/0,that enumerates all the possible integer types.

    Extend the cons_id/0 type to cover the new types.

compiler/builtin_ops.m:
    Parameterize the integer operations in the unary_op/0 and binary_op/0
    types by the new int_type/0 type.

    Add builtin operations for all the new types.

compiler/hlds_data.m:
    Add new tag types for the new types.

compiler/hlds_pred.m:
    Parameterize integers in the table_trie_step/0 type.

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_out_info.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.exection_path.m:
compiler/rtti.m:
compiler/rtti_to_mlds.m:
compiler/switch_util.m:
compiler/table_gen.m:
compiler/type_constraints.m:
compiler/type_ctor_info.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 generating the builtin operations for the new types.

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.

compiler/llds.m:
    Replace the lt_integer/0 and lt_unsigned functors of the llds_type/0,
    with a single lt_int/1 functor that is parameterized by the int_type/0
    type.

    Add a representations for constants of the new types to the LLDS.

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_global.m:
compiler/llds_out_instr.m:
compiler/lookup_switch.m:
compiler/middle_rec.m:
compiler/peephole.m:
compiler/pragma_c_gen.m:
compiler/stack_layout.m:
compiler/string_switch.m:
compiler/switch_gen.m:
compiler/tag_switch.m:
compiler/trace_gen.m:
compiler/transform_llds.m:
    Support the new types in the LLDS code generator.

compiler/mlds.m:
    Support constants of the new types in the MLDS.

compiler/ml_accurate_gc.m:
compiler/ml_call_gen.m:
compiler/ml_code_util.m:
compiler/ml_disj_gen.m:
compiler/ml_foreign_proc_gen.m:
compiler/ml_global_data.m:
compiler/ml_lookup_switch.m:
compiler/ml_simplify_switch.m:
compiler/ml_string_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/mlds_to_target_util.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_rtti.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 the polymorphic arguments.  These can be
    replaced after this change has bootstrapped.

    Update the Java list of TypeCtorRep constants.

library/int8.m:
library/int16.m:
library/int32.m:
library/uint8.m:
library/uint16.m:
library/uint32.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:
deep_profiler/program_representation_utils.m:
mdbcomp/program_representation.m:
    Handle the new types.

runtime/mercury_dotnet.cs.in:
java/runtime/TypeCtorRep.java:
runtime/mercury_type_info.h:
    Update the list of TypeCtorReps.

configure.ac:
runtime/mercury_conf.h.in:
    Check for the header stdint.h.

runtime/mercury_std.h:
    Include stdint.h; abort if that header is no present.

runtime/mercury_builtin_types.[ch]:
runtime/mercury_builtin_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.
2017-07-18 01:31:01 +10:00
Peter Wang
9424a6fe7e Handle sem_wait, sem_timedwait being interrupted by signal handlers.
sem_wait or sem_timedwait may be interrupted by signal handlers and
return an error. We must retry the call if errno is set to EINTR.

library/thread.m:
    Retry MR_SEM_WAIT if interrupted by a signal handler in
    ML_create_exclusive_thread.

    Call MR_fatal_error if MR_SEM_WAIT fails for any other reason.
    The only other documented error code is EINVAL if the semaphore is
    invalid; that should not happen.

runtime/mercury_context.c:
    Retry MR_SEM_WAIT if interrupted by a signal handler in
    MR_shutdown_ws_engines.

runtime/mercury_thread.h:
    Add the macro MR_SEM_IS_EINTR for checking if errno == EINTR
    after calling MR_SEM_WAIT or MR_SEM_TIMED_WAIT.
2017-07-10 10:38:49 +10:00
Julien Fischer
bfc5e2ed2f Fix term deconstruction for uints.
runtime/mercury_ml_expand_body.h:
library/rtti_implementation.m:
library/erlang_rtti_implementation.m:
    As above.

tests/hard_coded/deconstruct_arg.m:
     Add a test for uints.

     Avoid the use of a deprecated predicate.

tests/hard_coded/deconstruct_arg.{exp,exp2}:
     Update expected outputs for the above.
2017-06-18 21:16:46 +10:00
Julien Fischer
21597befe4 Adding missing uint code.
runtime/mercury_ml_expand_body.h:
     Add missing code for the uint case.
2017-06-15 22:12:43 +10:00
Zoltan Somogyi
c4c544c932 Fix grammar in comment. 2017-01-06 17:49:46 +11:00
Zoltan Somogyi
67557b68f9 Fix two C compiler warnings. 2016-10-30 00:25:48 +11:00
Julien Fischer
ff592131b3 Add a builtin unsigned word sized integer type -- Part 1b.
compiler/builtin_ops.m:
    Implement unchecked_quotient, unchecked_rem, /\, \/, xor and \
    as builtin operations.

compiler/bytecode.m:
compiler/c_util.m:
compiler/llds.m:
compiler/llds_out_data.m:
compiler/ml_global_data.m:
compiler/mlds_to_c.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
compiler/opt_debug.m:
     Conform to the above change.

compiler/ml_unify_gen.m:
    Fix a bug in my previous change: we should use uint_eq to test
    for equality of uints, not eq.

compiler/hlds_data.m:
     Document uint_tag/1.

runtime/mercury_tabling_macros.h:
     Address review comment from Peter.

runtime/mercury_tabling_preds.h:
     Add tabling macros for uints that I missed the first time around.
2016-10-25 23:56:52 +11:00
Julien Fischer
092e175f45 Add a builtin unsigned word sized integer type -- Part 1.
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.
2016-10-24 12:55:35 +11:00
Peter Wang
ef5a4fa59d Support building with AddressSanitizer and UndefinedBehaviorSanitizer.
configure.ac:
    Add configure option --enable-sanitizers.

Mmake.common.in:
scripts/Mercury.config.in:
    Add variables to be set when --enable-sanitizers is used.

scripts/mgnuc.in:
scripts/ml.in:
    Pass sanitizer options to the C compiler and the linker.

compiler/options.m:
    Add options --cflags-for-sanitizers and --linker-sanitizer-flags
    for receiving the configuration.

    Set --linker-trace-flags and --shlib-linker-trace-flags default
    values to empty instead of "-g" (likely copy error).

compiler/compile_target_code.m:
    Pass sanitizer options to the C compiler, and the linker when
    building an executable or shared library.

runtime/Mmakefile:
trace/Mmakefile:
    Pass sanitizer options to linker when building shared libraries.

README.sanitizers:
    Add instructions.
2016-10-13 17:15:10 +11:00
Peter Wang
f99dba9120 Disable file IDs on Windows.
Since the original commit 89a4d190c5, io.m
tested for the macro MR_BROKEN_STAT_ST_INO whereas mercury_conf_param.h
defined the macro MR_BROKEN_ST_INO.  The effect was that file IDs were
allowed on Windows even though stat.st_ino will not distinguish files.

library/io.m:
    Test directly for MR_WIN32 instead of MR_BROKEN_STAT_ST_INO.

    Delete unreachable code.

runtime/mercury_conf_param.h:
    Delete MR_BROKEN_ST_INO.
2016-10-06 17:50:13 +11:00
Julien Fischer
4966332290 Rename the macros for condition variables.
runtime/mercury_thread.h:
   Rename MR_WAIT to MR_COND_WAIT etc.

runtime/mercury_wrapper.c:
library/thread.m:
library/thread.semaphore.m:
    Conform to the above change.
2016-10-05 13:13:07 +11:00
Julien Fischer
333baa371e Fix a syntax error.
runtime/mercury_thread.h:
     Add a missing parenthesis.
2016-10-03 13:10:46 +11:00
Julien Fischer
9ce6dd2205 Address review comments.
runtime/mercury_thread.h:
    Address review comments from Peter.
2016-10-03 10:55:36 +11:00
Julien Fischer
1fc495c33c Fix bug #357: parallel conjunction broken on OS X.
The parallel version of the runtime makes use of POSIX unnamed semaphores,
which do not exist on OS X (although annoyingly most of the relevant functions
*do* exist, they just don't do anything).  This was originally a problem for
the low-level C version of the parallel runtime, but now affects both C
backends (i.e. it's currently impossible to use threads or parallel
conjunctions on OS X).  The fix is to replace the use of POSIX unnamed
semaphores on OS X, with the semaphore implementation for libdispatch (which is
part of Grand Central Dispatch).  Note that the .par grades are (presumably)
still broken in versions of OS X prior to 10.6 -- they'll now just fail to
compile rather than fail at runtime.

configure.ac:
runtime/mercury_conf.h.in:
    Check whether libdispatch is present.

runtime/mercury_conf_param.h:
    Define a macro that says whether we want to use libdispatch; always
    define this macro on OS X.  Using libdispatch (optionally) on other systems
    is future work.

runtime/mercury_thread.{c,h}
    Define the MercurySem type and its associated operations appropriately
    when using libdispatch.

library/Mmakefile:
    Recompile the thread and thread.semaphore if any of the runtime headers
    that define the macros they use change.
2016-10-02 22:29:53 +11:00
Julien Fischer
bd2e02f94c Fix definition of MR_SEM_TIMED_WAIT for non OS X systems.
runtime/mercury_thread.h:
    As above.
2016-10-01 18:25:33 +10:00
Julien Fischer
c74fa8c6b8 Add missing definition for MR_SEM_TIMED_WAIT.
runtime/mercury_thread.h:
    As above.

    Re-order the definitions here to correspond to the other cases.
2016-10-01 17:29:14 +10:00
Julien Fischer
74dfaa5953 Isolate all dependencies on POSIX unnamed semaphores.
Isolate all dependencies on POSIX unnamed semaphores to the runtime's
mercury_thread module.  This is a step towards fixing bug #357.

runtime/mercury_thread.{h,c}:
    Provide wrappers for the functions sem_destroy and sem_timedwait.
    The latter does not exist on OS X, so (for now) just abort if it
    is called.

runtime/mercury_context.c:
library/thread.m:
     Use the above wrappers instead of calling the sem_* functions
     directly.
2016-09-29 14:06:04 +10:00
Peter Wang
daae03f07f Delete unnecessary foreign_exported procedures.
library/io.m:
    Delete unused foreign_exported procedures.

    Add warning about using `ML_io_print_to_stream'.

runtime/mercury_init.h:
runtime/mercury_wrapper.c:
runtime/mercury_wrapper.h:
util/mkinit.c:
    Delete unused function pointer `MR_io_print_to_cur_stream'.
2016-09-28 11:10:33 +10:00
Paul Bone
d2238b4cce Make a collection optional when reporting memory attribution
As I upgraded the collector last week I noticed that we no-longer need to
run a garbage collection event in order to calculate memory attribution.
This patch makes running a collection optional.

library/benchmarking.m:
runtime/mercury_heap_profile.c:
runtime/mercury_heap_profile.h:
    Add an extra parameter to the Mercury predicates and C procedures to say
    whether a collection should occur.  The Mercury predicates were
    duplicated to preserve the old behaviour / compatibility.
2016-09-26 16:29:14 +10:00
Paul Bone
964112b866 Upgrade Boehm GC to 7.6.0
Upgrade Boehm GC from 7.4.x to 7.6.0 and libatomic_ops from 7.4.x to 7.4.4

.gitmodules:
boehm_gc:
    Update git submodule to new version of Boehm GC.

compiler/notes/upgrade_boehm_gc.html:
    Update notes about upgrading Boehm GC.

runtime/mercury_heap_profile.c:
    The code that enumerates the heap objects has been merged upstream in
    boehm_gc, and its interface has changed.  Conform to those changes.

NEWS:
    Announce this change.
2016-09-22 15:28:22 +10:00
Paul Bone
cffad33fd8 Fix a bug with I/O errors while reading files
Mercury did not properly test for I/O errors for file reading.  If an I/O
error occurred it would be reported as EOF.  If this happened at just the
right spot it could be silently ignored.  I found the mistake when trying to
open a directory as a file.  Opening the file succeeded but reading from it
incorrectly gave an EOF.

library/io.m:
    read_char_code has always been documented as returning -1 for EOF
    and -2 for an error.  But the C code did not correctly implement
    this.  fgetc will return EOF in either case and the caller must use
    ferror or feof to determine what has happened.

    Make it clearer that valid characters and bytes from read_char_code
    must be >= 0.

    Conform to changes in the runtime regarding supporting ferror

runtime/mercury_library_types.h:
    Add MR_FERROR macro

    Add ferror field to the MercuryFile struct.

runtime/mercury_file.[ch]:
    Add ferror field to the MercuryFile struct.

tests/general/Mmakefile:
tests/general/read_dir_regression.exp:
tests/general/read_dir_regression.exp2:
tests/general/read_dir_regression.exp3:
tests/general/read_dir_regression.exp4:
tests/general/read_dir_regression.m:
    Add regression test.

tests/.gitignore
    Add *.java_date to .gitignore.
2016-08-31 14:58:43 +10:00
Julien Fischer
94359989b9 Add missing function prototype for mercury_init_grade_check().
runtime/mercury_init.h:
     As above.
2016-07-25 10:24:17 +10:00
Julien Fischer
864e849f35 Fix formatting.
runtime/mercury_grade.h:
     As above.
2016-07-17 00:02:06 +10:00
Zoltan Somogyi
53b573692a Convert C code to use // style comments.
runtime/*.[ch]:
trace/*.[chyl]:
    As above. In some places, improve comments, e.g. by expanding contractions
    such as "we've". Add #ifndef guards against double inclusion around
    the trace/*.h files that did not already have them.

tools/*:
    Make the corresponding changes in shell scripts that generate .[ch] files
    in the runtime.

tests/*:
    Conform to a slight change in the text of a message.
2016-07-14 13:57:35 +02:00
Zoltan Somogyi
67326f16e4 Fix style issues in the runtime.
Move all .h and .c files to four-space indentation without tabs,
if they weren't there already.

Use the same vim line for all .h and .c files.

Align all backslashes at the ends of lines in macro definitions.
Align close comment signs.

In some places, fix inconsistent indentation.

Fix a bunch of comments. Add XXXs to a few of them.
2016-07-09 12:14:00 +02:00
Paul Bone
6aeb5bab7b Fixup calling convention in Boehm GC callback
runtime/mercury_wrapper.c:
    As above.
2016-06-09 15:16:47 +10:00
Paul Bone
471506367e Setup an OOM callback with Boehm GC
This is a simplier way to get an earlier abort when we run out of memory.
it also prints out the requested allocation size.

runtime/mercury_wrapper.c:
    As above.
2016-06-08 13:54:22 +10:00
Paul Bone
0bd301b59e Add thread.num_processors/3
Add a predicate that retrieves the number of processors available to this
process if known.

library/thread.m:
    As above.

runtime/mercury_context.c:
    The existing code that determines the number of processors was only used
    on thread safe low-level C grades.  Make it also available for thread
    safe high-level C grades.

    Add a fall back (less accurate) method of determining the number of
    processors.

    Remove an out-of-date comment.

runtime/mercury_context.h:
    Export the number of available processors.

scripts/ml.in:
    Link to libhwloc (if configured) on thread safe high and low-level C
    grades.

NEWS:
    Announce new predicate.

configure.ac:
    Update a --help message.
2016-05-13 16:17:52 +10:00
Paul Bone
7ff96f8454 Improve Mercury's temporary files and directories predicates.
+ Add support for retrieving the system/user's temporary directory.
 + Add support for creating temporary directories.

library/io.m:
    Add temp_directory/3

    Add make_temp_directory/3 and make_temp_directory/5.

    make_temp_file/3 and make_temp_file/5 now return the full pathname on
    the Java backends.

    On the Java backend make_temp_file/3 and make_temp_file/5 now create
    files chmod 600 on Unix-like systems, which is necessary when the
    temporary files are security sensitive.

    Document the limitations of these calls for the C# and Erlang backends.
2016-04-14 12:20:31 +10:00
Zoltan Somogyi
7836eb68e6 Move grade compatibility tests to mercury_grade.h.
Fix some comments (mostly in layout) in all the touched runtime headers.

runtime/mercury.h:
    Simplify the error message on the one grade compatibility test
    that is best kept out of mercury_grade.h, because it is next to
    the cause of the potential incompatibility.

runtime/mercury_grade.h:
    Add a comment about the grade compatibility test still in mercury.h.

    Move all the grade compatibility tests from mercury_conf_param.h here.
    Reword their error messages to talk directly about the user-visible
    grade components (or the Mercury compiler options enabling them,
    if there is no single grade component name for them) instead of the
    names of the C macros representing them.

    Group some related existing tests together.

runtime/mercury_conf_param.h:
    Move all the grade compatibility tests here to mercury_grade.h.

compiler/compile_target_code.m:
    Add a XXX.
2016-04-11 16:37:16 +10:00
Julien Fischer
686db7b076 Fix bitrot in low-level C agc runtime.
runtime/mercury_accurate_gc.c:
runtime/mercury_agc_debug.c:
    As above.
2016-04-06 11:49:19 +10:00
Julien Fischer
0226bedbaa Fix a typo.
runtime/mercury_agc_debug.c:
    s/intw/int/
2016-04-05 15:08:33 +10:00
Julien Fischer
3660654fda Add a missing #include.
runtime/mercury_term_size.c:
    #include mercury_runtime_util.h since this code requires
    a definition for MR_STRERROR_BUF_SIZE.
2016-04-05 13:36:19 +10:00
Peter Wang
c77d07781c Fix missing declarations of symbols for thread-pinning.
runtime/mercury_context.c:
	Define _GNU_SOURCE at top of file, otherwise including <sched.h>
	does not declare the glibc/Linux-specific symbols we use for
	thread pinning: sched_getaffinity, sched_setaffinity,
	sched_getcpu, and the cpu_set_t CPU_* macros.
2016-03-26 19:07:12 +11:00
Julien Fischer
d5bef1437c Fix a typo.
runtime/mercury_conf_param.h:
    Add a missing space.
2016-03-25 18:16:33 +11:00
Zoltan Somogyi
156ee8b37e Remove the long obsolete runtime/mercury_conf_bootstrap.h. 2016-03-17 23:32:23 +11:00
Zoltan Somogyi
6367930ce3 Delete long obslete bootstrap code. 2016-03-16 23:26:57 +11:00
Zoltan Somogyi
76aa8a5a74 Move comments to the code they apply to. 2016-02-26 05:20:34 +11:00
Julien Fischer
d08fa4dcd9 Delete stuff only used by the GCC back-end.
runtime/mercury_bootstrap.h:
runtime/mercury_std.h:
    Delete header includes that were only required when the GCC
    header files were also included.
2016-02-25 17:41:28 +11:00
Zoltan Somogyi
c8d718ec57 Remove the .regparm and .picreg grade components.
For picreg, this is only the first half of the change; it deletes code
that generates references to this grade component. When this diff has been
installed on all our machines, will come the second half, which will delete
the code that understands references to picreg. The delay is needed because
your current installed compiler is still generating such references.

runtime/mercury_grade.h:
    Remove both regparm and picreg as grade components.

doc/user_guide.texi:
    Remove the (commented out) documentation of picreg; regparm had
    no documentation to delete.

runtime/mercury_std.h:
    Remove the small bit of code that implemented regparm.

runtime/mercury_conf_param.h:
    Don't define MR_PIC_REG.

runtime/machdeps/i386_regs.h:
runtime/mercury_conf_bootstrap.h:
    Remove references to picreg.

scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/mgnuc.in:
scripts/parse_grade_options.sh-subr:
    Keep in place the code that accepts picreg grade components,
    but make them do nothing. Mark such do-nothing code so that
    it can be deleted when this first-half diff has been bootstrapped.

configure.ac:
    Delete the autoconfigured variable EXT_FOR_LINK_WITH_PIC_OBJECTS,
    which could be set to either 'lpic_o' or just 'o', because it is now
    *always* the latter.

scripts/Mercury.config.bootstrap.in:
scripts/Mercury.config.in:
    Remove code that transmitted the value of EXT_FOR_LINK_WITH_PIC_OBJECTS
    to the compiler via the --link-with-pic-object-file-extension option.

compiler/options.m:
    Keep the --link-with-pic-object-file-extension and --pic-reg options,
    but mark them for deletion in the second half of this change.

compiler/compile_target_code.m:
    Change the code that dealt with the value of the
    --link-with-pic-object-file-extension and --pic-reg options to assume
    that the former is always the same as the non-pic file extension,
    and that --pic-reg is never needed. The former means that we don't need
    to handle link_with_pic as a separate category of object files from
    just plain non_pic.

compiler/compute_grade.m:
    Keep accepting picreg grades, but mark the code that does this
    for deletion.

compiler/make.program_target.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
    Conform to the changes above.
2016-02-25 16:47:16 +11:00
Mark Brown
3acbf03059 Implement combined higher-order types and insts.
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.
2016-02-08 16:09:01 +11:00
Julien Fischer
d9ff3a3b46 Fix spelling.
runtime/machdeps/README:
    As above.
2015-12-30 02:56:48 +11:00
Julien Fischer
2ab1f11526 More work on installation with non-C grade compilers.
runtime/Mmakefile:
    Always install the runtime header files, even in non-C grades.
    Add a comment explaining why this needs to be done.

    Update the comment describing where all the different versions of
    the runtime live and how they are built.

    Delete now-unused code for building the IL backend version of the
    runtime.

compiler/Mmakefile:
     Document the how we install the C# version of the compiler.

     Add an XXX comment about a difference between Mono and .NET that
     we don't yet handle when the compiler is built in the C# grade.

library/Mmakefile:
     Delete code for cleaning up files generated by the IL backend.
2015-12-30 02:51:29 +11:00
Zoltan Somogyi
7c8eeadabf Fix comments. 2015-12-17 00:11:18 +11:00
Julien Fischer
e473001caf Don't export MR_make_argv from the runtime.
runtime/mercury_wrapper.[ch]:
     The function MR_make_argv was only exported from this module
     for the use of the GCC backend; since that no longer exists,
     we no longer need to export it.
2015-12-14 14:14:31 +11:00