Run-time checking of assertions

Author(s): Edison Mera.

This package provides a complete implementation of run-time checks of predicate assertions. The program is instrumented to check such assertions at run time, and in case a property does not hold, the error is reported. Note that there is also an older package called rtchecks, by David Trallero. The advantage of this one is that it can be used independently of CiaoPP and also has updated functionality.

There are two main applications of run-time checks:

  • To improve debugging of certain predicates, specifying some expected behavior that is checked at run-time with the assertions.

  • To avoid manual implementation of run-time checks that should be done in some predicates, leaving the code clean and understandable.

The run-time checks can be configured using prolog flags. Below we itemize the valid prolog flags with its values and a brief explanation of the meaning:

  • rtchecks_level
    • exports: Only use rtchecks for external calls of the exported predicates.
    • inner : Use also rtchecks for internal calls. Default.

  • rtchecks_trust
    • no : Disable rtchecks for trust assertions.
    • yes : Enable rtchecks for trust assertions. Default.

  • rtchecks_entry
    • no : Disable rtchecks for entry assertions.
    • yes : Enable rtchecks for entry assertions. Default.

  • rtchecks_exit
    • no : Disable rtchecks for exit assertions.
    • yes : Enable rtchecks for exit assertions. Default.

  • rtchecks_test
    • no : Disable rtchecks for test assertions. Default.
    • yes : Enable rtchecks for test assertions. Used for debugging purposes, but is better to use the unittest library.

  • rtchecks_inline
    • no : Instrument rtchecks using call to library predicates present in, and In this way, space is saved, but sacrifying performance due to usage of meta calls and external methods in the libraries. Default.
    • yes : Expand library predicates inline as far as possible. In this way, the code is faster, because its avoids metacalls and usage of external methods, but the final executable could be bigger.

  • rtchecks_asrloc Controls the usage of locators for the assertions in the error messages. The locator says the file and lines that contains the assertion that had failed. Valid values are:
    • no : Disabled.
    • yes : Enabled. Default.

  • rtchecks_predloc Controls the usage of locators for the predicate that caused the run-time check error. The locator says the first clause of the predicate that the violated assertion refers to.
    • no : Disabled.
    • yes : Enabled, Default.

  • rtchecks_callloc
    • no : Do not show the stack of predicates that caused the failure
    • predicate: Show the stack of predicates that caused the failure. Instrument it in the predicate. Default.
    • literal : Show the stack of predicates that caused the failure. Instrument it in the literal. This mode provides more information, because reports also the literal in the body of the predicate.

  • rtchecks_namefmt
    • long : Show the name of predicates, properties and the values of the variables
    • short : Only show the name of the predicate in a reduced format. Default.

Usage and interface

  • Library usage:
    :- use_package(rtchecks). or :- module(...,...,[rtchecks]).