Commit Graph

2427 Commits

Author SHA1 Message Date
Julien Fischer
2ff14bd80b Implement the system RNG on Windows.
On Windows we implement the system RNG by calling the CRT's rand_s() function.

library/random.system_rng.m:
    Implement the system RNG on Windows using rand_s().

runtime/mercury_std.h:
    On Windows define the macro _CRT_RAND_S before the initial
    inclusion of stdlib.h -- we must do this otherwise the declaration
    of rand_s() will not be visible.
2021-02-14 20:30:08 +11:00
Julien Fischer
4e717c649d Avoid a linker warning on aarch64 Linux.
runtime/mercury_goto.h:
    On aarch64 emit a .type directive that sets the type of
    entry labels to be code.
2021-01-25 16:32:49 +11:00
Julien Fischer
b34620214f Fix installation on aarch64 Linux.
runtime/Makefile:
    Install the aarch64 register definitions header.

    Put the MACHHDRS list in alphabetical order.
2021-01-25 15:06:02 +11:00
Julien Fischer
2eba9a6697 Avoid a warning from GCC.
runtime/mercury_context.c:
     As above.
2021-01-23 19:41:51 +11:00
Julien Fischer
f3d68031f5 Minor fixes for the doregtest script.
runtime/machdeps/doregtest:
    Fix some things identified by ShellCheck.
2021-01-13 15:24:23 +11:00
Julien Fischer
e613aabeea Distinguish between 32- and 64-bit ARM in a couple of spots.
runtime/machdeps/aarch64_regs.h:
runtime/machdeps/arm_regs.h:
    As above.
2021-01-13 14:27:22 +11:00
Julien Fischer
84b561a2a0 Use global registers on aarch64.
runtime/machdeps/aarch64_regs.h:
runtime/mercury_regs.h:
     Define global registers for aarch64.

configure.ac:
     Compile with -fomit-frame-pointer on aarch64.  (Doing so frees
     up register x29.)

     Compile with -fPIC instead of -fpic on aarch64-*-linux* systems
     in order to avoid size limits on the global offset table.
2021-01-13 14:22:21 +11:00
Peter Wang
524f4d72e2 Delete references to Erlang backend in makefiles.
Mmake.workspace:
Mmakefile:
*/Mmakefile:
tests/*/Mmakefile:
tests/valid/Mmake.valid.common:
trace/Mmakefile:
    As above.
2020-10-27 11:10:11 +11:00
Julien Fischer
b57cfb54a5 Update references to configure.in.
configure.ac:
compiler/notes/overall_design.html:
deep_profiler/conf.m:
runtime/mercury_context.h:
runtime/mercury_goto.h:
runtime/mercury_grade.h:
runtime/mercury_regs.h:
    As above -- the configure template has been named configure.ac
    for a long time now.
2020-10-25 14:45:35 +11:00
Julien Fischer
ff39b3463b Remove legacy support for the Alpha architecture.
README.Linux-Alpha:
runtime/machdeps/ALPHA_REGS:
runtime/machdeps/alpha_regs.h:
runtime/machdeps/alpha_regtest:
    Delete these files.

configure.ac:
runtime/Mmakefile:
runtime/mercury_goto.h:
runtime/mercury_regs.h:
README.md:
README.Linux:
README.Linux-PPC:
    Delete or update references to the Alpha architecture.

NEWS:
    Announce the above.

scripts/mgnuc.in:
    Unrelated: update a comment.
2020-10-18 16:35:52 +11:00
Peter Wang
bb98e8c7ba Delete unused MR_CAN_GET_PC_AT_SIGNAL macro.
runtime/mercury_conf_param.h:
    As above.
2020-10-13 13:32:32 +11:00
Peter Wang
14ce8638cc Simplify code to set SIGBUS/SIGSEGV handlers.
mercury_memory_handlers.c:
    Remove a layer of macros.
2020-10-13 13:32:32 +11:00
Peter Wang
7e2f38d301 Fix access to PC from signal handler context.
configure.ac:
    Deduplicate checks for how to access the program counter from a
    signal handler context.

    Check REG_RIP for x86-64 and REG_EIP for i386.

    Define _GNU_SOURCE for the register constants (REG_RIP, etc.)

    Drop support for accessing the PC on Alpha as it doesn't fit easily
    into the "uc_mcontext.gregs[$reg]" pattern.
2020-10-13 13:32:32 +11:00
Peter Wang
94e2ef3f2c Delete unnecessary test for sa_sigaction field.
configure.ac:
    Delete check for sa_sigaction field. If a call to sigaction()
    has the SA_SIGINFO flag set then the handler must be specified in
    the sa_sigaction field, not the sa_handler field.

runtime/mercury_conf.h.in:
    Delete MR_SIGACTION_FIELD macro.

runtime/mercury_signal.c:
    Don't use MR_SIGACTION_FIELD macro.

    Don't define dummy value for SA_SIGINFO.

tools/configure_mingw_cross:
    Don't set now-unused variable.
2020-10-13 13:32:32 +11:00
Peter Wang
388938ac1e Delete use of signal handlers taking sigcontext arguments.
The configure checks for sigcontext (aka sigcontext_struct) have failed
for a long time without anyone noticing. The MR_GET_FAULT_ADDR macro
that is also needed for the sigcontext code paths was only ever defined
for __i386__ and __mc68000__.

According to the sigaction(2) man page, the struct sigcontext
argument was obsoleted by the introduction of the SA_SIGINFO flag
(which we also have code for, though also not working either).

configure.ac:
    Delete checks related to struct sigcontext.

    Delete check for asm/sigcontext.h

runtime/mercury_conf.h.in:
    Delete macros that are no longer defined.

runtime/mercury_memory_handlers.c:
runtime/mercury_signal.c:
runtime/mercury_signal.h:
    Delete code for using signal handlers that take a sigcontext argument.

    Add XXX where native GC casts a context parameter to
    struct sigcontext * when it should be a ucontext_t *.
    Possibly never tested.

runtime/mercury_faultaddr.h:
    Delete this file containing only the MR_GET_FAULT_ADDR macro which is
    no longer used.

runtime/RESERVED_MACRO_NAMES:
ssdb/RESERVED_MACRO_NAMES:
trace/RESERVED_MACRO_NAMES:
    Delete macros that are no longer defined.

tools/configure_mingw_cross:
    Don't need to set variables mercury_cv_sigcontext_struct_2arg and
    mercury_cv_sigcontext_struct_3arg any more.
2020-10-13 13:32:32 +11:00
Zoltan Somogyi
d262d28c2d Ignore any errors running ctags. 2020-10-03 18:01:42 +10:00
Zoltan Somogyi
c5b35aca5f Fix the declarations of builtin proc layouts.
This should fix Mantis bug #514.

runtime/mercury_builtin_types_proc_layouts.h:
    Fix the first problem: refer to four type constructors defined
    in private_builtin.m by their correct arities, so that the proc layout
    structures we generate for their unify and compare predicates
    get generated with the correct names and contents.

    The arities were probably correct when the code was written;
    we changed them from 1 to 0 at some point, and simply forgot
    to update all the affected places.

runtime/mercury_stack_layout.h:
    Fix the second problem: add "extern" to the declarations of those
    proc layout structures. Without the "extern", compilers defaulting
    the -fcommon will place these structures into common storage,
    which can be used as *definitions*. With the "extern", compilers
    should do the right thing whether or not they default to -fcommon.

runtime/mercury_unify_compare_body.h:
    Conform to the change in mercury_builtin_types_proc_layouts.h:
    refer to the affected four types using the correct arities.
2020-07-24 17:14:07 +10:00
Zoltan Somogyi
78720b4537 Improve the user guide.
doc/user_guide.texi:
    Document the recent change that mmc -f *.m is needed if a module's
    file name does not match the fully qualified module name.

    Mention that the discussion of .c and .o files applies only
    to grades targeting C.

    Mention that LLDS details such as MERCURY_OPTIONS governing stack sizes
    apply only in (non-stseg) LLDS grades.

    Mention that mmake does not support Java, C# and Erlang grades,
    but comment out these mentions since I am not sure about exactly
    what we *can* say about this.

    Delete mention of the --assume-gmake option.

    Minor English improvements.

compiler/options.m:
    Delete the --assume-gmake option. It has long been unused.

runtime/mercury_wrapper.c:
    Add a reminder to update user_guide.texi if the default stack sizes
    are changed.
2020-05-30 23:13:42 +10:00
Zoltan Somogyi
ada627928c Stop supporting --tags none for C.
The effect of --tags none is to tell the compiler not to use any primary
tag bits. The option is not needed when targeting Java, C# or Erlang,
since with these languages we can't use primary tags. It was effective
only in C grades. However, since using primary tags is always faster,
the only use case for --tags none was to measure *how much* faster.
This was useful in Mercury's early development, but has become obsolete
ages ago.

compiler/options.m:
doc/user_guide.texi:
    Delete the --tags option. For non-C targets, it was never needed,
    and with the deletion of first --tags high and now --tags none,
    --tags low is the only supported value for C.

    Change the documentation of the --num-ptag-bits option to emphasize
    that name, not its older but less specific synonym, --num-tag-bits.
    Document that the only reason to use this option is cross-compilation.

    In user_guide.texi, also delete some references to long-deleted
    options for reserved addresses and objects, and some duplicate lines
    in comments.

NEWS:
    Document the option removal.

compiler/globals.m:
    Delete the tags_method field of the globals, since it is not
    needed anymore.

compiler/handle_options.m:
    Delete the code that converts the value of the --tags option to the
    value of the tags_method field of the globals.

    Ensure that the value of the num_ptag_bits option is (a) zero when
    not targeting C, and (b) either 2 or 3 when targeting C.

compiler/du_type_layout.m:
    Check that we are using 2 or 3 ptag bits when targeting C.

compiler/const_struct.m:
    Conform to the changes above.

runtime/mercury_grade.h:
    Generate an error if MR_TAGBITS is zero (which could happen
    only with --tags none).

runtime/mercury_tags.h:
    Delete the definitions of the list access macros for the MR_TAGBITS == 0
    case.
2020-04-28 13:36:58 +10:00
Zoltan Somogyi
af24cf08db Fix bootcheck in hlc.gc.pregen.
runtime/mercury_label.h:
    Add a #include of mercury_conf.h before the #include of
    mercury_conf_param.h.

    We #include mercury_conf.h anyway, indirectly through mercury_types.h,
    but this happens *after* mercury_conf_param.h. This was not a problem
    in the usual case when a .c file #included mercury_label.h, since
    its inclusion invariable came after inclusion of mercury_imp.h,
    which itself includes mercury_conf.h. It was a problem only in one
    very special case: when, as part of the namespace cleanliness check,
    mercury_label.h was compiled as the only thing #included in
    mercury_label.check.c, *and* the grade is the pregen grade.

    The problem was that MR_LOW_TAG_BITS is *defined* in mercury_conf.h,
    with a simple #define, but in the pregen grade, it is also *redefined*
    in mercury_conf_param.h with a #undef/#define sequence. without
    the fix, the compiler saw the sequence #undef/#define/#define, and
    balked at the double #define. The fix restores the intended
    #define/#undef/#define sequence. And the usual header guard macro
    protects against the double processing of the body of mercury_conf.h.

runtime/mercury_label.c:
    Delete a #include of mercury_conf.h, since it is (and was) redundant.

tests/EXPECT_FAIL_TESTS.hlc.gc.pregen:
    Expect the hard_coded/constant_prop_p1 test case to fail in the pregen
    grade, since one of the things it tests, arithmetic constant propagation,
    is explicitly disabled in this grade.
2020-04-28 10:55:18 +10:00
Peter Wang
a4b26739ba Reset es_action field when idle ws engine receives a notification.
In MR_do_idle_worksteal, reset the engine's es_action field to
MR_ENGINE_ACTION_NONE before performing the notified action.
This mirrors the behaviour in MR_do_sleep.

Fixes the assertion failure in Mantis bug #461: when an engine is
shut down, MR_verify_final_engine_sleep_sync checks that the engine's
es_action field is MR_ENGINE_ACTION_NONE.

runtime/mercury_context.c:
    As above.

NEWS:
    Announce change.
2020-04-20 12:41:45 +10:00
Zoltan Somogyi
3e894a7a9d Remove the hl grade component.
As we discussed, it has fallen into disuse. Its main purpose was to
pave the way for the .net backend and later for the java and csharp grades.
Now that the .net backend is ancient history and the java and csharp grades
are established, that purpose is gone, and for every other purpose,
hlc is better because it is simpler and faster.

compiler/options.m:
    Delete the --high-level-data option. It is no longer needed,
    bacause the data representation scheme is now a direct function
    of the target language.

doc/user_guide.texi:
    Delete references to the --high-level-data option.

NEWS:
    Mention that --high-level-data is no longer supported.

compiler/compute_grade.m:
    Delete references to the hl grade component, and conform
    to the deletion of the --high-level-data option.

compiler/compile_target_code.m:
    Give some predicates more meaningful names, and conform to the
    deletion of the --high-level-data option.

compiler/const_struct.m:
compiler/du_type_layout.m:
compiler/globals.m:
compiler/handle_options.m:
compiler/lco.m:
compiler/mercury_compile_main.m:
compiler/ml_gen_info.m:
compiler/ml_type_gen.m:
compiler/ml_unify_gen_construct.m:
compiler/mlds_to_c_data.m:
compiler/mlds_to_c_func.m:
compiler/mlds_to_c_type.m:
compiler/mlds_to_c_util.m:
    Conform to the deletion of the --high-level-data option.

grade_lib/grade_spec.m:
grade_lib/grade_vars.m:
    Delete the datarep solver variable, since the data representation
    is now a direct function of the target language.

    Delete the requirements involving the deleted solver variable.

grade_lib/grade_structure.m:
    Delete the datarep component of the representation of MLDS C grades,
    since its value would now be fixed.

grade_lib/grade_solver.m:
grade_lib/grade_string.m:
grade_lib/try_all_grade_structs.m:
grade_lib/var_value_names.m:
    Conform to the changes above.

grade_lib/Mmakefile:
    Link the grade library's test programs statically, like we do
    the executables in the other directories.

library/io.m:
library/robdd.m:
library/rtti_implementation.m:
runtime/mercury_conf_param.h:
runtime/mercury_grade.h:
runtime/mercury_hlc_types.h:
    Remove references to MR_HIGHLEVEL_DATA, as well as any code
    that was guarded by #ifdef MR_HIGHLEVEL_DATA.

scripts/Mmake.vars.in:
scripts/canonical_grade.sh-subr:
scripts/final_grade_options.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/mgnuc.in:
scripts/mgnuc_file_opts.sh-subr:
scripts/mmake.in:
scripts/mmc.in:
scripts/mtc:
scripts/parse_grade_options.sh-subr:
scripts/parse_ml_options.sh-subr.in:
    Remove references to --high-level-data options.

    In canonical_grade.sh-subr, compute the base grade more directly.

    Remove a few left-over references to the assembler backend.

    Add or fix vim modelines where relevant.

    Fix inconsistent indentation.

    Add missing ;;s in case statements.

    Switch to using ${var} references instead of just $var.

tests/invalid/Mercury.options:
    Make the test_feature_set test case run in grade java instead of hl.gc.

tests/invalid/test_feature_set.err_exp:
    Update the expected out for the grade change.
2020-04-11 19:30:58 +10:00
Julien Fischer
896e504580 Add missing out-of-line definitions for MR_box_{int64,uint64}.
runtime/mercury.c:
     Provide out-of-line definitions for MR_box_{int64,uint64} when using
     boxed 64-bit integers and *not* using GCC.
2020-03-15 17:05:47 +11:00
Julien Fischer
f60caca91c Use trail segments by default in trailing grades.
Until now, we have supported two variants of trailing grades, those that use a
fixed-size trail (.tr) and those that use trail segments (.trseg).  This change
removes support for fixed sized trails, and renames the .trseg grade component
to .tr. The .trseg grade now acts a synonym for .tr; it is deprecated, since we
intend to eventually delete it.  Until then, the behavior of the old .tr grade
component should be available, though to developers only, by compiling the
whole system with EXTRA_CFLAGS = -DMR_USE_FIXED_SIZE_TRAIL.

runtime/mercury_conf_param.h:
    Delete the MR_TRAIL_SEGMENTS macro. Its effect is now implied by
    MR_USE_TRAIL, unless a new macro, MR_USE_FIXED_SIZE_TRAIL, is defined.
    Developers can use this new macro to disable trail segments, should the
    need for doing that arise.

runtime/mercury_grade.h:
    Add a new macro that defines a binary compatibility version number for
    trailing; use that in the grade part for trailing.

    Use "_trfix" or "_trseg" as the prefix of the trailing part of the
    MR_GRADE_VAR depending on if MR_USE_FIXED_SIZE_TRAIL is defined or
    not.

runtime/mercury_trail.[ch]:
runtime/mercury_context.h:
    Enable trail segments by default, only disabling them if
    MR_USE_FIXED_SIZE_TRAIL is enabled.

runtime/mercury_wrapper.c:
trace/mercury_trace_cmd_developer.c:
    Conform to the above changes.

compiler/compile_target_code.m:
    Do not pass options for trail segments to the C compiler.

compiler/compute_grade.m:
    Treat trseg as a synonym for tr.

compiler/options.m:
    Deprecate --trail-segments.

grade_lib/grade_spec.m:
grade_lib/grade_string.m:
grade_lib/grade_structure.m:
grade_lib/grade_vars.m:
grade_lib/try_all_grade_structs.m:
grade_lib/var_value_names.m:
    Remove the trseg component.

scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/mgnuc.in:
scripts/parse_grade_options.sh-subr:
    Remove support for the --trail-segments option.

doc/user_guide.texi:
    Update the documentation for the --trail-segments.

    Comment out the documentation of the --trail-size and --trail-size-kwords
    runtime options; they are no longer useful to non-developers.

NEWS:
    Announce this change.
2020-02-18 13:07:24 +11:00
Peter Wang
c38acd1f0b Disable non-local gotos on x86 with GCC 5+ if dynamic linking is enabled.
An old hack allowing non-local gotos to work with PIC on x86
no longer works with GCC 5+; this change is a workaround.
Mantis bug #453.

configure.ac:
    Position the handling of the --enable-dynamic-link option before
    we check if non-local gotos can work.

    Disable non-local gotos on x86 with GCC 5+ if dynamic linking
    is enabled.

runtime/mercury_goto.h:
    Add comment.
2020-01-20 15:24:19 +11:00
Peter Wang
09877885f9 Avoid gcc stringop-truncation error.
Avoid these errors, seen when compiling with a gcc 10 snapshot:
    error: ‘strncpy’ output truncated before terminating nul copying 3 bytes
    from a string of the same length [-Werror=stringop-truncation]

runtime/mercury_trace_term.c:
    Replace use of strncpy with memcpy in a private function.
2020-01-17 17:09:49 +11:00
AlaskanEmily
3f3f2290a0 Use sizeof and (Visual C only) __assume for MR_assert
Using sizeof ensures that the argument to MR_assert is valid code, but does not
actually execute its argument. This is helpful to prevent bitrot.

__assume is a Visual C extension which hints that the argument is impossible.
This gives the compiler hints about unused variables (silencing some warnings),
and can also improve optimization.

runtime/mercury_std.h:
    As above.
2019-12-03 12:38:02 +11:00
Peter Wang
025bee0549 Check for surrogates when converting list of char to string.
library/string.m:
    Make from_char_list, from_rev_char_list, to_char_list throw an
    exception if the list of chars includes a surrogate code point that
    cannot be encoded in a UTF-8 string.

    Make semidet_from_char_list, semidet_from_rev_char_list,
    to_char_list fail if the list of chars includes a surrogate code
    point that cannot be encoded in a UTF-8 string.

runtime/mercury_string.h:
    Document return value of MR_utf8_width.

tests/hard_coded/Mmakefile:
tests/hard_coded/string_from_char_list_ilseq.exp:
tests/hard_coded/string_from_char_list_ilseq.exp2:
tests/hard_coded/string_from_char_list_ilseq.m:
    Add test case.

tests/hard_coded/null_char.exp:
    Expect new message in exceptions thrown by from_char_list,
    from_rev_char_list.

tests/hard_coded/string_hash.m:
    Don't generate surrogate code points in random strings.
2019-10-30 11:21:02 +11:00
Julien Fischer
ee9aaa8c1b Always use 64-bit offsets with fseek() and ftell().
Most sane systems use 64-bit offsets with those functions; Windows does not.

runtime/mercury_file.h:
   Define macros MR_fseek and MR_ftell that expand to the name of the
   fseek or ftell function that uses 64-bit offsets.

runtime/mercury_deep_profiling.c:
library/io.m:
    Use the new macros and always use 64-bit offsets.
2019-10-08 21:36:11 +11:00
Peter Wang
1a619af68e Add more TODOs relating to ill-formed code unit sequences. 2019-09-13 15:51:02 +10:00
Peter Wang
c08db9e5f7 Make MR_utf8_get return error for more ill-formed sequences.
runtime/mercury_string.c:
    Make MR_utf8_get, MR_utf8_get_mb return an error for code unit
    sequences that encode a surrogate code point, or a code point
    greater than U+10FFFF.

runtime/mercury_string.h:
    Adjust some comments.
2019-09-13 15:51:02 +10:00
Peter Wang
ed1b3fe19c Note some future work for handling ill-formed sequences in strings.
library/io.m:
library/string.m:
    Add warnings that Mercury strings are not limited to valid UTF-8 or
    UTF-16.

library/string.m
library/string.format.m
library/term_io.m
    Note some current behaviours of predicates/functions when passed
    strings containing invalid UTF-8 or UTF-16, and what to do about it.

runtime/mercury_string.h:
    Note behaviour of MR_utf8_encode.
2019-09-09 10:47:48 +10:00
Adrian Wong
a589fd1164 Fix some comments related to hashing.
library/hash_table.m:
library/string.m:
runtime/mercury_string.h:
    As above.
2019-07-29 11:35:53 +10:00
Peter Wang
544f3bf095 Use musl getopt implementation.
LICENSE:
    Mention files derived from musl library.

runtime/process_getopt:
    Process files from ../getopt/*.[ch] to produce
    mercury_getopt.h, mercury_getopt.c, mercury_getopt_long.c.

runtime/mercury_getopt.h:
runtime/mercury_getopt.c:
runtime/mercury_getopt_long.c:
    Add files generated by process_getopt.

runtime/Mmakefile:
    Update list of source files.

util/Mmakefile:
    Use musl getopt if the system C library does not have getopt().

tests/debugger/browser_test.exp:
tests/debugger/browser_test.exp2:
tests/debugger/browser_test.exp3:
tests/hard_coded/runtime_opt.exp:
    Update expected error messages to match new getopt() output.

changed exp output
2019-06-10 13:30:49 +10:00
Peter Wang
3162997f14 Delete GNU getopt implementation.
runtime/GETOPT/getopt.c:
runtime/GETOPT/getopt.h:
runtime/GETOPT/getopt1.c:
runtime/mercury_getopt.c:
runtime/mercury_getopt.h:
runtime/mercury_getopt1.c:
    Delete files.

runtime/RESERVED_MACRO_NAMES:
    Delete __GNU_LIBRARY__ macro.
2019-06-10 13:30:43 +10:00
Peter Wang
2e9b41d8a2 Store less-than-word-sized values in LSBs of box.
runtime/mercury_heap.h:
    Store less-than-word-sized values in least significant bits of a
    box. This makes no difference on little endian machines.
    On big endian machines, it affects the value printed out
    when the box is printed generically.
2019-06-08 16:40:24 +10:00
Peter Wang
dfab1619c2 Disambiguate references to editline.
There are multiple libraries named "editline" on the net.
The one that Mercury supports is (a port of) the NetBSD editline
library, sometimes also referred to as "libedit". Make it easier
for the user to install the correct library.

.INSTALL.in:
configure.ac:
m4/mercury.m4:
runtime/mercury_conf.h.in:
    Mention NetBSD and libedit in a few more places.
2019-06-08 14:06:53 +10:00
Zoltan Somogyi
02bf90da93 Fix a type-size-mismatch bug in RTTI.
runtime/mercury_stack_layout.h:
    Make the count of type params the same size as the descriptions
    of the locations of those type params, since they are filled in
    by values from the same compiler-generated array. The mismatch caused
    hard_coded/copy_pred_2.m to fail on a 64-bit big endian machine
    (AIX/PowerPC).
2019-06-05 17:33:10 +02:00
AlaskanEmily
2330a2f294 Fix comment ending a macro
runtime/mercury_goto.h:
    Switching one of the comments only seen in Sparc code cut off the end of a macro.
    Only block comments can be placed inside macros anyway, not single-lines.
2019-03-13 16:51:08 +11:00
AlaskanEmily
117eba02f1 Avoid using HZ to scale clock values on Linux.
HZ is no longer an accurate scaling factor, and is hardcoded to 100.

runtime/mercury_timing.h:
    As above.
2018-11-29 06:01:42 +00:00
Peter Wang
5f7d3e6bb2 Use consistent integer types for some RTTI fields.
runtime/mercury_type_info.h:
    Use unsigned integer types for a few RTTI structure fields that
    are known to hold non-negative values.

    Add comments for other field types that could be changed later.

compiler/rtti.m:
    Use fixed size integer types for fields matching the size
    and signedness of the corresponding C RTTI structure fields.

    Encode type ctor flags in a uint16 instead of int.

    Make type_ctor_details_num_ptags and type_ctor_details_num_functors
    return a maybe value, instead of a negative value to represent no
    primary tags or no function symbols, respectively.

compiler/type_ctor_info.m:
    Conform to type changes.

    Use uint16 to represent the "contains var" bit vector.

compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
    Conform to type changes.

    Add comments to make it easier to find the code that writes out
    each particular RTTI structure field.

compiler/ml_util.m:
    Add helper functions.

compiler/add_special_pred.m:
compiler/du_type_layout.m:
compiler/erl_rtti.m:
compiler/erlang_rtti.m:
compiler/hlds_data.m:
compiler/llds_out_data.m:
compiler/ml_unify_gen_construct.m:
compiler/opt_debug.m:
compiler/pseudo_type_info.m:
compiler/stack_layout.m:
compiler/unify_gen_construct.m:
    Conform to type changes.

compiler/parse_type_defn.m:
compiler/prog_data.m:
    Use uint32 for functor ordinal numbers.

library/rtti_implementation.m:
    Use fixed size integer types for RTTI field accessor functions,
    and update callers.

java/runtime/DuArgLocn.java:
java/runtime/DuExistInfo.java:
java/runtime/DuExistLocn.java:
java/runtime/DuFunctorDesc.java:
java/runtime/TypeCtorInfo_Struct.java:
    Use integer types in RTTI structure definitions for Java that match
    the types in the C versions of the same structures.

runtime/mercury_dotnet.cs.in:
    Use integer types in RTTI structure definitions for C# that match
    the types in the C versions of the same structures.
2018-11-19 12:37:36 +11:00
Julien Fischer
f8d188fda8 Fix minor documentation problems.
deep_profiler/display_report.m:
deep_profiler/message.m:
deep_profiler/recursion_patterns.m:
deep_profiler/var_use_analsis.m:
java/runtime/UnreachableDefault.java:
runtime/mercury_engine.c:
runtime/mercury_minimal_model.c:
runtime/mercury_signal.h:
runtime/mercury_stack_layout.h:
runtime/mercury_wrapper.c:
runtime/mercury_threadscope.c:
trace/mercury_trace_external.c:
HISTORY:
    As above.
2018-10-09 05:27:36 +00:00
Zoltan Somogyi
8303b503b6 Unify and compare packed args in bulk when possible.
compiler/unify_proc.m:
    Try to optimize the code we generate for unification and comparison
    predicates when a function symbol's arguments include sub-word-sized
    arguments packed together into a word.

    For unify predicates, generate code to test whether the two words
    at the same offset in the terms being unified are equal. This works
    regardless of whether the arguments are signed or unsigned.

    For compare predicates, generate code to compare the two words
    at the same offset in the terms being compared *if* all the arguments
    in the terms being compared are unsigned. This works because we put
    the earlier arguments in the more significant bit positions. But if
    some of the arguments are signed, then divide the argument word
    in sequences of zero or more unsigned arguments separated by signed
    arguments. We then generate code that compares any contiguous sequences
    of unsigned arguments in bulk, while comparing each signed field
    separately.

    Do the bulk unification and comparison via foreign_proc goals generated
    inline. This works only when we are generating C, but this is ok because
    we pack sub-word-sized arguments into a word only when generating C.

    We do the comparison of signed sub-word-sized fields (int8, int16 or int32)
    via foreign_proc goals generated inline as well. Doing them using unify
    goals would work as well, but would be less efficient in general. This is
    because having N such arguments in a function symbols requires storing
    only one value across calls for each term being compared (the term itself)
    when generating foreign_procs, but would require storing N values across
    calls (the values of the sub-word-sized signed arguments) when generating
    unifications. Generating inline foreign_procs is effectively a manual
    application of the optimization implemented by saved_vars.m.

library/private_builtin.m:
    Add the builtin predicates that unify_proc.m now generates calls to.

    We should never need their bodies, but the compiler does need to know
    the declarations of all predicates mentioned in inline foreign_procs.

configure.ac:
runtime/mercury_conf.h.in:
    Define either MR_MERCURY_IS_32_BITS or MR_MERCURY_IS_64_BITS depending
    on the word size. Make the configured value of MR_BITS_PER_WORD available
    to C code.

mdbcomp/program_representation.m:
    Register the new builtin predicates as no_typeinfo_builtins, i.e.
    builtins whose arguments' types contain type variables, that nevertheless
    should *not* be passed the typeinfos of the actual types bound to those
    type variables.

compiler/hlds_clauses.m:
    Bulk unification of arguments works only when all the arguments involved
    are initially ground. The optimized unification clauses we can now generate
    are thus appropriate only for <in,in> unifications. (Technically, they
    *would* work for unifications for which the function symbol arguments
    involved in bulk unify operations are ground even if some other arguments
    are initially free, but that distinction is too hard to make, compared
    to the extremely small performance gain that would be available
    if we *could* make that distinction.)

    Provide a way for unify_proc.m to mark a clause as being for use either
    in the <in,in> modes of unifications (for the optimized version using bulk
    unifications), or as in all other modes of unifications (for a version in
    which that optimization has been disabled).

    Replace two boolean fields in clauses_infos with bespoke types, for
    greater readability and reliability. These are a remnant of a different
    way to differentiate <in,in> vs non-<in,in> clauses that I ultimately
    decided against. These bespoke types are independent of the main change
    in this diff, but there is no reason to undo their use.

compiler/clause_to_proc.m:
    When copying clauses to procedure bodies inside type-specific unify
    predicates, pay attention to the markers that unify_proc.m put on
    those clauses about which are for <in,in> modes and which are for
    non-<in,in> modes.

    To make this possible, make our callers pass us extra information.

compiler/options.m:
    Add a bootstrapping option that governs whether unify_proc.m should
    try to apply the new optimization.

    Give an option that governs comparisons of function symbols for Erlang
    a name that reflects that fact.

compiler/hlds_pred.m:
    Fix a misleading predicate name.

compiler/add_class.m:
compiler/add_clause.m:
compiler/add_foreign_proc.m:
compiler/add_pragma_type_spec.m:
compiler/add_pred.m:
compiler/dead_proc_elim.m:
compiler/det_report.m:
compiler/erl_code_gen.m:
compiler/handle_options.m:
compiler/higher_order.m:
compiler/hlds_out_module.m:
compiler/hlds_out_pred.m:
compiler/hlds_statistics.m:
compiler/intermod.m:
compiler/mercury_compile_front_end.m:
compiler/ml_proc_gen.m:
compiler/modecheck_unify.m:
compiler/proc_gen.m:
compiler/proc_requests.m:
compiler/purity.m:
compiler/resolve_unify_functor.m:
compiler/structure_reuse.indirect.m:
compiler/structure_sharing.analysis.m:
compiler/tabling_analysis.m:
compiler/type_constraints.m:
compiler/typecheck.m:
compiler/unused_args.m:
    Conform to the changes above.
2018-10-03 08:32:29 +10:00
Peter Wang
bb35de8b3d Fix references to undeclared MR_ALLOC_ID in low-level C memprof grades.
runtime/mercury_ml_expand_body.h:
    Delete references to MR_ALLOC_ID in code that builds lists of univs.
2018-09-16 16:23:16 +10:00
Peter Wang
e40d54f89c Include <sys/select.h> for select() if available.
According to the man page, <sys/select.h> is the header to include
on POSIX systems for select() and associated APIs.
Fixes compilation with some versions of Cygwin (Github issue #49).

configure.ac:
runtime/mercury_conf.h.in
    Define MR_HAVE_SYS_SELECT_H if <sys/select.h> is available.

runtime/mercury_reg_workarounds.c
runtime/mercury_reg_workarounds.h
    Include <sys/select.h> if MR_HAVE_SYS_SELECT_H is defined.
2018-09-11 10:55:30 +10:00
Peter Wang
aef7167203 Avoid gcc misleading indentation warning.
runtime/mercury_deconstruct_macros.h:
    Reformat an else if in MR_get_arg_value() to prevent a warning from
    gcc 8 about misleading indentation when -ftrack-macro-expansion=0
    is used (which we pass to make error messages easier to filter).
2018-09-09 12:33:26 +10:00
Zoltan Somogyi
d1ec3e3f55 Pack characters as sub-word-sized arguments.
compiler/options.m:
    Add new options --allow-packing-chars and --allow-packing-mini-types,
    for use by developers only.

compiler/du_type_layout.m:
    If the new --allow-packing-chars option is set, then allow characters
    to be packed as sub-word-sized arguments.

    Record the value of the --allow-packing-mini-types in the parameters
    as well, without using it as yet. (That is for a future change.)

    Fix the test for what counts as suboptimal packing. Given an argument
    list such as <sub-word-sized args, word-sized arg, sub-word-sized args>
    where the two lots of sub-word-sized args could fit into a single word,
    the old code did NOT emit a "this is suboptimal" message for it. This
    was because it did not consider a reduction from 2n words to 2n-1 words
    to be significant, as boehm_gc would always round up the number of words
    to (at least) the next multiple of 2. The problem was that the code
    used to apply this test ONLY to the number of words occupied by
    sub-word-sized args. In this case, better packing would make that number
    go from 2 to 1, so it did emit the message, even though the *total*
    number of words in the memory cell would go from 3 to 2.

    We could fix this by applying the round-up-to-even the test to the total
    number of words, but it is simpler to eliminate round-up-to-even entirely.
    This is desirable anyway, since we *should* prefer compresssing e.g.
    a 4 word cell down to 3 if possible, since this would reduce traffic
    to and from (some levels of) cache, even if it would not reduce
    the size of the memory allocation.

    Fix some too-long lines.

compiler/prog_data.m:
    Add fill_char21 as a new kind of fill for sub-word-sized arguments.
    (The 21 is a reminder of the 21 bit size of Unicode chars.)

runtime/mercury_type_info.h:
    Document that fill_char21 arguments are treated the same way as enum args
    in the RTTI.

compiler/hlds_out_module.m:
compiler/ml_unify_gen_deconstruct.m:
compiler/ml_unify_gen_util.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/unify_gen_util.m:
    Conform to the changes above.
2018-08-30 23:26:56 +10:00
Zoltan Somogyi
86f563a94d Pack subword-sized arguments next to a remote sectag.
compiler/du_type_layout.m:
    If the --allow-packing-remote-sectag option is set, then try to pack
    an initial subsequence of subword-sized arguments next to remote sectags.

    To allow the polymorphism transformation to put the type_infos and/or
    typeclass_infos it adds to a function symbol's argument list at the
    *front* of that argument list, pack arguments next to remote sectags
    only in function symbols that won't have any such extra arguments
    added to them.

    Do not write all new code for the new optimization; instead, generalize
    the code that already does a very similar job for packing args next to
    local sectags.

    Delete the code we used to have that picked the packed representation
    over the base unpacked representation only if it reduced the
    "rounded-to-even" number of words. A case could be made for its usefulness,
    but in the presence of the new optimization the extra code complexity
    it requires is not worth it (in my opinion).

    Extend the code that informs users about possible argument order
    rearrangements that yield better packing to take packing next to sectags
    into account.

compiler/hlds_data.m:
    Provide a representation for cons_tags that use the new optimization.
    Instead of adding a new cons_tag, we do this by replacing several old
    cons_tags that all represent pointers to memory cells with a single
    cons_tag named remote_args_tag with an argument that selects among
    the old cons_tags being replaced, and adding a new alternative inside
    this new type. The new alternative is remote_args_shared with a
    remote_sectag whose size is rsectag_subword(...).

    Instead of representing the value of the "data" field in classes
    on the Java and C# backends as a strange kind of secondary tag
    that is added to a memory cell by a class constructor instead of
    having to be explicitly added to the front of the argument vector
    by the code of a unification, represent it more directly as separate
    kind of remote_args_tag. Continuing to treat it as a sectag would have
    been very confusing to readers of the code of ml_unify_gen_*.m in the
    presence of the new optimization.

    Replacing several cons_tags that were usually treated similarly with
    one cons_tag simplifies many switches. Instead of an switch with that
    branches to the same switch arm for single_functor_tag, unshared_tag
    and shared_remote_tag, and then switches on these three tags again
    to get e.g. the primary tag of each, the new code of the switch arm
    is executed for just cons_tag value (remote_args_tag), and switches
    on the various kinds of remote args tags only when it needs to.
    In is also more natural to pass around the argument of remote_args_tag
    than to pass around a variable of type cons_tag that can be bound to only
    single_functor_tag, unshared_tag or shared_remote_tag.

    Add an XXX about possible further steps along these lines, such as
    making a new cons_tag named something like "user_const_tag" represent
    all user-visible constants.

compiler/unify_gen_construct.m:
compiler/unify_gen_deconstruct.m:
compiler/unify_gen_test.m:
compiler/unify_gen_util.m:
compiler/ml_unify_gen_construct.m:
compiler/ml_unify_gen_deconstruct.m:
compiler/ml_unify_gen_test.m:
compiler/ml_unify_gen_util.m:
    Implement X = f(Yi) unifications where f uses the new representation,
    i.e. some of its arguments are stored next to a remote sectag.

    Some of the Yi are stored in a tagword (a word that also contains a tag,
    in this case the remote secondary tag), while some are stored in other
    words in a memory cell. This means that such unifications have similarities
    both to unifications involving arguments being packed next to local
    sectags, and to unifications involving ordinary arguments in memory cells.
    Therefore wherever possible, their implemenation uses suitably generalized
    versions of existing code that did those two jobs for two separate kinds of
    cons_tags.

    Making such generalizations possible in some cases required shifting the
    boundary between predicates, moving work from a caller to a callee
    or vice versa.

    In unify_gen_deconstruct.m, stop using uni_vals to represent *either* a var
    *or* a word in a memory cell. While this enabled us to factor out some
    common code, the predicate boundaries it lead to are unsuitable for the
    generalizations we now need.

    Consistently use unsigned ints to represent both the whole and the parts
    of words containing packed arguments (and maybe sectags), except when
    comparing ptag constants with the result of applying the "tag" unop
    to a word, (since that unop returns an int, at least for now).

    In a few cases, avoid the recomputation of some information that we
    already know. The motivation is not efficiency, since the recomputation
    we avoid is usually cheap, but the simplification of the code's correctness
    argument.

    Use more consistent terminology in things such as variable names.

    Note the possibility of further future improvements in several places.

compiler/ml_foreign_proc_gen.m:
    Delete a long unused predicate.

compiler/mlds.m:
    Add an XXX documenting a possible improvement.

compiler/rtti.m:
    Update the compiler's internal representation of RTTI data structures
    to make them able to describe secondary tags that are smaller than
    a full word.

compiler/rtti_out.m:
    Conform to the changes above, and delete a long-unused predicate.

compiler/type_ctor_info.m:
    Use the RTTI's du_hl_rep to represent cons_tags that distinguish
    between function symbols using a field in a class.

compiler/ml_type_gen.m:
    Provide a specialized form of a function for code in ml_unify_gen_*.m.
    Conform to the changes above.

compiler/add_special_pred.m:
compiler/bytecode_gen.m:
compiler/export.m:
compiler/hlds_code_util.m:
compiler/lco.m:
compiler/ml_closure_gen.m:
compiler/ml_switch_gen.m:
compiler/ml_tag_switch.m:
compiler/rtti_to_mlds.m:
compiler/switch_util.m:
compiler/tag_switch.m:
    Conform to the changes above.

runtime/mercury_type_info.h:
    Update the runtime's representation of RTTI data structures to make them
    able to describe remote secondary tags that are smaller than a full word.

runtime/mercury_deconstruct.[ch]:
runtime/mercury_deconstruct.h:
runtime/mercury_deconstruct_macros.h:
runtime/mercury_ml_expand_body.h:
runtime/mercury_ml_arg_body.h:
runtime/mercury_ml_deconstruct_body.h:
runtime/mercury_ml_functor_body.h:
    These modules collectively implement the predicates in deconstruct.m
    in the library, and provide access to its functionality to other C code,
    e.g. in the debugger. Update these to be able to handle terms with the
    new data representation optimization.

    This update requires a significant change in the distribution of work
    between these files for the predicates deconstruct.deconstruct and
    deconstruct.limited_deconstruct. We used to have mercury_ml_expand_body.h
    fill in the fields of their expand_info structures (whose types are
    defined in mercury_deconstruct.h) with pointers to three vectors:
    (a) a vector of arg_locns with one element per argument, with a NULL
    pointer being equivalent to a vector with a given element in every slot;
    (b) a vector of type_infos with one element per argument, constructed
    dynamically (and later freed) if necessary; and (c) a vector of argument
    words. Once upon a time, before double-word and sub-word arguments,
    vector (c) also had one word per argument, but that hasn't been true
    for a while; we added vector (a) help the consumers of the expand_info
    decode the difference. The consumers of this info  always used these
    vectors to build up a Mercury term containing a list of univs,
    with one univ for each argument.

    This structure could be stretched to handle function symbols that store
    *all* their arguments in a tagword next to a local sectag, but I found
    that stretching it to cover function symbols that have *some* of their
    arguments packed next to a remote sectag and *some other* of their
    arguments in a memory cell as usual would have required a well-nigh
    incomprehensibly complex, and therefore almost undebuggable, interface
    between mercury_ml_expand_body.h and the other files above. This diff
    therefore changes the interface to have mercury_ml_expand_body.h
    build the list of univs directly. This make its code relatively simple
    and self-contained, and it should be somewhat faster then the old code
    as well, since it never needs to allocate, fill in and then free
    vectors of type_infos (each such typeinfo now gets put into a univ
    as soon as it is constructed). The downside is that if we ever wanted
    to get all the arguments at once for a purpose other than constructing
    a list of univs from them, it would nevertheless require constructing
    that list of univs anyway as an intermediate data structure. I don't see
    this downside is significant, because (a) I don't think such a use case
    is very likely, and (b) even if one arises, debuggable but a bit slow
    is probably preferable to faster but very hard to debug.

    Reduce the level of indentation of some of these files to make the code
    easier to edit. Do this by

    - not adding an indent level from switch statements to their cases; and
    - not adding an indent level when a case in a switch has a local block.

    Move the break or return ending a case inside that case's block,
    if it has one.

runtime/mercury_deep_copy_body.h:
runtime/mercury_table_type_body.h:
    Update these to enable the copying or tabling of terms whose
    representations uses the new optimization.

    Use the techniques listed above to reduce the level of indentation
    make the code easier to edit.

runtime/mercury_tabling.c:
runtime/mercury_term_size.c:
    Conform to the changes above.

runtime/mercury_unify_compare_body.h:
    Make this code compile after the changes above. It does need to work
    correctly, since we only ever used this code to compare the speed
    of unify-by-rtti with the speed of unify-by-compiler-generated-code,
    and in real life, we always use the latter. (It hasn't been updated
    to work right with previous arg packing changes either.)

library/construct.m:
    Update to enable the code to construct terms whose representations
    uses the new optimization.

    Add some sanity checks.

library/private_builtin.m:
runtime/mercury_dotnet.cs.in:
java/runtime/Sectag_Locn.java:
    Update the list of possible sectag kinds.

library/store.m:
    Conform to the changes above.

trace/mercury_trace_vars.c:
    Conform to the changes above.

tests/hard_coded/deconstruct_arg.{m,exp,exp2}:
    Extend this test to test the deconstruction of terms whose
    representations uses the new optimization.

    Modify some of the existing terms being tested to make them more diverse,
    in order to make the output easier to navigate.

tests/hard_coded/construct_packed.{m,exp}:
    A new test case to test the construction of terms whose
    representations uses the new optimization.

tests/debugger/browse_packed.{m,exp}:
    A new test case to test access to the fields of terms whose
    representations uses the new optimization.

tests/tabling/test_packed.{m,exp}:
    A new test case to test the tabling of terms whose
    representations uses the new optimization.

tests/debugger/Mmakefile:
tests/hard_coded/Mmakefile:
tests/tabling/Mmakefile:
    Enable the new test cases.
2018-08-30 05:14:38 +10:00
Peter Wang
72f174b4e2 Don't print value of errno in MR_fatal_error.
The majority of calls to MR_fatal_error do not follow an operation that
sets errno, so printing out an error message unrelated to the reason for
the fatal error will lead to confusion. It can also cause test failures
if errno happens to be set to non-zero some time prior to an expected
call to MR_fatal_error. Fixes bug #464.

runtime/mercury_misc.c:
    Don't print value of errno in MR_fatal_error.

runtime/mercury_context.c:
runtime/mercury_thread.c:
    Pass strerror strings to MR_fatal_error where appropriate.

runtime/mercury_memory_zones.c:
runtime/mercury_memory_zones.h:
    Pass strerror strings to MR_fatal_error following failures of
    MR_protect_pages. Document that this assumes MR_protect_pages sets
    errno on error.

    Skip unnecessary call to sprintf before MR_fatal_error.

runtime/mercury_deep_profiling.c:
    Skip unnecessary call to sprintf before MR_fatal_error.

    Reduce size of some buffers.

runtime/mercury_overflow.c:
runtime/mercury_stack_trace.c:
    Pass a fixed format string to MR_fatal_error just in case
    the message string may contain percentage signs.

runtime/mercury_tabling.c:
    Skip unnecessary call to sprintf before MR_fatal_error.

deep_profiler/timeout.m:
library/thread.m:
mdbcomp/shared_utilities.m:
    Pass strerror strings to MR_fatal_error where appropriate.

trace/mercury_trace.c:
    Skip unnecessary call to sprintf before MR_fatal_error.

trace/mercury_trace_external.c:
    Pass a fixed format string to MR_fatal_error just in case.
2018-08-19 12:19:19 +10:00
Peter Wang
58345256f8 Fix compilation with musl.
musl warns if <sys/signal.h> is included, which now breaks the build due
to --halt-at-warn-if-possible. The comments state that the inclusion was
to work around a problem on FreeBSD, but it is no longer necessary for
FreeBSD 11.

runtime/mercury_memory_handlers.c:
runtime/mercury_memory_zones.c:
    Don't include <sys/signal.h>
2018-08-11 11:50:15 +10:00