Change the io.print family of predicates to print out the formatted version of
dates and durations rather than their underlying representation.
library/io.m:
library/stream.string_writer.m:
As above.
Avoid a change of tense in the middle of the descriptive comment
for {io,stream.string_writer}.print.
tests/hard_coded/Mmakefile:
tests/hard_coded/print_date.{m,exp}:
Add a test for the above.
compiler/module_imports.m:
Implicitly import stream.m if the module being compiled may call
stream.string_writer.format.
compiler/simplify_proc.m:
Keep stream.put around until format_call.m may need it.
compiler/pred_table.m:
If looking for a predicate fails, generate an error message that mentions
the module name part of the fully qualified predicate name being
looked for.
tests/hard_coded/stream_put_bug.{m,exp}:
New test case, based on one contributed by sebgod (the filer of
Mantis bug 369).
tests/hard_coded/Mmakefile:
Enable the new test case.
library/lexer.m:
Fix an old XXX: do not allow unterminated octal escapes in string
literals; we haven't needed to preserve bug-for-bug compatibility
with NU-Prolog for a very long time.
tests/hard_coded/special_char.m:
Terminate octal escapes.
tests/invalid/Mmakefile:
tests/invalid/unterminated_octal_escape.{m,err_exp}:
Check for an error if an unterminated octal escape is encountered.
library/psqueue.m:
Fix a bug: the adjust predicate was documented to fail if asked to adjust
the priority of a nonexistent key, but it succeeded anyway.
Fix a bug: the function that computed the size of a psqueue did not count
the priority/key pair in the winner structure.
Make the at_most predicate significantly more efficient, by eliminating
an expensive conversion to the min view. Most of the contents of the min
view was not needed. In Haskell (the language used in the paper that
this module is derived from), computing stuff that won't be looked at
is cheap due to lazyness; in Mercury, it can be expensive.
Make the at_most predicate significantly more efficient in another respect
as well, by using cords to avoid re-re-re-appending the same elements.
Make most other predicates more efficient by eliminating the redundant
checking for empty queues. For example, when you convert a nonempty queue
to the tournament view, you shouldn't need to check whether the result
is a tournament with no players; it will not be. This change required
two main changes in data structures. The first is to separate out
the concepts of psqueues that may be empty from those which may not.
The second is updating the tournament view to eliminate the possibility
of no players, and handling empty psqueues *without* converting them
to the tournament view.
Document the meanings of the module's data structures, both original
and updated, including their invariants (at least, the invariants
I can see).
Delete the type for min views, since after the performance fix to at_most,
it is no longer needed.
Delete the type for tree views, since it is isomorphic to the actual
data structure, and conversions to it just waste time.
Delete the t_ prefix from the names of types.
Change the documentation of predicates to use full sentences, not just
sentence fragments.
Do not include the predicates intended only for unit tests in the
publicly documented part of the interface.
Use the P, K order of type variables CONSISTENTLY. Change the order
of fields representing priority/key pairs in structures likewise.
Use consistent naming schemes for variables: PSQx for psqueues, LTreex
for ltrees, etc. Use xPrime instead of x0 for variables bound in the
conditions of if-then-elses. Use Maybe as a prefix on the names of
variables of maybe types.
Avoid the use of generic variable names such as "Res"; use names that
reflect the value being returned instead.
Avoid the use of numeric suffixes on variables when these do NOT denote
progression over time; use A and B, or L and R, suffixes instead.
Give some function symbols and predicates more meaningful names.
Internal operations do not need to be available as both functions
and predicates; pick whichever seems more appropriate, and remove
the other. Remove some other unused functions, such as construct_leaf.
Factor out some common code, e.g. for updating minimums and maximums.
Remove redundant "is det" declarations from functions.
Fix the type specializations. Specializing a predicate is useless
unless its caller either always calls it with values of the specialized
type, or is itself specialized the same way. This module needs the latter,
so add type specializations to all predicates between the exported
predicates and the primitives that can directly benefit from the
specializations.
tests/hard_coded/psqueue_test.{m,exp}:
Make this test case significantly harder. The old version did not
pick up the two bugs referred to above, but the new version does.
library/psqueue.m:
Make the psqueue interface more consistent with other standard library
modules.
tests/hard_coded/psqueue_test.exp:
tests/hard_coded/psqueue_test.m:
Update tests.
library/psqueue.m:
Update coding style.
In min_view/1 there's two variable names are incorrect (they should be
swapped) this doesn't change the program but may confuse people reading
the code.
tests/hard_coded/psqueue_test.exp:
tests/hard_coded/psqueue_test.m:
Also improve the coding style in the test code.
Add lables to all of the test outputs.
This implements a priority search queue ADT. This is a kind of blend
between priority queues and search trees; in contrast to a priority
queue, it also allows changing priorities of keys, looking up keys and
deleting keys.
This is an implementation based on the ICFP 2001 paper "A Simple
Implementation Technique for Priority Search Queues" by Ralf Hinze.
http://www.mercurylang.org/list-archives/users/2014-October/007804.html
Commit message paraphrased from Matthias' e-mail.
http://www.mercurylang.org/list-archives/reviews/2014-October/017414.html
library/psqueue.m:
Add new module.
library/MODULES_DOC:
library/library.m:
Include new module.
tests/hard_coded/Mmakefile:
tests/hard_coded/psqueue_test.exp:
tests/hard_coded/psqueue_test.m:
Add test for psqueue.m
library/calendar.m:
Add predicates and functions for converting between 1-based
and 0-based month numbers and values of the month/0 type.
The former are useful when dealing with human-provided dates
whereas the latter are useful when interacting with dates
provided from some foreign language (C and Java for example).
Add a predicate for testing for equality of dates ignoring
their time component.
Replace the locally defined predicate char_to_digit/2 with
calls to char.decimal_digit_to_int/2
Fix some formatting issues.
tests/hard_coded/calendar_test.{m,exp}:
Extend this test case to cover the functionality added
above.
NEWS:
Announce the additions.
compiler/format_call.m:
As above.
Factor out some common code.
compiler/module_imports.m:
Fix a cut-and-paste bug.
library/builtin_modules.m:
Add a way to retrieve the name of the stream module, since the compiler
can now generate calls to stream.put.
tests/hard_codes/opt_format.{m,exp}:
Expand this test case to include tests of calls to
stream.string_writer.format.
Make the existing tests a bit tougher as well.
The new construct looks like this:
require_switch_arms_det [C] (
(
C = 'a',
... compute Out ...
;
C = 'b',
... compute Out ...
)
)
If any of the goals computing Out are not det, the compiler will generate
an error message. The det at the end of the keyword can be replaced
by any of the other seven determinisms, though I don't think either
require_switch_arms_failure or require_switch_arms_erroneous will see much use.
This diff adds only the implementation. I will add the documentation
and the NEWS item after we all had a chance to install this diff and
try it out.
compiler/hlds_goal.m:
Add a scope representing this kind of goal in the HLDS.
compiler/prog_item.m:
Add a goal expression for this kind of goal in the parse tree.
compiler/prog_io_goal.m:
Look for the new kind of goal expression in terms when creating
the parse tree.
Factor out some commonalities between the parsing of the new goal
expression and existing types of goal expressions.
compiler/goal_expr_to_goal.m:
Convert the new kind of goal expression to the new scope in the HLDS.
compiler/det_report.m:
Implement the checks that the new goal type calls for.
Factor out some commonalities between the implementation of the new goal
type and existing goal types.
Move the types and predicates dealing with comparisons of determinisms
from here to prog_data.m, due to the sort-of-bugfix to modecheck_call.m.
compiler/prog_data.m:
Move the types and predicates dealing with comparisons of determinisms
from det_report.m to here. The old code for this was intended for only one
requirement, and did not deal well with comparisons of two determinisms
in which each determinism makes an assertion the other does not make.
Create a way to represent such comparison results.
compiler/modecheck_call.m:
When deciding which mode of a procedure to call, we prefer determinisms
that make more assertions about solution counts. However, when comparing
incomparable determinisms (such as semidet vs multi, each of which makes
an assertion the other doesn't), the algorithm chose based solely
on the ORDER of the modes. We now explicitly prefer modes that promise
lower maximum solution counts, giving less importance to cannot_fail
assertions.
compiler/*.m:
Conform to the change to hlds_goal.m or prog_item.m.
library/ops.m:
Add the new keywords as operators.
tests/hard_coded/require_scopes.{m,exp}:
Extend this test case to test the new construct in the absence of errors.
tests/invalid/require_scopes.{m,exp}:
Extend this test case to test the new construct in the presence of errors.
The following changes are necessary to compile the code following an
upcoming change to the mode checker. Some of them are mode errors.
browser/declarative_oracle.m:
The result of `query_oracle_kb' should be specific
to avoid mode errors in callers.
compiler/accumulator.m:
Help the compiler infer the declared inst.
compiler/mode_robdd.tfeirn.m:
`zero' must be declared to return a normalised tfeirn value to
avoid mode errors. Change `one' for symmetry.
`var_restrict_true' and `var_restrict_false' may return
unnormalised tfeirn values (judging by the code).
Modify `normalise' to help the compiler infer
the declared inst.
compiler/tupling.m:
deep_profiler/autopar_find_best_par.m:
Delete final insts that the compiler cannot verify.
library/tree234.m:
Help the mode checker out using an explicit switch.
tests/hard_coded/bitmap_test.m:
tests/hard_coded/bitmap_tester.m:
Add missing modes.
array.sort was broken since 2001 when the implementation was changed
from merge sort to SAM sort.
library/array.m:
Fix the confusion as to which output argument of samsort_up is
sorted.
Add optional runtime checks of the pre- and post-conditions
of samsort_up and samsort_down when built with a trace flag.
Add array.sort_fix_2014.
tests/hard_coded/Mmakefile:
tests/hard_coded/array_sort.exp:
tests/hard_coded/array_sort.m:
Add test program.
NEWS:
Announce the fix.
Add a constant function to the float module that returns positive infinity.
This is implemented for the C, Java, and C# backends.
The Erlang backend currently does not support it
library/float.m:
Add the new function.
Address review comments from Paul about my previous change.
tests/hard_coded/Mmakefile:
tests/hard_coded/test_infinity.{m,exp}:
Test various operations involving infinity.
NEWS:
Announce the addition.
The string representation of float special values is currently dependent on the
target language and, for C grades, the underlying platform. As a result,
values like NaN and Infinity are being printed or converted into strings in
variety of ways. (See, for example bug #348 in Mantis.)
This diff changes float->string conversion to detect float special values and
use a consistent string representation for them.
library/string.m:
library/io.m:
runtime/mercury_float.c:
Check if a float is not-a-number or of infinite magnitude when converting
floats into strings. If so, then use a standard representation of the
value: "nan" for not-a-number values, and "infinity" / "-infinity" for
values of infinite magnitude.
For uppercase conversion specifiers in format strings, we output the above
strings in uppercase (e.g. "NAN", "INFINITY").
library/float.m:
Add is_infinite/1 and is_nan_or_infinite/1 as synonyms for is_inf/1 and
is_nan_or_inf/1 respectively.
Group float classification predicates into their own section. Upcoming
change will add more of them.
NEWS:
Announce the above changes.
tests/general/string_format_special_floats.m:
tests/general/string_format_special_floats.exp:
Modify this test to check that we actually print float special values as
above.
tests/hard_coded/write_float_special.exp:
Conform to the above change.
tests/EXPECT_FAIL_TESTS.all_grades:
Do not expect the write_float_special test case to fail any more since
the expected outputs should be the same on every platform.
(1) The behaviour of digit_to_int/2 was inconsistent with that of is_digit/2.
The former succeeds for all of 0-9, a-z and A-Z while the latter succeeds only
for 0-9 (i.e. it was possible for digit_to_int/2 to succeed for non-decimal
characters, which is not what was intended in many of it uses).
(2) Predicates involving hexadecimal digits were inconsistently named, they
were "hex digits" in one predicate name, "hex chars" in another.
This change ensures that the following operations are supported for binary,
octal, decimal and hexadecimal digits and that we use a consistent naming
scheme for the predicates that implement them:
- testing if a character is a digit of the given base
- conversion to an int
- conversion from an int
In addition, we also add predicates for supporting these operations for user
defined bases, ranging from 2-36.
library/char.m:
Add the predicate is_decimal_digit/1, which is a synonym for is_digit/1.
Add the predicate is_base_digit/2.
Add the predicates int_to_{binary,octal,decimal,hex}_digit/2 and
base_int_to_digit/3.
Add the predicates {binary,octal,decimal,hex}_digit_to_int/2 and
base_digit_to_int/3.
Add det function versions of the above.
Delete the function det_digit_to_int/1 that I added the other day.
Mark the following as obsolete:
- is_hex_digit/2
- int_to_hex_char/2
- int_to_digit/2
- det_int_to_digit/1
- det_int_to_digit/2
Avoid redundant module qualification in the implementation.
Mark some C foreign_procs as not modifying the trail.
Re-order some declarations according to how the coding standard says they
should be ordered.
library/bitmap.m:
library/integer.m:
library/parsing_utils.m:
library/string.m:
compiler/prog_rep_tables.m:
Replace calls to obsolete predicates or functions.
NEWS:
Announce the above changes.
Add note advising users of digit_to_int/2 to check their code for the
problem described above.
tests/hard_coded/Mmakefile:
tests/hard_coded/test_char_digits.m:
tests/hard_coded/test_char_digits.exp:
Add a systematic test for the above predicates.
The old version_array rewind code used linear stack space in order to
perform it's updates in the right order (newest to oldest) by following the
structure's next pointers (which are a oldest to newest list). I previously
introduced week prev pointers so that walking over this structure newest to
oldest could be done with constant stack space. However that is less
efficient than the method suggested by Peter Wang.
Peter suggested using a bitmap and traversing oldest-to-newest, marking
each update in the bitmap and checking the bitmap before making any update.
Thus preserving older values over newer ones (which is good, this code
_rewinds_ updates). This patch implements Peter's suggestion and removes
the prev pointers from the structure for C and Java backends.
Thanks to Peter Wang for giving me a hand with C#.
library/version_array.m:
As above.
runtime/mercury_bitmap.h:
Add some macros for initialising bitmaps and testing, setting and clearing
their bits.
library/bitmap.m:
java/runtime/MercuryBitmap.java:
Move the Java MercuryBitmap class into the runtime library. This makes
it easier for other standard library modules to use this Java class.
library/bitmap.m:
runtime/mercury_dotnet.cs.in:
Move C# MercuryBitmap class into runtime/mercury_dotnet.cs
library/bitmap.m:
Add extra methods to the C# MercuryBitmap class.
tests/hard_coded/version_array_test.exp:
tests/hard_coded/version_array_test.m:
Ensure that the test verifies that rolling back updates to a version
array rolls back changes in the correct order: If two updates modify the
same cell, then the older one should be visible in the result.
Use longer arrays so that the bitmap used in the rollback code is more
than one byte in length.
Until this diff, the compiler used to crash on such inputs, as mentioned
by Mantis bugs 41, 62 and 268.
compiler/prog_io.m:
When reading in :- module and :- end_module items, we used to blindly
believe what they said. We now check whether they make sense, and report
a fatal error if they don't. Specifically,
- if the name of the module started by a :- module declaration is
qualified, that qualification has to match the name of the
previously-current module, and
- the name of the module ended by a :- end_module declaration
has to match the name of the previously-current module.
Simplify the code we used to use to remove the :- module/:- end_module
wrappers around the top level module. The root of the problem used
to be that this code used to let a malformed item list through to be
processed by later compiler passes, which did not expect it.
The reason WHY it let through malformed item lists seems to be
the loosening of the checks in this code, more than a decade ago.
This was done to account for the possibility that the final :- end_module
in a file's item list is for a submodule of the main module, and not
for the main module itself.
Simplify the code for reading in the whole item list. Previously
this was done by two mutually-recursive predicates, one of which
read in a term for the next item and one which had the term handed
to it by its caller. We now handle the two cases (one of which is
needed only by the special handling required by the first item)
in one self-recursive predicate with a maybe argument.
mdbcomp/prim_data.m:
Add a utility predicate for use by the new code in prog_io.m.
Remove a comment on code that duplicates the code on the declaration.
compiler/modules.m:
Improve some code that handles lists of items.
- Make some previously not-tail-recursive predicates tail recursive.
- Give some predicates and variables more meaningful names.
- Combine some checks where this allows us to reduce the number of
traversals over the item list.
doc/reference_manual.texi:
Fix bad punctuation, and expand the list of things
that can be declared but not defined.
tests/invalid/bad_end_module.{m,err_exp}:
Test the expected output.
tests/invalid/Mmakefile:
Enable the new test case.
tests/hard_coded/sub-module/g12_fe_bug.m:
Fix a typo in a comment.
The glibc implementation of malloc (commonly used on Linux) can use sbrk
to acquire more memory, and so does Boehm GC in its default configuration
on Linux. When both allocators are invoked simultaneously from different
threads then memory corruption may result.
configure.ac:
Add --enable-gc-mmap option.
Make --enable-gc-munmap imply --enable-gc-mmap.
Detect mmap and set MR_HAVE_MMAP.
Detect sbrk and set MR_HAVE_SBRK.
On Linux (and potentially other platforms), build Boehm GC for
threaded grades with -DUSE_MMAP if mmap was found.
Mmake.common.in:
Add ENABLE_BOEHM_USE_MMAP.
runtime/mercury_conf.h.in:
Add MR_HAVE_MMAP, although it is not used anywhere yet.
Add MR_HAVE_SBRK. It is only for used by the test program.
tests/hard_coded/Mmakefile:
tests/hard_coded/thread_sbrk.exp:
tests/hard_coded/thread_sbrk.exp2:
tests/hard_coded/thread_sbrk.m:
Add test program.
NEWS:
Announce changes.
(cherry picked from commit d63a294e1f)
tests/general/weak_ptr.m:
tests/general/weak_ptr.exp:
tests/hard_coded/Mmakefile:
tests/general/Mmakefile:
Move week_ptr test into tests/hard_coded
The weak_ptr test should te executed conditionally, this is easy to do in
the hard_coded/ test suite.
tests/general/weak_ptr.m:
Fix spelling error.
tests/general/weak_ptr.exp2:
Remove unnecessary file.
The glibc implementation of malloc (commonly used on Linux) can use sbrk
to acquire more memory, and so does Boehm GC in its default configuration
on Linux. When both allocators are invoked simultaneously from different
threads then memory corruption may result.
configure.ac:
Add --enable-gc-mmap option.
Make --enable-gc-munmap imply --enable-gc-mmap.
Detect mmap and set MR_HAVE_MMAP.
Detect sbrk and set MR_HAVE_SBRK.
On Linux (and potentially other platforms), build Boehm GC for
threaded grades with -DUSE_MMAP if mmap was found.
Mmake.common.in:
Add ENABLE_BOEHM_USE_MMAP.
runtime/mercury_conf.h.in:
Add MR_HAVE_MMAP, although it is not used anywhere yet.
Add MR_HAVE_SBRK. It is only for used by the test program.
tests/hard_coded/Mmakefile:
tests/hard_coded/thread_sbrk.exp:
tests/hard_coded/thread_sbrk.exp2:
tests/hard_coded/thread_sbrk.m:
Add test program.
NEWS:
Announce changes.
Although rewinding version arrays should be rare it is better if this code
uses constant stack space to avoid crashes. Currently the list of updates
made in a version array is kept in a singly linked list. This list needs to
be walked backwards to unwind updates, such as when updating an old version
of an array (to fork into two separate arrays). The stack is used to
perform this backwards work and can overflow for long histories.
This patch makes these lists doubly-linked so that they can be traversed in
either direction. The back pointers are implemented using weak pointers in
all backends. This avoids unnecessary memory retention when a programmer
only maintains a reference to the lastest version of the array, which is the
common case.
library/version_array.m:
As above; I developed this algorithm in the C implementation first and
then replicated the changes in the Java and C# implementations.
tests/hard_coded/version_array_test.m:
tests/hard_coded/version_array_test.exp:
Extend the test case to exercise implicitly unwinding a version array by
updating an old version of an array. Note that the implicit and
explicit unwind codepaths are different as they are out-of-place and
in-place respectively.
Most backends already mapped Mercury threads to "native" threads in spawn/3,
but it was and remains an implementation detail. spawn_native provides
that behaviour as a documented feature for programs which require it,
including for the low-level C backend.
While we are at it, add a `thread' handle type. It currently holds a
thread identifier (not yet formally exported), but it may also have
other uses such as a handle for a `thread.join' predicate, or a place to
hold result values or uncaught exceptions.
library/thread.m:
Add abstract type `thread'.
Add can_spawn_native.
Add spawn_native/4. It can report failure to start a thread,
which was missing from the spawn/3 interface.
Add spawn/4 to match spawn_native/4, without the native thread
requirement.
Make ML_create_exclusive_thread wait for a success code from
the new thread before continuing.
Reduce accessibility levels in C# and Java helper classes.
runtime/mercury_thread.c:
Make MR_init_thread_inner and MR_setup_engine_for_threads
return errors instead of aborting on failure.
tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
tests/hard_coded/spawn_native.exp2:
tests/hard_coded/spawn_native.exp:
tests/hard_coded/spawn_native.m:
Add test case.
NEWS:
Announce change.
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.
tests/hard_coded/Mmakefile:
Only run the target_mlobjs test case in C grades; directly linking
against an object file isn't possible in the non-C grades.
tests/hard_coded/Mercury.options:
Suppress irrelevant warnings generated by some tests.
tests/hard_coded/hash_init_bug.m:
Replace a call to an obsolete function.
Avoid some warnings during runtests.
tests/hard_coded/write.exp3:
Update this expected output.
tests/hard_coded/hash_bug.m:
Do not call an obsolete function.
tests/hard_coded/Mercury.options:
Do not warn about unresolved polymorphism in a test.
* Fix a problem that broke install_libgrades on non-Linux systems.
* Fix printing of special float values in C# grade.
* Clean up handling of special float values in string.format.
* Fix the printing of float special values with write_float in C grades.
* Fix string.format with special float values in non-C grades.
library/string.m:
In the C# grade, do not append ".0" to a special float
value when converting it to a string.
tests/hard_coded/write_special_float.exp3:
Alternative expected output for this for use with the
Java and C# grades.
NEWS:
Announce the fix.
runtime/mercury_float.c:
When printing floats, do not append ".0" to nan, inf or -inf.
tests/hard_coded/Mmakefile:
tests/hard_coded/write_float_special.{m,exp,exp2}:
Add a regression test for the above.
NEWS:
Announce the above.
MR_LOWLEVEL_DEBUG is set when compiling the no_refs_to_deleted_labels
test case to give MR_init_label macros some effect. However
MR_LOWLEVEL_DEBUG implies MR_DEBUG_GOTOS, and leads to link errors if
the runtime was not built with MR_DEBUG_GOTOS.
tests/hard_coded/Mercury.options:
Replace MR_LOWLEVEL_DEBUG with MR_DEBUG_LABEL_NAMES,
implying MR_INSERT_LABELS but not MR_DEBUG_GOTOS.
When I added this test recently I forgot to make it condition on any grade
with a par component, or the java and csharp grades. This patch fixes this.
tests/hard_coded/Mmakefile:
As above.
The directory stream was not closed if dir.open succeeded in opening
the directory, but failing to read the first entry (which may be as
simple as an empty directory).
The directory stream was also not closed when dir.foldl2_process_dir2
returns an error value.
library/dir.m:
As above.
tests/hard_coded/Mmakefile:
tests/hard_coded/dir_fold.exp:
tests/hard_coded/dir_fold.m:
Add regression test.
NEWS:
Announce change.
This test case is based off Sebastian Godelet's work, which found a bug that
can occur when release/3 is called on a barrier and then other calls to
wait/3 are made. The final call to wait/3 tries to execute the normal
'unblock the barrier' code and deadlocks there because the barrier is
already unlocked, specifically a value is already present in the "Go" mvar.
Thanks Sebastian for your test case.
library/thread.barrier.m:
Handle release/3 properly: release/3 now sets the number of remaining
threads to reach the barrier to zero, and wait/3 will determine why this
iz zero (it's normally at least one), and if it is because release was
called then no error is raised. The other reasion why the number of
remaining threads may be zero is because wait has been called too many
times, in this case wait/3 will throw an exception.
tests/hard_coded/Mmakefile:
tests/hard_coded/thread_barrier_test.exp:
tests/hard_coded/thread_barrier_test.m:
Add new test case.
tests/hard_coded/thread_test_utils.m
This module contains code that may be useful for other concurrency
tests.
The directory stream was not closed if dir.open succeeded in opening
the directory, but failing to read the first entry (which may be as
simple as an empty directory).
The directory stream was also not closed when dir.foldl2_process_dir2
returns an error value.
library/dir.m:
As above.
tests/hard_coded/Mmakefile:
tests/hard_coded/dir_fold.exp:
tests/hard_coded/dir_fold.m:
Add regression test.
NEWS:
Announce change.
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.
The abort was caused by the fact that when the parser found an item that
looks like a fact for an undeclared predicate, such as the predicate ','/,
it created a hlds_pred filled with a clause_info in which terms that the
user intended to be goals are instead taken to be terms. Any reference
to predicates in those terms are taken by purity-checking to be higher order
references, which need a mode declaration. If the reference is to a predicate
(such as ,/2) whose declaration is implicit, that mode declaration will be
missing.
The fix has two parts. First, do not generate an abort in purity checking
when finding the mode declaration of a predicate or function in (what seems to
be) a higher order term is missing. Second, do not generate implicit
declarations for ,/2, since this is NEVER what the user wants.
A third part of this diff is an improvement in the contexts we record
for terms, for better error messages. I noticed the need for this when
looking at the compiler's output for the new cases.
compiler/post_typecheck.m:
When finding an apparent reference to a predicate or function with
no mode declarations, do not abort; instead, report an error.
compiler/purity.m:
Record the error reported by post_typecheck.m.
compiler/add_clause.m:
If we see a clause for `,'/2, do NOT treat it as implicitly defining
a ,/2 predicate. Instead, generate a situation-specific error message that
mentions the usual cause of the error.
compiler/add_pred.m:
Clean up the predicates that add the implicit predicate declarations
by making them both update module_infos, and by putting their arguments
into a consistent order.
compiler/make_hlds_passes.m:
Do likewise for a couple of predicates here.
compiler/add_pragma.m:
Conform to the change to add_pred.m.
compiler/superhomogeneous.m:
When expanding a term such as
line 1: p(a,
line 2: p(b,
line 3: c))
associate line 2 with the unification of a fresh variable with b,
and line 3 with the unification of a fresh variable with c. We used
to use the context of the top level term, which in this case is line 1,
instead.
This makes the compiler generate better (less misleading) output for the
ref_to_implicit_pred.m test case below, as well as in many other cases.
compiler/state_var.m:
When replacing !.X or !:X with a fresh variable term, copy the context
of the original functor term to the new variable term. Before the change
to superhomogeneous.m, this wasn't needed since the context of that term
was ignored, but now we use it.
tests/invalid/ref_to_implicit_pred.{m,err_exp}:
New test case to test the first part of the fix.
tests/invalid/ref_to_implicit_comma.{m,err_exp}:
New test case to test the second part of the fix.
tests/invalid/Mmakefile:
Enable both new test cases.
tests/hard_coded/impl_def_literal.{m,exp}:
Update this expected output for the more accurate contexts we now
generate, and update the comment in the source code accordingly.
tests/invalid/ambiguous_overloading_error.exp:
tests/invalid/max_error_line_width.err_exp:
tests/invalid/transitive_import_class.err_exp:
tests/warnings/ambiguous_overloading.exp:
Update these expected outputs for the more accurate contexts we now
generate.
Add a function enum.det_from_int, as requested by Julien and Zoltan.
library/enum.m:
library/diet.m:
Move det_from_int from diet to enum.
tests/hard_coded/bitmap_simple.m:
Remove redundant and conflicting definition.
library/string.m:
As above.
NEWS:
Add a section for 14.01.1 news.
Mention the above change.
tests/hard_coded/string_string.{m,exp}:
Extend this test case to cover arrays and version arrays.
library/stream.string_writer.m:
Make the print family of predicates print the decimal representation
of integer/0 values instead of their underlying representation.
library/io.m:
Update the documentation of io.print to conform to the above change.
Fix a typo: s/hander/handler/
NEWS:
Announce the above change.
tests/hard_coded/Mmakefile:
tests/hard_coded/print_bigint.{m.exp}:
Test printing of integers with io.print.
The problem was introduced by my recent change that removed the definitions
of internal labels if those labels started while loops, and all references
to them would be converted into "continue" statements within those loops.
The diff removed the definitions of these labels, but they were still being
declared. Those declarations expand out to nothing in most cases, which is
why I did not notice the problem, but they are used in some situations,
such as when MR_LOWLEVEL_DEBUG is defined, in which case they register
the correspondence between the names of labels and the code addresses
they represent. The problem was that the code that was registering this
correspondence referred to a now-undefined label.
compiler/llds_out_file.m:
When gathering labels to declare, delete while labels that won't end up
being defined.
We used to compute the list of entry and internal labels three times:
when deciding the list of labels to forward-declare up front, when deciding
the list of labels to define in each module, and when deciding whether
a C module defined any labels without layout structures. We now
do it just once, up front, and record the result for later use.
Fix some out-of-date comments.
tests/hard_coded/no_refs_to_deleted_labels.{m,exp}:
A test case derived from the code that brought the problem to my attention.
tests/hard_coded/Mmakefile:
Enable the new test case for LLDS grades. (The problem isn't relevant
in other grades.)
tests/hard_coded/Mercury.options:
Specify -DMR_LOWLEVEL_DEBUG when compiling the new test case, to make
the test case fail without the bug fix.
compiler/opt_debug.m:
Fix white space in LLDS dumps.
Add the predicates io.write_line and io.print_line to the standard library.
These are versions of io.write and io.print respectively, that in addition to
printing their argument also print a final newline. While this is no different
to calling io.{write,print} and then calling io.nl, it is a little more concise
which can be convenient in some circumstances.
library/io.m:
Add the above predicates.
compiler/error_util.m:
Avoid ambiguity with the write_line/3 predicate defined
in this module.
NEWS:
Announce the new predicates.
tests/hard_coded/write.m:
Use up-to-date syntax in this module.
Call write_line in a few spots.