Minor cleanup private_builtin.m.

library/private_builtin.m:
    Remove two long-unneeded predicates, trailed_nondet_pragma_foreign_code
    and reclaim_heap_nondet_pragma_foreign_code.

    Move foreign_code pragmas together into a single group at the end of the
    module.

    Fix white space.

library/builtin.m:
    Fix white space.
Make the recently added keywords known to vim.

These are require_switch_arms_*. Also add semidet_false, which is old
but was missing before.

Sort the keywords of each type.
Step 2 of moving trace_*_io_state out of private_builtin.m.

At the moment private_builtin.m imports the io module. This is undesirable,
since private_builtin should not depend on any other module. The import
is needed only for trace_{get,set}_io_state, predicates that are used
in the implementation of trace [io(!IO)] scopes to create and destroy
dummy I/O states.

The obvious thing to do to remove this undesirable dependency is to move
those predicates to another module, and the io module is the obvious choice.
Since these two predicate can also be used to implement Mercury's version
of Haskell's unsafe_perform_io, give the moved versions names that reflect
this, unsafe_{get,set}_io_state.

However, since private_builtin.trace_{get,set}_io_state are builtins,
moving them requires several steps.

The first step is making io.unsafe{get,set}_io_state builtins, with definitions
identical to private_builtin.trace_{get,set}_io_state.

The second step, once the first step has been installed on all developers'
machines, is to add declarations for io.unsafe{get,set}_io_state to io.m
(but not definitions, since these should not be there for builtins), and
to get the compiler to generate references to these instead of to
private_builtin.trace_{get,set}_io_state.

The third step, once the second step has been similarly installed, will be
to remove the declarations of private_builtin.trace_{get,set}_io_state,
and to remove the undesirable import.

library/io.m:
    Add the declarations of unsafe_{get,set}_io_state.

library/add_pred.m:
    Add dummy definitions of unsafe_{get,set}_io_state, as we now do for
    private_builtin.trace_{get,set}_io_state.

compiler/add_pragma.m:
    Use io.unsafe_{get,set}_io_state instead of
    private_builtin.trace_{get,set}_io_state.

compiler/goal_expr_to_goal.m:
    Switch to using io.unsafe_{get,set}_io_state to implement trace [io(!IO)].

compiler/module_imports.m:
    Import the io module if the module contains trace [io(!IO)].
Fix compilation of library/version_array.m in memory profiling grades.

library/version_array.m:
    The macro MR_ALLOC_ID is only defined for foreign_proc pragmas *not* for
    foreign_code pragmas.  Commit ab44bba introduced several references to
    MR_ALLOC_ID inside functions defined foreign_code pragmas.  Fix this by
    passing the appropriate alloc id down from the foreign_proc pragmas
    that call the affected functions.
Fix spelling in psqueue module.

library/psqueue.m:
	As above.
Fix a typo.

library/psqueue.m:
	As above.
Significantly improve psqueue.m.

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.
Remove trace code accidentally left in.
Finish making pointer_equal a builtin.

library/private_builtin.m:
    Remove the definitions of pointer_equal.

compiler/options.m:
    Disable definitions for compiler builtins.
Speed up pred_info's setter predicates a bit.

compiler/hlds_pred.m:
    If the new value of a field of pred_info is likely to be bit-identical
    to the old value, then test the old and new bits for equality in the
    setter, and if they are the same, do not allocate a new pred_info
    structure that is guaranteed to be the same as the old one.

    By avoiding unnecessary memory turnover, this speeds up the compiler a bit,
    though I cannot nail down by how much. I measured it several times, with
    the results being no change, a speedup of 1%, and a speedup of 2%.

    Remove the unused setter predicate for the attributes field.

    Rename some access predicates to pred_infos to better reflect what they do.

    Add a distinguishing prefix to the fields of pred_infos.

compiler/*.m:
    Conform to the changes above.
Do not allow unterminated octal escapes in string literals.

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.
Use pointer_equal instead of a bespoke predicate.
Fix compiler abort looking for stream.put (Mantis bug 369).

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.
Minor improvements.

compiler/simplify_goal_ite.m:
    Fix the English in some comments.

compiler/simplify_goal_switch.m:
    Give a variable a better name.
[java] Remove dead code

java/runtime/MercuryThreadPool.java:
    As above.
[java] Fix locking bug in Java ThreadPool.

Fix a bug that made it possible that the tasks_lock could be locked but
never unlocked if an exception was thrown.

java/runtime/MercuryThreadPool.java:
    As above.
[java] The thread pool now works when Mercury is used as a library

The thread pool code used in the Java backend was tied the execution of
main/2.  However if Mercury is used as a library the thread pool won't have
been started and threads created with thread.spawn would not be executed.

This patch makes it possible to start and stop the thread pool independently of
main/2 by calling startup() and shutdown().  These calls are called
implicitly by calling runMain().  The thread pool can also be started on
demand.

This patch also adds the MercuryRuntime class, which now contains methods
that may be called by users' Java code to interact with the Mercury runtime
system, including a new finalise() method.

java/runtime/MercuryThreadPool.java:
    Add startup() method.

    shutdown() method is now public and it's meaning has changed, it now
    requests the shutdown rather than performing it.

    Renamed some variables to make their meanings clearer.

java/runtime/JavaInternal.java:
    Initialise the ThreadPool and MercuryOptions objects on demand.

    Make all members of this class static to avoid confusion.

    Add a private constructor.

java/runtime/MercuryRuntime.java:
    Add methods that can be called by Mercury users to interact with the
    runtime system.  Including a convenient finalise() method that does all
    the finalisation.

samples/java_interface/standalone_java/mercury_lib.m:
samples/java_interface/standalone_java/JavaMain.java:
    Extend the standalone Java example so that it makes use of threads: Add
    a fibs function in Mercury that uses concurrency and therefore starts
    the thread pool; call it from the Java code.

    Use the new finalise() method from the MercuryRuntime class inside of a
    finally block.

samples/java_interface/standalone_java/Makefile:
    Fix a minor error.