1

How to produce the Finalized executable with contract checking enabled? It is possible to keep the check statements intact, but can we keep all the pre/postconditions and class invariants?

I need this for testing a computationally expensive application and frozen with contracts executable is a bit too slow in my case.

Ilgiz Mustafin
  • 414
  • 1
  • 4
  • 15

1 Answers1

2

The IDE shows a dialog on request for finalization that asks whether the assertions should be kept in the generated executable. The dialog is discardable. If you select the checkbox "Do not ask me again", the assertions will NOT be generated and the IDE will NOT show this dialog anymore. You can reset this selection by going to the Parameters (e.g., from the main menu: Tools | Parameters), and restoring the default value for the finalization dialog under Interface | Dialogs.

In the command line, the compiler accepts an option -keep right after -finalize. It tells the compiler to keep assertions when finalizing the executable.

Both the IDE and the compiler pick the settings which assertions should be generated from the project settings. You can specify them for every group (system/library/cluster) and every class individually.

Edit. Here is a minimal example with 2 files:

example.e:

class EXAMPLE create make feature
    make
        local
            n: INTEGER
        do
            if n = 0 then f
            elseif n = 1 then g
            end
        rescue
            n := n + 1
            print ({EXCEPTIONS}.tag_name)
            retry
        end
    f require pre: out = "x" do end
    g do ensure post: out = "x" end
end

example.ecf:

<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-21-0" name="example">
    <target name="example">
        <root class="EXAMPLE" feature="make"/>
        <option>
            <assertions precondition="true" postcondition="true"/>
        </option>
        <setting name="console_application" value="true"/>
        <library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
        <cluster name="test" location="."/>
    </target>
</system>

Compilation with the options -finalize -keep -config example.ecf -c_compile produces an executable that prints prepost.

Alexander Kogtenkov
  • 5,770
  • 1
  • 27
  • 35
  • These options control the `check`s, not the contracts. I've checked both in GUI and in command line. I can trigger the check violation with `-finalize -keep` but I can't trigger precondition violation. This is what I am looking for. – Ilgiz Mustafin Sep 27 '21 at 18:16
  • @IlgizMustafin I've added an example to the answer. The precondition and postcondition violations are reported as expected in finalized mode. – Alexander Kogtenkov Sep 27 '21 at 18:57
  • It works with your example. There must be something wrong in my program. Thanks for your time! – Ilgiz Mustafin Sep 27 '21 at 19:10
  • @IlgizMustafin Could it be that assertions are not checked for library classes because the monitoring is not requested for the library in the project settings? – Alexander Kogtenkov Sep 28 '21 at 13:36
  • I think there was an error in my code. I will keep an eye for any problems and will keep an example for the next time, if it doesn't work. Thanks again. – Ilgiz Mustafin Sep 28 '21 at 18:50