Commit Graph

265 Commits

Author SHA1 Message Date
Julien Fischer
7dccb03be1 Delete an unused variable.
util/mkinit.c:
    Delete the variable "init_suffix", which has never been used.
    (It was added in commit 04e614485, where it was merged on to the then CVS
     trunk from the deep2 branch.)
2026-02-07 15:56:32 +11:00
Julien Fischer
0f2ee70edf Support wildcard argument expansion with MSVC.
In Unix expansion of wildcard arguments is done by the shell. On Windows,
this is not the case and programs are responsible for expanding wildcard
argument themselves. When using source file mapping, we typically used
wildcards to specify the source files to map. When native Windows Mercury
compilers are used in the Windows command prompt or PowerShell, this does
not work, which is inconvenient to say the least. (In environments like
Cygwin or MSYS2, the shell does do wildcard expansion.)

Microsoft's C runtime has an optional component that programs can
link against which will do wildcard expansion on the argument vector
before main is called. Set up builds with MSVC to link against this
component when building the Mercury compiler.

scripts/parse_ml_options.sh-subr.in:
scripts/ml.in:
    Add a new option --use-msvc-setargv-extension, which causes the the
    wsetargv.obj file that enables the extension to be passed the linker.
    (MSVC seems rather picky about where this is positioned. A a result
    we do it within the ml script where have we more control over the matter.)

compiler/Mmakefile:
    Pass --use-msvc-setargv-extension to the ml script if we are using MSVC.

    Unrelated: Fix the identity of a compiler in a comment.

    Unrelated: Add an XXX about something that looks suspicious.

util/mkinit.c:
    Add a pointer to scripts/ml.in, saying that if the Windows entry
    point (currently wmain) is updated, then the script may need to
    be updated.
2026-01-06 21:45:53 +11:00
Zoltan Somogyi
7a122b004c Better document the code creating .init files.
util/mkinit.c:
    Put the central list of the places that create .init files here.

compiler/compile_target_code.m:
scripts/c2init.in:
    Point to util/mkinit.c as the repository of that central list.

    Make some predicate names more descriptive.

util/mkinit_common.h:
    Replace /* */ comments with // comments.
2025-09-12 07:29:47 +10:00
Zoltan Somogyi
c148ce54fe Update style in a bunch of Mmakefiles.
Mmake.common.in:
bindist/Mmakefile:
compiler/Mmakefile:
compiler/notes/Mmakefile:
doc/Mmakefile:
extras/align_right/Mmakefile:
extras/base64/Mmakefile:
extras/dynamic_linking/Mmakefile:
extras/error/Mmakefile:
extras/fixed/Mmakefile:
extras/graphics/samples/gears/Mmakefile.MacOSX:
extras/graphics/samples/maze/Mmakefile.MacOSX:
extras/lex/Mmakefile:
extras/monte/Mmakefile:
extras/posix/Mmakefile:
extras/references/Mmakefile:
extras/references/samples/Mmakefile:
extras/split_file/Mmakefile:
library/Mmakefile:
mdbcomp/Mmakefile:
runtime/Mmakefile:
scripts/Mmakefile:
ssdb/Mmakefile:
tests/Mmake.common:
tests/mmc_make/Mmakefile:
trace/Mmakefile:
util/Mmakefile:
    Invoke the sh builtin "test" as "test", not as "[".

    Make some target names more descriptive.

    Fix indentation.
2024-09-17 11:09:18 +02:00
Julien Fischer
19d818209f Ignore *.obj files.
*/.gitignore:
    As above.

    Fix a few other omissions.
2023-06-26 20:05:24 +10:00
Julien Fischer
2a366cf295 Deprecate --no-ansi and --no-ansi-c.
--no-ansi (mgnuc) and --no-ansi-c (mmc) have not actually done anything for
many years now. Deprecate these options and remove their "use" throughout most
of the Mercury system. (The remaining uses are in the Makefiles for the Boehm
GC, which need to be updated separately.)

Also deprecate the internal compiler option --cflags-for-ansi.

compiler/options.m:
    Document that --no-ansi-c is now deprecated.

    Document that the internal option --cflags-for-ansi is now
    deprecated.

compiler/compile_target_code.m:
    Do not pass the ANSI options to the C compiler.

scripts/mgnuc.in:
scripts/mgnuc_file_opts.sh-subr:
    Deprecate the --no-ansi option; delete code that no longer does
    anything useful.

configure.ac:
    Delete the configuration variable CFLAGS_FOR_ANSI; it is only ever
    set to be empty. (The comment talks about --no-ansi doing other things
    in the mgnuc script. It used to also cause some preprocessor macros
    to be defined for compatibility with the system headers on some
    platforms -- that has not been the case since 2013.)

doc/user_guide.texi:
    Document that --no-ansi-c is deprecated.

bytecode/Mmakefile:
compiler/Mercury.options:
library/Mercury.options:
extras/odbc/odbc.m:
runtime/Mmakefile:
scripts/Mercury.config.bootstrap.in:
scripts/Mercury.config.in:
tests/hard_coded/Mercury.options:
tests/valid/Mercury.options:
trace/Mmakefile:
util/Mmakefile:
    Conform to the above change.

NEWS.md:
    Announce the above.
2023-05-31 17:44:26 +10:00
Peter Wang
1e7b2f6fbd Fix syntax error. 2023-03-19 13:11:01 +11:00
Zoltan Somogyi
af70cb4f84 Use . as the module qualifier.
We stopped using : as the module qualifier decades ago.
2023-03-19 00:26:21 +11:00
Zoltan Somogyi
2315f1660e Replace /* */ comments with // comments in util.
util/mdemangle.c:
util/mfiltercc.c:
util/mkinit_common.c:
util/pad_backslash.c:
    As above. The other .c files in util already used // comments.
2023-03-19 00:16:22 +11:00
Julien Fischer
ab72f07f4f Fix mkinit option processing.
util/mkinit.c:
    The -l option does not take an argument. An incorrect edit in
    commit fcb8ffe9 meant that it was expecting one.
2022-03-26 00:20:39 +11:00
Peter Wang
594b09c547 Handle argv[0] == NULL.
On some operating systems, e.g. Linux, it is possible to enter main()
with argv[0] == NULL if the parent process calls execve() with
argv[0] == NULL, or equivalently, passing NULL for the argv parameter.

runtime/mercury_wrapper.c:
runtime/mercury_wrapper.h:
    Do not assume argc > 0 and argv[0] != NULL in MR_process_args.
    If argv[0] is NULL then set MR_progname to the empty string
    so users of MR_progname can assume it points to a valid string.

    Add a new global variable MR_progname_is_known to indicate if
    argv[0] was NULL or not.

library/io.m:
    Make io.progname return the default program name if argv[0] was
    NULL.

util/mkinit.c:
    Set MR_progname to a valid string if argv[0] is NULL.
    This is not actually necessary, since, in that case, the subsequent
    call to parse_options() would immediately exit the program
    as no file names will be found in argv.
2022-01-31 14:11:08 +11:00
Julien Fischer
43195d1eda Avoid redefining some macros.
util/mkinit.c:
    Do not define _BSD_SOURCE or _DEFAULT_SOURCE if the user
    has already done so.  (This affects compilation of extras/net
    when the C compiler is set to treat redefined macros as an error.)
2022-01-14 19:29:20 +11:00
Peter Wang
fcb8ffe9db Delete mkinit_erl program.
util/.gitignore:
util/Mmakefile:
    Don't build or install the mkinit_erl program.

util/mkinit.c:
util/mkinit_common.c:
    Remove references to mkinit_erl.c.

    Delete handling of -m option (only used by mkinit_erl).

util/mkinit_erl.c:
    Delete source file.
2020-10-27 11:10:11 +11:00
Zoltan Somogyi
f7c911ab36 Bring the style of mkinit.c up to date.
Replace /* */ with //.

Generate C code with four space indentation. The existing code intended
to do this by aligning the code on four-space boundaries in mkinit.c,
but the " at the start of each string ate one position, so the generated
code lines started in columns 4, 8, 12 etc, instead of 5, 9, 13 etc.
2020-08-15 02:57:17 +10:00
Zoltan Somogyi
a06ae2c6ef Simplify the code of the mdb help system.
browser/help.m:
    Simplify the data types representing the nested structure
    of help information. Simplify the code of the predicates
    that work on that structure.

    Simplify some of the predicates, e.g. by having a search predicate
    do *just* search.

    Give types and predicates more meaningful names. Make argument order
    more suitable for state-variables. Move a predicate next to its
    only call site.

browser/declarative_user.m:
    Conform to the change in help.m.

    Replace two bools with values of bespoke types.

browser/declarative_debugger.m:
browser/declarative_oracle.m:
    Conform to the changes in help.m and declarative_user.m.

doc/generate_mdb_doc:
    Fix the vim modeline.

trace/mercury_trace_declarative.c:
trace/mercury_trace_help.c:
    Conform to the changes in the browser directory.

util/info_to_mdb.c:
    Switch from /**/ to // for comments.

    Give a macro a meaningful name.

    Fix indentation.
2020-08-14 11:04:17 +10:00
Zoltan Somogyi
b8b845a568 Fix mmakefile rules for os,cs,css,javas.
The main objective of this change is to get bootchecks in the csharp
and java grades to actually build the slice, profiler, deep_profiler
and mfilterjavac directories, which (due to the bug this diff fixes)
they weren't doing before.

However, since one side effect of this change is to eliminate
one source of annoying warnings from mmake about references to undefined
variables, a subsidiary objective is to eliminate other sources of such
warnings as well, which mostly come from the rules for making tags files.

browser/Mmakefile:
deep_profiler/Mmakefile:
library/Mmakefile:
mdbcomp/Mmakefile:
profiler/Mmakefile:
slice/Mmakefile:
ssdb/Mmakefile:
    When creating stage 3, the bootcheck builds, in each directory,
    only the files that it wants to compare against their stage 2 versions.
    This means that it wants to build all the .c, .cs or .java files,
    which it does via the cs, css and javas mmake targets.

    The correct definitions of the rules of these targets depends on
    whether mmc --make is being used or not, so we need at least two
    sets of definitions: one for mmc --make, and for no mmc --make,
    and conditionally selecting the appropriate one. The latter definition
    has the problem that it refers to mmake variables that are intended
    to be defined in .dv files created by mmc --generate-dependencies,
    but until that has been run, those mmake variables are undefined.

    Until now, the only directories that had both the mmc --make
    and the no mmc --make definitions were the ones needed to build
    the compiler. Bootchecks in the csharp and java grades, which
    always use --make make, got errors when they tried to build
    the directories that bootcheck builds after the compiler:
    the slice, profiler, deep_prof and mfilterjavac directories.

    This diff ensures that all directories we build in bootcheck
    get all both versions of the os, cs, css, and javas targets.
    In fact, they get two subversions of the no mmc --make version:
    one for use in the presence of .dv files, and one for use in their
    absence. The latter just builds the .dv files and invokes mmake
    again. This avoids one source of warnings about undefined mmake
    variables.

    To avoid another source, make the rules for tags files and their
    proxies depends on *.m instead of mmake variables such as $(mcov.ms),
    since this makes sense even before making dependencies. The only price
    is that any untracked Mercury source files in the directory have to
    either be given some other suffix, or moved somewhere else.

    Where relevant, make the mtags invocation prefer the master versions
    of files that are copied from the mdbcomp directory to other directories,
    since this is the only writeable version.

    Make the os and cs rules consistently NOT build the _init.[co] files.
    The way we use those files in bootcheck, we never need them;
    when we need them, the right target to give is the executable anyway.

    In the slice directory, don't put mcov between mtc_union and mtc_diff.

    Eliminate unnecessary duplication, e.g. of sources in rules.

    Eliminate double negatives in conditionals.

    Fix formatting.

Mmake.common.in:
bindist/Mmakefile:
bytecode/Mmakefile:
compiler/Mmakefile:
doc/Mmakefile:
grade_lib/Mmakefile:
robdd/Mmakefile:
samples/Mmakefile:
scripts/Mmakefile:
tools/Mmakefile:
trace/Mmakefile:
util/Mmakefile:
    Add "ft=make" to vim modelines. This is redundant for the files whose
    names is Mmakefile, but it is needed for Mmake.common.
2020-04-11 20:10:38 +10:00
Peter Wang
ac29292e9a Delete util/getopt.h
util/getopt.h:
    Delete this file.

util/Mmakefile:
    Pass -I../getopt to the C compiler.

util/mkinit.c:
util/mkinit_erl.c:
    Include either <unistd.h> or ../getopt/getopt.h for the declaration
    of getopt(). We don't include both in case there may be conflicting
    declarations of getopt() on some system.
2019-06-10 13:30:51 +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
5116277e5e Delete workaround for old gcc.
util/Mmakefile:
    As above.
2019-06-01 16:15:36 +10:00
Peter Wang
bb52ce0804 Fix unintended fallthrough.
util/mkinit.c:
util/mkinit_erl.c:
    Fix unintended fallthrough in switch (harmless).
2019-06-01 16:15:36 +10:00
Peter Wang
c33f811c37 Check availability of getopt() directly.
configure.ac:
Mmake.common.in:
    Check for availability of getopt() in the C library,
    setting the HAVE_GETOPT variable as appropriate.

    Delete GETOPT_H_AVAILABLE variable.

util/Mmakefile:
    Use getopt() if available. This can be true even without getopt.h
    as getopt() is declared in <unistd.h> according to POSIX.

util/getopt.h:
    Add a comment.
2019-05-31 18:13:54 +10:00
Peter Wang
05e9f4b2b6 Delete old code setting GC_stackbottom on AIX.
util/mkinit.c:
    Delete last reference to GC_stackbottom (which has been deprecated).
    The code to set GC_stackbottom was only left for old AIX, but is not
    required at least with AIX 7.1 on POWER, and likely hasn't been
    relevant for a long time.
2019-05-31 15:54:21 +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
Julien Fischer
10c210dc16 Fix bug #196: binary compatibility checks in C grades do not work.
These have been broken since 2011 because GCC and clang (at least) began
optimising away the MR_grade variable we emit at the end of each generated .c
file.  The fix is to replace the MR_grade variable with an exported function
that references MR_GRADE_VAR in each generated .c file.

compiler/llds_out_file.m:
compiler/mlds_to_c.m:
util/mkinit.c:
     In each generated .c file, emit an exported function that references
     MR_GRADE_VAR.
2016-07-17 20:48:39 +10:00
Zoltan Somogyi
c6ab550db8 Remove the code for automatic initialization of solver vars.
We haven't supported it in years, and keeping it in the compiler
is just a maintenance burden and a performance problem.

mdbcomp/prim_data.m:
    Delete the spec_pred_init functor, since we don't support special
    "init" predicates anymore.

compiler/prog_data.m:
    Delete the slot in solver type details that record the name of the
    auto-initialization predicate.

compiler/prog_io_type_defn.m:
    Don't allow a type definition to specify an auto-initialization predicate.

compiler/options.m:
compiler/globals.m:
    Delete the option that allowed support for auto-initialization to be
    turned back on.

compiler/inst_match.m:
compiler/inst_util.m:
    Delete comments about auto-initialization.

compiler/mode_info.m:
    Delete the record of whether we have variables that can be
    auto-initialized (we never do anymore) and the flag that controls whether
    auto-initialization is permitted or not.

compiler/modecheck_conj.m:
    Simplify the code that modechecks conjunctions, since it no longer
    has to figure out where to insert auto-initializations of solver vars.

compiler/modecheck_goal.m:
    Delete the code that ensured that if one branch of a branched
    control structure auto-initialized a solver variable, then they
    all did.

compiler/modecheck_unify.m:
    Don't auto-initializate variables before unifications.

compiler/modecheck_util.m:
    Delete the code that auto-initialized solver variables at the ends
    of procedure bodies if this needed to be done and wasn't done before.

compiler/add_special_pred.m:
compiler/equiv_type.m:
compiler/equiv_type_hlds.m:
compiler/get_dependencies.m:
compiler/hlds_module.m:
compiler/hlds_pred.m:
compiler/modecheck_call.m:
compiler/modes.m:
compiler/module_qual.qualify_items.m:
compiler/parse_tree_out.m:
compiler/post_term_analysis.m:
compiler/smm_common.m:
compiler/special_pred.m:
compiler/term_constr_errors.m:
compiler/term_constr_initial.m:
compiler/term_util.m:
compiler/termination.m:
compiler/trace_params.m:
compiler/type_util.m:
compiler/unify_proc.m:
    Delete code that handled stuff related to auto-initialization,
    and now always take the path that would normally be taken in the
    absence of auto-initialization.

deep_profiler/read_profile.m:
runtime/mercury_layout_util.c:
runtime/mercury_stack_trace.c:
util/mdemangle.c:
    Remove code that recognized the compiler-generated name of initialization
    predicates.

tests/debugger/solver_test.m:
tests/hard_coded/solver_construction_init_test.m:
tests/hard_coded/solver_disj_inits.m:
tests/hard_coded/solver_ite_inits.m:
tests/invalid/missing_init_pred.m:
tests/invalid/zinc2mer_lib.m:
tests/valid/fz_conf.m:
tests/valid/solver_type_bug_2.m:
tests/valid/solver_type_mutable_bug.m:
    These tests tested the handling of auto-initialization, which we
    no longer support. Keep them around (and a bit more visible than
    inside the git repo) in case we need them again, but add a comment
    to each saying that the test is disabled.

tests/debugger/Mercury.options:
tests/debugger/Mmakefile:
tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/invalid/Mercury.options:
tests/invalid/Mmakefile:
tests/valid/Mercury.options:
tests/valid/Mmakefile:
    Disable those tests.

tests/warnings/non_term_user_special.{m,exp}:
    Part of this test tested the handling of auto-initialization;
    delete that part.

tests/warnings/Mercury.options:
    Delete the flag required by the deleted part, since we don't support it
    anymore.
2015-12-03 05:06:28 +11:00
Julien Fischer
94535ec121 Fix spelling and formatting throughout the system.
configure.ac:
browser/*.m:
compiler/*.m:
deep_profiler/*.m:
library/*.m:
ssdb/*.m:
runtime/mercury_conf.h.in:
runtime/*.[ch]:
scripts/Mmake.vars.in:
trace/*.[ch]:
util/*.c:
	Fix spelling and doubled-up words.

	Delete trailing whitespace.

	Convert tabs into spaces (where appropriate).
2015-12-02 18:46:14 +11:00
Paul Bone
eed9cc75bd Make changes required to upgrade to Boehm GC 7.4.2
GC_stackbottom, GC_gc_no and GC_dont_gc are now deprecated.  These changes
use new options in the API where possible.

Update scripts to copy the boehm_gc and libatomic_ops directories correctly.

Pass Boehm GC the correct flags for thread support

Update documentation regarding the version of Boehm GC.

runtime/mercury_wrapper.c:
    Don't use the deprecated GC_dont_gc variable.

library/benchmarking.m:
    Use GC_get_stackbottom() to get the bottom of stack and GC_get_gc_no()
    to get the number of collections so far.

util/mkinit.c:
    Do not explicitly set GC_stackbottom anymore, except on AIX where it
    cannot be found automatically.

scripts/prepare_install_dir.in:
tools/bootcheck:
tools/build_srcdist:
    Add some missing files present in Boehm GC 7.4.2 that wern't present
    earlier and remove some old ones.

    Coby and link the libatomic_ops directory correctly.

.README.in:
bindist/bindist.README:
    Update documentation regarding the version of Boehm GC.

configure.ac:
    Something in Boehm GC's build system has changed and we must now pass
    -DGC_THREADS whenever building threadsafe versions of BOehm GC.  This is now
    done using the BOEHM_MISC_CFLAGS_FOR_THREADS autoconf variable, which has
    been renamed to BOEHM_CFLAGS_FOR_THREADS now that it is more generally used.

    Boehm GC no longer (or perhaps never did) require developers to specify the
    type of threading to use, eg -DGC_LINUX_THREADS rather than -DGC_THREADS.
    With the exception of win32-pthreads.  We now pass -DGC_THREADS whereever
    possible.

Mmake.common.in:
    Rename BOEHM_MISC_CFLAGS_FOR_THREADS.
2015-10-01 10:26:46 +10:00
Julien Fischer
e6b669a933 Fix bug #379: warnings about deprecated feature macros with glibc 2.20.
glibc version 2.20 will emit a warning if the macros _BSD_SOURCE or
_SVID_SOURCE are defined.  (They have been deprecated in favour of the macro
_DEFAULT_SOURCE).  The C files generated by mkinit define _BSD_SOURCE,
consequently causing a warning to be emitted by the preprocessor every time you
build an executable on systems with the affected version of glibc.

Also defining _DEFAULT_SOURCE will disable the warning.

util/mkinit.c:
	Define _DEFAULT_SOURCE in order to suppress the warning described
        above.
2015-02-19 11:39:34 +11:00
Zoltan Somogyi
d33273d033 Tell vim not to expand tabs in Makefiles.
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.
2015-01-08 22:07:29 +11:00
Zoltan Somogyi
cd72d000a8 Remove support for the MPS garbage collector.
As Tomas By's recent emails suggest, this support is doing more harm than good,
by falsely implying to people that MPS is a viable alternative to the Boehm
collector. The MPS collector was only ever experimental, and never performed
as well as Boehm. MPS isn't even in the git repository on git hub. It was
stored in a separate CVS repository on mundula, and (as far as I know)
wasn't carried over to github. The code of MPS was last touched a long time
ago; I would be surprised if it worked on today's systems without changes.

Mmake.common.in:
Mmake.workspace:
RESERVED_MACRO_NAMES:
boehm_gc/Mmakefile:
compiler/add_pragma.m:
compiler/compile_target_code.m:
compiler/globals.m:
compiler/handle_options.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c.m:
compiler/options.m:
compiler/peephole.m:
doc/user_guide.texi:
library/benchmarking.m:
runtime/Mmakefile.m:
runtime/mercury.h:
runtime/mercury_conf_param.h:
runtime/mercury_grade.h:
runtime/mercury_heap.h:
runtime/mercury_init.h:
runtime/mercury_memory.h:
runtime/mercury_wrapper.[ch]:
scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/mgnuc.in:
scripts/ml.in:
scripts/parse_grade_options.sh-subr:
util/mkinit.c:
    Remove all references to MPS.
2014-08-05 15:45:33 +02:00
Peter Wang
06647ff390 Implement unify/compare of tuples in Mercury.
The hand-written C unify and compare predicates for tuples did not preserve
deep profiler invariants correctly across the recursive unify/compare of
tuple arguments.  I tried to do so, and failed.  Instead, implement the
predicates in Mercury so the compiler can perform the deep profiling
transformation on them.  Bug #3.

A micro-benchmark on my machine is about twice as fast in asm_fast.gc
after this patch, and about the same in hlc.gc.  The change to the
high-level C backend is only to reduce code duplication.

library/library.m:
	Add foreign-exported predicates to take the place of `io.init_state'
	and `io.finalize_state' as overall initialization/finalization
	predicates.

library/builtin.m:
	Add `unify_tuple', `compare_tuple', `compare_rep_tuple' predicates.

	Add initializer which sets `MR_special_pred_hooks' to point to those
	predicates.

	Delete unused predicates `call_rtti_generic_unify',
	`call_rtti_generic_compare'.

	Reorder some code.

library/io.m:
	Add `io.finalize_state' to hidden interface.

	Delete foreign exports for `io.init_state' and `io.finalize_state'.

	Reorder some code.

runtime/mercury_ho_call.c:
runtime/mercury_ho_call.h:
	Add a global variable `MR_special_pred_hooks' for the library to
	set up during initialisation.

	Add `tailcall' macros for use by `mercury_unify_compare_body.h'.
	Rename `tailcall_user_pred' to `tailcall_tci_pred'.

	Call the new unify/compare predicates in the high-level C
	backend via `MR_special_pred_hooks'.

	Delete `unify_tuples' and `compare_tuples' for the high-level C
	and call the Mercury predicates set in `MR_special_pred_hooks'.

runtime/mercury_unify_compare_body.h:
	Delete the unify and compare code for tuples in the low-level C
	backend.  Jump to the Mercury predicates set in
	`MR_special_pred_hooks' instead.

	Add some comments.

compiler/elds_to_erlang.m:
runtime/mercury_init.h:
runtime/mercury_wrapper.c:
util/mkinit.c:
	Conform to the library initializer/finalizer change.

tests/hard_coded/Mmakefile:
tests/hard_coded/tuple_test2.exp
tests/hard_coded/tuple_test2.m:
	Add test case.

NEWS:
	Announce the change.
2014-07-10 13:24:05 +10:00
Zoltan Somogyi
f6fafa150d Fix Mantis bug 314 for temp frames created by nondet procedures.
Also fix some bugs in related code, and improve the related debugging
infrastructure.

-------------------

runtime/mercury_stacks.[ch]:
   Fix bug 314 for temp frames created by nondet procedures. The fix will
   probably also work for *det* procedures that create temp frames on the
   nondet stack, but I can't think of a way to test that, because det
   procedures create such frames only in very specific circumstances,
   and I cannot think of a way to nest a recursive call inside those
   circumstances.

   The problem was that when we were creating new temp frames on
   the nondet stack, we did not check whether the current nondet stack segment
   had room for them. We now do.

   The stack trace tracing code needs to know the size of each nondet stack
   frame, since it uses the size to classify frames as temp or ordinary.
   The size is given by the difference in address between the address of the
   frame and the address of the previous frame. This difference would yield
   an incorrect size and hence an incorrect frame classification if a temp
   frame were allowed to have a frame on a different segment as its
   immediate predecessor.

   We prevent this by putting an ordinary (i.e. non-temp) frame at the bottom
   of every new nondet stack segment as a sentinel. We hand-build this frame,
   since it is not an "ordinary" ordinary frame. It is not created by a call,
   so it has no meaningful success continuation, and since it does not make
   any calls, no other frame's success continuation can point to it either.

   If backtracking reaches this sentinel frame, we use this fact to free
   all the segments beyond the one the sentinel frame is in, but keep the
   frame the sentinel frame is in, since we are likely to need it again.

   Document the reason why MR_incr_sp_leaf() does not have to check
   whether a new stack segment is needed. (See the fix to llds_out_instr.m
   below.)

runtime/mercury_stack_trace.[ch]:
   When traversing the nondet stack, treat the sentinel frame specially.
   We have to, since it is an ordinary frame (i.e. it is not a temp frame),
   but it is not an "ordinary" ordinary frame: it does not make calls,
   and hence calls cannot return to it, and it does not return to any
   other frame either. It therefore does not have the layout structures
   (label and proc) that the nondet stack traversal expects to find.

   Fix an old bug: the nondet stack traversal used a simple directional
   pointer comparison to check whether it has reached the bottom of the nondet
   stack. This is NOT guaranteed to work in the presence of stack segments:
   depending on exactly what addresses new stack segments get, a stack frame
   can have an address BELOW the address of the initial stack frame
   even if it is logically ABOVE that stack frame.

   Another old bug was that a difference between two pointers, which could
   be 64 bit, was stored in an int, which could be 32 bit.

   The nondet stack traversal code used a similar directional comparison
   to implement optionally stopping at an arbitrary point on the nondet stack.
   Fixing this facility (the limit_addr parameter of MR_dump_nondet_stack)
   while preserving reasonable efficiency would not be trivial, but it would
   also be pointless, since the facility is not actually used. This diff
   deletes the parameter instead.

   Move some loop invariant code out of its loop.

trace/mercury_trace_cmd_developer.c:
trace/mercury_trace_external.c:
   Don't pass the now-deleted parameter to mercury_stack_trace.c.

runtime/mercury_wrapper.c:
   Record the zone of the initial nondet stack frame, since the fix
   of mercury_stack_trace.c needs that info, and it is much more efficient
   to set it up just once.

tests/hard_coded/bug314.{m,exp}:
   The regression test for this bug.

tests/hard_coded/Mercury.options:
   Compile the new test case with the options it needs.

tests/hard_coded/Mmakefile:
   Enable the new test case.

-------------------

runtime/mercury_wrapper.c:
   The compiler knows the number of words in a stack frame it is creating,
   not necessarily the number of bytes (though it could put bounds on that
   from the number of tag bits). Since this size must sync with the runtime,
   change the runtime's variable holding this size to also be in words.

   Note that similar changes would also be beneficial for other sizes.

compiler/llds_out_instr.m:
   Conform to the change in mercury_wrapper.c, fixing an old bug
   (mercury_wrapper.c reserved 128 BYTES for leaf procedures, but
   llds_out_instr.m was using that space for procedures whose frames
   were up to 128 WORDS in size.)

compiler/mercury_memory.c:
   Conform to the change in mercury_wrapper.c.

-------------------

runtime/mercury_memory_zones.h:
   Instead of starting to use EVERY zone at a different offset, do this
   only for the INITIAL zones in each memory area, since only on these
   is it useful. When the program first starts up, it WILL be using
   the initial parts of the det stack, nondet stack and heap, so it is
   useful to make sure that these do not collide in the cache. However,
   when we allocate e.g. the second zone in e.g. the nondet stack, we are
   no more likely to be beating on the initial part of any segment
   of the det stack than on any other part of such segments.

   If a new debug macro, MR_DEBUG_STACK_SEGMENTS_SET_SIZE is set (to an int),
   use only that many words in each segment. This allows the segment switchover
   code to be exercised and debugged with smaller test cases.

runtime/mercury_conf_param.h:
   Document the MR_DEBUG_STACK_SEGMENTS_SET_SIZE macro.

   Convert this file to four-space indentation with tabs expanded.

-------------------

runtime/mercury_overflow.h:
   Make abort messages from overflows and underflows more useful by including
   more information.

runtime/mercury_overflow.c:
   Add a new function to help with the better abort messages.
   Since this file did not exist before, create it.

runtime/Mmakefile:
   Add the new source file to the list of source files.

-------------------

runtime/mercury_debug.[ch]:
   Fix problems with the formatting of the debugging output from existing
   functions.

   Add new functions for dumping info about memory zones.

   Factor out some common code.

   Convert the header file to four-space indentation.

-------------------

runtime/mercury_grade.c:
   Generate an error if stack segments are specified together with stack
   extension

-------------------

trace/.gitignore:
util/.gitignore:
tests/debugger/.gitignore:
   List some more files.

-------------------

runtime/mercury_context.c:
runtime/mercury_engine.[ch]:
runtime/mercury_misc.h:
compiler/notes/failure.html:
   Fix white space.
2014-04-18 02:02:35 +10:00
Julien Fischer
6851f943ec Avoid C compiler warnings that occur when using clang with -Wall.
Except where noted otherwise below most of these warnings relate to implicit
conversions between 64- and 32-bit integers or the signedness of integers
differing in spots.

library/construct.m:
	Delete an unused local variable in the implementation of get_functor_lex.

library/bitmap.m:
	The function MR_bitmap_cmp returns an MR_Integer not an int.

library/thread.semaphore.m:
	Change the count field of the ML_SEMAPHORE_STRUCT structure into
	an MR_Integer (which is what gets passed in).

trace/mercury_trace_declarative.c:
	Avoid a warning about fprintf being called where its second argument
	is not a string literal.  (In this case it can be replaced by a call
	to fputs.)

library/io.m:
mdbcomp/rtti_access.m:
trace/mercury_trace.c:
trace/mercury_trace_cmd_breakpoint.c:
trace/mercury_trace_cmd_help.c:
trace/mercury_trace_completion.m:
trace/mercury_trace_declarative.[ch]:
trace/mercury_trace_external.c:
trace/mercury_trace_internal.c:
trace/mercury_trace_source.c:
trace/mercury_trace_tables.c:
trace/mercury_trace_vars.c:
util/info_to_mdb.c:
util/mfiltercc.c:
util/mdemangle.c:
util/mkinit.c:
util/mkinit_erl.c:
util/mkinit_common.h:
util/mkinit_common.c:
	As above.
2014-03-31 00:31:36 +11:00
Julien Fischer
e9d90b2891 Avoid warnings from clang in the runtime and util directories.
runtime/mercury_stack_trace.c:
	In the function MR_dump_stack_from_layout_clique initialise the variable
	lines_dumped_so_far.  (This appears to be an actual bug.)

runtime/mercury_prof.c:
	Only define the static global in_profiling_code if either of call count
	profiling or time profiling is enabled.

runtime/mercury_context.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_profiling.c:
	Only define some local variables in grades that require them.

runtime/mercury_float.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_construct.c:
runtime/mercury_memory_zones.c:
runtime/mercury_stm.c:
runtime/mercury_trace_base.c:
runtime/mercury_type_info.c:
	Delete unused local variables.

util/mdemangle.c:
	Delete an unused static global variable.

	Use fputs in place of fprintf in a couple of places in order
	to avoid warnings about format strings that are not string literals.

	Delete an unused function.

util/mkinit.c:
util/mkinit_erl.c:
	Delete unused local variables.
2014-03-20 17:01:15 +11:00
Zoltan Somogyi
7e1cdb70aa Fix a problem that truncated mdb_doc files.
util/info_to_doc.c:
    Fix a problem that caused the generation of truncated mdb_doc files,
    and from that truncated test/debugger/mdb_command_test.inp files.
    The problem was that this program expected the info program to quote
    the initial line of each mdb command like this:

        `cmdname options ...'

    but on some machines, including mine, it quotes them like this:

        'cmdname options ...'

    i.e. with the initial as well as the final quote being a forward quote.
    This program now accepts either.

util/Mmakefile:
    Fix white space.

doc/generate_mdb_doc:
    Fix inconsistent indentation. Protect shell variable references.

doc/Mmakefile:
    Generate an error message if a similar problem occurs again
    when creating mdb_doc.

    Fix indentation.

tools/bootcheck:
    Generate an error message if a similar problem occurs again
    when copying tests/debugger/mdb_command_test.inp.
2014-01-22 09:31:37 +11:00
Julien Fischer
4e6828214d Fix bug #288.
Components of the Mercury system that were implemented directly in C were not
respecting the mmake LDFLAGS and EXTRA_LDFLAGS variables (or LD_LIBFLAGS,
EXTRA_LDLIBFLAGS for libraries).

The following patch was contributed by Keri Harris -- I have extended it
slightly to fix some omissions in the handling of .dylib files (i.e.  Mac OS X
style shared libraries).

NEWS:
    Announce the resolution of bug #288.

boehm_gc/Makefile.direct:
runtime/Mmakefile
trace/Mmakefile:
util/Mmakefile:
	Pass options set via LD_FLAGS or EXTRA_LDFLAGS (or the library
	versions) to the linker when building executables (or shared
	libraries) in these directories.
2013-06-20 18:13:41 +10:00
Julien Fischer
fc29b6c0b6 Update the list of reserved macro names.
browser/RESERVED_MACRO_NAMES:
library/RESERVED_MACRO_NAMES:
mdbcomp/RESERVED_MACRO_NAMES:
runtime/RESERVED_MACRO_NAMES:
ssdb/RESERVED_MACRO_NAMES:
trace/RESERVED_MACRO_NAMES:
	Ignore the __USE_MINGW_ANSI_STDIO macro which we
	need to define on MinGW64.

	Ignore the __GCC_HAVE_DWARF2_CFI_ASM macro which
	some versions of GCC define if -g is enabled.

compiler/.gitignore:
deep_profiler/.gitignore:
profiler/.gitignore:
slice/.gitignore:
util/.gitignore:
	Have git ignore .exe files in these directories.
2013-04-03 15:21:22 +11:00
Julien Fischer
1eda59e3da Convert .cvsignore files into .gitignore files.
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.
2013-01-03 13:12:22 +11:00
Paul Bone
428d5a1cc2 Move the sbrk profiling code into the mercury_main() function.
The mercury_main() function is used in both standalone and library builds of
Mercury code.  However the main function where the code was was only used in
standalone programs.  The Mercury compiler is built as a library and
usually liked with main.c in the root directory, this is done so that it can
be used with GCC for the GCC backend.  I have moved the sbrk profiling code
into mercury_main so that it will be executed by the compiler.  I used this
to generate memory usage information in my thesis.

util/mkinit.c:
    As above.
2012-11-11 01:42:00 +00:00
Zoltan Somogyi
b902f5cf60 Minor style cleanups.
Estimated hours taken: 0.5
Branches: main

util/*.c:
	Minor style cleanups.
2012-06-05 16:16:47 +00:00
Peter Wang
a7bac78bf9 Suppress spurious "used but never defined" warnings from gcc 4.6+.
Branches: main, 11.07

Suppress spurious "used but never defined" warnings from gcc 4.6+.
Fixes bug #250.

util/mfiltercc.c:
	Update `drop_line' to match the error message from newer versions of
	gcc, which add a suffix to the message.

	Allow the same message for non-Mercury-generated functions to pass
	through.
2012-05-10 00:12:08 +00:00
Julien Fischer
f6dd75cc54 Make it possible to initialise the Mercury runtime using an external interface
Branches: main

Make it possible to initialise the Mercury runtime using an external interface
without providing the address of the base of the stack.
This should work on most systems and can be useful when the top-level of a
program is not written in C or C++.
(In principle, this probably always worked, so the main change here is to
document it.)

util/mkinit.c:
	If mercury_init's stackbottom argument is NULL then don't
	set GC_stackbottom.

doc/user_guide.texi:
	Extend the description of the mercury_init function in the
	standalone-interfaces section to include the above.
2012-01-11 04:58:12 +00:00
Peter Wang
6b1f89831e Let Mercury be built with a MinGW cross-compiler.
Branches: main

Let Mercury be built with a MinGW cross-compiler.

tools/configure_mingw_cross:
	Add shell script to prepare for cross-compilation.

README.MinGW-cross:
	Document how to use the shell script.

configure.in:
Mmake.common.in:
	Set a new variable CROSS_COMPILING.

	Set FULLARCH and BUILD_C_PROGS_FOR_BUILD_SYSTEM variables
	to be passed to the Boehm GC build system.

	Use $host-ar for AR when cross-compiling.

m4/mercury.m4:
	Determine gcc version with gcc -dumpversion instead of building
	a program and running it.

	Don't run test for mercury_cv_cc_type if set explicitly.

Mmake.workspace:
	Use the default c2init and mkinit when cross-compiling.
	The copies in the util directory would not be usable then.

boehm_gc/Mmakefile:
	Pass configured values of AR, RANLIB down to sub-make.

boehm_gc/Makefile.direct:
boehm_gc/build_atomic_ops.sh:
	Use configured value from Mmake.common for HOSTCC.

	Pass --host when configuring libatomic_ops.

util/Mmakefile:
	Make tools with .exe suffixes on Windows.

Mmakefile:
	Use the bootstrap compiler to build libgrades when cross-compiling.

	Conform to changed target names in the util directory.

compiler/Mmakefile:
deep_profiler/Mmakefile:
profiler/Mmakefile:
slice/Mmakefile:
	Conform to changed target names in the util directory.

Makefile:
	Clean .exe files on Windows.
2012-01-09 00:35:41 +00:00
Julien Fischer
c8b3fd0d02 Don't call the GC before it has been initialised.
Branches: main, 11.07

util/mkinit.c:
	Don't call the GC before it has been initialised.
2011-12-17 04:11:04 +00:00
Julien Fischer
608df4f718 Fix handling of Unicode command-line arguments on Windows with either MinGW or
Branches: main, 11.07

Fix handling of Unicode command-line arguments on Windows with either MinGW or
MSVC.  (For other compilers on Windows, Unicode command-line arguments are not
currently supported.)

The existing approach using GetCommandLineW and CommandLineToArgW caused the
command-line to be parsed in a weird way, e.g. for

   c:\> "C:\ws"\foo.exe

argv[0] was split in two:

   ["c:\ws", "\foo.exe"]


util/mkinit.c:
	Use wmain instead of main with MSVC; this gives us direct access
	to the wide version of the argument vector.

	Use __wgetmainargs to get the wide version of the command-line
	arguments with MinGW.  MinGW doesn't support wmain so we can't
	use that.

	Don't include shellapi.h on Windows, it's no longer required.


compiler/compile_target_code.m:
	Use the wide entry point to the C runtime with MSVC so that
	wmain is invoke isntead of main.
2011-12-16 03:38:20 +00:00
Peter Wang
f205ce9425 Support Unicode characters in command line arguments on Windows.
Branches: main, 11.07

Support Unicode characters in command line arguments on Windows.

util/mkinit.c:
	Retrieve the array of wide-character command-line argument
	strings with GetCommandLineW and CommandLineToArgvW.

	Convert the strings to UTF-8.

	Pass the array of UTF-8 argument strings to mercury_main as usual.
2011-12-14 05:12:42 +00:00
Paul Bone
a885ef1910 Add support for tracking the number, and amount of memory consumed by memory
zones.  The current and maximum values are tracked.  This support is only
compiled in if the MR_PROFILE_ZONES C macro is defined when building the
runtime system.

runtime/mercury_memory_zones.[ch]:
    As above.

runtime/mercury_wrapper.c:
    Print out the zone profiling data as the runtime is exiting.

util/mkinit.c:
    Add support for measuring the top of heap before and after executing
    mercury_main and writing out this difference.  This support is only enabled
    if the MR_PROFILE_SBRK macro is defined when compiling an application.
2011-11-23 10:53:01 +00:00
Julien Fischer
bb457814ba Don't use -O0 with Visual C.
Branches: main, 11.07

util/Mmakefile:
	Don't use -O0 with Visual C.

	Use -Fe instead of -o with Visual C.
2011-07-15 07:34:23 +00:00
Julien Fischer
6a8844236b Protect a reference to GC_stackbottom with #ifdef MR_BOEHM_GC.
Branches: main

util/mkinit.c:
	Protect a reference to GC_stackbottom with #ifdef MR_BOEHM_GC.

library/bag.m:
	Fix some inconsistent indentation.
2011-06-08 04:19:58 +00:00
Paul Bone
322feaf217 Add more threadscope instrumentation.
This change introduces instrumentation that tracks sparks as well as parallel
conjunctions and their conjuncts.  This should hopefully give us more
information to diagnose runtime performance issues.

As of this date the ThreadScope program hasn't been updated to read or
understand these new events.

runtime/mercury_threadscope.[ch]:
    Added a function and types to register all the threadscope strings from an
    array.

    Add functions to post the new events (see below).

runtime/mercury_threadscope.c:
    Added support for 5 new threadscope events.
        Registering a string so that other messages may refer to a constant
        string.

        Marking the beginning and ends of parallel conjunctions.

        Creating a spark for a parallel conjunct.

        Finishing a parallel conjunct.

    Re-arranged event IDs, I've started allocating IDs from 38 onwards for
    general purposes and 100 onwards for mercury specific events after talking
    with Duncan Coutts.

    Trimmed excess whitespace from the end of lines.

runtime/mercury_context.h:
    Post a beginning parallel conjunction message when the sync term for the
    parallel conjunction is initialized.

    Post an event when creating a spark for a parallel conjunction.

    Add a MR_spark_id field to the MR_Spark structure, these identify sparks to
    threadscope.

runtime/mercury_context.c:
    Post threadscope messages when a spark is about to be executed.

    Post a threadscope event when a parallel conjunct is completed.

    Add a missing memory barrier.

runtime/mercury_wrapper.[ch]:
    Create a global function pointer for the code that registers strings in the
    threadscope string table, this is filled in by mkinit.

    Call this function pointer immediatly after setting up threadscope.

runtime/mercury_wsdeque.[ch]:
    Modify MR_wsdeque_pop_bottom to return the spark pointer (which points onto
    the queue) rather then returning a result through a pointer and bool if the
    operation was successful.  This pointer is safe to dereference until
    MR_wsdeque_push_bottom is used.

runtime/mercury_wsdeque.c:
    Corrected a code comment.

runtime/mercury_engine.h:
    Documented some of the fields of the engine structure that hadn't been
    documented.

    Add a next spark ID field to the engine structure.

    Change the type of the engine ID field to MR_uint_least16_t

compiler/llds.m:
    Add a third field to the init_sync_term instruction that stores the index
    into the threadscope string table of the static conjunction ID.

    Add a field to the c_file structure containing the threadscope string
    table.

compiler/layout.m:
    Added a new layout array name for the threadscope string table.

compiler/layout_out.m:
    Implement code to write out the threadscope string table.

compiler/llds_out_file.m:
    Write out the threadscope string table when writing out the c_file.

compiler/par_conj_gen.m:
    Create strings that statically identify parallel conjunctions for each
    init_sync_term LLDS instruction.  These strings are added to a table in the
    !CodeInfo and the index of the string is added to the init_sync_term
    instruction.

    Add an extra instruction after a parallel conjunction to post the message
    that the parallel conjunction has completed.

compiler/global_data.m:
    Add fields to the global data structure to represent the threadscope string
    table and its current size.

    Add predicates to update and retrieve the table.

    Handle merging of threadscope string tables in global data by allowing the
    references to the strings to be remapped.

    Refactored remapping code so that a caller such as proc_gen only needs to
    call one remapping predicate after merging global data..

compiler/code_info.m:
    Add a table of strings for use with threadscope to the code_info_persistent
    type.

    Modify the code_info_init to initialise the threadscope string table fields.

    Add a predicate to get the string table and another to update it.

compiler/proc_gen.m:
    Build the containing goal map before code generation for procedures with
    parallel conjunctions in a parallel grade.  par_conj_gen.m depends on this.

    Conform to changes in code_info.m and global_data.m

compiler/llds_out_instr.m:
    Write out the extra parameter in the init_sync_term instruction.

compiler/dupelim.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_to_x86_64.m:
compiler/mercury_compile_llds_back_end.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/peephole.m:
compiler/reassign.m:
compiler/use_local_vars.m:
    Conform to changes in llds.m

compiler/opt_debug.m:
    Conform to changes in layout.m

compiler/mercury_compile_llds_back_end.m:
    Fix some trailing whitespace.

util/mkinit.c:
    Build an initialisation function that registers all the strings in
    threadscope string tables.

    Correct the layout of a comment.
2011-03-25 03:13:42 +00:00