<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://dev.eiffel.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Nadia+Polikarpova</id>
		<title>EiffelStudio: an EiffelSoftware project - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://dev.eiffel.com/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Nadia+Polikarpova"/>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/Special:Contributions/Nadia_Polikarpova"/>
		<updated>2026-04-29T13:31:30Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.24.1</generator>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=CITADEL&amp;diff=10136</id>
		<title>CITADEL</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=CITADEL&amp;diff=10136"/>
				<updated>2007-12-25T12:33:31Z</updated>
		
		<summary type="html">&lt;p&gt;Nadia Polikarpova: /* Inferring contracts for generic classes */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Assertion checking]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
CITADEL (Contract-Inference Tool that Applies Daikon to the Eiffel Language) is a tool that provides an Eiffel front-end for the Daikon invariant detector. It is being implemented as a Master's project by Nadia Polikarpova supervised by Ilinca Ciupa (ETH).&lt;br /&gt;
&lt;br /&gt;
==Discussions==&lt;br /&gt;
===Unfolded variables===&lt;br /&gt;
 Nadia: Daikon can process values of only few types: five scalar types (boolean, &lt;br /&gt;
  integer, double, string and hashcode) and five more types, which are &lt;br /&gt;
  arrays of these scalars.&lt;br /&gt;
  So, if in Eiffel code we a have a variable of one of basic types &lt;br /&gt;
  (BOOLEAN, NATURAL, INTEGER, CHARACTER, REAL or STRING) we can print &lt;br /&gt;
  its value directly as if it has one of Daikon's types.&lt;br /&gt;
  If, however, we have a variable of any other type, we have to collect &lt;br /&gt;
  all the information about it that is of interest and is available at &lt;br /&gt;
  certain program point, and present this information to Daikon as a set &lt;br /&gt;
  of  variables, which have Daikon types. The information of interest &lt;br /&gt;
  about a variable includes results of all queries that can be called on &lt;br /&gt;
  this variable at this program point.  However, since queries results may &lt;br /&gt;
  themselves be of non-basic types, we have to perform this operation &lt;br /&gt;
  recursively (to a certain depth).&lt;br /&gt;
  For a reference variable information of interest includes also its &lt;br /&gt;
  address (Daikon type &amp;quot;hashcode&amp;quot; is intended for representing object &lt;br /&gt;
  addresses).&lt;br /&gt;
  For example, if we had a variable c: POINT, queries of class POINT &lt;br /&gt;
  available at current program point were `x: REAL', `y: REAL' and `twin: &lt;br /&gt;
  POINT' and unfolding depth were set to 2, then `c.unfolded' would be a &lt;br /&gt;
  set of variables: {$c, c.x, c.y, $c.twin, c.twin.x, c.twin.y}.&lt;br /&gt;
  &lt;br /&gt;
  Containers need special kind of unfolding. If we want Daikon to handle &lt;br /&gt;
  them sensibly, they should be converted to arrays of scalars (to be more &lt;br /&gt;
  precise, it should be done only if all container elements are observable &lt;br /&gt;
  at current program point...). It isn't difficult for descendants of &lt;br /&gt;
  CONTAINER class from standard library. Instrumenter may check, if a &lt;br /&gt;
  variable is an indirect instance of CONTAINER, get its &lt;br /&gt;
  `linear_representation', then traverse it and output as array. I think &lt;br /&gt;
  that in the first version we may leave aside those containers, that &lt;br /&gt;
  aren't inherited from CONTAINER.&lt;br /&gt;
&lt;br /&gt;
====Functions in unfolded form====&lt;br /&gt;
 Ilinca: I'm not sure about the idea of including argument-less functions in &lt;br /&gt;
  this unfolded form. What if the precondition of the function doesn't &lt;br /&gt;
  hold or we run into some kind of trouble when executing the function &lt;br /&gt;
  body (trouble such as the contracts of a sub-call made by this &lt;br /&gt;
  function not holding or other bugs)? On the other hand, including &lt;br /&gt;
  functions would bring significantly more information about the state &lt;br /&gt;
  of the object... Does the Daikon frontend for Java, for instance, by &lt;br /&gt;
  default evaluate functions too as part of the unfolded form of the &lt;br /&gt;
  objects?&lt;br /&gt;
&lt;br /&gt;
 Nadia: Well, this idea is disputable, of cause.&lt;br /&gt;
  In Java considering argument-less functions as variables is more &lt;br /&gt;
  dangerous, because Java, like all C-family languages, encourages &lt;br /&gt;
  side-effects in functions. However, in Daikon front-end for Java there &lt;br /&gt;
  exists an option that allows using functions as variables. Together with &lt;br /&gt;
  enabling this option user has to provide a special &amp;quot;purity&amp;quot; file that &lt;br /&gt;
  lists those functions from the system, that are side-effect free. This &lt;br /&gt;
  feature is described in Daikon User Manual, page 82.&lt;br /&gt;
  Considering functions as variables is even more relevant in Eiffel &lt;br /&gt;
  context by two main reasons. Firstly, Eiffel encourages absence of &lt;br /&gt;
  abstract side-effects in functions (and, I believe, most Eiffel &lt;br /&gt;
  functions indeed do not have abstract side-effect, am I right?). For &lt;br /&gt;
  those cases, when some functions in system are known to have &lt;br /&gt;
  side-effect, we can allow user to specify an &amp;quot;impurity&amp;quot; file, that would &lt;br /&gt;
  list those functions. I think that these cases would be rare.&lt;br /&gt;
  &lt;br /&gt;
    Ilinca: Indeed, I also think these cases would be rare, but, depending on the &lt;br /&gt;
    size of the system, it might be very cumbersome for users to determine &lt;br /&gt;
    these functions.&lt;br /&gt;
&lt;br /&gt;
        Nadia: Well, a parameter may be introduced that will turn this facility on &lt;br /&gt;
        and off. So, if a user knows that there are many impure functions in system, &lt;br /&gt;
        he/she will just turn it off. I think, that its enough for the first version.&lt;br /&gt;
        &lt;br /&gt;
        In future some additional functionality may be introduced. In fact, a user may &lt;br /&gt;
        not know about all impure functions in system (especially in code that was written &lt;br /&gt;
        by someone else). The tool can help user to determine, did anything go wrong with &lt;br /&gt;
        using functions in unfolding. For example, it may do instrumentation twice: first &lt;br /&gt;
        time using only attributes and second time using functions also. As a result two &lt;br /&gt;
        trace files are produces. Then the tool can compare attributes values in two files. &lt;br /&gt;
        If they are the same, then with certain degree of confidence we can say, that called &lt;br /&gt;
        functions had no abstract side effect.&lt;br /&gt;
&lt;br /&gt;
        As I understand, precise analysis of abstract side-effect presence or absence in beyond &lt;br /&gt;
        the state of the art. However, some methods which perform approximate analysis may be &lt;br /&gt;
        introduced.&lt;br /&gt;
&lt;br /&gt;
        Another interesting solution that came to mind is to store object's state each time before &lt;br /&gt;
        calling a function and then recover object after the call. In this case we don't care about &lt;br /&gt;
        function purity, we just get a result that this function might have had, if it was called at &lt;br /&gt;
        this point :)&lt;br /&gt;
&lt;br /&gt;
        Anyway, different partial solutions to this problem may be implemented and user may combine &lt;br /&gt;
        different strategies to get a desired result with a desired degree of confidence.&lt;br /&gt;
&lt;br /&gt;
        Conceptually, my point here is: why an &amp;quot;honest&amp;quot; Eiffel programmer, who never writes impure &lt;br /&gt;
        functions, has to suffer (get less expressive contracts) because of other programmers, who &lt;br /&gt;
        sometimes write impure functions?:)&lt;br /&gt;
&lt;br /&gt;
            Ilinca: :) Indeed, the honest Eiffel programmer shouldn't suffer. So in conclusion, I &lt;br /&gt;
            think we should go for the solution with the file containing the names of impure functions, &lt;br /&gt;
            as Daikon does it. Adding the switch which turns it on and off is also a good idea. &lt;br /&gt;
&lt;br /&gt;
    Ilinca: Something else: what Daikon calls &amp;quot;purity&amp;quot; is actually &lt;br /&gt;
    weak purity, isn't it? (Weak purity means that creations of local &lt;br /&gt;
    variables are allowed in the body of a pure function. Strong purity &lt;br /&gt;
    disallows this.)&lt;br /&gt;
&lt;br /&gt;
        Nadia: Chicory (Java front end) doesn't check purity of functions that are listed in a purity &lt;br /&gt;
        file. User is totally responsible for what he/she writes in this file. So, I would say that, what &lt;br /&gt;
        Chicory calls purity isn't actually any special kind of purity. It only means that user allowed &lt;br /&gt;
        Chicory to call this functions anywhere in the system, and if something goes wrong, it's user's &lt;br /&gt;
        fault&lt;br /&gt;
  &lt;br /&gt;
  Nadia: Secondly, Eiffel advocates uniform access principle. Routine's clients &lt;br /&gt;
  don't have to know, which queries, used in precondition, are attributes &lt;br /&gt;
  and which are functions. If inferred preconditions contained only &lt;br /&gt;
  attributes, it would be inconsistent with uniform access principle, I &lt;br /&gt;
  think...&lt;br /&gt;
&lt;br /&gt;
  As for troubles that may arise when calling functions... As I &lt;br /&gt;
  understand, exception in a function, called when its precondition holds, &lt;br /&gt;
  is a bug. So, if it happens, we can just tell user that we found a bug &lt;br /&gt;
  in certain function and that before inferring contracts the bug should &lt;br /&gt;
  be fixed.&lt;br /&gt;
&lt;br /&gt;
====Checking preconditions (static vs. dynamic)====  &lt;br /&gt;
  The issue with functions' preconditions that you've mentioned isn't a &lt;br /&gt;
  big problem. If after unfolding we got a variable of the form, e.g., &lt;br /&gt;
  `x.f1.f2', where `f1' and `f2' are functions, printing instructions for &lt;br /&gt;
  this variable can be like this:&lt;br /&gt;
    if x.f1_precondition_holds and then x.f1.f2_precondition_holds&lt;br /&gt;
    then&lt;br /&gt;
       print (x.f1.f2)&lt;br /&gt;
    else&lt;br /&gt;
       print (Nonsensical)&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
  &amp;quot;Nonsensical&amp;quot; is a special Daikon value that indicates that variable &lt;br /&gt;
  cannot be evaluated.&lt;br /&gt;
  Function preconditions are known after parsing. To be able to evaluate &lt;br /&gt;
  them separately, we may, for example, wrap them into functions. &lt;br /&gt;
  `f1_precondition_holds' in the above code is an example of such a &lt;br /&gt;
  function, that was introduced by instrumenter and added to x's &lt;br /&gt;
  generating class.&lt;br /&gt;
  &lt;br /&gt;
    Ilinca: I don't think it's that easy, mainly because of polymorphism. Statically &lt;br /&gt;
    you can't determine the type that x will be a direct instance of at &lt;br /&gt;
    runtime. Hence, you don't know which preconditions to wrap. Of course, &lt;br /&gt;
    since redefined routines can keep or weaken the preconditions of the &lt;br /&gt;
    original routines, you can take the pessimistic approach of wrapping &lt;br /&gt;
    only the precondition of the function from the static type of x, but &lt;br /&gt;
    then you might miss cases in which the weakened version of the &lt;br /&gt;
    precondition does hold. Do you understand my point?&lt;br /&gt;
&lt;br /&gt;
        Nadia: Yeah, I see...&lt;br /&gt;
        I think that the main question here is: should we check &amp;quot;static&amp;quot; or &amp;quot;dynamic&amp;quot; &lt;br /&gt;
        preconditions when calling a function?&lt;br /&gt;
&lt;br /&gt;
        On the one hand, in Eiffel we can write something like:&lt;br /&gt;
        class A&lt;br /&gt;
           ...&lt;br /&gt;
           sqrt (x: REAL): REAL&lt;br /&gt;
               require&lt;br /&gt;
                   x &amp;gt;= 0.0&lt;br /&gt;
               do ... end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        class B&lt;br /&gt;
           inherit A&lt;br /&gt;
              redefine sqrt end&lt;br /&gt;
           ...&lt;br /&gt;
           sqrt (x: REAL): REAL&lt;br /&gt;
               require else&lt;br /&gt;
                 True&lt;br /&gt;
               do ... end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        class TEST&lt;br /&gt;
            ...&lt;br /&gt;
            an_a: A&lt;br /&gt;
&lt;br /&gt;
            make is&lt;br /&gt;
               do&lt;br /&gt;
                    create {B} an_a&lt;br /&gt;
                    print (an_a.sqrt (-1.0))&lt;br /&gt;
               end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        It works, and assertion checking mechanism doesn't indicate any error.&lt;br /&gt;
        But, on the other hand, is it legal? Am I allowed to call a function if it's &lt;br /&gt;
        static precondition doesn't hold?&lt;br /&gt;
&lt;br /&gt;
        As I understand, if I want to make sure that it's legal to call a routine at some &lt;br /&gt;
        program point, I have to check it's static precondition. Even if today I'm sure that &lt;br /&gt;
        dynamic type of `an_a' is always `B', this needn't remain the same tomorrow...&lt;br /&gt;
&lt;br /&gt;
            Ilinca: That's correct. If the &amp;quot;static&amp;quot; precondition of a routine holds, this &lt;br /&gt;
            implies of course that the preconditions of all its redefinitions will also hold. &lt;br /&gt;
            But I was calling this approach &amp;quot;pessimistic&amp;quot; because the precondition of a redefined &lt;br /&gt;
            version of a routine may hold even though the &amp;quot;static&amp;quot; precondition doesn't.&lt;br /&gt;
&lt;br /&gt;
        So, if a programmer wanted to know function value at a program point, he/she would check &lt;br /&gt;
        its static precondition. Then why instrumenter should act differently? Well, actually &lt;br /&gt;
        there is a difference:  instrumenter not only avoids function call when precondition &lt;br /&gt;
        doesn't hold, but also claims that function value is nonsensical. From one point of view, &lt;br /&gt;
        such behavior is incorrect, because function actually could be called and a sensible value &lt;br /&gt;
        could be received. From the other point, since it was illegal to call the function this time, &lt;br /&gt;
        it makes sense to declare function value nonsensical.&lt;br /&gt;
&lt;br /&gt;
        To sum up, I think that it is rather a philosophical then a technical problem, but, as for me, &lt;br /&gt;
        checking static preconditions is more appropriate.&lt;br /&gt;
&lt;br /&gt;
        However, if we wanted to check a dynamic precondition, it's also possible. We can wrap function's &lt;br /&gt;
        precondition into a special function and redefine that special function any time the original &lt;br /&gt;
        function is redefined. It is possible since instrumenter has access to the whole system.&lt;br /&gt;
&lt;br /&gt;
            Ilinca: Well, this would definitely be the more... correct solution, but it's also a lot more &lt;br /&gt;
            work. Couldn't this also be done by not wrapping the function, but simply calling it and adding &lt;br /&gt;
            some exception handling code to the unfolder? I mean, the unfolder would try to call all &lt;br /&gt;
            argument-less functions of a class on an object, and, if it gets a precondition violation, &lt;br /&gt;
            it catches the exception and it declares that particular function as nonsensical?&lt;br /&gt;
&lt;br /&gt;
 Nadia: I would like to return to the subject of checking &amp;quot;static&amp;quot; or &amp;quot;dynamic&amp;quot; preconditions &lt;br /&gt;
 before function calls in unfolding. I think that this problem arises because the semantics &lt;br /&gt;
 of special variable value &amp;quot;nonsensical&amp;quot; in Daikon is ambiguous.&lt;br /&gt;
&lt;br /&gt;
 In Java and C there are no preconditions, so this value is originally used in Daikon for the &lt;br /&gt;
 only purpose: if a pointer of reference is null, then the dereferenced value (and its attributes, &lt;br /&gt;
 if the value is not of primitive type) is declared &amp;quot;nonsensical&amp;quot;. In Eiffel we will use &lt;br /&gt;
 &amp;quot;nonsensical&amp;quot; for this purpose too: if a reference entity is void, then its queries will be output &lt;br /&gt;
 as &amp;quot;nonsensical&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
 However, in Eiffel we have one more source of problems with evaluating variables: if a variable is &lt;br /&gt;
 a result of a function call, then function precondition may not hold, so we won't be able to &lt;br /&gt;
 evaluate its result. In this case the variable value should also be declared &amp;quot;nonsensical&amp;quot;, because &lt;br /&gt;
 this is the only special value in Daikon, which denotes that variable can't be evaluated. However, &lt;br /&gt;
 in this case there appears a question: what does it mean that the variable can't be evaluated? Does &lt;br /&gt;
 it mean that something terrible will happen (e.g., exception), if we try to evaluate it? Or does &lt;br /&gt;
 it mean that it isn't legal to evaluate this variable in this program state?&lt;br /&gt;
&lt;br /&gt;
 If we take the first point, then we should check dynamic precondition, because if static precondition &lt;br /&gt;
 doesn't hold, but dynamic does, nothing terrible will happen during function call.&lt;br /&gt;
&lt;br /&gt;
 If we take the second point, we should check static precondition, because if it doesn't hold then &lt;br /&gt;
 it's illegal to call this function, even if dynamic precondition holds. This point seems more &lt;br /&gt;
 correct to me, and here is an example that illustrates the situation.&lt;br /&gt;
&lt;br /&gt;
 Consider class `INT_LIST' (with feature `item' that has a precondition `not off') and it's heir - &lt;br /&gt;
 class EXTRAPOLATED_INT_LIST (that weakens precondition of `item'):&lt;br /&gt;
&lt;br /&gt;
 class INT_LIST&lt;br /&gt;
 ...&lt;br /&gt;
 feature&lt;br /&gt;
    item: INTEGER is&lt;br /&gt;
       require&lt;br /&gt;
          not off&lt;br /&gt;
       ...&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class EXTRAPOLATED_INT_LIST&lt;br /&gt;
 inherit&lt;br /&gt;
    INT_LIST&lt;br /&gt;
    redefine&lt;br /&gt;
       item&lt;br /&gt;
    end&lt;br /&gt;
 ...&lt;br /&gt;
 feature&lt;br /&gt;
    item: INTEGER is&lt;br /&gt;
       require else True&lt;br /&gt;
       do&lt;br /&gt;
          if not off then&lt;br /&gt;
             Result := Precursor&lt;br /&gt;
          else&lt;br /&gt;
             Result := 0&lt;br /&gt;
          end&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Consider also class CLIENT, which is a client of INT_LIST:&lt;br /&gt;
&lt;br /&gt;
 class CLIENT&lt;br /&gt;
 ...&lt;br /&gt;
 feature&lt;br /&gt;
    test (a_list: INT_LIST) is&lt;br /&gt;
       do ... end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Imagine that during system execution, when contracts were inferred, actual argument of `test' was &lt;br /&gt;
 always a direct instance of EXTRAPOLATED_INT_LIST,  and in addition it was always passed to this &lt;br /&gt;
 procedure in such a state that cursor was before the first element (`off' was true). If we check &lt;br /&gt;
 dynamic preconditions for functions in unfolding, than a precondition, inferred for `test', will &lt;br /&gt;
 be something like this:&lt;br /&gt;
&lt;br /&gt;
 require&lt;br /&gt;
   a_list /= Void&lt;br /&gt;
   a_list.off&lt;br /&gt;
   a_list.item = 0&lt;br /&gt;
&lt;br /&gt;
 But this contract isn't correct (as for me), although it is, certainly, true for a specific system &lt;br /&gt;
 execution. It becomes a little more correct, if we infer:&lt;br /&gt;
&lt;br /&gt;
 require&lt;br /&gt;
   a_list /= Void&lt;br /&gt;
   a_list.off&lt;br /&gt;
   a_list.generator = &amp;quot;EXTRAPOLATED_INT_LIST&amp;quot;&lt;br /&gt;
   a_list.item = 0&lt;br /&gt;
&lt;br /&gt;
 However, such contracts (connected with dynamic type of variable) seem useless to me. One of the &lt;br /&gt;
 goals of dynamic contract inference is to eliminate those properties that happened by chance and &lt;br /&gt;
 are not intended properties of the code. Properties that are connected with dynamic types definitely &lt;br /&gt;
 happen by chance: they can't be intended properties, because if programmer wanted his software to &lt;br /&gt;
 have such a property, he would change static entity type to a more specific (based on descendant).&lt;br /&gt;
&lt;br /&gt;
 Such properties may be useful only if we treat them not as contracts but rather as some kind of &lt;br /&gt;
 runtime statistics. Programmer may be interested in information that is true for a specific system &lt;br /&gt;
 execution, e.g. for debug purposes. It might be useful to add such a feature (inference of dynamic &lt;br /&gt;
 type information and properties, connected with dynamic types) in future, but it isn't &amp;quot;classic&amp;quot; &lt;br /&gt;
 contract inference, as for me, so I don't think that we need it in the first version. And if we &lt;br /&gt;
 don't want to know anything about dynamic types, then we should check static preconditions of &lt;br /&gt;
 functions during unfolding.&lt;br /&gt;
&lt;br /&gt;
====Checking hand-written contracts====&lt;br /&gt;
    Ilinca: There's one further problem with this approach: when a function &lt;br /&gt;
    is called as part of the evaluation of a contract, this function's &lt;br /&gt;
    contracts are not checked. The reason for this is to avoid infinite &lt;br /&gt;
    loops. If you wrap your precondition into a function, the contracts of &lt;br /&gt;
    any routines it calls will be evaluated, and thus the system can &lt;br /&gt;
    actually behave differently.&lt;br /&gt;
&lt;br /&gt;
    Should we check at all the hand-written contracts of a system for which CITADEL  &lt;br /&gt;
    is trying to infer contracts? We could also start from the assumption that Daikon &lt;br /&gt;
    uses: the tool is given a set of passing test cases and from those it has to infer &lt;br /&gt;
    contracts. If the inferred contracts somehow contradict the hand-written ones, then &lt;br /&gt;
    there's a problem in the system, and the source of the  problem may be that the &lt;br /&gt;
    hand-written contracts are faulty. What do you think?&lt;br /&gt;
    &lt;br /&gt;
        Nadia: I think that it makes sense to turn assertion checking off when running &lt;br /&gt;
        instrumented system. This will solve the problem with functions inside wrapped &lt;br /&gt;
        preconditions, which you've mentioned.&lt;br /&gt;
&lt;br /&gt;
        In current version instrumented system is supposed to behave exactly the same way &lt;br /&gt;
        as the original system did (except for creating a trace file). So, if a user was &lt;br /&gt;
        sure about the original, hand-written contracts and wanted to check the system against &lt;br /&gt;
        them, he/she could run the original system with assertion checking on, make sure that &lt;br /&gt;
        everything is ok and after that perform contract inference.&lt;br /&gt;
&lt;br /&gt;
        On the other hand, returning to using functions in unfolding: for these calls we have to &lt;br /&gt;
        check hand-written preconditions, because they were introduced by instrumenter, so they are &lt;br /&gt;
        not parts of &amp;quot;passing test cases&amp;quot;. Fortunately, as you said before, erroneous preconditions &lt;br /&gt;
        are very rare.&lt;br /&gt;
&lt;br /&gt;
====Checking preconditions (wrapping vs. qualification)====&lt;br /&gt;
 Nadia: I started implementing function preconditions checks in unfolding recently and realized &lt;br /&gt;
 that my first idea (to wrap these preconditions into functions) has an important disadvantage. &lt;br /&gt;
 Without creating new functions for preconditions if we instrument a class, then only the source &lt;br /&gt;
 code of that very class changes. However, if during class instrumentation we add functions to &lt;br /&gt;
 its clients, then the source code of those clients also changes. It isn't a disaster, of cause, &lt;br /&gt;
 but it's an unpleasant property, as for me. It would be nice, if class instrumentation affected &lt;br /&gt;
 only the class itself.&lt;br /&gt;
&lt;br /&gt;
 The other solution is not to wrap preconditions into functions, but to &amp;quot;qualify&amp;quot; them: if we want &lt;br /&gt;
 to check precondition before calling a function `x.f', we should take f's precondition and &lt;br /&gt;
 replaced all unqualified calls in it by qualified calls with target `x' and all occurrences of &lt;br /&gt;
 `Current' by `x'. This replacement is not difficult conceptually, but its implementation is quite &lt;br /&gt;
 voluminous (during this operation we have to replace some identifiers in an expression with function &lt;br /&gt;
 calls, so we need to redefine all `process_&amp;lt;something&amp;gt;' procedures of ET_AST_ITERATOR, where &lt;br /&gt;
 &amp;lt;something&amp;gt; can appear in expression and can contain identifiers).&lt;br /&gt;
&lt;br /&gt;
 What do you think about these two solutions (&amp;quot;wrapping into functions&amp;quot; and &amp;quot;qualification&amp;quot;)?&lt;br /&gt;
&lt;br /&gt;
    Ilinca: I think the best way to go is to wrap the precondition in a function in the class that &lt;br /&gt;
    it belongs to. Wrapping it in a function in clients would break encapsulation: you would only &lt;br /&gt;
    be allowed to access the exported features. I don't see any advantages of qualification over &lt;br /&gt;
    function-wrapping, so I think it makes sense to choose the least-work solution&lt;br /&gt;
&lt;br /&gt;
        Nadia: My previous explanation of the problem with &amp;quot;wrapping&amp;quot; was a little bit confused &lt;br /&gt;
        (I wrote that functions have to be added to clients of instrumented class, but actually &lt;br /&gt;
        I meant quite the opposite: that they should be added to suppliers:) )&lt;br /&gt;
&lt;br /&gt;
        Wrapping a precondition in a function in the class that it belongs to is exactly what I &lt;br /&gt;
        wanted to do firstly. The reason for it was that, if we instrument a class `C' and it has, &lt;br /&gt;
        say, an attribute `x: LIST[INTEGER]', then unfolded form of `Current' variable will include &lt;br /&gt;
        a variable `x.first'. Precondition of function `first' in class LIST is `not empty'. However, &lt;br /&gt;
        we need to check this precondition not inside LIST, but inside routines of class `C'. In fact, &lt;br /&gt;
        printing instruction for variable `x.first' should be guarded by condition like this:&lt;br /&gt;
        if x /= Void and then not x.empty then&lt;br /&gt;
           print (x.first)&lt;br /&gt;
        end&lt;br /&gt;
        We can't just take a precondition from `first' and insert it into the guarding condition as is, &lt;br /&gt;
        instead we should &amp;quot;qualify&amp;quot; the call to `empty' with target `x'.&lt;br /&gt;
&lt;br /&gt;
        Firstly qualification seemed too complex to me, so I decided to wrap `not empty' into function, say,&lt;br /&gt;
        `first_precondition: BOOLEAN' and add it to class `LIST', so that inside `C' I can check simpler &lt;br /&gt;
        condition before printing x.first:&lt;br /&gt;
        if x /= Void and then x.first_precondition then&lt;br /&gt;
            print (x.first)&lt;br /&gt;
        end.&lt;br /&gt;
        However, as you can see, it involves modifying class `LIST' (and possibly any other supplier of &lt;br /&gt;
        `C') while instrumenting `C'. If only `C' changed, then we could print only its source code after &lt;br /&gt;
        instrumentation, we could compile only `C' (if incremental compilation is used) and don't recompile &lt;br /&gt;
        base library, we would have no problems with tracking added functions (the problems are like this: &lt;br /&gt;
        if we instrument class `LIST' after `C', we probably don't want neither to instrument added functions, &lt;br /&gt;
        nor to see them in unfolded form of `Current' variable of class `LIST'). As for me, wrapping adds &lt;br /&gt;
        surplus dependencies into the system, and software never benefits from dependencies :)&lt;br /&gt;
&lt;br /&gt;
        That is why later I inclined to &amp;quot;qualification&amp;quot; solution. Actually, I have already mostly implemented &lt;br /&gt;
        it:) Current implementation might be incomplete, there are several syntactic constructs that it doesn't &lt;br /&gt;
        handle, because I'm not sure that they can appear in preconditions, but I'll check it and fix the problem.&lt;br /&gt;
&lt;br /&gt;
            Ilinca: Ok, so what I was thinking about was that you wanted to wrap the whole precondition of &lt;br /&gt;
            `first' into a function in class C. So, in class C you would have a routine&lt;br /&gt;
            precondition_first (l: LIST[G]): BOOLEAN&lt;br /&gt;
                 require&lt;br /&gt;
                      l_not_void: l /= Void&lt;br /&gt;
                 do&lt;br /&gt;
                      Result := not l.empty&lt;br /&gt;
                 end&lt;br /&gt;
            Then the guard for printing x.first would be&lt;br /&gt;
                 if x /= Void and then precondition_first (x) then&lt;br /&gt;
                      print (x.first)&lt;br /&gt;
                 end&lt;br /&gt;
&lt;br /&gt;
            But of course whether or not you wrap the precondition in a function or just quote it in the if &lt;br /&gt;
            statement does not make a big difference.&lt;br /&gt;
&lt;br /&gt;
 One more question: should the tool allow instrumenting library classes? If a library was precompiled, &lt;br /&gt;
 then instrumenting any of its classes will result in recompiling the whole library, am I right? Are &lt;br /&gt;
 precompiled libraries anyway recompiled during system finalization or not? (It matters for choosing &lt;br /&gt;
 between &amp;quot;wrapping into functions&amp;quot; and &amp;quot;qualification&amp;quot; solutions, because &amp;quot;wrapping into functions&amp;quot; can &lt;br /&gt;
 change library classes, even if user wants to implement only classes from his own clusters).&lt;br /&gt;
&lt;br /&gt;
===Support for loop invariants===&lt;br /&gt;
 Ilinca: Does the &amp;quot;classic&amp;quot; Daikon support loop invariants?&lt;br /&gt;
&lt;br /&gt;
 Nadia: Daikon uses standard program point &lt;br /&gt;
  suffixes to infer more invariants. E.g., it understands that &lt;br /&gt;
  some_routine:::ENTER and some_routine:::EXIT are entry and exit points &lt;br /&gt;
  of the same routine. Thanks to this, it knows `old' values of variables &lt;br /&gt;
  at exit and can infer invariants like &amp;quot;x = old x&amp;quot;. As I understood, if &lt;br /&gt;
  Daikon sees an unknown suffix, it treats corresponding program point as, &lt;br /&gt;
  so to say, &amp;quot;standalone&amp;quot; and doesn't try to connect it with any other.&lt;br /&gt;
  We don't need any extra support from Daikon to handle loop invariants.&lt;br /&gt;
&lt;br /&gt;
    Ilinca: You'll have to pay attention though to inserting the corresponding &lt;br /&gt;
    program point(s) at the right location(s). A loop invariant has to hold after &lt;br /&gt;
    initialization (the &amp;quot;from&amp;quot; clause) and be preserved by the loop body, i.e. it &lt;br /&gt;
    must hold after every execution of the loop body, including when the exit &lt;br /&gt;
    condition becomes true. So actually, I guess the program point should be in &lt;br /&gt;
    the &amp;quot;until&amp;quot; clause, because it gets evaluated after initialization and then &lt;br /&gt;
    after every execution of the loop body. What do you think?&lt;br /&gt;
&lt;br /&gt;
        Nadia: `Until' clause is conceptually the right place, but instructions &lt;br /&gt;
        can't be inserted in there. So printing instructions can be inserted at &lt;br /&gt;
        the end of `from' clause and at the end of  `loop' clause. As I understand, &lt;br /&gt;
        all variable values that are observed in `until' condition appear at one of &lt;br /&gt;
        those points.&lt;br /&gt;
  &lt;br /&gt;
  Nadia: If we want to infer loop invariants, we should introduce a separate &lt;br /&gt;
  program point for each loop. So, we need a way to distinguish loops &lt;br /&gt;
  within a routine. One way is to take its position in source code as &lt;br /&gt;
  index. However, I thought, that position is too unstable to become loop &lt;br /&gt;
  identifier, so I chose instruction number instead. These numbers are &lt;br /&gt;
  unique numbers of instructions within surrounding routine, they may be &lt;br /&gt;
  used not only for loops, but for arbitrary instructions. &lt;br /&gt;
  CI_INSTRUCTION_COUNTER is responsible for counting instruction while &lt;br /&gt;
  iterating through AST.&lt;br /&gt;
&lt;br /&gt;
===Inferring contracts for generic classes===&lt;br /&gt;
 Nadia: there are actually two different cases.&lt;br /&gt;
  1. Contracts inside generic classes. This is not really a problem. &lt;br /&gt;
  Entities, which have parameter type, can be treated as if their &lt;br /&gt;
  generator is constraining class (ANY, if genericity is unconstrained).&lt;br /&gt;
  &lt;br /&gt;
  2. Contracts in clients of generic classes. Here some problems arise. If &lt;br /&gt;
  we have an entity `x: ARRAYED_LIST[INTEGER]', its unfolding involves &lt;br /&gt;
  processing the `item' query. `item' is declared to be of type `G' in &lt;br /&gt;
  ARRAYED_LIST and, as I understand, parsing is not enough (some type &lt;br /&gt;
  analysis is needed) to infer that `G' means `INTEGER' in current &lt;br /&gt;
  context. Two approaches to this problem, that I see at present, are: &lt;br /&gt;
  perform such a type analysis in compile time (with the help of gobo &lt;br /&gt;
  compilation facilities) or leave some unfolding work until runtime, &lt;br /&gt;
  when reflections may be used to determine variable's generating class.&lt;br /&gt;
&lt;br /&gt;
      Ilinca: As far as I know gobo is able to do this kind of analysis. &lt;br /&gt;
      I think it's preferable that all variables get unfolded statically &lt;br /&gt;
      -- it would be a cleaner system design. Besides, doesn't Daikon need &lt;br /&gt;
      the .decls files as input?&lt;br /&gt;
&lt;br /&gt;
          Nadia: I also think that static unfolding is better.&lt;br /&gt;
&lt;br /&gt;
          As for .decls files: if a batch version of Daikon is used, then Daikon &lt;br /&gt;
          itself is run only after instrumented system terminates. A .decls file &lt;br /&gt;
          thus may be generated not only during instrumentation, but also during &lt;br /&gt;
          instrumented system execution.&lt;br /&gt;
&lt;br /&gt;
          If an on-line Daikon version is used, Daikon is executed simultaneously &lt;br /&gt;
          with instrumented system. However, even in this case it is possible to &lt;br /&gt;
          generate program point declarations during runtime. Actually, Daikon &lt;br /&gt;
          allows to place declarations not only in separate .decls file, but also &lt;br /&gt;
          inside the .dtace file, together with program point samples. The only &lt;br /&gt;
          requirement is that a declaration of a program point must appear before &lt;br /&gt;
          any sample of this program point.&lt;br /&gt;
&lt;br /&gt;
          On my opinion, a separate .decls file, generated during instrumentation &lt;br /&gt;
          phase, is a better design decision.&lt;/div&gt;</summary>
		<author><name>Nadia Polikarpova</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=CITADEL&amp;diff=10135</id>
		<title>CITADEL</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=CITADEL&amp;diff=10135"/>
				<updated>2007-12-25T12:28:00Z</updated>
		
		<summary type="html">&lt;p&gt;Nadia Polikarpova: /* Support for loop invariants */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Assertion checking]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
CITADEL (Contract-Inference Tool that Applies Daikon to the Eiffel Language) is a tool that provides an Eiffel front-end for the Daikon invariant detector. It is being implemented as a Master's project by Nadia Polikarpova supervised by Ilinca Ciupa (ETH).&lt;br /&gt;
&lt;br /&gt;
==Discussions==&lt;br /&gt;
===Unfolded variables===&lt;br /&gt;
 Nadia: Daikon can process values of only few types: five scalar types (boolean, &lt;br /&gt;
  integer, double, string and hashcode) and five more types, which are &lt;br /&gt;
  arrays of these scalars.&lt;br /&gt;
  So, if in Eiffel code we a have a variable of one of basic types &lt;br /&gt;
  (BOOLEAN, NATURAL, INTEGER, CHARACTER, REAL or STRING) we can print &lt;br /&gt;
  its value directly as if it has one of Daikon's types.&lt;br /&gt;
  If, however, we have a variable of any other type, we have to collect &lt;br /&gt;
  all the information about it that is of interest and is available at &lt;br /&gt;
  certain program point, and present this information to Daikon as a set &lt;br /&gt;
  of  variables, which have Daikon types. The information of interest &lt;br /&gt;
  about a variable includes results of all queries that can be called on &lt;br /&gt;
  this variable at this program point.  However, since queries results may &lt;br /&gt;
  themselves be of non-basic types, we have to perform this operation &lt;br /&gt;
  recursively (to a certain depth).&lt;br /&gt;
  For a reference variable information of interest includes also its &lt;br /&gt;
  address (Daikon type &amp;quot;hashcode&amp;quot; is intended for representing object &lt;br /&gt;
  addresses).&lt;br /&gt;
  For example, if we had a variable c: POINT, queries of class POINT &lt;br /&gt;
  available at current program point were `x: REAL', `y: REAL' and `twin: &lt;br /&gt;
  POINT' and unfolding depth were set to 2, then `c.unfolded' would be a &lt;br /&gt;
  set of variables: {$c, c.x, c.y, $c.twin, c.twin.x, c.twin.y}.&lt;br /&gt;
  &lt;br /&gt;
  Containers need special kind of unfolding. If we want Daikon to handle &lt;br /&gt;
  them sensibly, they should be converted to arrays of scalars (to be more &lt;br /&gt;
  precise, it should be done only if all container elements are observable &lt;br /&gt;
  at current program point...). It isn't difficult for descendants of &lt;br /&gt;
  CONTAINER class from standard library. Instrumenter may check, if a &lt;br /&gt;
  variable is an indirect instance of CONTAINER, get its &lt;br /&gt;
  `linear_representation', then traverse it and output as array. I think &lt;br /&gt;
  that in the first version we may leave aside those containers, that &lt;br /&gt;
  aren't inherited from CONTAINER.&lt;br /&gt;
&lt;br /&gt;
====Functions in unfolded form====&lt;br /&gt;
 Ilinca: I'm not sure about the idea of including argument-less functions in &lt;br /&gt;
  this unfolded form. What if the precondition of the function doesn't &lt;br /&gt;
  hold or we run into some kind of trouble when executing the function &lt;br /&gt;
  body (trouble such as the contracts of a sub-call made by this &lt;br /&gt;
  function not holding or other bugs)? On the other hand, including &lt;br /&gt;
  functions would bring significantly more information about the state &lt;br /&gt;
  of the object... Does the Daikon frontend for Java, for instance, by &lt;br /&gt;
  default evaluate functions too as part of the unfolded form of the &lt;br /&gt;
  objects?&lt;br /&gt;
&lt;br /&gt;
 Nadia: Well, this idea is disputable, of cause.&lt;br /&gt;
  In Java considering argument-less functions as variables is more &lt;br /&gt;
  dangerous, because Java, like all C-family languages, encourages &lt;br /&gt;
  side-effects in functions. However, in Daikon front-end for Java there &lt;br /&gt;
  exists an option that allows using functions as variables. Together with &lt;br /&gt;
  enabling this option user has to provide a special &amp;quot;purity&amp;quot; file that &lt;br /&gt;
  lists those functions from the system, that are side-effect free. This &lt;br /&gt;
  feature is described in Daikon User Manual, page 82.&lt;br /&gt;
  Considering functions as variables is even more relevant in Eiffel &lt;br /&gt;
  context by two main reasons. Firstly, Eiffel encourages absence of &lt;br /&gt;
  abstract side-effects in functions (and, I believe, most Eiffel &lt;br /&gt;
  functions indeed do not have abstract side-effect, am I right?). For &lt;br /&gt;
  those cases, when some functions in system are known to have &lt;br /&gt;
  side-effect, we can allow user to specify an &amp;quot;impurity&amp;quot; file, that would &lt;br /&gt;
  list those functions. I think that these cases would be rare.&lt;br /&gt;
  &lt;br /&gt;
    Ilinca: Indeed, I also think these cases would be rare, but, depending on the &lt;br /&gt;
    size of the system, it might be very cumbersome for users to determine &lt;br /&gt;
    these functions.&lt;br /&gt;
&lt;br /&gt;
        Nadia: Well, a parameter may be introduced that will turn this facility on &lt;br /&gt;
        and off. So, if a user knows that there are many impure functions in system, &lt;br /&gt;
        he/she will just turn it off. I think, that its enough for the first version.&lt;br /&gt;
        &lt;br /&gt;
        In future some additional functionality may be introduced. In fact, a user may &lt;br /&gt;
        not know about all impure functions in system (especially in code that was written &lt;br /&gt;
        by someone else). The tool can help user to determine, did anything go wrong with &lt;br /&gt;
        using functions in unfolding. For example, it may do instrumentation twice: first &lt;br /&gt;
        time using only attributes and second time using functions also. As a result two &lt;br /&gt;
        trace files are produces. Then the tool can compare attributes values in two files. &lt;br /&gt;
        If they are the same, then with certain degree of confidence we can say, that called &lt;br /&gt;
        functions had no abstract side effect.&lt;br /&gt;
&lt;br /&gt;
        As I understand, precise analysis of abstract side-effect presence or absence in beyond &lt;br /&gt;
        the state of the art. However, some methods which perform approximate analysis may be &lt;br /&gt;
        introduced.&lt;br /&gt;
&lt;br /&gt;
        Another interesting solution that came to mind is to store object's state each time before &lt;br /&gt;
        calling a function and then recover object after the call. In this case we don't care about &lt;br /&gt;
        function purity, we just get a result that this function might have had, if it was called at &lt;br /&gt;
        this point :)&lt;br /&gt;
&lt;br /&gt;
        Anyway, different partial solutions to this problem may be implemented and user may combine &lt;br /&gt;
        different strategies to get a desired result with a desired degree of confidence.&lt;br /&gt;
&lt;br /&gt;
        Conceptually, my point here is: why an &amp;quot;honest&amp;quot; Eiffel programmer, who never writes impure &lt;br /&gt;
        functions, has to suffer (get less expressive contracts) because of other programmers, who &lt;br /&gt;
        sometimes write impure functions?:)&lt;br /&gt;
&lt;br /&gt;
            Ilinca: :) Indeed, the honest Eiffel programmer shouldn't suffer. So in conclusion, I &lt;br /&gt;
            think we should go for the solution with the file containing the names of impure functions, &lt;br /&gt;
            as Daikon does it. Adding the switch which turns it on and off is also a good idea. &lt;br /&gt;
&lt;br /&gt;
    Ilinca: Something else: what Daikon calls &amp;quot;purity&amp;quot; is actually &lt;br /&gt;
    weak purity, isn't it? (Weak purity means that creations of local &lt;br /&gt;
    variables are allowed in the body of a pure function. Strong purity &lt;br /&gt;
    disallows this.)&lt;br /&gt;
&lt;br /&gt;
        Nadia: Chicory (Java front end) doesn't check purity of functions that are listed in a purity &lt;br /&gt;
        file. User is totally responsible for what he/she writes in this file. So, I would say that, what &lt;br /&gt;
        Chicory calls purity isn't actually any special kind of purity. It only means that user allowed &lt;br /&gt;
        Chicory to call this functions anywhere in the system, and if something goes wrong, it's user's &lt;br /&gt;
        fault&lt;br /&gt;
  &lt;br /&gt;
  Nadia: Secondly, Eiffel advocates uniform access principle. Routine's clients &lt;br /&gt;
  don't have to know, which queries, used in precondition, are attributes &lt;br /&gt;
  and which are functions. If inferred preconditions contained only &lt;br /&gt;
  attributes, it would be inconsistent with uniform access principle, I &lt;br /&gt;
  think...&lt;br /&gt;
&lt;br /&gt;
  As for troubles that may arise when calling functions... As I &lt;br /&gt;
  understand, exception in a function, called when its precondition holds, &lt;br /&gt;
  is a bug. So, if it happens, we can just tell user that we found a bug &lt;br /&gt;
  in certain function and that before inferring contracts the bug should &lt;br /&gt;
  be fixed.&lt;br /&gt;
&lt;br /&gt;
====Checking preconditions (static vs. dynamic)====  &lt;br /&gt;
  The issue with functions' preconditions that you've mentioned isn't a &lt;br /&gt;
  big problem. If after unfolding we got a variable of the form, e.g., &lt;br /&gt;
  `x.f1.f2', where `f1' and `f2' are functions, printing instructions for &lt;br /&gt;
  this variable can be like this:&lt;br /&gt;
    if x.f1_precondition_holds and then x.f1.f2_precondition_holds&lt;br /&gt;
    then&lt;br /&gt;
       print (x.f1.f2)&lt;br /&gt;
    else&lt;br /&gt;
       print (Nonsensical)&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
  &amp;quot;Nonsensical&amp;quot; is a special Daikon value that indicates that variable &lt;br /&gt;
  cannot be evaluated.&lt;br /&gt;
  Function preconditions are known after parsing. To be able to evaluate &lt;br /&gt;
  them separately, we may, for example, wrap them into functions. &lt;br /&gt;
  `f1_precondition_holds' in the above code is an example of such a &lt;br /&gt;
  function, that was introduced by instrumenter and added to x's &lt;br /&gt;
  generating class.&lt;br /&gt;
  &lt;br /&gt;
    Ilinca: I don't think it's that easy, mainly because of polymorphism. Statically &lt;br /&gt;
    you can't determine the type that x will be a direct instance of at &lt;br /&gt;
    runtime. Hence, you don't know which preconditions to wrap. Of course, &lt;br /&gt;
    since redefined routines can keep or weaken the preconditions of the &lt;br /&gt;
    original routines, you can take the pessimistic approach of wrapping &lt;br /&gt;
    only the precondition of the function from the static type of x, but &lt;br /&gt;
    then you might miss cases in which the weakened version of the &lt;br /&gt;
    precondition does hold. Do you understand my point?&lt;br /&gt;
&lt;br /&gt;
        Nadia: Yeah, I see...&lt;br /&gt;
        I think that the main question here is: should we check &amp;quot;static&amp;quot; or &amp;quot;dynamic&amp;quot; &lt;br /&gt;
        preconditions when calling a function?&lt;br /&gt;
&lt;br /&gt;
        On the one hand, in Eiffel we can write something like:&lt;br /&gt;
        class A&lt;br /&gt;
           ...&lt;br /&gt;
           sqrt (x: REAL): REAL&lt;br /&gt;
               require&lt;br /&gt;
                   x &amp;gt;= 0.0&lt;br /&gt;
               do ... end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        class B&lt;br /&gt;
           inherit A&lt;br /&gt;
              redefine sqrt end&lt;br /&gt;
           ...&lt;br /&gt;
           sqrt (x: REAL): REAL&lt;br /&gt;
               require else&lt;br /&gt;
                 True&lt;br /&gt;
               do ... end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        class TEST&lt;br /&gt;
            ...&lt;br /&gt;
            an_a: A&lt;br /&gt;
&lt;br /&gt;
            make is&lt;br /&gt;
               do&lt;br /&gt;
                    create {B} an_a&lt;br /&gt;
                    print (an_a.sqrt (-1.0))&lt;br /&gt;
               end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        It works, and assertion checking mechanism doesn't indicate any error.&lt;br /&gt;
        But, on the other hand, is it legal? Am I allowed to call a function if it's &lt;br /&gt;
        static precondition doesn't hold?&lt;br /&gt;
&lt;br /&gt;
        As I understand, if I want to make sure that it's legal to call a routine at some &lt;br /&gt;
        program point, I have to check it's static precondition. Even if today I'm sure that &lt;br /&gt;
        dynamic type of `an_a' is always `B', this needn't remain the same tomorrow...&lt;br /&gt;
&lt;br /&gt;
            Ilinca: That's correct. If the &amp;quot;static&amp;quot; precondition of a routine holds, this &lt;br /&gt;
            implies of course that the preconditions of all its redefinitions will also hold. &lt;br /&gt;
            But I was calling this approach &amp;quot;pessimistic&amp;quot; because the precondition of a redefined &lt;br /&gt;
            version of a routine may hold even though the &amp;quot;static&amp;quot; precondition doesn't.&lt;br /&gt;
&lt;br /&gt;
        So, if a programmer wanted to know function value at a program point, he/she would check &lt;br /&gt;
        its static precondition. Then why instrumenter should act differently? Well, actually &lt;br /&gt;
        there is a difference:  instrumenter not only avoids function call when precondition &lt;br /&gt;
        doesn't hold, but also claims that function value is nonsensical. From one point of view, &lt;br /&gt;
        such behavior is incorrect, because function actually could be called and a sensible value &lt;br /&gt;
        could be received. From the other point, since it was illegal to call the function this time, &lt;br /&gt;
        it makes sense to declare function value nonsensical.&lt;br /&gt;
&lt;br /&gt;
        To sum up, I think that it is rather a philosophical then a technical problem, but, as for me, &lt;br /&gt;
        checking static preconditions is more appropriate.&lt;br /&gt;
&lt;br /&gt;
        However, if we wanted to check a dynamic precondition, it's also possible. We can wrap function's &lt;br /&gt;
        precondition into a special function and redefine that special function any time the original &lt;br /&gt;
        function is redefined. It is possible since instrumenter has access to the whole system.&lt;br /&gt;
&lt;br /&gt;
            Ilinca: Well, this would definitely be the more... correct solution, but it's also a lot more &lt;br /&gt;
            work. Couldn't this also be done by not wrapping the function, but simply calling it and adding &lt;br /&gt;
            some exception handling code to the unfolder? I mean, the unfolder would try to call all &lt;br /&gt;
            argument-less functions of a class on an object, and, if it gets a precondition violation, &lt;br /&gt;
            it catches the exception and it declares that particular function as nonsensical?&lt;br /&gt;
&lt;br /&gt;
 Nadia: I would like to return to the subject of checking &amp;quot;static&amp;quot; or &amp;quot;dynamic&amp;quot; preconditions &lt;br /&gt;
 before function calls in unfolding. I think that this problem arises because the semantics &lt;br /&gt;
 of special variable value &amp;quot;nonsensical&amp;quot; in Daikon is ambiguous.&lt;br /&gt;
&lt;br /&gt;
 In Java and C there are no preconditions, so this value is originally used in Daikon for the &lt;br /&gt;
 only purpose: if a pointer of reference is null, then the dereferenced value (and its attributes, &lt;br /&gt;
 if the value is not of primitive type) is declared &amp;quot;nonsensical&amp;quot;. In Eiffel we will use &lt;br /&gt;
 &amp;quot;nonsensical&amp;quot; for this purpose too: if a reference entity is void, then its queries will be output &lt;br /&gt;
 as &amp;quot;nonsensical&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
 However, in Eiffel we have one more source of problems with evaluating variables: if a variable is &lt;br /&gt;
 a result of a function call, then function precondition may not hold, so we won't be able to &lt;br /&gt;
 evaluate its result. In this case the variable value should also be declared &amp;quot;nonsensical&amp;quot;, because &lt;br /&gt;
 this is the only special value in Daikon, which denotes that variable can't be evaluated. However, &lt;br /&gt;
 in this case there appears a question: what does it mean that the variable can't be evaluated? Does &lt;br /&gt;
 it mean that something terrible will happen (e.g., exception), if we try to evaluate it? Or does &lt;br /&gt;
 it mean that it isn't legal to evaluate this variable in this program state?&lt;br /&gt;
&lt;br /&gt;
 If we take the first point, then we should check dynamic precondition, because if static precondition &lt;br /&gt;
 doesn't hold, but dynamic does, nothing terrible will happen during function call.&lt;br /&gt;
&lt;br /&gt;
 If we take the second point, we should check static precondition, because if it doesn't hold then &lt;br /&gt;
 it's illegal to call this function, even if dynamic precondition holds. This point seems more &lt;br /&gt;
 correct to me, and here is an example that illustrates the situation.&lt;br /&gt;
&lt;br /&gt;
 Consider class `INT_LIST' (with feature `item' that has a precondition `not off') and it's heir - &lt;br /&gt;
 class EXTRAPOLATED_INT_LIST (that weakens precondition of `item'):&lt;br /&gt;
&lt;br /&gt;
 class INT_LIST&lt;br /&gt;
 ...&lt;br /&gt;
 feature&lt;br /&gt;
    item: INTEGER is&lt;br /&gt;
       require&lt;br /&gt;
          not off&lt;br /&gt;
       ...&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class EXTRAPOLATED_INT_LIST&lt;br /&gt;
 inherit&lt;br /&gt;
    INT_LIST&lt;br /&gt;
    redefine&lt;br /&gt;
       item&lt;br /&gt;
    end&lt;br /&gt;
 ...&lt;br /&gt;
 feature&lt;br /&gt;
    item: INTEGER is&lt;br /&gt;
       require else True&lt;br /&gt;
       do&lt;br /&gt;
          if not off then&lt;br /&gt;
             Result := Precursor&lt;br /&gt;
          else&lt;br /&gt;
             Result := 0&lt;br /&gt;
          end&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Consider also class CLIENT, which is a client of INT_LIST:&lt;br /&gt;
&lt;br /&gt;
 class CLIENT&lt;br /&gt;
 ...&lt;br /&gt;
 feature&lt;br /&gt;
    test (a_list: INT_LIST) is&lt;br /&gt;
       do ... end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Imagine that during system execution, when contracts were inferred, actual argument of `test' was &lt;br /&gt;
 always a direct instance of EXTRAPOLATED_INT_LIST,  and in addition it was always passed to this &lt;br /&gt;
 procedure in such a state that cursor was before the first element (`off' was true). If we check &lt;br /&gt;
 dynamic preconditions for functions in unfolding, than a precondition, inferred for `test', will &lt;br /&gt;
 be something like this:&lt;br /&gt;
&lt;br /&gt;
 require&lt;br /&gt;
   a_list /= Void&lt;br /&gt;
   a_list.off&lt;br /&gt;
   a_list.item = 0&lt;br /&gt;
&lt;br /&gt;
 But this contract isn't correct (as for me), although it is, certainly, true for a specific system &lt;br /&gt;
 execution. It becomes a little more correct, if we infer:&lt;br /&gt;
&lt;br /&gt;
 require&lt;br /&gt;
   a_list /= Void&lt;br /&gt;
   a_list.off&lt;br /&gt;
   a_list.generator = &amp;quot;EXTRAPOLATED_INT_LIST&amp;quot;&lt;br /&gt;
   a_list.item = 0&lt;br /&gt;
&lt;br /&gt;
 However, such contracts (connected with dynamic type of variable) seem useless to me. One of the &lt;br /&gt;
 goals of dynamic contract inference is to eliminate those properties that happened by chance and &lt;br /&gt;
 are not intended properties of the code. Properties that are connected with dynamic types definitely &lt;br /&gt;
 happen by chance: they can't be intended properties, because if programmer wanted his software to &lt;br /&gt;
 have such a property, he would change static entity type to a more specific (based on descendant).&lt;br /&gt;
&lt;br /&gt;
 Such properties may be useful only if we treat them not as contracts but rather as some kind of &lt;br /&gt;
 runtime statistics. Programmer may be interested in information that is true for a specific system &lt;br /&gt;
 execution, e.g. for debug purposes. It might be useful to add such a feature (inference of dynamic &lt;br /&gt;
 type information and properties, connected with dynamic types) in future, but it isn't &amp;quot;classic&amp;quot; &lt;br /&gt;
 contract inference, as for me, so I don't think that we need it in the first version. And if we &lt;br /&gt;
 don't want to know anything about dynamic types, then we should check static preconditions of &lt;br /&gt;
 functions during unfolding.&lt;br /&gt;
&lt;br /&gt;
====Checking hand-written contracts====&lt;br /&gt;
    Ilinca: There's one further problem with this approach: when a function &lt;br /&gt;
    is called as part of the evaluation of a contract, this function's &lt;br /&gt;
    contracts are not checked. The reason for this is to avoid infinite &lt;br /&gt;
    loops. If you wrap your precondition into a function, the contracts of &lt;br /&gt;
    any routines it calls will be evaluated, and thus the system can &lt;br /&gt;
    actually behave differently.&lt;br /&gt;
&lt;br /&gt;
    Should we check at all the hand-written contracts of a system for which CITADEL  &lt;br /&gt;
    is trying to infer contracts? We could also start from the assumption that Daikon &lt;br /&gt;
    uses: the tool is given a set of passing test cases and from those it has to infer &lt;br /&gt;
    contracts. If the inferred contracts somehow contradict the hand-written ones, then &lt;br /&gt;
    there's a problem in the system, and the source of the  problem may be that the &lt;br /&gt;
    hand-written contracts are faulty. What do you think?&lt;br /&gt;
    &lt;br /&gt;
        Nadia: I think that it makes sense to turn assertion checking off when running &lt;br /&gt;
        instrumented system. This will solve the problem with functions inside wrapped &lt;br /&gt;
        preconditions, which you've mentioned.&lt;br /&gt;
&lt;br /&gt;
        In current version instrumented system is supposed to behave exactly the same way &lt;br /&gt;
        as the original system did (except for creating a trace file). So, if a user was &lt;br /&gt;
        sure about the original, hand-written contracts and wanted to check the system against &lt;br /&gt;
        them, he/she could run the original system with assertion checking on, make sure that &lt;br /&gt;
        everything is ok and after that perform contract inference.&lt;br /&gt;
&lt;br /&gt;
        On the other hand, returning to using functions in unfolding: for these calls we have to &lt;br /&gt;
        check hand-written preconditions, because they were introduced by instrumenter, so they are &lt;br /&gt;
        not parts of &amp;quot;passing test cases&amp;quot;. Fortunately, as you said before, erroneous preconditions &lt;br /&gt;
        are very rare.&lt;br /&gt;
&lt;br /&gt;
====Checking preconditions (wrapping vs. qualification)====&lt;br /&gt;
 Nadia: I started implementing function preconditions checks in unfolding recently and realized &lt;br /&gt;
 that my first idea (to wrap these preconditions into functions) has an important disadvantage. &lt;br /&gt;
 Without creating new functions for preconditions if we instrument a class, then only the source &lt;br /&gt;
 code of that very class changes. However, if during class instrumentation we add functions to &lt;br /&gt;
 its clients, then the source code of those clients also changes. It isn't a disaster, of cause, &lt;br /&gt;
 but it's an unpleasant property, as for me. It would be nice, if class instrumentation affected &lt;br /&gt;
 only the class itself.&lt;br /&gt;
&lt;br /&gt;
 The other solution is not to wrap preconditions into functions, but to &amp;quot;qualify&amp;quot; them: if we want &lt;br /&gt;
 to check precondition before calling a function `x.f', we should take f's precondition and &lt;br /&gt;
 replaced all unqualified calls in it by qualified calls with target `x' and all occurrences of &lt;br /&gt;
 `Current' by `x'. This replacement is not difficult conceptually, but its implementation is quite &lt;br /&gt;
 voluminous (during this operation we have to replace some identifiers in an expression with function &lt;br /&gt;
 calls, so we need to redefine all `process_&amp;lt;something&amp;gt;' procedures of ET_AST_ITERATOR, where &lt;br /&gt;
 &amp;lt;something&amp;gt; can appear in expression and can contain identifiers).&lt;br /&gt;
&lt;br /&gt;
 What do you think about these two solutions (&amp;quot;wrapping into functions&amp;quot; and &amp;quot;qualification&amp;quot;)?&lt;br /&gt;
&lt;br /&gt;
    Ilinca: I think the best way to go is to wrap the precondition in a function in the class that &lt;br /&gt;
    it belongs to. Wrapping it in a function in clients would break encapsulation: you would only &lt;br /&gt;
    be allowed to access the exported features. I don't see any advantages of qualification over &lt;br /&gt;
    function-wrapping, so I think it makes sense to choose the least-work solution&lt;br /&gt;
&lt;br /&gt;
        Nadia: My previous explanation of the problem with &amp;quot;wrapping&amp;quot; was a little bit confused &lt;br /&gt;
        (I wrote that functions have to be added to clients of instrumented class, but actually &lt;br /&gt;
        I meant quite the opposite: that they should be added to suppliers:) )&lt;br /&gt;
&lt;br /&gt;
        Wrapping a precondition in a function in the class that it belongs to is exactly what I &lt;br /&gt;
        wanted to do firstly. The reason for it was that, if we instrument a class `C' and it has, &lt;br /&gt;
        say, an attribute `x: LIST[INTEGER]', then unfolded form of `Current' variable will include &lt;br /&gt;
        a variable `x.first'. Precondition of function `first' in class LIST is `not empty'. However, &lt;br /&gt;
        we need to check this precondition not inside LIST, but inside routines of class `C'. In fact, &lt;br /&gt;
        printing instruction for variable `x.first' should be guarded by condition like this:&lt;br /&gt;
        if x /= Void and then not x.empty then&lt;br /&gt;
           print (x.first)&lt;br /&gt;
        end&lt;br /&gt;
        We can't just take a precondition from `first' and insert it into the guarding condition as is, &lt;br /&gt;
        instead we should &amp;quot;qualify&amp;quot; the call to `empty' with target `x'.&lt;br /&gt;
&lt;br /&gt;
        Firstly qualification seemed too complex to me, so I decided to wrap `not empty' into function, say,&lt;br /&gt;
        `first_precondition: BOOLEAN' and add it to class `LIST', so that inside `C' I can check simpler &lt;br /&gt;
        condition before printing x.first:&lt;br /&gt;
        if x /= Void and then x.first_precondition then&lt;br /&gt;
            print (x.first)&lt;br /&gt;
        end.&lt;br /&gt;
        However, as you can see, it involves modifying class `LIST' (and possibly any other supplier of &lt;br /&gt;
        `C') while instrumenting `C'. If only `C' changed, then we could print only its source code after &lt;br /&gt;
        instrumentation, we could compile only `C' (if incremental compilation is used) and don't recompile &lt;br /&gt;
        base library, we would have no problems with tracking added functions (the problems are like this: &lt;br /&gt;
        if we instrument class `LIST' after `C', we probably don't want neither to instrument added functions, &lt;br /&gt;
        nor to see them in unfolded form of `Current' variable of class `LIST'). As for me, wrapping adds &lt;br /&gt;
        surplus dependencies into the system, and software never benefits from dependencies :)&lt;br /&gt;
&lt;br /&gt;
        That is why later I inclined to &amp;quot;qualification&amp;quot; solution. Actually, I have already mostly implemented &lt;br /&gt;
        it:) Current implementation might be incomplete, there are several syntactic constructs that it doesn't &lt;br /&gt;
        handle, because I'm not sure that they can appear in preconditions, but I'll check it and fix the problem.&lt;br /&gt;
&lt;br /&gt;
            Ilinca: Ok, so what I was thinking about was that you wanted to wrap the whole precondition of &lt;br /&gt;
            `first' into a function in class C. So, in class C you would have a routine&lt;br /&gt;
            precondition_first (l: LIST[G]): BOOLEAN&lt;br /&gt;
                 require&lt;br /&gt;
                      l_not_void: l /= Void&lt;br /&gt;
                 do&lt;br /&gt;
                      Result := not l.empty&lt;br /&gt;
                 end&lt;br /&gt;
            Then the guard for printing x.first would be&lt;br /&gt;
                 if x /= Void and then precondition_first (x) then&lt;br /&gt;
                      print (x.first)&lt;br /&gt;
                 end&lt;br /&gt;
&lt;br /&gt;
            But of course whether or not you wrap the precondition in a function or just quote it in the if &lt;br /&gt;
            statement does not make a big difference.&lt;br /&gt;
&lt;br /&gt;
 One more question: should the tool allow instrumenting library classes? If a library was precompiled, &lt;br /&gt;
 then instrumenting any of its classes will result in recompiling the whole library, am I right? Are &lt;br /&gt;
 precompiled libraries anyway recompiled during system finalization or not? (It matters for choosing &lt;br /&gt;
 between &amp;quot;wrapping into functions&amp;quot; and &amp;quot;qualification&amp;quot; solutions, because &amp;quot;wrapping into functions&amp;quot; can &lt;br /&gt;
 change library classes, even if user wants to implement only classes from his own clusters).&lt;br /&gt;
&lt;br /&gt;
===Support for loop invariants===&lt;br /&gt;
 Ilinca: Does the &amp;quot;classic&amp;quot; Daikon support loop invariants?&lt;br /&gt;
&lt;br /&gt;
 Nadia: Daikon uses standard program point &lt;br /&gt;
  suffixes to infer more invariants. E.g., it understands that &lt;br /&gt;
  some_routine:::ENTER and some_routine:::EXIT are entry and exit points &lt;br /&gt;
  of the same routine. Thanks to this, it knows `old' values of variables &lt;br /&gt;
  at exit and can infer invariants like &amp;quot;x = old x&amp;quot;. As I understood, if &lt;br /&gt;
  Daikon sees an unknown suffix, it treats corresponding program point as, &lt;br /&gt;
  so to say, &amp;quot;standalone&amp;quot; and doesn't try to connect it with any other.&lt;br /&gt;
  We don't need any extra support from Daikon to handle loop invariants.&lt;br /&gt;
&lt;br /&gt;
    Ilinca: You'll have to pay attention though to inserting the corresponding &lt;br /&gt;
    program point(s) at the right location(s). A loop invariant has to hold after &lt;br /&gt;
    initialization (the &amp;quot;from&amp;quot; clause) and be preserved by the loop body, i.e. it &lt;br /&gt;
    must hold after every execution of the loop body, including when the exit &lt;br /&gt;
    condition becomes true. So actually, I guess the program point should be in &lt;br /&gt;
    the &amp;quot;until&amp;quot; clause, because it gets evaluated after initialization and then &lt;br /&gt;
    after every execution of the loop body. What do you think?&lt;br /&gt;
&lt;br /&gt;
        Nadia: `Until' clause is conceptually the right place, but instructions &lt;br /&gt;
        can't be inserted in there. So printing instructions can be inserted at &lt;br /&gt;
        the end of `from' clause and at the end of  `loop' clause. As I understand, &lt;br /&gt;
        all variable values that are observed in `until' condition appear at one of &lt;br /&gt;
        those points.&lt;br /&gt;
  &lt;br /&gt;
  Nadia: If we want to infer loop invariants, we should introduce a separate &lt;br /&gt;
  program point for each loop. So, we need a way to distinguish loops &lt;br /&gt;
  within a routine. One way is to take its position in source code as &lt;br /&gt;
  index. However, I thought, that position is too unstable to become loop &lt;br /&gt;
  identifier, so I chose instruction number instead. These numbers are &lt;br /&gt;
  unique numbers of instructions within surrounding routine, they may be &lt;br /&gt;
  used not only for loops, but for arbitrary instructions. &lt;br /&gt;
  CI_INSTRUCTION_COUNTER is responsible for counting instruction while &lt;br /&gt;
  iterating through AST.&lt;br /&gt;
&lt;br /&gt;
===Inferring contracts for generic classes===&lt;br /&gt;
 Nadia: there are actually two different cases.&lt;br /&gt;
  1. Contracts inside generic classes. This is not really a problem. &lt;br /&gt;
  Entities, which have parameter type, can be treated as if their &lt;br /&gt;
  generator is constraining class (ANY, if genericity is unconstrained).&lt;br /&gt;
  &lt;br /&gt;
  2. Contracts in clients of generic classes. Here some problems arise. If &lt;br /&gt;
  we have an entity `x: ARRAYED_LIST[INTEGER]', its unfolding involves &lt;br /&gt;
  processing the `item' query. `item' is declared to be of type `G' in &lt;br /&gt;
  ARRAYED_LIST and, as I understand, parsing is not enough (some type &lt;br /&gt;
  analysis is needed) to infer that `G' means `INTEGER' in current &lt;br /&gt;
  context. Two approaches to this problem, that I see at present, are: &lt;br /&gt;
  perform such a type analysis in compile time (with the help of gobo &lt;br /&gt;
  compilation facilities) or leave some unfolding work until runtime, &lt;br /&gt;
  when reflections may be used to determine variable's generating class.&lt;/div&gt;</summary>
		<author><name>Nadia Polikarpova</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=CITADEL&amp;diff=10134</id>
		<title>CITADEL</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=CITADEL&amp;diff=10134"/>
				<updated>2007-12-25T12:22:37Z</updated>
		
		<summary type="html">&lt;p&gt;Nadia Polikarpova: /* Unfolded variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Assertion checking]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
CITADEL (Contract-Inference Tool that Applies Daikon to the Eiffel Language) is a tool that provides an Eiffel front-end for the Daikon invariant detector. It is being implemented as a Master's project by Nadia Polikarpova supervised by Ilinca Ciupa (ETH).&lt;br /&gt;
&lt;br /&gt;
==Discussions==&lt;br /&gt;
===Unfolded variables===&lt;br /&gt;
 Nadia: Daikon can process values of only few types: five scalar types (boolean, &lt;br /&gt;
  integer, double, string and hashcode) and five more types, which are &lt;br /&gt;
  arrays of these scalars.&lt;br /&gt;
  So, if in Eiffel code we a have a variable of one of basic types &lt;br /&gt;
  (BOOLEAN, NATURAL, INTEGER, CHARACTER, REAL or STRING) we can print &lt;br /&gt;
  its value directly as if it has one of Daikon's types.&lt;br /&gt;
  If, however, we have a variable of any other type, we have to collect &lt;br /&gt;
  all the information about it that is of interest and is available at &lt;br /&gt;
  certain program point, and present this information to Daikon as a set &lt;br /&gt;
  of  variables, which have Daikon types. The information of interest &lt;br /&gt;
  about a variable includes results of all queries that can be called on &lt;br /&gt;
  this variable at this program point.  However, since queries results may &lt;br /&gt;
  themselves be of non-basic types, we have to perform this operation &lt;br /&gt;
  recursively (to a certain depth).&lt;br /&gt;
  For a reference variable information of interest includes also its &lt;br /&gt;
  address (Daikon type &amp;quot;hashcode&amp;quot; is intended for representing object &lt;br /&gt;
  addresses).&lt;br /&gt;
  For example, if we had a variable c: POINT, queries of class POINT &lt;br /&gt;
  available at current program point were `x: REAL', `y: REAL' and `twin: &lt;br /&gt;
  POINT' and unfolding depth were set to 2, then `c.unfolded' would be a &lt;br /&gt;
  set of variables: {$c, c.x, c.y, $c.twin, c.twin.x, c.twin.y}.&lt;br /&gt;
  &lt;br /&gt;
  Containers need special kind of unfolding. If we want Daikon to handle &lt;br /&gt;
  them sensibly, they should be converted to arrays of scalars (to be more &lt;br /&gt;
  precise, it should be done only if all container elements are observable &lt;br /&gt;
  at current program point...). It isn't difficult for descendants of &lt;br /&gt;
  CONTAINER class from standard library. Instrumenter may check, if a &lt;br /&gt;
  variable is an indirect instance of CONTAINER, get its &lt;br /&gt;
  `linear_representation', then traverse it and output as array. I think &lt;br /&gt;
  that in the first version we may leave aside those containers, that &lt;br /&gt;
  aren't inherited from CONTAINER.&lt;br /&gt;
&lt;br /&gt;
====Functions in unfolded form====&lt;br /&gt;
 Ilinca: I'm not sure about the idea of including argument-less functions in &lt;br /&gt;
  this unfolded form. What if the precondition of the function doesn't &lt;br /&gt;
  hold or we run into some kind of trouble when executing the function &lt;br /&gt;
  body (trouble such as the contracts of a sub-call made by this &lt;br /&gt;
  function not holding or other bugs)? On the other hand, including &lt;br /&gt;
  functions would bring significantly more information about the state &lt;br /&gt;
  of the object... Does the Daikon frontend for Java, for instance, by &lt;br /&gt;
  default evaluate functions too as part of the unfolded form of the &lt;br /&gt;
  objects?&lt;br /&gt;
&lt;br /&gt;
 Nadia: Well, this idea is disputable, of cause.&lt;br /&gt;
  In Java considering argument-less functions as variables is more &lt;br /&gt;
  dangerous, because Java, like all C-family languages, encourages &lt;br /&gt;
  side-effects in functions. However, in Daikon front-end for Java there &lt;br /&gt;
  exists an option that allows using functions as variables. Together with &lt;br /&gt;
  enabling this option user has to provide a special &amp;quot;purity&amp;quot; file that &lt;br /&gt;
  lists those functions from the system, that are side-effect free. This &lt;br /&gt;
  feature is described in Daikon User Manual, page 82.&lt;br /&gt;
  Considering functions as variables is even more relevant in Eiffel &lt;br /&gt;
  context by two main reasons. Firstly, Eiffel encourages absence of &lt;br /&gt;
  abstract side-effects in functions (and, I believe, most Eiffel &lt;br /&gt;
  functions indeed do not have abstract side-effect, am I right?). For &lt;br /&gt;
  those cases, when some functions in system are known to have &lt;br /&gt;
  side-effect, we can allow user to specify an &amp;quot;impurity&amp;quot; file, that would &lt;br /&gt;
  list those functions. I think that these cases would be rare.&lt;br /&gt;
  &lt;br /&gt;
    Ilinca: Indeed, I also think these cases would be rare, but, depending on the &lt;br /&gt;
    size of the system, it might be very cumbersome for users to determine &lt;br /&gt;
    these functions.&lt;br /&gt;
&lt;br /&gt;
        Nadia: Well, a parameter may be introduced that will turn this facility on &lt;br /&gt;
        and off. So, if a user knows that there are many impure functions in system, &lt;br /&gt;
        he/she will just turn it off. I think, that its enough for the first version.&lt;br /&gt;
        &lt;br /&gt;
        In future some additional functionality may be introduced. In fact, a user may &lt;br /&gt;
        not know about all impure functions in system (especially in code that was written &lt;br /&gt;
        by someone else). The tool can help user to determine, did anything go wrong with &lt;br /&gt;
        using functions in unfolding. For example, it may do instrumentation twice: first &lt;br /&gt;
        time using only attributes and second time using functions also. As a result two &lt;br /&gt;
        trace files are produces. Then the tool can compare attributes values in two files. &lt;br /&gt;
        If they are the same, then with certain degree of confidence we can say, that called &lt;br /&gt;
        functions had no abstract side effect.&lt;br /&gt;
&lt;br /&gt;
        As I understand, precise analysis of abstract side-effect presence or absence in beyond &lt;br /&gt;
        the state of the art. However, some methods which perform approximate analysis may be &lt;br /&gt;
        introduced.&lt;br /&gt;
&lt;br /&gt;
        Another interesting solution that came to mind is to store object's state each time before &lt;br /&gt;
        calling a function and then recover object after the call. In this case we don't care about &lt;br /&gt;
        function purity, we just get a result that this function might have had, if it was called at &lt;br /&gt;
        this point :)&lt;br /&gt;
&lt;br /&gt;
        Anyway, different partial solutions to this problem may be implemented and user may combine &lt;br /&gt;
        different strategies to get a desired result with a desired degree of confidence.&lt;br /&gt;
&lt;br /&gt;
        Conceptually, my point here is: why an &amp;quot;honest&amp;quot; Eiffel programmer, who never writes impure &lt;br /&gt;
        functions, has to suffer (get less expressive contracts) because of other programmers, who &lt;br /&gt;
        sometimes write impure functions?:)&lt;br /&gt;
&lt;br /&gt;
            Ilinca: :) Indeed, the honest Eiffel programmer shouldn't suffer. So in conclusion, I &lt;br /&gt;
            think we should go for the solution with the file containing the names of impure functions, &lt;br /&gt;
            as Daikon does it. Adding the switch which turns it on and off is also a good idea. &lt;br /&gt;
&lt;br /&gt;
    Ilinca: Something else: what Daikon calls &amp;quot;purity&amp;quot; is actually &lt;br /&gt;
    weak purity, isn't it? (Weak purity means that creations of local &lt;br /&gt;
    variables are allowed in the body of a pure function. Strong purity &lt;br /&gt;
    disallows this.)&lt;br /&gt;
&lt;br /&gt;
        Nadia: Chicory (Java front end) doesn't check purity of functions that are listed in a purity &lt;br /&gt;
        file. User is totally responsible for what he/she writes in this file. So, I would say that, what &lt;br /&gt;
        Chicory calls purity isn't actually any special kind of purity. It only means that user allowed &lt;br /&gt;
        Chicory to call this functions anywhere in the system, and if something goes wrong, it's user's &lt;br /&gt;
        fault&lt;br /&gt;
  &lt;br /&gt;
  Nadia: Secondly, Eiffel advocates uniform access principle. Routine's clients &lt;br /&gt;
  don't have to know, which queries, used in precondition, are attributes &lt;br /&gt;
  and which are functions. If inferred preconditions contained only &lt;br /&gt;
  attributes, it would be inconsistent with uniform access principle, I &lt;br /&gt;
  think...&lt;br /&gt;
&lt;br /&gt;
  As for troubles that may arise when calling functions... As I &lt;br /&gt;
  understand, exception in a function, called when its precondition holds, &lt;br /&gt;
  is a bug. So, if it happens, we can just tell user that we found a bug &lt;br /&gt;
  in certain function and that before inferring contracts the bug should &lt;br /&gt;
  be fixed.&lt;br /&gt;
&lt;br /&gt;
====Checking preconditions (static vs. dynamic)====  &lt;br /&gt;
  The issue with functions' preconditions that you've mentioned isn't a &lt;br /&gt;
  big problem. If after unfolding we got a variable of the form, e.g., &lt;br /&gt;
  `x.f1.f2', where `f1' and `f2' are functions, printing instructions for &lt;br /&gt;
  this variable can be like this:&lt;br /&gt;
    if x.f1_precondition_holds and then x.f1.f2_precondition_holds&lt;br /&gt;
    then&lt;br /&gt;
       print (x.f1.f2)&lt;br /&gt;
    else&lt;br /&gt;
       print (Nonsensical)&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
  &amp;quot;Nonsensical&amp;quot; is a special Daikon value that indicates that variable &lt;br /&gt;
  cannot be evaluated.&lt;br /&gt;
  Function preconditions are known after parsing. To be able to evaluate &lt;br /&gt;
  them separately, we may, for example, wrap them into functions. &lt;br /&gt;
  `f1_precondition_holds' in the above code is an example of such a &lt;br /&gt;
  function, that was introduced by instrumenter and added to x's &lt;br /&gt;
  generating class.&lt;br /&gt;
  &lt;br /&gt;
    Ilinca: I don't think it's that easy, mainly because of polymorphism. Statically &lt;br /&gt;
    you can't determine the type that x will be a direct instance of at &lt;br /&gt;
    runtime. Hence, you don't know which preconditions to wrap. Of course, &lt;br /&gt;
    since redefined routines can keep or weaken the preconditions of the &lt;br /&gt;
    original routines, you can take the pessimistic approach of wrapping &lt;br /&gt;
    only the precondition of the function from the static type of x, but &lt;br /&gt;
    then you might miss cases in which the weakened version of the &lt;br /&gt;
    precondition does hold. Do you understand my point?&lt;br /&gt;
&lt;br /&gt;
        Nadia: Yeah, I see...&lt;br /&gt;
        I think that the main question here is: should we check &amp;quot;static&amp;quot; or &amp;quot;dynamic&amp;quot; &lt;br /&gt;
        preconditions when calling a function?&lt;br /&gt;
&lt;br /&gt;
        On the one hand, in Eiffel we can write something like:&lt;br /&gt;
        class A&lt;br /&gt;
           ...&lt;br /&gt;
           sqrt (x: REAL): REAL&lt;br /&gt;
               require&lt;br /&gt;
                   x &amp;gt;= 0.0&lt;br /&gt;
               do ... end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        class B&lt;br /&gt;
           inherit A&lt;br /&gt;
              redefine sqrt end&lt;br /&gt;
           ...&lt;br /&gt;
           sqrt (x: REAL): REAL&lt;br /&gt;
               require else&lt;br /&gt;
                 True&lt;br /&gt;
               do ... end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        class TEST&lt;br /&gt;
            ...&lt;br /&gt;
            an_a: A&lt;br /&gt;
&lt;br /&gt;
            make is&lt;br /&gt;
               do&lt;br /&gt;
                    create {B} an_a&lt;br /&gt;
                    print (an_a.sqrt (-1.0))&lt;br /&gt;
               end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        It works, and assertion checking mechanism doesn't indicate any error.&lt;br /&gt;
        But, on the other hand, is it legal? Am I allowed to call a function if it's &lt;br /&gt;
        static precondition doesn't hold?&lt;br /&gt;
&lt;br /&gt;
        As I understand, if I want to make sure that it's legal to call a routine at some &lt;br /&gt;
        program point, I have to check it's static precondition. Even if today I'm sure that &lt;br /&gt;
        dynamic type of `an_a' is always `B', this needn't remain the same tomorrow...&lt;br /&gt;
&lt;br /&gt;
            Ilinca: That's correct. If the &amp;quot;static&amp;quot; precondition of a routine holds, this &lt;br /&gt;
            implies of course that the preconditions of all its redefinitions will also hold. &lt;br /&gt;
            But I was calling this approach &amp;quot;pessimistic&amp;quot; because the precondition of a redefined &lt;br /&gt;
            version of a routine may hold even though the &amp;quot;static&amp;quot; precondition doesn't.&lt;br /&gt;
&lt;br /&gt;
        So, if a programmer wanted to know function value at a program point, he/she would check &lt;br /&gt;
        its static precondition. Then why instrumenter should act differently? Well, actually &lt;br /&gt;
        there is a difference:  instrumenter not only avoids function call when precondition &lt;br /&gt;
        doesn't hold, but also claims that function value is nonsensical. From one point of view, &lt;br /&gt;
        such behavior is incorrect, because function actually could be called and a sensible value &lt;br /&gt;
        could be received. From the other point, since it was illegal to call the function this time, &lt;br /&gt;
        it makes sense to declare function value nonsensical.&lt;br /&gt;
&lt;br /&gt;
        To sum up, I think that it is rather a philosophical then a technical problem, but, as for me, &lt;br /&gt;
        checking static preconditions is more appropriate.&lt;br /&gt;
&lt;br /&gt;
        However, if we wanted to check a dynamic precondition, it's also possible. We can wrap function's &lt;br /&gt;
        precondition into a special function and redefine that special function any time the original &lt;br /&gt;
        function is redefined. It is possible since instrumenter has access to the whole system.&lt;br /&gt;
&lt;br /&gt;
            Ilinca: Well, this would definitely be the more... correct solution, but it's also a lot more &lt;br /&gt;
            work. Couldn't this also be done by not wrapping the function, but simply calling it and adding &lt;br /&gt;
            some exception handling code to the unfolder? I mean, the unfolder would try to call all &lt;br /&gt;
            argument-less functions of a class on an object, and, if it gets a precondition violation, &lt;br /&gt;
            it catches the exception and it declares that particular function as nonsensical?&lt;br /&gt;
&lt;br /&gt;
 Nadia: I would like to return to the subject of checking &amp;quot;static&amp;quot; or &amp;quot;dynamic&amp;quot; preconditions &lt;br /&gt;
 before function calls in unfolding. I think that this problem arises because the semantics &lt;br /&gt;
 of special variable value &amp;quot;nonsensical&amp;quot; in Daikon is ambiguous.&lt;br /&gt;
&lt;br /&gt;
 In Java and C there are no preconditions, so this value is originally used in Daikon for the &lt;br /&gt;
 only purpose: if a pointer of reference is null, then the dereferenced value (and its attributes, &lt;br /&gt;
 if the value is not of primitive type) is declared &amp;quot;nonsensical&amp;quot;. In Eiffel we will use &lt;br /&gt;
 &amp;quot;nonsensical&amp;quot; for this purpose too: if a reference entity is void, then its queries will be output &lt;br /&gt;
 as &amp;quot;nonsensical&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
 However, in Eiffel we have one more source of problems with evaluating variables: if a variable is &lt;br /&gt;
 a result of a function call, then function precondition may not hold, so we won't be able to &lt;br /&gt;
 evaluate its result. In this case the variable value should also be declared &amp;quot;nonsensical&amp;quot;, because &lt;br /&gt;
 this is the only special value in Daikon, which denotes that variable can't be evaluated. However, &lt;br /&gt;
 in this case there appears a question: what does it mean that the variable can't be evaluated? Does &lt;br /&gt;
 it mean that something terrible will happen (e.g., exception), if we try to evaluate it? Or does &lt;br /&gt;
 it mean that it isn't legal to evaluate this variable in this program state?&lt;br /&gt;
&lt;br /&gt;
 If we take the first point, then we should check dynamic precondition, because if static precondition &lt;br /&gt;
 doesn't hold, but dynamic does, nothing terrible will happen during function call.&lt;br /&gt;
&lt;br /&gt;
 If we take the second point, we should check static precondition, because if it doesn't hold then &lt;br /&gt;
 it's illegal to call this function, even if dynamic precondition holds. This point seems more &lt;br /&gt;
 correct to me, and here is an example that illustrates the situation.&lt;br /&gt;
&lt;br /&gt;
 Consider class `INT_LIST' (with feature `item' that has a precondition `not off') and it's heir - &lt;br /&gt;
 class EXTRAPOLATED_INT_LIST (that weakens precondition of `item'):&lt;br /&gt;
&lt;br /&gt;
 class INT_LIST&lt;br /&gt;
 ...&lt;br /&gt;
 feature&lt;br /&gt;
    item: INTEGER is&lt;br /&gt;
       require&lt;br /&gt;
          not off&lt;br /&gt;
       ...&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class EXTRAPOLATED_INT_LIST&lt;br /&gt;
 inherit&lt;br /&gt;
    INT_LIST&lt;br /&gt;
    redefine&lt;br /&gt;
       item&lt;br /&gt;
    end&lt;br /&gt;
 ...&lt;br /&gt;
 feature&lt;br /&gt;
    item: INTEGER is&lt;br /&gt;
       require else True&lt;br /&gt;
       do&lt;br /&gt;
          if not off then&lt;br /&gt;
             Result := Precursor&lt;br /&gt;
          else&lt;br /&gt;
             Result := 0&lt;br /&gt;
          end&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Consider also class CLIENT, which is a client of INT_LIST:&lt;br /&gt;
&lt;br /&gt;
 class CLIENT&lt;br /&gt;
 ...&lt;br /&gt;
 feature&lt;br /&gt;
    test (a_list: INT_LIST) is&lt;br /&gt;
       do ... end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Imagine that during system execution, when contracts were inferred, actual argument of `test' was &lt;br /&gt;
 always a direct instance of EXTRAPOLATED_INT_LIST,  and in addition it was always passed to this &lt;br /&gt;
 procedure in such a state that cursor was before the first element (`off' was true). If we check &lt;br /&gt;
 dynamic preconditions for functions in unfolding, than a precondition, inferred for `test', will &lt;br /&gt;
 be something like this:&lt;br /&gt;
&lt;br /&gt;
 require&lt;br /&gt;
   a_list /= Void&lt;br /&gt;
   a_list.off&lt;br /&gt;
   a_list.item = 0&lt;br /&gt;
&lt;br /&gt;
 But this contract isn't correct (as for me), although it is, certainly, true for a specific system &lt;br /&gt;
 execution. It becomes a little more correct, if we infer:&lt;br /&gt;
&lt;br /&gt;
 require&lt;br /&gt;
   a_list /= Void&lt;br /&gt;
   a_list.off&lt;br /&gt;
   a_list.generator = &amp;quot;EXTRAPOLATED_INT_LIST&amp;quot;&lt;br /&gt;
   a_list.item = 0&lt;br /&gt;
&lt;br /&gt;
 However, such contracts (connected with dynamic type of variable) seem useless to me. One of the &lt;br /&gt;
 goals of dynamic contract inference is to eliminate those properties that happened by chance and &lt;br /&gt;
 are not intended properties of the code. Properties that are connected with dynamic types definitely &lt;br /&gt;
 happen by chance: they can't be intended properties, because if programmer wanted his software to &lt;br /&gt;
 have such a property, he would change static entity type to a more specific (based on descendant).&lt;br /&gt;
&lt;br /&gt;
 Such properties may be useful only if we treat them not as contracts but rather as some kind of &lt;br /&gt;
 runtime statistics. Programmer may be interested in information that is true for a specific system &lt;br /&gt;
 execution, e.g. for debug purposes. It might be useful to add such a feature (inference of dynamic &lt;br /&gt;
 type information and properties, connected with dynamic types) in future, but it isn't &amp;quot;classic&amp;quot; &lt;br /&gt;
 contract inference, as for me, so I don't think that we need it in the first version. And if we &lt;br /&gt;
 don't want to know anything about dynamic types, then we should check static preconditions of &lt;br /&gt;
 functions during unfolding.&lt;br /&gt;
&lt;br /&gt;
====Checking hand-written contracts====&lt;br /&gt;
    Ilinca: There's one further problem with this approach: when a function &lt;br /&gt;
    is called as part of the evaluation of a contract, this function's &lt;br /&gt;
    contracts are not checked. The reason for this is to avoid infinite &lt;br /&gt;
    loops. If you wrap your precondition into a function, the contracts of &lt;br /&gt;
    any routines it calls will be evaluated, and thus the system can &lt;br /&gt;
    actually behave differently.&lt;br /&gt;
&lt;br /&gt;
    Should we check at all the hand-written contracts of a system for which CITADEL  &lt;br /&gt;
    is trying to infer contracts? We could also start from the assumption that Daikon &lt;br /&gt;
    uses: the tool is given a set of passing test cases and from those it has to infer &lt;br /&gt;
    contracts. If the inferred contracts somehow contradict the hand-written ones, then &lt;br /&gt;
    there's a problem in the system, and the source of the  problem may be that the &lt;br /&gt;
    hand-written contracts are faulty. What do you think?&lt;br /&gt;
    &lt;br /&gt;
        Nadia: I think that it makes sense to turn assertion checking off when running &lt;br /&gt;
        instrumented system. This will solve the problem with functions inside wrapped &lt;br /&gt;
        preconditions, which you've mentioned.&lt;br /&gt;
&lt;br /&gt;
        In current version instrumented system is supposed to behave exactly the same way &lt;br /&gt;
        as the original system did (except for creating a trace file). So, if a user was &lt;br /&gt;
        sure about the original, hand-written contracts and wanted to check the system against &lt;br /&gt;
        them, he/she could run the original system with assertion checking on, make sure that &lt;br /&gt;
        everything is ok and after that perform contract inference.&lt;br /&gt;
&lt;br /&gt;
        On the other hand, returning to using functions in unfolding: for these calls we have to &lt;br /&gt;
        check hand-written preconditions, because they were introduced by instrumenter, so they are &lt;br /&gt;
        not parts of &amp;quot;passing test cases&amp;quot;. Fortunately, as you said before, erroneous preconditions &lt;br /&gt;
        are very rare.&lt;br /&gt;
&lt;br /&gt;
====Checking preconditions (wrapping vs. qualification)====&lt;br /&gt;
 Nadia: I started implementing function preconditions checks in unfolding recently and realized &lt;br /&gt;
 that my first idea (to wrap these preconditions into functions) has an important disadvantage. &lt;br /&gt;
 Without creating new functions for preconditions if we instrument a class, then only the source &lt;br /&gt;
 code of that very class changes. However, if during class instrumentation we add functions to &lt;br /&gt;
 its clients, then the source code of those clients also changes. It isn't a disaster, of cause, &lt;br /&gt;
 but it's an unpleasant property, as for me. It would be nice, if class instrumentation affected &lt;br /&gt;
 only the class itself.&lt;br /&gt;
&lt;br /&gt;
 The other solution is not to wrap preconditions into functions, but to &amp;quot;qualify&amp;quot; them: if we want &lt;br /&gt;
 to check precondition before calling a function `x.f', we should take f's precondition and &lt;br /&gt;
 replaced all unqualified calls in it by qualified calls with target `x' and all occurrences of &lt;br /&gt;
 `Current' by `x'. This replacement is not difficult conceptually, but its implementation is quite &lt;br /&gt;
 voluminous (during this operation we have to replace some identifiers in an expression with function &lt;br /&gt;
 calls, so we need to redefine all `process_&amp;lt;something&amp;gt;' procedures of ET_AST_ITERATOR, where &lt;br /&gt;
 &amp;lt;something&amp;gt; can appear in expression and can contain identifiers).&lt;br /&gt;
&lt;br /&gt;
 What do you think about these two solutions (&amp;quot;wrapping into functions&amp;quot; and &amp;quot;qualification&amp;quot;)?&lt;br /&gt;
&lt;br /&gt;
    Ilinca: I think the best way to go is to wrap the precondition in a function in the class that &lt;br /&gt;
    it belongs to. Wrapping it in a function in clients would break encapsulation: you would only &lt;br /&gt;
    be allowed to access the exported features. I don't see any advantages of qualification over &lt;br /&gt;
    function-wrapping, so I think it makes sense to choose the least-work solution&lt;br /&gt;
&lt;br /&gt;
        Nadia: My previous explanation of the problem with &amp;quot;wrapping&amp;quot; was a little bit confused &lt;br /&gt;
        (I wrote that functions have to be added to clients of instrumented class, but actually &lt;br /&gt;
        I meant quite the opposite: that they should be added to suppliers:) )&lt;br /&gt;
&lt;br /&gt;
        Wrapping a precondition in a function in the class that it belongs to is exactly what I &lt;br /&gt;
        wanted to do firstly. The reason for it was that, if we instrument a class `C' and it has, &lt;br /&gt;
        say, an attribute `x: LIST[INTEGER]', then unfolded form of `Current' variable will include &lt;br /&gt;
        a variable `x.first'. Precondition of function `first' in class LIST is `not empty'. However, &lt;br /&gt;
        we need to check this precondition not inside LIST, but inside routines of class `C'. In fact, &lt;br /&gt;
        printing instruction for variable `x.first' should be guarded by condition like this:&lt;br /&gt;
        if x /= Void and then not x.empty then&lt;br /&gt;
           print (x.first)&lt;br /&gt;
        end&lt;br /&gt;
        We can't just take a precondition from `first' and insert it into the guarding condition as is, &lt;br /&gt;
        instead we should &amp;quot;qualify&amp;quot; the call to `empty' with target `x'.&lt;br /&gt;
&lt;br /&gt;
        Firstly qualification seemed too complex to me, so I decided to wrap `not empty' into function, say,&lt;br /&gt;
        `first_precondition: BOOLEAN' and add it to class `LIST', so that inside `C' I can check simpler &lt;br /&gt;
        condition before printing x.first:&lt;br /&gt;
        if x /= Void and then x.first_precondition then&lt;br /&gt;
            print (x.first)&lt;br /&gt;
        end.&lt;br /&gt;
        However, as you can see, it involves modifying class `LIST' (and possibly any other supplier of &lt;br /&gt;
        `C') while instrumenting `C'. If only `C' changed, then we could print only its source code after &lt;br /&gt;
        instrumentation, we could compile only `C' (if incremental compilation is used) and don't recompile &lt;br /&gt;
        base library, we would have no problems with tracking added functions (the problems are like this: &lt;br /&gt;
        if we instrument class `LIST' after `C', we probably don't want neither to instrument added functions, &lt;br /&gt;
        nor to see them in unfolded form of `Current' variable of class `LIST'). As for me, wrapping adds &lt;br /&gt;
        surplus dependencies into the system, and software never benefits from dependencies :)&lt;br /&gt;
&lt;br /&gt;
        That is why later I inclined to &amp;quot;qualification&amp;quot; solution. Actually, I have already mostly implemented &lt;br /&gt;
        it:) Current implementation might be incomplete, there are several syntactic constructs that it doesn't &lt;br /&gt;
        handle, because I'm not sure that they can appear in preconditions, but I'll check it and fix the problem.&lt;br /&gt;
&lt;br /&gt;
            Ilinca: Ok, so what I was thinking about was that you wanted to wrap the whole precondition of &lt;br /&gt;
            `first' into a function in class C. So, in class C you would have a routine&lt;br /&gt;
            precondition_first (l: LIST[G]): BOOLEAN&lt;br /&gt;
                 require&lt;br /&gt;
                      l_not_void: l /= Void&lt;br /&gt;
                 do&lt;br /&gt;
                      Result := not l.empty&lt;br /&gt;
                 end&lt;br /&gt;
            Then the guard for printing x.first would be&lt;br /&gt;
                 if x /= Void and then precondition_first (x) then&lt;br /&gt;
                      print (x.first)&lt;br /&gt;
                 end&lt;br /&gt;
&lt;br /&gt;
            But of course whether or not you wrap the precondition in a function or just quote it in the if &lt;br /&gt;
            statement does not make a big difference.&lt;br /&gt;
&lt;br /&gt;
 One more question: should the tool allow instrumenting library classes? If a library was precompiled, &lt;br /&gt;
 then instrumenting any of its classes will result in recompiling the whole library, am I right? Are &lt;br /&gt;
 precompiled libraries anyway recompiled during system finalization or not? (It matters for choosing &lt;br /&gt;
 between &amp;quot;wrapping into functions&amp;quot; and &amp;quot;qualification&amp;quot; solutions, because &amp;quot;wrapping into functions&amp;quot; can &lt;br /&gt;
 change library classes, even if user wants to implement only classes from his own clusters).&lt;br /&gt;
&lt;br /&gt;
===Support for loop invariants===&lt;br /&gt;
 Ilinca: Does the &amp;quot;classic&amp;quot; Daikon support loop invariants?&lt;br /&gt;
&lt;br /&gt;
 Nadia: Daikon uses standard program point &lt;br /&gt;
  suffixes to infer more invariants. E.g., it understands that &lt;br /&gt;
  some_routine:::ENTER and some_routine:::EXIT are entry and exit points &lt;br /&gt;
  of the same routine. Thanks to this, it knows `old' values of variables &lt;br /&gt;
  at exit and can infer invariants like &amp;quot;x = old x&amp;quot;. As I understood, if &lt;br /&gt;
  Daikon sees an unknown suffix, it treats corresponding program point as, &lt;br /&gt;
  so to say, &amp;quot;standalone&amp;quot; and doesn't try to connect it with any other.&lt;br /&gt;
  We don't need any extra support from Daikon to handle loop invariants.&lt;br /&gt;
  &lt;br /&gt;
  If we want to infer loop invariants, we should introduce a separate &lt;br /&gt;
  program point for each loop. So, we need a way to distinguish loops &lt;br /&gt;
  within a routine. One way is to take its position in source code as &lt;br /&gt;
  index. However, I thought, that position is too unstable to become loop &lt;br /&gt;
  identifier, so I chose instruction number instead. These numbers are &lt;br /&gt;
  unique numbers of instructions within surrounding routine, they may be &lt;br /&gt;
  used not only for loops, but for arbitrary instructions. &lt;br /&gt;
  CI_INSTRUCTION_COUNTER is responsible for counting instruction while &lt;br /&gt;
  iterating through AST.&lt;br /&gt;
&lt;br /&gt;
===Inferring contracts for generic classes===&lt;br /&gt;
 Nadia: there are actually two different cases.&lt;br /&gt;
  1. Contracts inside generic classes. This is not really a problem. &lt;br /&gt;
  Entities, which have parameter type, can be treated as if their &lt;br /&gt;
  generator is constraining class (ANY, if genericity is unconstrained).&lt;br /&gt;
  &lt;br /&gt;
  2. Contracts in clients of generic classes. Here some problems arise. If &lt;br /&gt;
  we have an entity `x: ARRAYED_LIST[INTEGER]', its unfolding involves &lt;br /&gt;
  processing the `item' query. `item' is declared to be of type `G' in &lt;br /&gt;
  ARRAYED_LIST and, as I understand, parsing is not enough (some type &lt;br /&gt;
  analysis is needed) to infer that `G' means `INTEGER' in current &lt;br /&gt;
  context. Two approaches to this problem, that I see at present, are: &lt;br /&gt;
  perform such a type analysis in compile time (with the help of gobo &lt;br /&gt;
  compilation facilities) or leave some unfolding work until runtime, &lt;br /&gt;
  when reflections may be used to determine variable's generating class.&lt;/div&gt;</summary>
		<author><name>Nadia Polikarpova</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=CITADEL&amp;diff=10133</id>
		<title>CITADEL</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=CITADEL&amp;diff=10133"/>
				<updated>2007-12-25T12:17:43Z</updated>
		
		<summary type="html">&lt;p&gt;Nadia Polikarpova: /* Unfolded variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Assertion checking]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
CITADEL (Contract-Inference Tool that Applies Daikon to the Eiffel Language) is a tool that provides an Eiffel front-end for the Daikon invariant detector. It is being implemented as a Master's project by Nadia Polikarpova supervised by Ilinca Ciupa (ETH).&lt;br /&gt;
&lt;br /&gt;
==Discussions==&lt;br /&gt;
===Unfolded variables===&lt;br /&gt;
 Nadia: Daikon can process values of only few types: five scalar types (boolean, &lt;br /&gt;
  integer, double, string and hashcode) and five more types, which are &lt;br /&gt;
  arrays of these scalars.&lt;br /&gt;
  So, if in Eiffel code we a have a variable of one of basic types &lt;br /&gt;
  (BOOLEAN, NATURAL, INTEGER, REAL or STRING) we can print its value &lt;br /&gt;
  directly as if it has one of Daikon's types.&lt;br /&gt;
  If, however, we have a variable of any other type, we have to collect &lt;br /&gt;
  all the information about it that is of interest and is available at &lt;br /&gt;
  certain program point, and present this information to Daikon as a set &lt;br /&gt;
  of  variables, which have Daikon types. The information of interest &lt;br /&gt;
  about a variable includes results of all queries that can be called on &lt;br /&gt;
  this variable at this program point.  However, since queries results may &lt;br /&gt;
  themselves be of non-basic types, we have to perform this operation &lt;br /&gt;
  recursively (to a certain depth).&lt;br /&gt;
  For a reference variable information of interest includes also its &lt;br /&gt;
  address (Daikon type &amp;quot;hashcode&amp;quot; is intended for representing object &lt;br /&gt;
  addresses).&lt;br /&gt;
  For example, if we had a variable c: POINT, queries of class POINT &lt;br /&gt;
  available at current program point were `x: REAL', `y: REAL' and `twin: &lt;br /&gt;
  POINT' and unfolding depth were set to 2, then `c.unfolded' would be a &lt;br /&gt;
  set of variables: {$c, c.x, c.y, $c.twin, c.twin.x, c.twin.y}.&lt;br /&gt;
  &lt;br /&gt;
  Containers need special kind of unfolding. If we want Daikon to handle &lt;br /&gt;
  them sensibly, they should be converted to arrays of scalars (to be more &lt;br /&gt;
  precise, it should be done only if all container elements are observable &lt;br /&gt;
  at current program point...). It isn't difficult for descendants of &lt;br /&gt;
  CONTAINER class from standard library. Instrumenter may check, if a &lt;br /&gt;
  variable is an indirect instance of CONTAINER, get its &lt;br /&gt;
  `linear_representation', then traverse it and output as array. I think &lt;br /&gt;
  that in the first version we may leave aside those containers, that &lt;br /&gt;
  aren't inherited from CONTAINER.&lt;br /&gt;
&lt;br /&gt;
====Functions in unfolded form====&lt;br /&gt;
 Ilinca: I'm not sure about the idea of including argument-less functions in &lt;br /&gt;
  this unfolded form. What if the precondition of the function doesn't &lt;br /&gt;
  hold or we run into some kind of trouble when executing the function &lt;br /&gt;
  body (trouble such as the contracts of a sub-call made by this &lt;br /&gt;
  function not holding or other bugs)? On the other hand, including &lt;br /&gt;
  functions would bring significantly more information about the state &lt;br /&gt;
  of the object... Does the Daikon frontend for Java, for instance, by &lt;br /&gt;
  default evaluate functions too as part of the unfolded form of the &lt;br /&gt;
  objects?&lt;br /&gt;
&lt;br /&gt;
 Nadia: Well, this idea is disputable, of cause.&lt;br /&gt;
  In Java considering argument-less functions as variables is more &lt;br /&gt;
  dangerous, because Java, like all C-family languages, encourages &lt;br /&gt;
  side-effects in functions. However, in Daikon front-end for Java there &lt;br /&gt;
  exists an option that allows using functions as variables. Together with &lt;br /&gt;
  enabling this option user has to provide a special &amp;quot;purity&amp;quot; file that &lt;br /&gt;
  lists those functions from the system, that are side-effect free. This &lt;br /&gt;
  feature is described in Daikon User Manual, page 82.&lt;br /&gt;
  Considering functions as variables is even more relevant in Eiffel &lt;br /&gt;
  context by two main reasons. Firstly, Eiffel encourages absence of &lt;br /&gt;
  abstract side-effects in functions (and, I believe, most Eiffel &lt;br /&gt;
  functions indeed do not have abstract side-effect, am I right?). For &lt;br /&gt;
  those cases, when some functions in system are known to have &lt;br /&gt;
  side-effect, we can allow user to specify an &amp;quot;impurity&amp;quot; file, that would &lt;br /&gt;
  list those functions. I think that these cases would be rare.&lt;br /&gt;
  &lt;br /&gt;
    Ilinca: Indeed, I also think these cases would be rare, but, depending on the &lt;br /&gt;
    size of the system, it might be very cumbersome for users to determine &lt;br /&gt;
    these functions.&lt;br /&gt;
&lt;br /&gt;
        Nadia: Well, a parameter may be introduced that will turn this facility on &lt;br /&gt;
        and off. So, if a user knows that there are many impure functions in system, &lt;br /&gt;
        he/she will just turn it off. I think, that its enough for the first version.&lt;br /&gt;
        &lt;br /&gt;
        In future some additional functionality may be introduced. In fact, a user may &lt;br /&gt;
        not know about all impure functions in system (especially in code that was written &lt;br /&gt;
        by someone else). The tool can help user to determine, did anything go wrong with &lt;br /&gt;
        using functions in unfolding. For example, it may do instrumentation twice: first &lt;br /&gt;
        time using only attributes and second time using functions also. As a result two &lt;br /&gt;
        trace files are produces. Then the tool can compare attributes values in two files. &lt;br /&gt;
        If they are the same, then with certain degree of confidence we can say, that called &lt;br /&gt;
        functions had no abstract side effect.&lt;br /&gt;
&lt;br /&gt;
        As I understand, precise analysis of abstract side-effect presence or absence in beyond &lt;br /&gt;
        the state of the art. However, some methods which perform approximate analysis may be &lt;br /&gt;
        introduced.&lt;br /&gt;
&lt;br /&gt;
        Another interesting solution that came to mind is to store object's state each time before &lt;br /&gt;
        calling a function and then recover object after the call. In this case we don't care about &lt;br /&gt;
        function purity, we just get a result that this function might have had, if it was called at &lt;br /&gt;
        this point :)&lt;br /&gt;
&lt;br /&gt;
        Anyway, different partial solutions to this problem may be implemented and user may combine &lt;br /&gt;
        different strategies to get a desired result with a desired degree of confidence.&lt;br /&gt;
&lt;br /&gt;
        Conceptually, my point here is: why an &amp;quot;honest&amp;quot; Eiffel programmer, who never writes impure &lt;br /&gt;
        functions, has to suffer (get less expressive contracts) because of other programmers, who &lt;br /&gt;
        sometimes write impure functions?:)&lt;br /&gt;
&lt;br /&gt;
            Ilinca: :) Indeed, the honest Eiffel programmer shouldn't suffer. So in conclusion, I &lt;br /&gt;
            think we should go for the solution with the file containing the names of impure functions, &lt;br /&gt;
            as Daikon does it. Adding the switch which turns it on and off is also a good idea. &lt;br /&gt;
&lt;br /&gt;
    Ilinca: Something else: what Daikon calls &amp;quot;purity&amp;quot; is actually &lt;br /&gt;
    weak purity, isn't it? (Weak purity means that creations of local &lt;br /&gt;
    variables are allowed in the body of a pure function. Strong purity &lt;br /&gt;
    disallows this.)&lt;br /&gt;
&lt;br /&gt;
        Nadia: Chicory (Java front end) doesn't check purity of functions that are listed in a purity &lt;br /&gt;
        file. User is totally responsible for what he/she writes in this file. So, I would say that, what &lt;br /&gt;
        Chicory calls purity isn't actually any special kind of purity. It only means that user allowed &lt;br /&gt;
        Chicory to call this functions anywhere in the system, and if something goes wrong, it's user's &lt;br /&gt;
        fault&lt;br /&gt;
  &lt;br /&gt;
  Nadia: Secondly, Eiffel advocates uniform access principle. Routine's clients &lt;br /&gt;
  don't have to know, which queries, used in precondition, are attributes &lt;br /&gt;
  and which are functions. If inferred preconditions contained only &lt;br /&gt;
  attributes, it would be inconsistent with uniform access principle, I &lt;br /&gt;
  think...&lt;br /&gt;
&lt;br /&gt;
  As for troubles that may arise when calling functions... As I &lt;br /&gt;
  understand, exception in a function, called when its precondition holds, &lt;br /&gt;
  is a bug. So, if it happens, we can just tell user that we found a bug &lt;br /&gt;
  in certain function and that before inferring contracts the bug should &lt;br /&gt;
  be fixed.&lt;br /&gt;
&lt;br /&gt;
====Checking preconditions (static vs. dynamic)====  &lt;br /&gt;
  The issue with functions' preconditions that you've mentioned isn't a &lt;br /&gt;
  big problem. If after unfolding we got a variable of the form, e.g., &lt;br /&gt;
  `x.f1.f2', where `f1' and `f2' are functions, printing instructions for &lt;br /&gt;
  this variable can be like this:&lt;br /&gt;
    if x.f1_precondition_holds and then x.f1.f2_precondition_holds&lt;br /&gt;
    then&lt;br /&gt;
       print (x.f1.f2)&lt;br /&gt;
    else&lt;br /&gt;
       print (Nonsensical)&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
  &amp;quot;Nonsensical&amp;quot; is a special Daikon value that indicates that variable &lt;br /&gt;
  cannot be evaluated.&lt;br /&gt;
  Function preconditions are known after parsing. To be able to evaluate &lt;br /&gt;
  them separately, we may, for example, wrap them into functions. &lt;br /&gt;
  `f1_precondition_holds' in the above code is an example of such a &lt;br /&gt;
  function, that was introduced by instrumenter and added to x's &lt;br /&gt;
  generating class.&lt;br /&gt;
  &lt;br /&gt;
    Ilinca: I don't think it's that easy, mainly because of polymorphism. Statically &lt;br /&gt;
    you can't determine the type that x will be a direct instance of at &lt;br /&gt;
    runtime. Hence, you don't know which preconditions to wrap. Of course, &lt;br /&gt;
    since redefined routines can keep or weaken the preconditions of the &lt;br /&gt;
    original routines, you can take the pessimistic approach of wrapping &lt;br /&gt;
    only the precondition of the function from the static type of x, but &lt;br /&gt;
    then you might miss cases in which the weakened version of the &lt;br /&gt;
    precondition does hold. Do you understand my point?&lt;br /&gt;
&lt;br /&gt;
        Nadia: Yeah, I see...&lt;br /&gt;
        I think that the main question here is: should we check &amp;quot;static&amp;quot; or &amp;quot;dynamic&amp;quot; &lt;br /&gt;
        preconditions when calling a function?&lt;br /&gt;
&lt;br /&gt;
        On the one hand, in Eiffel we can write something like:&lt;br /&gt;
        class A&lt;br /&gt;
           ...&lt;br /&gt;
           sqrt (x: REAL): REAL&lt;br /&gt;
               require&lt;br /&gt;
                   x &amp;gt;= 0.0&lt;br /&gt;
               do ... end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        class B&lt;br /&gt;
           inherit A&lt;br /&gt;
              redefine sqrt end&lt;br /&gt;
           ...&lt;br /&gt;
           sqrt (x: REAL): REAL&lt;br /&gt;
               require else&lt;br /&gt;
                 True&lt;br /&gt;
               do ... end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        class TEST&lt;br /&gt;
            ...&lt;br /&gt;
            an_a: A&lt;br /&gt;
&lt;br /&gt;
            make is&lt;br /&gt;
               do&lt;br /&gt;
                    create {B} an_a&lt;br /&gt;
                    print (an_a.sqrt (-1.0))&lt;br /&gt;
               end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        It works, and assertion checking mechanism doesn't indicate any error.&lt;br /&gt;
        But, on the other hand, is it legal? Am I allowed to call a function if it's &lt;br /&gt;
        static precondition doesn't hold?&lt;br /&gt;
&lt;br /&gt;
        As I understand, if I want to make sure that it's legal to call a routine at some &lt;br /&gt;
        program point, I have to check it's static precondition. Even if today I'm sure that &lt;br /&gt;
        dynamic type of `an_a' is always `B', this needn't remain the same tomorrow...&lt;br /&gt;
&lt;br /&gt;
            Ilinca: That's correct. If the &amp;quot;static&amp;quot; precondition of a routine holds, this &lt;br /&gt;
            implies of course that the preconditions of all its redefinitions will also hold. &lt;br /&gt;
            But I was calling this approach &amp;quot;pessimistic&amp;quot; because the precondition of a redefined &lt;br /&gt;
            version of a routine may hold even though the &amp;quot;static&amp;quot; precondition doesn't.&lt;br /&gt;
&lt;br /&gt;
        So, if a programmer wanted to know function value at a program point, he/she would check &lt;br /&gt;
        its static precondition. Then why instrumenter should act differently? Well, actually &lt;br /&gt;
        there is a difference:  instrumenter not only avoids function call when precondition &lt;br /&gt;
        doesn't hold, but also claims that function value is nonsensical. From one point of view, &lt;br /&gt;
        such behavior is incorrect, because function actually could be called and a sensible value &lt;br /&gt;
        could be received. From the other point, since it was illegal to call the function this time, &lt;br /&gt;
        it makes sense to declare function value nonsensical.&lt;br /&gt;
&lt;br /&gt;
        To sum up, I think that it is rather a philosophical then a technical problem, but, as for me, &lt;br /&gt;
        checking static preconditions is more appropriate.&lt;br /&gt;
&lt;br /&gt;
        However, if we wanted to check a dynamic precondition, it's also possible. We can wrap function's &lt;br /&gt;
        precondition into a special function and redefine that special function any time the original &lt;br /&gt;
        function is redefined. It is possible since instrumenter has access to the whole system.&lt;br /&gt;
&lt;br /&gt;
            Ilinca: Well, this would definitely be the more... correct solution, but it's also a lot more &lt;br /&gt;
            work. Couldn't this also be done by not wrapping the function, but simply calling it and adding &lt;br /&gt;
            some exception handling code to the unfolder? I mean, the unfolder would try to call all &lt;br /&gt;
            argument-less functions of a class on an object, and, if it gets a precondition violation, &lt;br /&gt;
            it catches the exception and it declares that particular function as nonsensical?&lt;br /&gt;
&lt;br /&gt;
 Nadia: I would like to return to the subject of checking &amp;quot;static&amp;quot; or &amp;quot;dynamic&amp;quot; preconditions &lt;br /&gt;
 before function calls in unfolding. I think that this problem arises because the semantics &lt;br /&gt;
 of special variable value &amp;quot;nonsensical&amp;quot; in Daikon is ambiguous.&lt;br /&gt;
&lt;br /&gt;
 In Java and C there are no preconditions, so this value is originally used in Daikon for the &lt;br /&gt;
 only purpose: if a pointer of reference is null, then the dereferenced value (and its attributes, &lt;br /&gt;
 if the value is not of primitive type) is declared &amp;quot;nonsensical&amp;quot;. In Eiffel we will use &lt;br /&gt;
 &amp;quot;nonsensical&amp;quot; for this purpose too: if a reference entity is void, then its queries will be output &lt;br /&gt;
 as &amp;quot;nonsensical&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
 However, in Eiffel we have one more source of problems with evaluating variables: if a variable is &lt;br /&gt;
 a result of a function call, then function precondition may not hold, so we won't be able to &lt;br /&gt;
 evaluate its result. In this case the variable value should also be declared &amp;quot;nonsensical&amp;quot;, because &lt;br /&gt;
 this is the only special value in Daikon, which denotes that variable can't be evaluated. However, &lt;br /&gt;
 in this case there appears a question: what does it mean that the variable can't be evaluated? Does &lt;br /&gt;
 it mean that something terrible will happen (e.g., exception), if we try to evaluate it? Or does &lt;br /&gt;
 it mean that it isn't legal to evaluate this variable in this program state?&lt;br /&gt;
&lt;br /&gt;
 If we take the first point, then we should check dynamic precondition, because if static precondition &lt;br /&gt;
 doesn't hold, but dynamic does, nothing terrible will happen during function call.&lt;br /&gt;
&lt;br /&gt;
 If we take the second point, we should check static precondition, because if it doesn't hold then &lt;br /&gt;
 it's illegal to call this function, even if dynamic precondition holds. This point seems more &lt;br /&gt;
 correct to me, and here is an example that illustrates the situation.&lt;br /&gt;
&lt;br /&gt;
 Consider class `INT_LIST' (with feature `item' that has a precondition `not off') and it's heir - &lt;br /&gt;
 class EXTRAPOLATED_INT_LIST (that weakens precondition of `item'):&lt;br /&gt;
&lt;br /&gt;
 class INT_LIST&lt;br /&gt;
 ...&lt;br /&gt;
 feature&lt;br /&gt;
    item: INTEGER is&lt;br /&gt;
       require&lt;br /&gt;
          not off&lt;br /&gt;
       ...&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class EXTRAPOLATED_INT_LIST&lt;br /&gt;
 inherit&lt;br /&gt;
    INT_LIST&lt;br /&gt;
    redefine&lt;br /&gt;
       item&lt;br /&gt;
    end&lt;br /&gt;
 ...&lt;br /&gt;
 feature&lt;br /&gt;
    item: INTEGER is&lt;br /&gt;
       require else True&lt;br /&gt;
       do&lt;br /&gt;
          if not off then&lt;br /&gt;
             Result := Precursor&lt;br /&gt;
          else&lt;br /&gt;
             Result := 0&lt;br /&gt;
          end&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Consider also class CLIENT, which is a client of INT_LIST:&lt;br /&gt;
&lt;br /&gt;
 class CLIENT&lt;br /&gt;
 ...&lt;br /&gt;
 feature&lt;br /&gt;
    test (a_list: INT_LIST) is&lt;br /&gt;
       do ... end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Imagine that during system execution, when contracts were inferred, actual argument of `test' was &lt;br /&gt;
 always a direct instance of EXTRAPOLATED_INT_LIST,  and in addition it was always passed to this &lt;br /&gt;
 procedure in such a state that cursor was before the first element (`off' was true). If we check &lt;br /&gt;
 dynamic preconditions for functions in unfolding, than a precondition, inferred for `test', will &lt;br /&gt;
 be something like this:&lt;br /&gt;
&lt;br /&gt;
 require&lt;br /&gt;
   a_list /= Void&lt;br /&gt;
   a_list.off&lt;br /&gt;
   a_list.item = 0&lt;br /&gt;
&lt;br /&gt;
 But this contract isn't correct (as for me), although it is, certainly, true for a specific system &lt;br /&gt;
 execution. It becomes a little more correct, if we infer:&lt;br /&gt;
&lt;br /&gt;
 require&lt;br /&gt;
   a_list /= Void&lt;br /&gt;
   a_list.off&lt;br /&gt;
   a_list.generator = &amp;quot;EXTRAPOLATED_INT_LIST&amp;quot;&lt;br /&gt;
   a_list.item = 0&lt;br /&gt;
&lt;br /&gt;
 However, such contracts (connected with dynamic type of variable) seem useless to me. One of the &lt;br /&gt;
 goals of dynamic contract inference is to eliminate those properties that happened by chance and &lt;br /&gt;
 are not intended properties of the code. Properties that are connected with dynamic types definitely &lt;br /&gt;
 happen by chance: they can't be intended properties, because if programmer wanted his software to &lt;br /&gt;
 have such a property, he would change static entity type to a more specific (based on descendant).&lt;br /&gt;
&lt;br /&gt;
 Such properties may be useful only if we treat them not as contracts but rather as some kind of &lt;br /&gt;
 runtime statistics. Programmer may be interested in information that is true for a specific system &lt;br /&gt;
 execution, e.g. for debug purposes. It might be useful to add such a feature (inference of dynamic &lt;br /&gt;
 type information and properties, connected with dynamic types) in future, but it isn't &amp;quot;classic&amp;quot; &lt;br /&gt;
 contract inference, as for me, so I don't think that we need it in the first version. And if we &lt;br /&gt;
 don't want to know anything about dynamic types, then we should check static preconditions of &lt;br /&gt;
 functions during unfolding.&lt;br /&gt;
&lt;br /&gt;
====Checking hand-written contracts====&lt;br /&gt;
    Ilinca: There's one further problem with this approach: when a function &lt;br /&gt;
    is called as part of the evaluation of a contract, this function's &lt;br /&gt;
    contracts are not checked. The reason for this is to avoid infinite &lt;br /&gt;
    loops. If you wrap your precondition into a function, the contracts of &lt;br /&gt;
    any routines it calls will be evaluated, and thus the system can &lt;br /&gt;
    actually behave differently.&lt;br /&gt;
&lt;br /&gt;
    Should we check at all the hand-written contracts of a system for which CITADEL  &lt;br /&gt;
    is trying to infer contracts? We could also start from the assumption that Daikon &lt;br /&gt;
    uses: the tool is given a set of passing test cases and from those it has to infer &lt;br /&gt;
    contracts. If the inferred contracts somehow contradict the hand-written ones, then &lt;br /&gt;
    there's a problem in the system, and the source of the  problem may be that the &lt;br /&gt;
    hand-written contracts are faulty. What do you think?&lt;br /&gt;
    &lt;br /&gt;
        Nadia: I think that it makes sense to turn assertion checking off when running &lt;br /&gt;
        instrumented system. This will solve the problem with functions inside wrapped &lt;br /&gt;
        preconditions, which you've mentioned.&lt;br /&gt;
&lt;br /&gt;
        In current version instrumented system is supposed to behave exactly the same way &lt;br /&gt;
        as the original system did (except for creating a trace file). So, if a user was &lt;br /&gt;
        sure about the original, hand-written contracts and wanted to check the system against &lt;br /&gt;
        them, he/she could run the original system with assertion checking on, make sure that &lt;br /&gt;
        everything is ok and after that perform contract inference.&lt;br /&gt;
&lt;br /&gt;
        On the other hand, returning to using functions in unfolding: for these calls we have to &lt;br /&gt;
        check hand-written preconditions, because they were introduced by instrumenter, so they are &lt;br /&gt;
        not parts of &amp;quot;passing test cases&amp;quot;. Fortunately, as you said before, erroneous preconditions &lt;br /&gt;
        are very rare.&lt;br /&gt;
&lt;br /&gt;
====Checking preconditions (wrapping vs. qualification)====&lt;br /&gt;
 Nadia: I started implementing function preconditions checks in unfolding recently and realized &lt;br /&gt;
 that my first idea (to wrap these preconditions into functions) has an important disadvantage. &lt;br /&gt;
 Without creating new functions for preconditions if we instrument a class, then only the source &lt;br /&gt;
 code of that very class changes. However, if during class instrumentation we add functions to &lt;br /&gt;
 its clients, then the source code of those clients also changes. It isn't a disaster, of cause, &lt;br /&gt;
 but it's an unpleasant property, as for me. It would be nice, if class instrumentation affected &lt;br /&gt;
 only the class itself.&lt;br /&gt;
&lt;br /&gt;
 The other solution is not to wrap preconditions into functions, but to &amp;quot;qualify&amp;quot; them: if we want &lt;br /&gt;
 to check precondition before calling a function `x.f', we should take f's precondition and &lt;br /&gt;
 replaced all unqualified calls in it by qualified calls with target `x' and all occurrences of &lt;br /&gt;
 `Current' by `x'. This replacement is not difficult conceptually, but its implementation is quite &lt;br /&gt;
 voluminous (during this operation we have to replace some identifiers in an expression with function &lt;br /&gt;
 calls, so we need to redefine all `process_&amp;lt;something&amp;gt;' procedures of ET_AST_ITERATOR, where &lt;br /&gt;
 &amp;lt;something&amp;gt; can appear in expression and can contain identifiers).&lt;br /&gt;
&lt;br /&gt;
 What do you think about these two solutions (&amp;quot;wrapping into functions&amp;quot; and &amp;quot;qualification&amp;quot;)?&lt;br /&gt;
&lt;br /&gt;
    Ilinca: I think the best way to go is to wrap the precondition in a function in the class that &lt;br /&gt;
    it belongs to. Wrapping it in a function in clients would break encapsulation: you would only &lt;br /&gt;
    be allowed to access the exported features. I don't see any advantages of qualification over &lt;br /&gt;
    function-wrapping, so I think it makes sense to choose the least-work solution&lt;br /&gt;
&lt;br /&gt;
        Nadia: My previous explanation of the problem with &amp;quot;wrapping&amp;quot; was a little bit confused &lt;br /&gt;
        (I wrote that functions have to be added to clients of instrumented class, but actually &lt;br /&gt;
        I meant quite the opposite: that they should be added to suppliers:) )&lt;br /&gt;
&lt;br /&gt;
        Wrapping a precondition in a function in the class that it belongs to is exactly what I &lt;br /&gt;
        wanted to do firstly. The reason for it was that, if we instrument a class `C' and it has, &lt;br /&gt;
        say, an attribute `x: LIST[INTEGER]', then unfolded form of `Current' variable will include &lt;br /&gt;
        a variable `x.first'. Precondition of function `first' in class LIST is `not empty'. However, &lt;br /&gt;
        we need to check this precondition not inside LIST, but inside routines of class `C'. In fact, &lt;br /&gt;
        printing instruction for variable `x.first' should be guarded by condition like this:&lt;br /&gt;
        if x /= Void and then not x.empty then&lt;br /&gt;
           print (x.first)&lt;br /&gt;
        end&lt;br /&gt;
        We can't just take a precondition from `first' and insert it into the guarding condition as is, &lt;br /&gt;
        instead we should &amp;quot;qualify&amp;quot; the call to `empty' with target `x'.&lt;br /&gt;
&lt;br /&gt;
        Firstly qualification seemed too complex to me, so I decided to wrap `not empty' into function, say,&lt;br /&gt;
        `first_precondition: BOOLEAN' and add it to class `LIST', so that inside `C' I can check simpler &lt;br /&gt;
        condition before printing x.first:&lt;br /&gt;
        if x /= Void and then x.first_precondition then&lt;br /&gt;
            print (x.first)&lt;br /&gt;
        end.&lt;br /&gt;
        However, as you can see, it involves modifying class `LIST' (and possibly any other supplier of &lt;br /&gt;
        `C') while instrumenting `C'. If only `C' changed, then we could print only its source code after &lt;br /&gt;
        instrumentation, we could compile only `C' (if incremental compilation is used) and don't recompile &lt;br /&gt;
        base library, we would have no problems with tracking added functions (the problems are like this: &lt;br /&gt;
        if we instrument class `LIST' after `C', we probably don't want neither to instrument added functions, &lt;br /&gt;
        nor to see them in unfolded form of `Current' variable of class `LIST'). As for me, wrapping adds &lt;br /&gt;
        surplus dependencies into the system, and software never benefits from dependencies :)&lt;br /&gt;
&lt;br /&gt;
        That is why later I inclined to &amp;quot;qualification&amp;quot; solution. Actually, I have already mostly implemented &lt;br /&gt;
        it:) Current implementation might be incomplete, there are several syntactic constructs that it doesn't &lt;br /&gt;
        handle, because I'm not sure that they can appear in preconditions, but I'll check it and fix the problem.&lt;br /&gt;
&lt;br /&gt;
            Ilinca: Ok, so what I was thinking about was that you wanted to wrap the whole precondition of &lt;br /&gt;
            `first' into a function in class C. So, in class C you would have a routine&lt;br /&gt;
            precondition_first (l: LIST[G]): BOOLEAN&lt;br /&gt;
                 require&lt;br /&gt;
                      l_not_void: l /= Void&lt;br /&gt;
                 do&lt;br /&gt;
                      Result := not l.empty&lt;br /&gt;
                 end&lt;br /&gt;
            Then the guard for printing x.first would be&lt;br /&gt;
                 if x /= Void and then precondition_first (x) then&lt;br /&gt;
                      print (x.first)&lt;br /&gt;
                 end&lt;br /&gt;
&lt;br /&gt;
            But of course whether or not you wrap the precondition in a function or just quote it in the if &lt;br /&gt;
            statement does not make a big difference.&lt;br /&gt;
&lt;br /&gt;
 One more question: should the tool allow instrumenting library classes? If a library was precompiled, &lt;br /&gt;
 then instrumenting any of its classes will result in recompiling the whole library, am I right? Are &lt;br /&gt;
 precompiled libraries anyway recompiled during system finalization or not? (It matters for choosing &lt;br /&gt;
 between &amp;quot;wrapping into functions&amp;quot; and &amp;quot;qualification&amp;quot; solutions, because &amp;quot;wrapping into functions&amp;quot; can &lt;br /&gt;
 change library classes, even if user wants to implement only classes from his own clusters).&lt;br /&gt;
&lt;br /&gt;
===Support for loop invariants===&lt;br /&gt;
 Ilinca: Does the &amp;quot;classic&amp;quot; Daikon support loop invariants?&lt;br /&gt;
&lt;br /&gt;
 Nadia: Daikon uses standard program point &lt;br /&gt;
  suffixes to infer more invariants. E.g., it understands that &lt;br /&gt;
  some_routine:::ENTER and some_routine:::EXIT are entry and exit points &lt;br /&gt;
  of the same routine. Thanks to this, it knows `old' values of variables &lt;br /&gt;
  at exit and can infer invariants like &amp;quot;x = old x&amp;quot;. As I understood, if &lt;br /&gt;
  Daikon sees an unknown suffix, it treats corresponding program point as, &lt;br /&gt;
  so to say, &amp;quot;standalone&amp;quot; and doesn't try to connect it with any other.&lt;br /&gt;
  We don't need any extra support from Daikon to handle loop invariants.&lt;br /&gt;
  &lt;br /&gt;
  If we want to infer loop invariants, we should introduce a separate &lt;br /&gt;
  program point for each loop. So, we need a way to distinguish loops &lt;br /&gt;
  within a routine. One way is to take its position in source code as &lt;br /&gt;
  index. However, I thought, that position is too unstable to become loop &lt;br /&gt;
  identifier, so I chose instruction number instead. These numbers are &lt;br /&gt;
  unique numbers of instructions within surrounding routine, they may be &lt;br /&gt;
  used not only for loops, but for arbitrary instructions. &lt;br /&gt;
  CI_INSTRUCTION_COUNTER is responsible for counting instruction while &lt;br /&gt;
  iterating through AST.&lt;br /&gt;
&lt;br /&gt;
===Inferring contracts for generic classes===&lt;br /&gt;
 Nadia: there are actually two different cases.&lt;br /&gt;
  1. Contracts inside generic classes. This is not really a problem. &lt;br /&gt;
  Entities, which have parameter type, can be treated as if their &lt;br /&gt;
  generator is constraining class (ANY, if genericity is unconstrained).&lt;br /&gt;
  &lt;br /&gt;
  2. Contracts in clients of generic classes. Here some problems arise. If &lt;br /&gt;
  we have an entity `x: ARRAYED_LIST[INTEGER]', its unfolding involves &lt;br /&gt;
  processing the `item' query. `item' is declared to be of type `G' in &lt;br /&gt;
  ARRAYED_LIST and, as I understand, parsing is not enough (some type &lt;br /&gt;
  analysis is needed) to infer that `G' means `INTEGER' in current &lt;br /&gt;
  context. Two approaches to this problem, that I see at present, are: &lt;br /&gt;
  perform such a type analysis in compile time (with the help of gobo &lt;br /&gt;
  compilation facilities) or leave some unfolding work until runtime, &lt;br /&gt;
  when reflections may be used to determine variable's generating class.&lt;/div&gt;</summary>
		<author><name>Nadia Polikarpova</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=CITADEL&amp;diff=10132</id>
		<title>CITADEL</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=CITADEL&amp;diff=10132"/>
				<updated>2007-12-25T12:16:38Z</updated>
		
		<summary type="html">&lt;p&gt;Nadia Polikarpova: /* Unfolded variables */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Assertion checking]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
CITADEL (Contract-Inference Tool that Applies Daikon to the Eiffel Language) is a tool that provides an Eiffel front-end for the Daikon invariant detector. It is being implemented as a Master's project by Nadia Polikarpova supervised by Ilinca Ciupa (ETH).&lt;br /&gt;
&lt;br /&gt;
==Discussions==&lt;br /&gt;
===Unfolded variables===&lt;br /&gt;
 Nadia: Daikon can process values of only few types: five scalar types (boolean, &lt;br /&gt;
  integer, double, string and hashcode) and five more types, which are &lt;br /&gt;
  arrays of these scalars.&lt;br /&gt;
  So, if in Eiffel code we a have a variable of one of basic types &lt;br /&gt;
  (BOOLEAN, NATURAL, INTEGER, REAL or STRING) we can print its value &lt;br /&gt;
  directly as if it has one of Daikon's types.&lt;br /&gt;
  If, however, we have a variable of any other type, we have to collect &lt;br /&gt;
  all the information about it that is of interest and is available at &lt;br /&gt;
  certain program point, and present this information to Daikon as a set &lt;br /&gt;
  of  variables, which have Daikon types. The information of interest &lt;br /&gt;
  about a variable includes results of all queries that can be called on &lt;br /&gt;
  this variable at this program point.  However, since queries results may &lt;br /&gt;
  themselves be of non-basic types, we have to perform this operation &lt;br /&gt;
  recursively (to a certain depth).&lt;br /&gt;
  For a reference variable information of interest includes also its &lt;br /&gt;
  address (Daikon type &amp;quot;hashcode&amp;quot; is intended for representing object &lt;br /&gt;
  addresses).&lt;br /&gt;
  For example, if we had a variable c: POINT, queries of class POINT &lt;br /&gt;
  available at current program point were `x: REAL', `y: REAL' and `twin: &lt;br /&gt;
  POINT' and unfolding depth were set to 2, then `c.unfolded' would be a &lt;br /&gt;
  set of variables: {$c, c.x, c.y, $c.twin, c.twin.x, c.twin.y}.&lt;br /&gt;
  &lt;br /&gt;
  Containers need special kind of unfolding. If we want Daikon to handle &lt;br /&gt;
  them sensibly, they should be converted to arrays of scalars (to be more &lt;br /&gt;
  precise, it should be done only if all container elements are observable &lt;br /&gt;
  at current program point...). It isn't difficult for descendants of &lt;br /&gt;
  CONTAINER class from standard library. Instrumenter may check, if a &lt;br /&gt;
  variable is an indirect instance of CONTAINER, get its &lt;br /&gt;
  `linear_representation', then traverse it and output as array. I think &lt;br /&gt;
  that in the first version we may leave aside those containers, that &lt;br /&gt;
  aren't inherited from CONTAINER.&lt;br /&gt;
&lt;br /&gt;
====Functions in unfolded form====&lt;br /&gt;
 Ilinca: I'm not sure about the idea of including argument-less functions in &lt;br /&gt;
  this unfolded form. What if the precondition of the function doesn't &lt;br /&gt;
  hold or we run into some kind of trouble when executing the function &lt;br /&gt;
  body (trouble such as the contracts of a sub-call made by this &lt;br /&gt;
  function not holding or other bugs)? On the other hand, including &lt;br /&gt;
  functions would bring significantly more information about the state &lt;br /&gt;
  of the object... Does the Daikon frontend for Java, for instance, by &lt;br /&gt;
  default evaluate functions too as part of the unfolded form of the &lt;br /&gt;
  objects?&lt;br /&gt;
&lt;br /&gt;
 Nadia: Well, this idea is disputable, of cause.&lt;br /&gt;
  In Java considering argument-less functions as variables is more &lt;br /&gt;
  dangerous, because Java, like all C-family languages, encourages &lt;br /&gt;
  side-effects in functions. However, in Daikon front-end for Java there &lt;br /&gt;
  exists an option that allows using functions as variables. Together with &lt;br /&gt;
  enabling this option user has to provide a special &amp;quot;purity&amp;quot; file that &lt;br /&gt;
  lists those functions from the system, that are side-effect free. This &lt;br /&gt;
  feature is described in Daikon User Manual, page 82.&lt;br /&gt;
  Considering functions as variables is even more relevant in Eiffel &lt;br /&gt;
  context by two main reasons. Firstly, Eiffel encourages absence of &lt;br /&gt;
  abstract side-effects in functions (and, I believe, most Eiffel &lt;br /&gt;
  functions indeed do not have abstract side-effect, am I right?). For &lt;br /&gt;
  those cases, when some functions in system are known to have &lt;br /&gt;
  side-effect, we can allow user to specify an &amp;quot;impurity&amp;quot; file, that would &lt;br /&gt;
  list those functions. I think that these cases would be rare.&lt;br /&gt;
  &lt;br /&gt;
    Ilinca: Indeed, I also think these cases would be rare, but, depending on the &lt;br /&gt;
    size of the system, it might be very cumbersome for users to determine &lt;br /&gt;
    these functions.&lt;br /&gt;
&lt;br /&gt;
        Nadia: Well, a parameter may be introduced that will turn this facility on &lt;br /&gt;
        and off. So, if a user knows that there are many impure functions in system, &lt;br /&gt;
        he/she will just turn it off. I think, that its enough for the first version.&lt;br /&gt;
        In future some additional functionality may be introduced. In fact, a user may &lt;br /&gt;
        not know about all impure functions in system (especially in code that was written &lt;br /&gt;
        by someone else). The tool can help user to determine, did anything go wrong with &lt;br /&gt;
        using functions in unfolding. For example, it may do instrumentation twice: first &lt;br /&gt;
        time using only attributes and second time using functions also. As a result two &lt;br /&gt;
        trace files are produces. Then the tool can compare attributes values in two files. &lt;br /&gt;
        If they are the same, then with certain degree of confidence we can say, that called &lt;br /&gt;
        functions had no abstract side effect.&lt;br /&gt;
        As I understand, precise analysis of abstract side-effect presence or absence in beyond &lt;br /&gt;
        the state of the art. However, some methods which perform approximate analysis may be &lt;br /&gt;
        introduced.&lt;br /&gt;
        Another interesting solution that came to mind is to store object's state each time before &lt;br /&gt;
        calling a function and then recover object after the call. In this case we don't care about &lt;br /&gt;
        function purity, we just get a result that this function might have had, if it was called at &lt;br /&gt;
        this point :)&lt;br /&gt;
        Anyway, different partial solutions to this problem may be implemented and user may combine &lt;br /&gt;
        different strategies to get a desired result with a desired degree of confidence.&lt;br /&gt;
        Conceptually, my point here is: why an &amp;quot;honest&amp;quot; Eiffel programmer, who never writes impure &lt;br /&gt;
        functions, has to suffer (get less expressive contracts) because of other programmers, who &lt;br /&gt;
        sometimes write impure functions?:)&lt;br /&gt;
&lt;br /&gt;
            Ilinca: :) Indeed, the honest Eiffel programmer shouldn't suffer. So in conclusion, I &lt;br /&gt;
            think we should go for the solution with the file containing the names of impure functions, &lt;br /&gt;
            as Daikon does it. Adding the switch which turns it on and off is also a good idea. &lt;br /&gt;
&lt;br /&gt;
    Ilinca: Something else: what Daikon calls &amp;quot;purity&amp;quot; is actually &lt;br /&gt;
    weak purity, isn't it? (Weak purity means that creations of local &lt;br /&gt;
    variables are allowed in the body of a pure function. Strong purity &lt;br /&gt;
    disallows this.)&lt;br /&gt;
&lt;br /&gt;
        Nadia: Chicory (Java front end) doesn't check purity of functions that are listed in a purity &lt;br /&gt;
        file. User is totally responsible for what he/she writes in this file. So, I would say that, what &lt;br /&gt;
        Chicory calls purity isn't actually any special kind of purity. It only means that user allowed &lt;br /&gt;
        Chicory to call this functions anywhere in the system, and if something goes wrong, it's user's &lt;br /&gt;
        fault&lt;br /&gt;
  &lt;br /&gt;
  Nadia: Secondly, Eiffel advocates uniform access principle. Routine's clients &lt;br /&gt;
  don't have to know, which queries, used in precondition, are attributes &lt;br /&gt;
  and which are functions. If inferred preconditions contained only &lt;br /&gt;
  attributes, it would be inconsistent with uniform access principle, I &lt;br /&gt;
  think...&lt;br /&gt;
&lt;br /&gt;
  Nadia: As for troubles that may arise when calling functions... As I &lt;br /&gt;
  understand, exception in a function, called when its precondition holds, &lt;br /&gt;
  is a bug. So, if it happens, we can just tell user that we found a bug &lt;br /&gt;
  in certain function and that before inferring contracts the bug should &lt;br /&gt;
  be fixed.&lt;br /&gt;
&lt;br /&gt;
====Checking preconditions (static vs. dynamic)====  &lt;br /&gt;
  The issue with functions' preconditions that you've mentioned isn't a &lt;br /&gt;
  big problem. If after unfolding we got a variable of the form, e.g., &lt;br /&gt;
  `x.f1.f2', where `f1' and `f2' are functions, printing instructions for &lt;br /&gt;
  this variable can be like this:&lt;br /&gt;
    if x.f1_precondition_holds and then x.f1.f2_precondition_holds&lt;br /&gt;
    then&lt;br /&gt;
       print (x.f1.f2)&lt;br /&gt;
    else&lt;br /&gt;
       print (Nonsensical)&lt;br /&gt;
    end&lt;br /&gt;
  &amp;quot;Nonsensical&amp;quot; is a special Daikon value that indicates that variable &lt;br /&gt;
  cannot be evaluated.&lt;br /&gt;
  Function preconditions are known after parsing. To be able to evaluate &lt;br /&gt;
  them separately, we may, for example, wrap them into functions. &lt;br /&gt;
  `f1_precondition_holds' in the above code is an example of such a &lt;br /&gt;
  function, that was introduced by instrumenter and added to x's &lt;br /&gt;
  generating class.&lt;br /&gt;
  &lt;br /&gt;
    Ilinca: I don't think it's that easy, mainly because of polymorphism. Statically &lt;br /&gt;
    you can't determine the type that x will be a direct instance of at &lt;br /&gt;
    runtime. Hence, you don't know which preconditions to wrap. Of course, &lt;br /&gt;
    since redefined routines can keep or weaken the preconditions of the &lt;br /&gt;
    original routines, you can take the pessimistic approach of wrapping &lt;br /&gt;
    only the precondition of the function from the static type of x, but &lt;br /&gt;
    then you might miss cases in which the weakened version of the &lt;br /&gt;
    precondition does hold. Do you understand my point?&lt;br /&gt;
&lt;br /&gt;
        Nadia: Yeah, I see...&lt;br /&gt;
        I think that the main question here is: should we check &amp;quot;static&amp;quot; or &amp;quot;dynamic&amp;quot; &lt;br /&gt;
        preconditions when calling a function?&lt;br /&gt;
        On the one hand, in Eiffel we can write something like:&lt;br /&gt;
        class A&lt;br /&gt;
           ...&lt;br /&gt;
           sqrt (x: REAL): REAL&lt;br /&gt;
               require&lt;br /&gt;
                   x &amp;gt;= 0.0&lt;br /&gt;
               do ... end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        class B&lt;br /&gt;
           inherit A&lt;br /&gt;
              redefine sqrt end&lt;br /&gt;
           ...&lt;br /&gt;
           sqrt (x: REAL): REAL&lt;br /&gt;
               require else&lt;br /&gt;
                 True&lt;br /&gt;
               do ... end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        class TEST&lt;br /&gt;
            ...&lt;br /&gt;
            an_a: A&lt;br /&gt;
&lt;br /&gt;
            make is&lt;br /&gt;
               do&lt;br /&gt;
                    create {B} an_a&lt;br /&gt;
                    print (an_a.sqrt (-1.0))&lt;br /&gt;
               end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        It works, and assertion checking mechanism doesn't indicate any error.&lt;br /&gt;
        But, on the other hand, is it legal? Am I allowed to call a function if it's &lt;br /&gt;
        static precondition doesn't hold?&lt;br /&gt;
        As I understand, if I want to make sure that it's legal to call a routine at some &lt;br /&gt;
        program point, I have to check it's static precondition. Even if today I'm sure that &lt;br /&gt;
        dynamic type of `an_a' is always `B', this needn't remain the same tomorrow...&lt;br /&gt;
&lt;br /&gt;
            Ilinca: That's correct. If the &amp;quot;static&amp;quot; precondition of a routine holds, this &lt;br /&gt;
            implies of course that the preconditions of all its redefinitions will also hold. &lt;br /&gt;
            But I was calling this approach &amp;quot;pessimistic&amp;quot; because the precondition of a redefined &lt;br /&gt;
            version of a routine may hold even though the &amp;quot;static&amp;quot; precondition doesn't.&lt;br /&gt;
&lt;br /&gt;
        So, if a programmer wanted to know function value at a program point, he/she would check &lt;br /&gt;
        its static precondition. Then why instrumenter should act differently? Well, actually &lt;br /&gt;
        there is a difference:  instrumenter not only avoids function call when precondition &lt;br /&gt;
        doesn't hold, but also claims that function value is nonsensical. From one point of view, &lt;br /&gt;
        such behavior is incorrect, because function actually could be called and a sensible value &lt;br /&gt;
        could be received. From the other point, since it was illegal to call the function this time, &lt;br /&gt;
        it makes sense to declare function value nonsensical.&lt;br /&gt;
        To sum up, I think that it is rather a philosophical then a technical problem, but, as for me, &lt;br /&gt;
        checking static preconditions is more appropriate.&lt;br /&gt;
        However, if we wanted to check a dynamic precondition, it's also possible. We can wrap function's &lt;br /&gt;
        precondition into a special function and redefine that special function any time the original &lt;br /&gt;
        function is redefined. It is possible since instrumenter has access to the whole system.&lt;br /&gt;
&lt;br /&gt;
            Ilinca: Well, this would definitely be the more... correct solution, but it's also a lot more &lt;br /&gt;
            work. Couldn't this also be done by not wrapping the function, but simply calling it and adding &lt;br /&gt;
            some exception handling code to the unfolder? I mean, the unfolder would try to call all &lt;br /&gt;
            argument-less functions of a class on an object, and, if it gets a precondition violation, &lt;br /&gt;
            it catches the exception and it declares that particular function as nonsensical?&lt;br /&gt;
&lt;br /&gt;
 Nadia: I would like to return to the subject of checking &amp;quot;static&amp;quot; or &amp;quot;dynamic&amp;quot; preconditions &lt;br /&gt;
 before function calls in unfolding. I think that this problem arises because the semantics &lt;br /&gt;
 of special variable value &amp;quot;nonsensical&amp;quot; in Daikon is ambiguous.&lt;br /&gt;
 In Java and C there are no preconditions, so this value is originally used in Daikon for the &lt;br /&gt;
 only purpose: if a pointer of reference is null, then the dereferenced value (and its attributes, &lt;br /&gt;
 if the value is not of primitive type) is declared &amp;quot;nonsensical&amp;quot;. In Eiffel we will use &lt;br /&gt;
 &amp;quot;nonsensical&amp;quot; for this purpose too: if a reference entity is void, then its queries will be output &lt;br /&gt;
 as &amp;quot;nonsensical&amp;quot;.&lt;br /&gt;
 However, in Eiffel we have one more source of problems with evaluating variables: if a variable is &lt;br /&gt;
 a result of a function call, then function precondition may not hold, so we won't be able to &lt;br /&gt;
 evaluate its result. In this case the variable value should also be declared &amp;quot;nonsensical&amp;quot;, because &lt;br /&gt;
 this is the only special value in Daikon, which denotes that variable can't be evaluated. However, &lt;br /&gt;
 in this case there appears a question: what does it mean that the variable can't be evaluated? Does &lt;br /&gt;
 it mean that something terrible will happen (e.g., exception), if we try to evaluate it? Or does &lt;br /&gt;
 it mean that it isn't legal to evaluate this variable in this program state?&lt;br /&gt;
 If we take the first point, then we should check dynamic precondition, because if static precondition &lt;br /&gt;
 doesn't hold, but dynamic does, nothing terrible will happen during function call.&lt;br /&gt;
 If we take the second point, we should check static precondition, because if it doesn't hold then &lt;br /&gt;
 it's illegal to call this function, even if dynamic precondition holds. This point seems more &lt;br /&gt;
 correct to me, and here is an example that illustrates the situation.&lt;br /&gt;
 Consider class `INT_LIST' (with feature `item' that has a precondition `not off') and it's heir - &lt;br /&gt;
 class EXTRAPOLATED_INT_LIST (that weakens precondition of `item'):&lt;br /&gt;
&lt;br /&gt;
 class INT_LIST&lt;br /&gt;
 ...&lt;br /&gt;
 feature&lt;br /&gt;
    item: INTEGER is&lt;br /&gt;
       require&lt;br /&gt;
          not off&lt;br /&gt;
       ...&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class EXTRAPOLATED_INT_LIST&lt;br /&gt;
 inherit&lt;br /&gt;
    INT_LIST&lt;br /&gt;
    redefine&lt;br /&gt;
       item&lt;br /&gt;
    end&lt;br /&gt;
 ...&lt;br /&gt;
 feature&lt;br /&gt;
    item: INTEGER is&lt;br /&gt;
       require else True&lt;br /&gt;
       do&lt;br /&gt;
          if not off then&lt;br /&gt;
             Result := Precursor&lt;br /&gt;
          else&lt;br /&gt;
             Result := 0&lt;br /&gt;
          end&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Consider also class CLIENT, which is a client of INT_LIST:&lt;br /&gt;
&lt;br /&gt;
 class CLIENT&lt;br /&gt;
 ...&lt;br /&gt;
 feature&lt;br /&gt;
    test (a_list: INT_LIST) is&lt;br /&gt;
       do ... end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Imagine that during system execution, when contracts were inferred, actual argument of `test' was &lt;br /&gt;
 always a direct instance of EXTRAPOLATED_INT_LIST,  and in addition it was always passed to this &lt;br /&gt;
 procedure in such a state that cursor was before the first element (`off' was true). If we check &lt;br /&gt;
 dynamic preconditions for functions in unfolding, than a precondition, inferred for `test', will &lt;br /&gt;
 be something like this:&lt;br /&gt;
&lt;br /&gt;
 require&lt;br /&gt;
   a_list /= Void&lt;br /&gt;
   a_list.off&lt;br /&gt;
   a_list.item = 0&lt;br /&gt;
&lt;br /&gt;
 But this contract isn't correct (as for me), although it is, certainly, true for a specific system &lt;br /&gt;
 execution. It becomes a little more correct, if we infer:&lt;br /&gt;
&lt;br /&gt;
 require&lt;br /&gt;
   a_list /= Void&lt;br /&gt;
   a_list.off&lt;br /&gt;
   a_list.generator = &amp;quot;EXTRAPOLATED_INT_LIST&amp;quot;&lt;br /&gt;
   a_list.item = 0&lt;br /&gt;
&lt;br /&gt;
 However, such contracts (connected with dynamic type of variable) seem useless to me. One of the &lt;br /&gt;
 goals of dynamic contract inference is to eliminate those properties that happened by chance and &lt;br /&gt;
 are not intended properties of the code. Properties that are connected with dynamic types definitely &lt;br /&gt;
 happen by chance: they can't be intended properties, because if programmer wanted his software to &lt;br /&gt;
 have such a property, he would change static entity type to a more specific (based on descendant).&lt;br /&gt;
 Such properties may be useful only if we treat them not as contracts but rather as some kind of &lt;br /&gt;
 runtime statistics. Programmer may be interested in information that is true for a specific system &lt;br /&gt;
 execution, e.g. for debug purposes. It might be useful to add such a feature (inference of dynamic &lt;br /&gt;
 type information and properties, connected with dynamic types) in future, but it isn't &amp;quot;classic&amp;quot; &lt;br /&gt;
 contract inference, as for me, so I don't think that we need it in the first version. And if we &lt;br /&gt;
 don't want to know anything about dynamic types, then we should check static preconditions of &lt;br /&gt;
 functions during unfolding.&lt;br /&gt;
&lt;br /&gt;
====Checking hand-written contracts====&lt;br /&gt;
    Ilinca: There's one further problem with this approach: when a function &lt;br /&gt;
    is called as part of the evaluation of a contract, this function's &lt;br /&gt;
    contracts are not checked. The reason for this is to avoid infinite &lt;br /&gt;
    loops. If you wrap your precondition into a function, the contracts of &lt;br /&gt;
    any routines it calls will be evaluated, and thus the system can &lt;br /&gt;
    actually behave differently.&lt;br /&gt;
    Should we check at all the hand-written contracts of a system for which CITADEL  &lt;br /&gt;
    is trying to infer contracts? We could also start from the assumption that Daikon &lt;br /&gt;
    uses: the tool is given a set of passing test cases and from those it has to infer &lt;br /&gt;
    contracts. If the inferred contracts somehow contradict the hand-written ones, then &lt;br /&gt;
    there's a problem in the system, and the source of the  problem may be that the &lt;br /&gt;
    hand-written contracts are faulty. What do you think?&lt;br /&gt;
    &lt;br /&gt;
        Nadia: I think that it makes sense to turn assertion checking off when running &lt;br /&gt;
        instrumented system. This will solve the problem with functions inside wrapped &lt;br /&gt;
        preconditions, which you've mentioned.&lt;br /&gt;
        In current version instrumented system is supposed to behave exactly the same way &lt;br /&gt;
        as the original system did (except for creating a trace file). So, if a user was &lt;br /&gt;
        sure about the original, hand-written contracts and wanted to check the system against &lt;br /&gt;
        them, he/she could run the original system with assertion checking on, make sure that &lt;br /&gt;
        everything is ok and after that perform contract inference.&lt;br /&gt;
        On the other hand, returning to using functions in unfolding: for these calls we have to &lt;br /&gt;
        check hand-written preconditions, because they were introduced by instrumenter, so they are &lt;br /&gt;
        not parts of &amp;quot;passing test cases&amp;quot;. Fortunately, as you said before, erroneous preconditions &lt;br /&gt;
        are very rare.&lt;br /&gt;
&lt;br /&gt;
====Checking preconditions (wrapping vs. qualification)====&lt;br /&gt;
 Nadia: I started implementing function preconditions checks in unfolding recently and realized &lt;br /&gt;
 that my first idea (to wrap these preconditions into functions) has an important disadvantage. &lt;br /&gt;
 Without creating new functions for preconditions if we instrument a class, then only the source &lt;br /&gt;
 code of that very class changes. However, if during class instrumentation we add functions to &lt;br /&gt;
 its clients, then the source code of those clients also changes. It isn't a disaster, of cause, &lt;br /&gt;
 but it's an unpleasant property, as for me. It would be nice, if class instrumentation affected &lt;br /&gt;
 only the class itself.&lt;br /&gt;
 The other solution is not to wrap preconditions into functions, but to &amp;quot;qualify&amp;quot; them: if we want &lt;br /&gt;
 to check precondition before calling a function `x.f', we should take f's precondition and &lt;br /&gt;
 replaced all unqualified calls in it by qualified calls with target `x' and all occurrences of &lt;br /&gt;
 `Current' by `x'. This replacement is not difficult conceptually, but its implementation is quite &lt;br /&gt;
 voluminous (during this operation we have to replace some identifiers in an expression with function &lt;br /&gt;
 calls, so we need to redefine all `process_&amp;lt;something&amp;gt;' procedures of ET_AST_ITERATOR, where &lt;br /&gt;
 &amp;lt;something&amp;gt; can appear in expression and can contain identifiers).&lt;br /&gt;
 What do you think about these two solutions (&amp;quot;wrapping into functions&amp;quot; and &amp;quot;qualification&amp;quot;)?&lt;br /&gt;
&lt;br /&gt;
    Ilinca: I think the best way to go is to wrap the precondition in a function in the class that &lt;br /&gt;
    it belongs to. Wrapping it in a function in clients would break encapsulation: you would only &lt;br /&gt;
    be allowed to access the exported features. I don't see any advantages of qualification over &lt;br /&gt;
    function-wrapping, so I think it makes sense to choose the least-work solution&lt;br /&gt;
&lt;br /&gt;
        Nadia: My previous explanation of the problem with &amp;quot;wrapping&amp;quot; was a little bit confused &lt;br /&gt;
        (I wrote that functions have to be added to clients of instrumented class, but actually &lt;br /&gt;
        I meant quite the opposite: that they should be added to suppliers:) )&lt;br /&gt;
        Wrapping a precondition in a function in the class that it belongs to is exactly what I &lt;br /&gt;
        wanted to do firstly. The reason for it was that, if we instrument a class `C' and it has, &lt;br /&gt;
        say, an attribute `x: LIST[INTEGER]', then unfolded form of `Current' variable will include &lt;br /&gt;
        a variable `x.first'. Precondition of function `first' in class LIST is `not empty'. However, &lt;br /&gt;
        we need to check this precondition not inside LIST, but inside routines of class `C'. In fact, &lt;br /&gt;
        printing instruction for variable `x.first' should be guarded by condition like this:&lt;br /&gt;
        if x /= Void and then not x.empty then&lt;br /&gt;
           print (x.first)&lt;br /&gt;
        end&lt;br /&gt;
        We can't just take a precondition from `first' and insert it into the guarding condition as is, &lt;br /&gt;
        instead we should &amp;quot;qualify&amp;quot; the call to `empty' with target `x'.&lt;br /&gt;
        Firstly qualification seemed too complex to me, so I decided to wrap `not empty' into function, say,&lt;br /&gt;
        `first_precondition: BOOLEAN' and add it to class `LIST', so that inside `C' I can check simpler &lt;br /&gt;
        condition before printing x.first:&lt;br /&gt;
        if x /= Void and then x.first_precondition then&lt;br /&gt;
            print (x.first)&lt;br /&gt;
        end.&lt;br /&gt;
        However, as you can see, it involves modifying class `LIST' (and possibly any other supplier of &lt;br /&gt;
        `C') while instrumenting `C'. If only `C' changed, then we could print only its source code after &lt;br /&gt;
        instrumentation, we could compile only `C' (if incremental compilation is used) and don't recompile &lt;br /&gt;
        base library, we would have no problems with tracking added functions (the problems are like this: &lt;br /&gt;
        if we instrument class `LIST' after `C', we probably don't want neither to instrument added functions, &lt;br /&gt;
        nor to see them in unfolded form of `Current' variable of class `LIST'). As for me, wrapping adds &lt;br /&gt;
        surplus dependencies into the system, and software never benefits from dependencies :)&lt;br /&gt;
        That is why later I inclined to &amp;quot;qualification&amp;quot; solution. Actually, I have already mostly implemented &lt;br /&gt;
        it:) Current implementation might be incomplete, there are several syntactic constructs that it doesn't &lt;br /&gt;
        handle, because I'm not sure that they can appear in preconditions, but I'll check it and fix the problem.&lt;br /&gt;
&lt;br /&gt;
            Ilinca: Ok, so what I was thinking about was that you wanted to wrap the whole precondition of &lt;br /&gt;
            `first' into a function in class C. So, in class C you would have a routine&lt;br /&gt;
            precondition_first (l: LIST[G]): BOOLEAN&lt;br /&gt;
                 require&lt;br /&gt;
                      l_not_void: l /= Void&lt;br /&gt;
                 do&lt;br /&gt;
                      Result := not l.empty&lt;br /&gt;
                 end&lt;br /&gt;
            Then the guard for printing x.first would be&lt;br /&gt;
                 if x /= Void and then precondition_first (x) then&lt;br /&gt;
                      print (x.first)&lt;br /&gt;
                 end&lt;br /&gt;
            But of course whether or not you wrap the precondition in a function or just quote it in the if &lt;br /&gt;
            statement does not make a big difference.&lt;br /&gt;
&lt;br /&gt;
 One more question: should the tool allow instrumenting library classes? If a library was precompiled, &lt;br /&gt;
 then instrumenting any of its classes will result in recompiling the whole library, am I right? Are &lt;br /&gt;
 precompiled libraries anyway recompiled during system finalization or not? (It matters for choosing &lt;br /&gt;
 between &amp;quot;wrapping into functions&amp;quot; and &amp;quot;qualification&amp;quot; solutions, because &amp;quot;wrapping into functions&amp;quot; can &lt;br /&gt;
 change library classes, even if user wants to implement only classes from his own clusters).&lt;br /&gt;
&lt;br /&gt;
===Support for loop invariants===&lt;br /&gt;
 Ilinca: Does the &amp;quot;classic&amp;quot; Daikon support loop invariants?&lt;br /&gt;
&lt;br /&gt;
 Nadia: Daikon uses standard program point &lt;br /&gt;
  suffixes to infer more invariants. E.g., it understands that &lt;br /&gt;
  some_routine:::ENTER and some_routine:::EXIT are entry and exit points &lt;br /&gt;
  of the same routine. Thanks to this, it knows `old' values of variables &lt;br /&gt;
  at exit and can infer invariants like &amp;quot;x = old x&amp;quot;. As I understood, if &lt;br /&gt;
  Daikon sees an unknown suffix, it treats corresponding program point as, &lt;br /&gt;
  so to say, &amp;quot;standalone&amp;quot; and doesn't try to connect it with any other.&lt;br /&gt;
  We don't need any extra support from Daikon to handle loop invariants.&lt;br /&gt;
  &lt;br /&gt;
  If we want to infer loop invariants, we should introduce a separate &lt;br /&gt;
  program point for each loop. So, we need a way to distinguish loops &lt;br /&gt;
  within a routine. One way is to take its position in source code as &lt;br /&gt;
  index. However, I thought, that position is too unstable to become loop &lt;br /&gt;
  identifier, so I chose instruction number instead. These numbers are &lt;br /&gt;
  unique numbers of instructions within surrounding routine, they may be &lt;br /&gt;
  used not only for loops, but for arbitrary instructions. &lt;br /&gt;
  CI_INSTRUCTION_COUNTER is responsible for counting instruction while &lt;br /&gt;
  iterating through AST.&lt;br /&gt;
&lt;br /&gt;
===Inferring contracts for generic classes===&lt;br /&gt;
 Nadia: there are actually two different cases.&lt;br /&gt;
  1. Contracts inside generic classes. This is not really a problem. &lt;br /&gt;
  Entities, which have parameter type, can be treated as if their &lt;br /&gt;
  generator is constraining class (ANY, if genericity is unconstrained).&lt;br /&gt;
  &lt;br /&gt;
  2. Contracts in clients of generic classes. Here some problems arise. If &lt;br /&gt;
  we have an entity `x: ARRAYED_LIST[INTEGER]', its unfolding involves &lt;br /&gt;
  processing the `item' query. `item' is declared to be of type `G' in &lt;br /&gt;
  ARRAYED_LIST and, as I understand, parsing is not enough (some type &lt;br /&gt;
  analysis is needed) to infer that `G' means `INTEGER' in current &lt;br /&gt;
  context. Two approaches to this problem, that I see at present, are: &lt;br /&gt;
  perform such a type analysis in compile time (with the help of gobo &lt;br /&gt;
  compilation facilities) or leave some unfolding work until runtime, &lt;br /&gt;
  when reflections may be used to determine variable's generating class.&lt;/div&gt;</summary>
		<author><name>Nadia Polikarpova</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=CITADEL&amp;diff=10131</id>
		<title>CITADEL</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=CITADEL&amp;diff=10131"/>
				<updated>2007-12-25T12:13:42Z</updated>
		
		<summary type="html">&lt;p&gt;Nadia Polikarpova: Added topics: &amp;quot;chechink preconditions&amp;quot; (&amp;quot;static vs. dynamic&amp;quot; and &amp;quot;wrapping vs. qualification&amp;quot;) and &amp;quot;checking hand-written contracts&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Assertion checking]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
CITADEL (Contract-Inference Tool that Applies Daikon to the Eiffel Language) is a tool that provides an Eiffel front-end for the Daikon invariant detector. It is being implemented as a Master's project by Nadia Polikarpova supervised by Ilinca Ciupa (ETH).&lt;br /&gt;
&lt;br /&gt;
==Discussions==&lt;br /&gt;
===Unfolded variables===&lt;br /&gt;
 Nadia: Daikon can process values of only few types: five scalar types (boolean, &lt;br /&gt;
  integer, double, string and hashcode) and five more types, which are &lt;br /&gt;
  arrays of these scalars.&lt;br /&gt;
  So, if in Eiffel code we a have a variable of one of basic types &lt;br /&gt;
  (BOOLEAN, NATURAL, INTEGER, REAL or STRING) we can print its value &lt;br /&gt;
  directly as if it has one of Daikon's types.&lt;br /&gt;
  If, however, we have a variable of any other type, we have to collect &lt;br /&gt;
  all the information about it that is of interest and is available at &lt;br /&gt;
  certain program point, and present this information to Daikon as a set &lt;br /&gt;
  of  variables, which have Daikon types. The information of interest &lt;br /&gt;
  about a variable includes results of all queries that can be called on &lt;br /&gt;
  this variable at this program point.  However, since queries results may &lt;br /&gt;
  themselves be of non-basic types, we have to perform this operation &lt;br /&gt;
  recursively (to a certain depth).&lt;br /&gt;
  For a reference variable information of interest includes also its &lt;br /&gt;
  address (Daikon type &amp;quot;hashcode&amp;quot; is intended for representing object &lt;br /&gt;
  addresses).&lt;br /&gt;
  For example, if we had a variable c: POINT, queries of class POINT &lt;br /&gt;
  available at current program point were `x: REAL', `y: REAL' and `twin: &lt;br /&gt;
  POINT' and unfolding depth were set to 2, then `c.unfolded' would be a &lt;br /&gt;
  set of variables: {$c, c.x, c.y, $c.twin, c.twin.x, c.twin.y}.&lt;br /&gt;
  &lt;br /&gt;
  Containers need special kind of unfolding. If we want Daikon to handle &lt;br /&gt;
  them sensibly, they should be converted to arrays of scalars (to be more &lt;br /&gt;
  precise, it should be done only if all container elements are observable &lt;br /&gt;
  at current program point...). It isn't difficult for descendants of &lt;br /&gt;
  CONTAINER class from standard library. Instrumenter may check, if a &lt;br /&gt;
  variable is an indirect instance of CONTAINER, get its &lt;br /&gt;
  `linear_representation', then traverse it and output as array. I think &lt;br /&gt;
  that in the first version we may leave aside those containers, that &lt;br /&gt;
  aren't inherited from CONTAINER.&lt;br /&gt;
&lt;br /&gt;
====Functions in unfolded form====&lt;br /&gt;
 Ilinca: I'm not sure about the idea of including argument-less functions in &lt;br /&gt;
  this unfolded form. What if the precondition of the function doesn't &lt;br /&gt;
  hold or we run into some kind of trouble when executing the function &lt;br /&gt;
  body (trouble such as the contracts of a sub-call made by this &lt;br /&gt;
  function not holding or other bugs)? On the other hand, including &lt;br /&gt;
  functions would bring significantly more information about the state &lt;br /&gt;
  of the object... Does the Daikon frontend for Java, for instance, by &lt;br /&gt;
  default evaluate functions too as part of the unfolded form of the &lt;br /&gt;
  objects?&lt;br /&gt;
&lt;br /&gt;
 Nadia: Well, this idea is disputable, of cause.&lt;br /&gt;
  In Java considering argument-less functions as variables is more &lt;br /&gt;
  dangerous, because Java, like all C-family languages, encourages &lt;br /&gt;
  side-effects in functions. However, in Daikon front-end for Java there &lt;br /&gt;
  exists an option that allows using functions as variables. Together with &lt;br /&gt;
  enabling this option user has to provide a special &amp;quot;purity&amp;quot; file that &lt;br /&gt;
  lists those functions from the system, that are side-effect free. This &lt;br /&gt;
  feature is described in Daikon User Manual, page 82.&lt;br /&gt;
  Considering functions as variables is even more relevant in Eiffel &lt;br /&gt;
  context by two main reasons. Firstly, Eiffel encourages absence of &lt;br /&gt;
  abstract side-effects in functions (and, I believe, most Eiffel &lt;br /&gt;
  functions indeed do not have abstract side-effect, am I right?). For &lt;br /&gt;
  those cases, when some functions in system are known to have &lt;br /&gt;
  side-effect, we can allow user to specify an &amp;quot;impurity&amp;quot; file, that would &lt;br /&gt;
  list those functions. I think that these cases would be rare.&lt;br /&gt;
  &lt;br /&gt;
    Ilinca: Indeed, I also think these cases would be rare, but, depending on the &lt;br /&gt;
    size of the system, it might be very cumbersome for users to determine &lt;br /&gt;
    these functions.&lt;br /&gt;
&lt;br /&gt;
        Nadia: Well, a parameter may be introduced that will turn this facility on &lt;br /&gt;
        and off. So, if a user knows that there are many impure functions in system, &lt;br /&gt;
        he/she will just turn it off. I think, that its enough for the first version.&lt;br /&gt;
        &lt;br /&gt;
        In future some additional functionality may be introduced. In fact, a user may &lt;br /&gt;
        not know about all impure functions in system (especially in code that was written &lt;br /&gt;
        by someone else). The tool can help user to determine, did anything go wrong with &lt;br /&gt;
        using functions in unfolding. For example, it may do instrumentation twice: first &lt;br /&gt;
        time using only attributes and second time using functions also. As a result two &lt;br /&gt;
        trace files are produces. Then the tool can compare attributes values in two files. &lt;br /&gt;
        If they are the same, then with certain degree of confidence we can say, that called &lt;br /&gt;
        functions had no abstract side effect.&lt;br /&gt;
&lt;br /&gt;
        As I understand, precise analysis of abstract side-effect presence or absence in beyond &lt;br /&gt;
        the state of the art. However, some methods which perform approximate analysis may be &lt;br /&gt;
        introduced.&lt;br /&gt;
&lt;br /&gt;
        Another interesting solution that came to mind is to store object's state each time before &lt;br /&gt;
        calling a function and then recover object after the call. In this case we don't care about &lt;br /&gt;
        function purity, we just get a result that this function might have had, if it was called at &lt;br /&gt;
        this point :)&lt;br /&gt;
&lt;br /&gt;
        Anyway, different partial solutions to this problem may be implemented and user may combine &lt;br /&gt;
        different strategies to get a desired result with a desired degree of confidence.&lt;br /&gt;
&lt;br /&gt;
        Conceptually, my point here is: why an &amp;quot;honest&amp;quot; Eiffel programmer, who never writes impure &lt;br /&gt;
        functions, has to suffer (get less expressive contracts) because of other programmers, who &lt;br /&gt;
        sometimes write impure functions?:)&lt;br /&gt;
&lt;br /&gt;
            Ilinca: :) Indeed, the honest Eiffel programmer shouldn't suffer. So in conclusion, I &lt;br /&gt;
            think we should go for the solution with the file containing the names of impure functions, &lt;br /&gt;
            as Daikon does it. Adding the switch which turns it on and off is also a good idea. &lt;br /&gt;
&lt;br /&gt;
    Ilinca: Something else: what Daikon calls &amp;quot;purity&amp;quot; is actually &lt;br /&gt;
    weak purity, isn't it? (Weak purity means that creations of local &lt;br /&gt;
    variables are allowed in the body of a pure function. Strong purity &lt;br /&gt;
    disallows this.)&lt;br /&gt;
&lt;br /&gt;
        Nadia: Chicory (Java front end) doesn't check purity of functions that are listed in a purity &lt;br /&gt;
        file. User is totally responsible for what he/she writes in this file. So, I would say that, what &lt;br /&gt;
        Chicory calls purity isn't actually any special kind of purity. It only means that user allowed &lt;br /&gt;
        Chicory to call this functions anywhere in the system, and if something goes wrong, it's user's &lt;br /&gt;
        fault&lt;br /&gt;
  &lt;br /&gt;
  Nadia: Secondly, Eiffel advocates uniform access principle. Routine's clients &lt;br /&gt;
  don't have to know, which queries, used in precondition, are attributes &lt;br /&gt;
  and which are functions. If inferred preconditions contained only &lt;br /&gt;
  attributes, it would be inconsistent with uniform access principle, I &lt;br /&gt;
  think...&lt;br /&gt;
&lt;br /&gt;
  As for troubles that may arise when calling functions... As I &lt;br /&gt;
  understand, exception in a function, called when its precondition holds, &lt;br /&gt;
  is a bug. So, if it happens, we can just tell user that we found a bug &lt;br /&gt;
  in certain function and that before inferring contracts the bug should &lt;br /&gt;
  be fixed.&lt;br /&gt;
&lt;br /&gt;
====Checking preconditions (static vs. dynamic)====  &lt;br /&gt;
  The issue with functions' preconditions that you've mentioned isn't a &lt;br /&gt;
  big problem. If after unfolding we got a variable of the form, e.g., &lt;br /&gt;
  `x.f1.f2', where `f1' and `f2' are functions, printing instructions for &lt;br /&gt;
  this variable can be like this:&lt;br /&gt;
    if x.f1_precondition_holds and then x.f1.f2_precondition_holds&lt;br /&gt;
    then&lt;br /&gt;
       print (x.f1.f2)&lt;br /&gt;
    else&lt;br /&gt;
       print (Nonsensical)&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
  &amp;quot;Nonsensical&amp;quot; is a special Daikon value that indicates that variable &lt;br /&gt;
  cannot be evaluated.&lt;br /&gt;
  Function preconditions are known after parsing. To be able to evaluate &lt;br /&gt;
  them separately, we may, for example, wrap them into functions. &lt;br /&gt;
  `f1_precondition_holds' in the above code is an example of such a &lt;br /&gt;
  function, that was introduced by instrumenter and added to x's &lt;br /&gt;
  generating class.&lt;br /&gt;
  &lt;br /&gt;
    Ilinca: I don't think it's that easy, mainly because of polymorphism. Statically &lt;br /&gt;
    you can't determine the type that x will be a direct instance of at &lt;br /&gt;
    runtime. Hence, you don't know which preconditions to wrap. Of course, &lt;br /&gt;
    since redefined routines can keep or weaken the preconditions of the &lt;br /&gt;
    original routines, you can take the pessimistic approach of wrapping &lt;br /&gt;
    only the precondition of the function from the static type of x, but &lt;br /&gt;
    then you might miss cases in which the weakened version of the &lt;br /&gt;
    precondition does hold. Do you understand my point?&lt;br /&gt;
&lt;br /&gt;
        Nadia: Yeah, I see...&lt;br /&gt;
        I think that the main question here is: should we check &amp;quot;static&amp;quot; or &amp;quot;dynamic&amp;quot; &lt;br /&gt;
        preconditions when calling a function?&lt;br /&gt;
&lt;br /&gt;
        On the one hand, in Eiffel we can write something like:&lt;br /&gt;
        class A&lt;br /&gt;
           ...&lt;br /&gt;
           sqrt (x: REAL): REAL&lt;br /&gt;
               require&lt;br /&gt;
                   x &amp;gt;= 0.0&lt;br /&gt;
               do ... end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        class B&lt;br /&gt;
           inherit A&lt;br /&gt;
              redefine sqrt end&lt;br /&gt;
           ...&lt;br /&gt;
           sqrt (x: REAL): REAL&lt;br /&gt;
               require else&lt;br /&gt;
                 True&lt;br /&gt;
               do ... end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        class TEST&lt;br /&gt;
            ...&lt;br /&gt;
            an_a: A&lt;br /&gt;
&lt;br /&gt;
            make is&lt;br /&gt;
               do&lt;br /&gt;
                    create {B} an_a&lt;br /&gt;
                    print (an_a.sqrt (-1.0))&lt;br /&gt;
               end&lt;br /&gt;
        end&lt;br /&gt;
&lt;br /&gt;
        It works, and assertion checking mechanism doesn't indicate any error.&lt;br /&gt;
        But, on the other hand, is it legal? Am I allowed to call a function if it's &lt;br /&gt;
        static precondition doesn't hold?&lt;br /&gt;
&lt;br /&gt;
        As I understand, if I want to make sure that it's legal to call a routine at some &lt;br /&gt;
        program point, I have to check it's static precondition. Even if today I'm sure that &lt;br /&gt;
        dynamic type of `an_a' is always `B', this needn't remain the same tomorrow...&lt;br /&gt;
&lt;br /&gt;
            Ilinca: That's correct. If the &amp;quot;static&amp;quot; precondition of a routine holds, this &lt;br /&gt;
            implies of course that the preconditions of all its redefinitions will also hold. &lt;br /&gt;
            But I was calling this approach &amp;quot;pessimistic&amp;quot; because the precondition of a redefined &lt;br /&gt;
            version of a routine may hold even though the &amp;quot;static&amp;quot; precondition doesn't.&lt;br /&gt;
&lt;br /&gt;
        So, if a programmer wanted to know function value at a program point, he/she would check &lt;br /&gt;
        its static precondition. Then why instrumenter should act differently? Well, actually &lt;br /&gt;
        there is a difference:  instrumenter not only avoids function call when precondition &lt;br /&gt;
        doesn't hold, but also claims that function value is nonsensical. From one point of view, &lt;br /&gt;
        such behavior is incorrect, because function actually could be called and a sensible value &lt;br /&gt;
        could be received. From the other point, since it was illegal to call the function this time, &lt;br /&gt;
        it makes sense to declare function value nonsensical.&lt;br /&gt;
&lt;br /&gt;
        To sum up, I think that it is rather a philosophical then a technical problem, but, as for me, &lt;br /&gt;
        checking static preconditions is more appropriate.&lt;br /&gt;
&lt;br /&gt;
        However, if we wanted to check a dynamic precondition, it's also possible. We can wrap function's &lt;br /&gt;
        precondition into a special function and redefine that special function any time the original &lt;br /&gt;
        function is redefined. It is possible since instrumenter has access to the whole system.&lt;br /&gt;
&lt;br /&gt;
            Ilinca: Well, this would definitely be the more... correct solution, but it's also a lot more &lt;br /&gt;
            work. Couldn't this also be done by not wrapping the function, but simply calling it and adding &lt;br /&gt;
            some exception handling code to the unfolder? I mean, the unfolder would try to call all &lt;br /&gt;
            argument-less functions of a class on an object, and, if it gets a precondition violation, &lt;br /&gt;
            it catches the exception and it declares that particular function as nonsensical?&lt;br /&gt;
&lt;br /&gt;
 Nadia: I would like to return to the subject of checking &amp;quot;static&amp;quot; or &amp;quot;dynamic&amp;quot; preconditions &lt;br /&gt;
 before function calls in unfolding. I think that this problem arises because the semantics &lt;br /&gt;
 of special variable value &amp;quot;nonsensical&amp;quot; in Daikon is ambiguous.&lt;br /&gt;
&lt;br /&gt;
 In Java and C there are no preconditions, so this value is originally used in Daikon for the &lt;br /&gt;
 only purpose: if a pointer of reference is null, then the dereferenced value (and its attributes, &lt;br /&gt;
 if the value is not of primitive type) is declared &amp;quot;nonsensical&amp;quot;. In Eiffel we will use &lt;br /&gt;
 &amp;quot;nonsensical&amp;quot; for this purpose too: if a reference entity is void, then its queries will be output &lt;br /&gt;
 as &amp;quot;nonsensical&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
 However, in Eiffel we have one more source of problems with evaluating variables: if a variable is &lt;br /&gt;
 a result of a function call, then function precondition may not hold, so we won't be able to &lt;br /&gt;
 evaluate its result. In this case the variable value should also be declared &amp;quot;nonsensical&amp;quot;, because &lt;br /&gt;
 this is the only special value in Daikon, which denotes that variable can't be evaluated. However, &lt;br /&gt;
 in this case there appears a question: what does it mean that the variable can't be evaluated? Does &lt;br /&gt;
 it mean that something terrible will happen (e.g., exception), if we try to evaluate it? Or does &lt;br /&gt;
 it mean that it isn't legal to evaluate this variable in this program state?&lt;br /&gt;
&lt;br /&gt;
 If we take the first point, then we should check dynamic precondition, because if static precondition &lt;br /&gt;
 doesn't hold, but dynamic does, nothing terrible will happen during function call.&lt;br /&gt;
&lt;br /&gt;
 If we take the second point, we should check static precondition, because if it doesn't hold then &lt;br /&gt;
 it's illegal to call this function, even if dynamic precondition holds. This point seems more &lt;br /&gt;
 correct to me, and here is an example that illustrates the situation.&lt;br /&gt;
&lt;br /&gt;
 Consider class `INT_LIST' (with feature `item' that has a precondition `not off') and it's heir - &lt;br /&gt;
 class EXTRAPOLATED_INT_LIST (that weakens precondition of `item'):&lt;br /&gt;
&lt;br /&gt;
 class INT_LIST&lt;br /&gt;
 ...&lt;br /&gt;
 feature&lt;br /&gt;
    item: INTEGER is&lt;br /&gt;
       require&lt;br /&gt;
          not off&lt;br /&gt;
       ...&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 class EXTRAPOLATED_INT_LIST&lt;br /&gt;
 inherit&lt;br /&gt;
    INT_LIST&lt;br /&gt;
    redefine&lt;br /&gt;
       item&lt;br /&gt;
    end&lt;br /&gt;
 ...&lt;br /&gt;
 feature&lt;br /&gt;
    item: INTEGER is&lt;br /&gt;
       require else True&lt;br /&gt;
       do&lt;br /&gt;
          if not off then&lt;br /&gt;
             Result := Precursor&lt;br /&gt;
          else&lt;br /&gt;
             Result := 0&lt;br /&gt;
          end&lt;br /&gt;
       end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Consider also class CLIENT, which is a client of INT_LIST:&lt;br /&gt;
&lt;br /&gt;
 class CLIENT&lt;br /&gt;
 ...&lt;br /&gt;
 feature&lt;br /&gt;
    test (a_list: INT_LIST) is&lt;br /&gt;
       do ... end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
 Imagine that during system execution, when contracts were inferred, actual argument of `test' was &lt;br /&gt;
 always a direct instance of EXTRAPOLATED_INT_LIST,  and in addition it was always passed to this &lt;br /&gt;
 procedure in such a state that cursor was before the first element (`off' was true). If we check &lt;br /&gt;
 dynamic preconditions for functions in unfolding, than a precondition, inferred for `test', will &lt;br /&gt;
 be something like this:&lt;br /&gt;
&lt;br /&gt;
 require&lt;br /&gt;
   a_list /= Void&lt;br /&gt;
   a_list.off&lt;br /&gt;
   a_list.item = 0&lt;br /&gt;
&lt;br /&gt;
 But this contract isn't correct (as for me), although it is, certainly, true for a specific system &lt;br /&gt;
 execution. It becomes a little more correct, if we infer:&lt;br /&gt;
&lt;br /&gt;
 require&lt;br /&gt;
   a_list /= Void&lt;br /&gt;
   a_list.off&lt;br /&gt;
   a_list.generator = &amp;quot;EXTRAPOLATED_INT_LIST&amp;quot;&lt;br /&gt;
   a_list.item = 0&lt;br /&gt;
&lt;br /&gt;
 However, such contracts (connected with dynamic type of variable) seem useless to me. One of the &lt;br /&gt;
 goals of dynamic contract inference is to eliminate those properties that happened by chance and &lt;br /&gt;
 are not intended properties of the code. Properties that are connected with dynamic types definitely &lt;br /&gt;
 happen by chance: they can't be intended properties, because if programmer wanted his software to &lt;br /&gt;
 have such a property, he would change static entity type to a more specific (based on descendant).&lt;br /&gt;
&lt;br /&gt;
 Such properties may be useful only if we treat them not as contracts but rather as some kind of &lt;br /&gt;
 runtime statistics. Programmer may be interested in information that is true for a specific system &lt;br /&gt;
 execution, e.g. for debug purposes. It might be useful to add such a feature (inference of dynamic &lt;br /&gt;
 type information and properties, connected with dynamic types) in future, but it isn't &amp;quot;classic&amp;quot; &lt;br /&gt;
 contract inference, as for me, so I don't think that we need it in the first version. And if we &lt;br /&gt;
 don't want to know anything about dynamic types, then we should check static preconditions of &lt;br /&gt;
 functions during unfolding.&lt;br /&gt;
&lt;br /&gt;
====Checking hand-written contracts====&lt;br /&gt;
    Ilinca: There's one further problem with this approach: when a function &lt;br /&gt;
    is called as part of the evaluation of a contract, this function's &lt;br /&gt;
    contracts are not checked. The reason for this is to avoid infinite &lt;br /&gt;
    loops. If you wrap your precondition into a function, the contracts of &lt;br /&gt;
    any routines it calls will be evaluated, and thus the system can &lt;br /&gt;
    actually behave differently.&lt;br /&gt;
&lt;br /&gt;
    Should we check at all the hand-written contracts of a system for which CITADEL  &lt;br /&gt;
    is trying to infer contracts? We could also start from the assumption that Daikon &lt;br /&gt;
    uses: the tool is given a set of passing test cases and from those it has to infer &lt;br /&gt;
    contracts. If the inferred contracts somehow contradict the hand-written ones, then &lt;br /&gt;
    there's a problem in the system, and the source of the  problem may be that the &lt;br /&gt;
    hand-written contracts are faulty. What do you think?&lt;br /&gt;
    &lt;br /&gt;
        Nadia: I think that it makes sense to turn assertion checking off when running &lt;br /&gt;
        instrumented system. This will solve the problem with functions inside wrapped &lt;br /&gt;
        preconditions, which you've mentioned.&lt;br /&gt;
&lt;br /&gt;
        In current version instrumented system is supposed to behave exactly the same way &lt;br /&gt;
        as the original system did (except for creating a trace file). So, if a user was &lt;br /&gt;
        sure about the original, hand-written contracts and wanted to check the system against &lt;br /&gt;
        them, he/she could run the original system with assertion checking on, make sure that &lt;br /&gt;
        everything is ok and after that perform contract inference.&lt;br /&gt;
&lt;br /&gt;
        On the other hand, returning to using functions in unfolding: for these calls we have to &lt;br /&gt;
        check hand-written preconditions, because they were introduced by instrumenter, so they are &lt;br /&gt;
        not parts of &amp;quot;passing test cases&amp;quot;. Fortunately, as you said before, erroneous preconditions &lt;br /&gt;
        are very rare.&lt;br /&gt;
&lt;br /&gt;
====Checking preconditions (wrapping vs. qualification)====&lt;br /&gt;
 Nadia: I started implementing function preconditions checks in unfolding recently and realized &lt;br /&gt;
 that my first idea (to wrap these preconditions into functions) has an important disadvantage. &lt;br /&gt;
 Without creating new functions for preconditions if we instrument a class, then only the source &lt;br /&gt;
 code of that very class changes. However, if during class instrumentation we add functions to &lt;br /&gt;
 its clients, then the source code of those clients also changes. It isn't a disaster, of cause, &lt;br /&gt;
 but it's an unpleasant property, as for me. It would be nice, if class instrumentation affected &lt;br /&gt;
 only the class itself.&lt;br /&gt;
&lt;br /&gt;
 The other solution is not to wrap preconditions into functions, but to &amp;quot;qualify&amp;quot; them: if we want &lt;br /&gt;
 to check precondition before calling a function `x.f', we should take f's precondition and &lt;br /&gt;
 replaced all unqualified calls in it by qualified calls with target `x' and all occurrences of &lt;br /&gt;
 `Current' by `x'. This replacement is not difficult conceptually, but its implementation is quite &lt;br /&gt;
 voluminous (during this operation we have to replace some identifiers in an expression with function &lt;br /&gt;
 calls, so we need to redefine all `process_&amp;lt;something&amp;gt;' procedures of ET_AST_ITERATOR, where &lt;br /&gt;
 &amp;lt;something&amp;gt; can appear in expression and can contain identifiers).&lt;br /&gt;
&lt;br /&gt;
 What do you think about these two solutions (&amp;quot;wrapping into functions&amp;quot; and &amp;quot;qualification&amp;quot;)?&lt;br /&gt;
&lt;br /&gt;
    Ilinca: I think the best way to go is to wrap the precondition in a function in the class that &lt;br /&gt;
    it belongs to. Wrapping it in a function in clients would break encapsulation: you would only &lt;br /&gt;
    be allowed to access the exported features. I don't see any advantages of qualification over &lt;br /&gt;
    function-wrapping, so I think it makes sense to choose the least-work solution&lt;br /&gt;
&lt;br /&gt;
        Nadia: My previous explanation of the problem with &amp;quot;wrapping&amp;quot; was a little bit confused &lt;br /&gt;
        (I wrote that functions have to be added to clients of instrumented class, but actually &lt;br /&gt;
        I meant quite the opposite: that they should be added to suppliers:) )&lt;br /&gt;
&lt;br /&gt;
        Wrapping a precondition in a function in the class that it belongs to is exactly what I &lt;br /&gt;
        wanted to do firstly. The reason for it was that, if we instrument a class `C' and it has, &lt;br /&gt;
        say, an attribute `x: LIST[INTEGER]', then unfolded form of `Current' variable will include &lt;br /&gt;
        a variable `x.first'. Precondition of function `first' in class LIST is `not empty'. However, &lt;br /&gt;
        we need to check this precondition not inside LIST, but inside routines of class `C'. In fact, &lt;br /&gt;
        printing instruction for variable `x.first' should be guarded by condition like this:&lt;br /&gt;
        if x /= Void and then not x.empty then&lt;br /&gt;
           print (x.first)&lt;br /&gt;
        end&lt;br /&gt;
        We can't just take a precondition from `first' and insert it into the guarding condition as is, &lt;br /&gt;
        instead we should &amp;quot;qualify&amp;quot; the call to `empty' with target `x'.&lt;br /&gt;
&lt;br /&gt;
        Firstly qualification seemed too complex to me, so I decided to wrap `not empty' into function, say,&lt;br /&gt;
        `first_precondition: BOOLEAN' and add it to class `LIST', so that inside `C' I can check simpler &lt;br /&gt;
        condition before printing x.first:&lt;br /&gt;
        if x /= Void and then x.first_precondition then&lt;br /&gt;
            print (x.first)&lt;br /&gt;
        end.&lt;br /&gt;
        However, as you can see, it involves modifying class `LIST' (and possibly any other supplier of &lt;br /&gt;
        `C') while instrumenting `C'. If only `C' changed, then we could print only its source code after &lt;br /&gt;
        instrumentation, we could compile only `C' (if incremental compilation is used) and don't recompile &lt;br /&gt;
        base library, we would have no problems with tracking added functions (the problems are like this: &lt;br /&gt;
        if we instrument class `LIST' after `C', we probably don't want neither to instrument added functions, &lt;br /&gt;
        nor to see them in unfolded form of `Current' variable of class `LIST'). As for me, wrapping adds &lt;br /&gt;
        surplus dependencies into the system, and software never benefits from dependencies :)&lt;br /&gt;
&lt;br /&gt;
        That is why later I inclined to &amp;quot;qualification&amp;quot; solution. Actually, I have already mostly implemented &lt;br /&gt;
        it:) Current implementation might be incomplete, there are several syntactic constructs that it doesn't &lt;br /&gt;
        handle, because I'm not sure that they can appear in preconditions, but I'll check it and fix the problem.&lt;br /&gt;
&lt;br /&gt;
            Ilinca: Ok, so what I was thinking about was that you wanted to wrap the whole precondition of &lt;br /&gt;
            `first' into a function in class C. So, in class C you would have a routine&lt;br /&gt;
            precondition_first (l: LIST[G]): BOOLEAN&lt;br /&gt;
                 require&lt;br /&gt;
                      l_not_void: l /= Void&lt;br /&gt;
                 do&lt;br /&gt;
                      Result := not l.empty&lt;br /&gt;
                 end&lt;br /&gt;
            Then the guard for printing x.first would be&lt;br /&gt;
                 if x /= Void and then precondition_first (x) then&lt;br /&gt;
                      print (x.first)&lt;br /&gt;
                 end&lt;br /&gt;
&lt;br /&gt;
            But of course whether or not you wrap the precondition in a function or just quote it in the if &lt;br /&gt;
            statement does not make a big difference.&lt;br /&gt;
&lt;br /&gt;
 One more question: should the tool allow instrumenting library classes? If a library was precompiled, &lt;br /&gt;
 then instrumenting any of its classes will result in recompiling the whole library, am I right? Are &lt;br /&gt;
 precompiled libraries anyway recompiled during system finalization or not? (It matters for choosing &lt;br /&gt;
 between &amp;quot;wrapping into functions&amp;quot; and &amp;quot;qualification&amp;quot; solutions, because &amp;quot;wrapping into functions&amp;quot; can &lt;br /&gt;
 change library classes, even if user wants to implement only classes from his own clusters).&lt;br /&gt;
&lt;br /&gt;
===Support for loop invariants===&lt;br /&gt;
 Ilinca: Does the &amp;quot;classic&amp;quot; Daikon support loop invariants?&lt;br /&gt;
&lt;br /&gt;
 Nadia: Daikon uses standard program point &lt;br /&gt;
  suffixes to infer more invariants. E.g., it understands that &lt;br /&gt;
  some_routine:::ENTER and some_routine:::EXIT are entry and exit points &lt;br /&gt;
  of the same routine. Thanks to this, it knows `old' values of variables &lt;br /&gt;
  at exit and can infer invariants like &amp;quot;x = old x&amp;quot;. As I understood, if &lt;br /&gt;
  Daikon sees an unknown suffix, it treats corresponding program point as, &lt;br /&gt;
  so to say, &amp;quot;standalone&amp;quot; and doesn't try to connect it with any other.&lt;br /&gt;
  We don't need any extra support from Daikon to handle loop invariants.&lt;br /&gt;
  &lt;br /&gt;
  If we want to infer loop invariants, we should introduce a separate &lt;br /&gt;
  program point for each loop. So, we need a way to distinguish loops &lt;br /&gt;
  within a routine. One way is to take its position in source code as &lt;br /&gt;
  index. However, I thought, that position is too unstable to become loop &lt;br /&gt;
  identifier, so I chose instruction number instead. These numbers are &lt;br /&gt;
  unique numbers of instructions within surrounding routine, they may be &lt;br /&gt;
  used not only for loops, but for arbitrary instructions. &lt;br /&gt;
  CI_INSTRUCTION_COUNTER is responsible for counting instruction while &lt;br /&gt;
  iterating through AST.&lt;br /&gt;
&lt;br /&gt;
===Inferring contracts for generic classes===&lt;br /&gt;
 Nadia: there are actually two different cases.&lt;br /&gt;
  1. Contracts inside generic classes. This is not really a problem. &lt;br /&gt;
  Entities, which have parameter type, can be treated as if their &lt;br /&gt;
  generator is constraining class (ANY, if genericity is unconstrained).&lt;br /&gt;
  &lt;br /&gt;
  2. Contracts in clients of generic classes. Here some problems arise. If &lt;br /&gt;
  we have an entity `x: ARRAYED_LIST[INTEGER]', its unfolding involves &lt;br /&gt;
  processing the `item' query. `item' is declared to be of type `G' in &lt;br /&gt;
  ARRAYED_LIST and, as I understand, parsing is not enough (some type &lt;br /&gt;
  analysis is needed) to infer that `G' means `INTEGER' in current &lt;br /&gt;
  context. Two approaches to this problem, that I see at present, are: &lt;br /&gt;
  perform such a type analysis in compile time (with the help of gobo &lt;br /&gt;
  compilation facilities) or leave some unfolding work until runtime, &lt;br /&gt;
  when reflections may be used to determine variable's generating class.&lt;/div&gt;</summary>
		<author><name>Nadia Polikarpova</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=CITADEL&amp;diff=10130</id>
		<title>CITADEL</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=CITADEL&amp;diff=10130"/>
				<updated>2007-12-25T11:07:11Z</updated>
		
		<summary type="html">&lt;p&gt;Nadia Polikarpova: Term &amp;quot;flattening&amp;quot; changed to &amp;quot;unfolding&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Assertion checking]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
CITADEL (Contract-Inference Tool that Applies Daikon to the Eiffel Language) is a tool that provides an Eiffel front-end for the Daikon invariant detector. It is being implemented as a Master's project by Nadia Polikarpova supervised by Ilinca Ciupa (ETH).&lt;br /&gt;
&lt;br /&gt;
==Discussions==&lt;br /&gt;
===Unfolded variables===&lt;br /&gt;
 Nadia: Daikon can process values of only few types: five scalar types (boolean, &lt;br /&gt;
  integer, double, string and hashcode) and five more types, which are &lt;br /&gt;
  arrays of these scalars.&lt;br /&gt;
  So, if in Eiffel code we a have a variable of one of basic types &lt;br /&gt;
  (BOOLEAN, NATURAL, INTEGER, REAL or STRING) we can print its value &lt;br /&gt;
  directly as if it has one of Daikon's types.&lt;br /&gt;
  If, however, we have a variable of any other type, we have to collect &lt;br /&gt;
  all the information about it that is of interest and is available at &lt;br /&gt;
  certain program point, and present this information to Daikon as a set &lt;br /&gt;
  of  variables, which have Daikon types. The information of interest &lt;br /&gt;
  about a variable includes results of all queries that can be called on &lt;br /&gt;
  this variable at this program point.  However, since queries results may &lt;br /&gt;
  themselves be of non-basic types, we have to perform this operation &lt;br /&gt;
  recursively (to a certain depth).&lt;br /&gt;
  For a reference variable information of interest includes also its &lt;br /&gt;
  address (Daikon type &amp;quot;hashcode&amp;quot; is intended for representing object &lt;br /&gt;
  addresses).&lt;br /&gt;
  For example, if we had a variable c: POINT, queries of class POINT &lt;br /&gt;
  available at current program point were `x: REAL', `y: REAL' and `twin: &lt;br /&gt;
  POINT' and unfolding depth were set to 2, then `c.unfolded' would be a &lt;br /&gt;
  set of variables: {$c, c.x, c.y, $c.twin, c.twin.x, c.twin.y}.&lt;br /&gt;
  &lt;br /&gt;
  Containers need special kind of unfolding. If we want Daikon to handle &lt;br /&gt;
  them sensibly, they should be converted to arrays of scalars (to be more &lt;br /&gt;
  precise, it should be done only if all container elements are observable &lt;br /&gt;
  at current program point...). It isn't difficult for descendants of &lt;br /&gt;
  CONTAINER class from standard library. Instrumenter may check, if a &lt;br /&gt;
  variable is an indirect instance of CONTAINER, get its &lt;br /&gt;
  `linear_representation', then traverse it and output as array. I think &lt;br /&gt;
  that in the first version we may leave aside those containers, that &lt;br /&gt;
  aren't inherited from CONTAINER.&lt;br /&gt;
&lt;br /&gt;
 Ilinca: I'm not sure about the idea of including argument-less functions in &lt;br /&gt;
  this unfolded form. What if the precondition of the function doesn't &lt;br /&gt;
  hold or we run into some kind of trouble when executing the function &lt;br /&gt;
  body (trouble such as the contracts of a sub-call made by this &lt;br /&gt;
  function not holding or other bugs)? On the other hand, including &lt;br /&gt;
  functions would bring significantly more information about the state &lt;br /&gt;
  of the object... Does the Daikon frontend for Java, for instance, by &lt;br /&gt;
  default evaluate functions too as part of the unfolded form of the &lt;br /&gt;
  objects?&lt;br /&gt;
&lt;br /&gt;
 Nadia: Well, this idea is disputable, of cause.&lt;br /&gt;
  In Java considering argument-less functions as variables is more &lt;br /&gt;
  dangerous, because Java, like all C-family languages, encourages &lt;br /&gt;
  side-effects in functions. However, in Daikon front-end for Java there &lt;br /&gt;
  exists an option that allows using functions as variables. Together with &lt;br /&gt;
  enabling this option user has to provide a special &amp;quot;purity&amp;quot; file that &lt;br /&gt;
  lists those functions from the system, that are side-effect free. This &lt;br /&gt;
  feature is described in Daikon User Manual, page 82.&lt;br /&gt;
  Considering functions as variables is even more relevant in Eiffel &lt;br /&gt;
  context by two main reasons. Firstly, Eiffel encourages absence of &lt;br /&gt;
  abstract side-effects in functions (and, I believe, most Eiffel &lt;br /&gt;
  functions indeed do not have abstract side-effect, am I right?). For &lt;br /&gt;
  those cases, when some functions in system are known to have &lt;br /&gt;
  side-effect, we can allow user to specify an &amp;quot;impurity&amp;quot; file, that would &lt;br /&gt;
  list those functions. I think that these cases would be rare.&lt;br /&gt;
  &lt;br /&gt;
    Ilinca: Indeed, I also think these cases would be rare, but, depending on the &lt;br /&gt;
    size of the system, it might be very cumbersome for users to determine &lt;br /&gt;
    these functions. Something else: what Daikon calls &amp;quot;purity&amp;quot; is actually &lt;br /&gt;
    weak purity, isn't it? (Weak purity means that creations of local &lt;br /&gt;
    variables are allowed in the body of a pure function. Strong purity &lt;br /&gt;
    disallows this.)&lt;br /&gt;
  &lt;br /&gt;
  Secondly, Eiffel advocates uniform access principle. Routine's clients &lt;br /&gt;
  don't have to know, which queries, used in precondition, are attributes &lt;br /&gt;
  and which are functions. If inferred preconditions contained only &lt;br /&gt;
  attributes, it would be inconsistent with uniform access principle, I &lt;br /&gt;
  think...&lt;br /&gt;
  &lt;br /&gt;
  The issue with functions' preconditions that you've mentioned isn't a &lt;br /&gt;
  big problem. If after unfolding we got a variable of the form, e.g., &lt;br /&gt;
  `x.f1.f2', where `f1' and `f2' are functions, printing instructions for &lt;br /&gt;
  this variable can be like this:&lt;br /&gt;
    if x.f1_precondition_holds and then x.f1.f2_precondition_holds&lt;br /&gt;
    then&lt;br /&gt;
       print (x.f1.f2)&lt;br /&gt;
    else&lt;br /&gt;
       print (Nonsensical)&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
  &amp;quot;Nonsensical&amp;quot; is a special Daikon value that indicates that variable &lt;br /&gt;
  cannot be evaluated.&lt;br /&gt;
  Function preconditions are known after parsing. To be able to evaluate &lt;br /&gt;
  them separately, we may, for example, wrap them into functions. &lt;br /&gt;
  `f1_precondition_holds' in the above code is an example of such a &lt;br /&gt;
  function, that was introduced by instrumenter and added to x's &lt;br /&gt;
  generating class.&lt;br /&gt;
  &lt;br /&gt;
    Ilinca: I don't think it's that easy, mainly because of polymorphism. Statically &lt;br /&gt;
    you can't determine the type that x will be a direct instance of at &lt;br /&gt;
    runtime. Hence, you don't know which preconditions to wrap. Of course, &lt;br /&gt;
    since redefined routines can keep or weaken the preconditions of the &lt;br /&gt;
    original routines, you can take the pessimistic approach of wrapping &lt;br /&gt;
    only the precondition of the function from the static type of x, but &lt;br /&gt;
    then you might miss cases in which the weakened version of the &lt;br /&gt;
    precondition does hold. Do you understand my point?&lt;br /&gt;
    &lt;br /&gt;
    There's one further problem with this approach: when a function is &lt;br /&gt;
    called as part of the evaluation of a contract, this function's &lt;br /&gt;
    contracts are not checked. The reason for this is to avoid infinite &lt;br /&gt;
    loops. If you wrap your precondition into a function, the contracts of &lt;br /&gt;
    any routines it calls will be evaluated, and thus the system can &lt;br /&gt;
    actually behave differently.&lt;br /&gt;
    &lt;br /&gt;
  BTW, for attributes we also need check in printing instructions: the &lt;br /&gt;
  target on which attribute is called should be non-void, otherwise &lt;br /&gt;
  attribute value should be printed as `Nonsensical'.&lt;br /&gt;
  &lt;br /&gt;
  As for troubles that may arise when calling functions... As I &lt;br /&gt;
  understand, exception in a function, called when its precondition holds, &lt;br /&gt;
  is a bug. So, if it happens, we can just tell user that we found a bug &lt;br /&gt;
  in certain function and that before inferring contracts the bug should &lt;br /&gt;
  be fixed.&lt;br /&gt;
&lt;br /&gt;
===Support for loop invariants===&lt;br /&gt;
 Ilinca: Does the &amp;quot;classic&amp;quot; Daikon support loop invariants?&lt;br /&gt;
&lt;br /&gt;
 Nadia: Daikon uses standard program point &lt;br /&gt;
  suffixes to infer more invariants. E.g., it understands that &lt;br /&gt;
  some_routine:::ENTER and some_routine:::EXIT are entry and exit points &lt;br /&gt;
  of the same routine. Thanks to this, it knows `old' values of variables &lt;br /&gt;
  at exit and can infer invariants like &amp;quot;x = old x&amp;quot;. As I understood, if &lt;br /&gt;
  Daikon sees an unknown suffix, it treats corresponding program point as, &lt;br /&gt;
  so to say, &amp;quot;standalone&amp;quot; and doesn't try to connect it with any other.&lt;br /&gt;
  We don't need any extra support from Daikon to handle loop invariants.&lt;br /&gt;
  &lt;br /&gt;
  If we want to infer loop invariants, we should introduce a separate &lt;br /&gt;
  program point for each loop. So, we need a way to distinguish loops &lt;br /&gt;
  within a routine. One way is to take its position in source code as &lt;br /&gt;
  index. However, I thought, that position is too unstable to become loop &lt;br /&gt;
  identifier, so I chose instruction number instead. These numbers are &lt;br /&gt;
  unique numbers of instructions within surrounding routine, they may be &lt;br /&gt;
  used not only for loops, but for arbitrary instructions. &lt;br /&gt;
  CI_INSTRUCTION_COUNTER is responsible for counting instruction while &lt;br /&gt;
  iterating through AST.&lt;br /&gt;
&lt;br /&gt;
===Inferring contracts for generic classes===&lt;br /&gt;
 Nadia: there are actually two different cases.&lt;br /&gt;
  1. Contracts inside generic classes. This is not really a problem. &lt;br /&gt;
  Entities, which have parameter type, can be treated as if their &lt;br /&gt;
  generator is constraining class (ANY, if genericity is unconstrained).&lt;br /&gt;
  &lt;br /&gt;
  2. Contracts in clients of generic classes. Here some problems arise. If &lt;br /&gt;
  we have an entity `x: ARRAYED_LIST[INTEGER]', its unfolding involves &lt;br /&gt;
  processing the `item' query. `item' is declared to be of type `G' in &lt;br /&gt;
  ARRAYED_LIST and, as I understand, parsing is not enough (some type &lt;br /&gt;
  analysis is needed) to infer that `G' means `INTEGER' in current &lt;br /&gt;
  context. Two approaches to this problem, that I see at present, are: &lt;br /&gt;
  perform such a type analysis in compile time (with the help of gobo &lt;br /&gt;
  compilation facilities) or leave some unfolding work until runtime, &lt;br /&gt;
  when reflections may be used to determine variable's generating class.&lt;/div&gt;</summary>
		<author><name>Nadia Polikarpova</name></author>	</entry>

	<entry>
		<id>https://dev.eiffel.com/index.php?title=CITADEL&amp;diff=10129</id>
		<title>CITADEL</title>
		<link rel="alternate" type="text/html" href="https://dev.eiffel.com/index.php?title=CITADEL&amp;diff=10129"/>
				<updated>2007-12-25T11:06:04Z</updated>
		
		<summary type="html">&lt;p&gt;Nadia Polikarpova: Term &amp;quot;flattened&amp;quot; changed to &amp;quot;unfolded&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[Category:Assertion checking]]&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
CITADEL (Contract-Inference Tool that Applies Daikon to the Eiffel Language) is a tool that provides an Eiffel front-end for the Daikon invariant detector. It is being implemented as a Master's project by Nadia Polikarpova supervised by Ilinca Ciupa (ETH).&lt;br /&gt;
&lt;br /&gt;
==Discussions==&lt;br /&gt;
===Unfolded variables===&lt;br /&gt;
 Nadia: Daikon can process values of only few types: five scalar types (boolean, &lt;br /&gt;
  integer, double, string and hashcode) and five more types, which are &lt;br /&gt;
  arrays of these scalars.&lt;br /&gt;
  So, if in Eiffel code we a have a variable of one of basic types &lt;br /&gt;
  (BOOLEAN, NATURAL, INTEGER, REAL or STRING) we can print its value &lt;br /&gt;
  directly as if it has one of Daikon's types.&lt;br /&gt;
  If, however, we have a variable of any other type, we have to collect &lt;br /&gt;
  all the information about it that is of interest and is available at &lt;br /&gt;
  certain program point, and present this information to Daikon as a set &lt;br /&gt;
  of  variables, which have Daikon types. The information of interest &lt;br /&gt;
  about a variable includes results of all queries that can be called on &lt;br /&gt;
  this variable at this program point.  However, since queries results may &lt;br /&gt;
  themselves be of non-basic types, we have to perform this operation &lt;br /&gt;
  recursively (to a certain depth).&lt;br /&gt;
  For a reference variable information of interest includes also its &lt;br /&gt;
  address (Daikon type &amp;quot;hashcode&amp;quot; is intended for representing object &lt;br /&gt;
  addresses).&lt;br /&gt;
  For example, if we had a variable c: POINT, queries of class POINT &lt;br /&gt;
  available at current program point were `x: REAL', `y: REAL' and `twin: &lt;br /&gt;
  POINT' and unfolding depth were set to 2, then `c.unfolded' would be a &lt;br /&gt;
  set of variables: {$c, c.x, c.y, $c.twin, c.twin.x, c.twin.y}.&lt;br /&gt;
  &lt;br /&gt;
  Containers need special kind of unfolding. If we want Daikon to handle &lt;br /&gt;
  them sensibly, they should be converted to arrays of scalars (to be more &lt;br /&gt;
  precise, it should be done only if all container elements are observable &lt;br /&gt;
  at current program point...). It isn't difficult for descendants of &lt;br /&gt;
  CONTAINER class from standard library. Instrumenter may check, if a &lt;br /&gt;
  variable is an indirect instance of CONTAINER, get its &lt;br /&gt;
  `linear_representation', then traverse it and output as array. I think &lt;br /&gt;
  that in the first version we may leave aside those containers, that &lt;br /&gt;
  aren't inherited from CONTAINER.&lt;br /&gt;
&lt;br /&gt;
 Ilinca: I'm not sure about the idea of including argument-less functions in &lt;br /&gt;
  this unfolded form. What if the precondition of the function doesn't &lt;br /&gt;
  hold or we run into some kind of trouble when executing the function &lt;br /&gt;
  body (trouble such as the contracts of a sub-call made by this &lt;br /&gt;
  function not holding or other bugs)? On the other hand, including &lt;br /&gt;
  functions would bring significantly more information about the state &lt;br /&gt;
  of the object... Does the Daikon frontend for Java, for instance, by &lt;br /&gt;
  default evaluate functions too as part of the unfolded form of the &lt;br /&gt;
  objects?&lt;br /&gt;
&lt;br /&gt;
 Nadia: Well, this idea is disputable, of cause.&lt;br /&gt;
  In Java considering argument-less functions as variables is more &lt;br /&gt;
  dangerous, because Java, like all C-family languages, encourages &lt;br /&gt;
  side-effects in functions. However, in Daikon front-end for Java there &lt;br /&gt;
  exists an option that allows using functions as variables. Together with &lt;br /&gt;
  enabling this option user has to provide a special &amp;quot;purity&amp;quot; file that &lt;br /&gt;
  lists those functions from the system, that are side-effect free. This &lt;br /&gt;
  feature is described in Daikon User Manual, page 82.&lt;br /&gt;
  Considering functions as variables is even more relevant in Eiffel &lt;br /&gt;
  context by two main reasons. Firstly, Eiffel encourages absence of &lt;br /&gt;
  abstract side-effects in functions (and, I believe, most Eiffel &lt;br /&gt;
  functions indeed do not have abstract side-effect, am I right?). For &lt;br /&gt;
  those cases, when some functions in system are known to have &lt;br /&gt;
  side-effect, we can allow user to specify an &amp;quot;impurity&amp;quot; file, that would &lt;br /&gt;
  list those functions. I think that these cases would be rare.&lt;br /&gt;
  &lt;br /&gt;
    Ilinca: Indeed, I also think these cases would be rare, but, depending on the &lt;br /&gt;
    size of the system, it might be very cumbersome for users to determine &lt;br /&gt;
    these functions. Something else: what Daikon calls &amp;quot;purity&amp;quot; is actually &lt;br /&gt;
    weak purity, isn't it? (Weak purity means that creations of local &lt;br /&gt;
    variables are allowed in the body of a pure function. Strong purity &lt;br /&gt;
    disallows this.)&lt;br /&gt;
  &lt;br /&gt;
  Secondly, Eiffel advocates uniform access principle. Routine's clients &lt;br /&gt;
  don't have to know, which queries, used in precondition, are attributes &lt;br /&gt;
  and which are functions. If inferred preconditions contained only &lt;br /&gt;
  attributes, it would be inconsistent with uniform access principle, I &lt;br /&gt;
  think...&lt;br /&gt;
  &lt;br /&gt;
  The issue with functions' preconditions that you've mentioned isn't a &lt;br /&gt;
  big problem. If after unfolding we got a variable of the form, e.g., &lt;br /&gt;
  `x.f1.f2', where `f1' and `f2' are functions, printing instructions for &lt;br /&gt;
  this variable can be like this:&lt;br /&gt;
    if x.f1_precondition_holds and then x.f1.f2_precondition_holds&lt;br /&gt;
    then&lt;br /&gt;
       print (x.f1.f2)&lt;br /&gt;
    else&lt;br /&gt;
       print (Nonsensical)&lt;br /&gt;
    end&lt;br /&gt;
  &lt;br /&gt;
  &amp;quot;Nonsensical&amp;quot; is a special Daikon value that indicates that variable &lt;br /&gt;
  cannot be evaluated.&lt;br /&gt;
  Function preconditions are known after parsing. To be able to evaluate &lt;br /&gt;
  them separately, we may, for example, wrap them into functions. &lt;br /&gt;
  `f1_precondition_holds' in the above code is an example of such a &lt;br /&gt;
  function, that was introduced by instrumenter and added to x's &lt;br /&gt;
  generating class.&lt;br /&gt;
  &lt;br /&gt;
    Ilinca: I don't think it's that easy, mainly because of polymorphism. Statically &lt;br /&gt;
    you can't determine the type that x will be a direct instance of at &lt;br /&gt;
    runtime. Hence, you don't know which preconditions to wrap. Of course, &lt;br /&gt;
    since redefined routines can keep or weaken the preconditions of the &lt;br /&gt;
    original routines, you can take the pessimistic approach of wrapping &lt;br /&gt;
    only the precondition of the function from the static type of x, but &lt;br /&gt;
    then you might miss cases in which the weakened version of the &lt;br /&gt;
    precondition does hold. Do you understand my point?&lt;br /&gt;
    &lt;br /&gt;
    There's one further problem with this approach: when a function is &lt;br /&gt;
    called as part of the evaluation of a contract, this function's &lt;br /&gt;
    contracts are not checked. The reason for this is to avoid infinite &lt;br /&gt;
    loops. If you wrap your precondition into a function, the contracts of &lt;br /&gt;
    any routines it calls will be evaluated, and thus the system can &lt;br /&gt;
    actually behave differently.&lt;br /&gt;
    &lt;br /&gt;
  BTW, for attributes we also need check in printing instructions: the &lt;br /&gt;
  target on which attribute is called should be non-void, otherwise &lt;br /&gt;
  attribute value should be printed as `Nonsensical'.&lt;br /&gt;
  &lt;br /&gt;
  As for troubles that may arise when calling functions... As I &lt;br /&gt;
  understand, exception in a function, called when its precondition holds, &lt;br /&gt;
  is a bug. So, if it happens, we can just tell user that we found a bug &lt;br /&gt;
  in certain function and that before inferring contracts the bug should &lt;br /&gt;
  be fixed.&lt;br /&gt;
&lt;br /&gt;
===Support for loop invariants===&lt;br /&gt;
 Ilinca: Does the &amp;quot;classic&amp;quot; Daikon support loop invariants?&lt;br /&gt;
&lt;br /&gt;
 Nadia: Daikon uses standard program point &lt;br /&gt;
  suffixes to infer more invariants. E.g., it understands that &lt;br /&gt;
  some_routine:::ENTER and some_routine:::EXIT are entry and exit points &lt;br /&gt;
  of the same routine. Thanks to this, it knows `old' values of variables &lt;br /&gt;
  at exit and can infer invariants like &amp;quot;x = old x&amp;quot;. As I understood, if &lt;br /&gt;
  Daikon sees an unknown suffix, it treats corresponding program point as, &lt;br /&gt;
  so to say, &amp;quot;standalone&amp;quot; and doesn't try to connect it with any other.&lt;br /&gt;
  We don't need any extra support from Daikon to handle loop invariants.&lt;br /&gt;
  &lt;br /&gt;
  If we want to infer loop invariants, we should introduce a separate &lt;br /&gt;
  program point for each loop. So, we need a way to distinguish loops &lt;br /&gt;
  within a routine. One way is to take its position in source code as &lt;br /&gt;
  index. However, I thought, that position is too unstable to become loop &lt;br /&gt;
  identifier, so I chose instruction number instead. These numbers are &lt;br /&gt;
  unique numbers of instructions within surrounding routine, they may be &lt;br /&gt;
  used not only for loops, but for arbitrary instructions. &lt;br /&gt;
  CI_INSTRUCTION_COUNTER is responsible for counting instruction while &lt;br /&gt;
  iterating through AST.&lt;br /&gt;
&lt;br /&gt;
===Inferring contracts for generic classes===&lt;br /&gt;
 Nadia: there are actually two different cases.&lt;br /&gt;
  1. Contracts inside generic classes. This is not really a problem. &lt;br /&gt;
  Entities, which have parameter type, can be treated as if their &lt;br /&gt;
  generator is constraining class (ANY, if genericity is unconstrained).&lt;br /&gt;
  &lt;br /&gt;
  2. Contracts in clients of generic classes. Here some problems arise. If &lt;br /&gt;
  we have an entity `x: ARRAYED_LIST[INTEGER]', its flattening involves &lt;br /&gt;
  processing the `item' query. `item' is declared to be of type `G' in &lt;br /&gt;
  ARRAYED_LIST and, as I understand, parsing is not enough (some type &lt;br /&gt;
  analysis is needed) to infer that `G' means `INTEGER' in current &lt;br /&gt;
  context. Two approaches to this problem, that I see at present, are: &lt;br /&gt;
  perform such a type analysis in compile time (with the help of gobo &lt;br /&gt;
  compilation facilities) or leave some flattening work until runtime, &lt;br /&gt;
  when reflections may be used to determine variable's generating class.&lt;/div&gt;</summary>
		<author><name>Nadia Polikarpova</name></author>	</entry>

	</feed>