Hi
Since Johan found a more manageable example than the one I had when I posted this in the first place, I have been able to debug this some more.
I found that it occurs in the following situation:
· A.c1() & C.c2() are circular attributes
· B.nc() is a non-circular attribute
· During the LAST_CYCLE call to A.c1_compute():
o A.c1_compute() calls B.nc()
o B.nc_compute() calls C.c2()
· However, C.c2() is not called during the iteration calls of A.c1_compute()
I assume that this is not supposed to be able to happen, i.e. the LAST_CYCLE call should be exactly the same as the last iteration call. I'll see if I can dig a little more into why it does.
I have discovered that changing the generated code for B.nc() from
boolean interruptedCircle = false;
if(state.IN_CIRCLE) {
interruptedCircle = true;
state.IN_CIRCLE = false;
state.pushEvalStack();
}
// Call to the compute method
if(interruptedCircle) {
state.IN_CIRCLE = true;
state.popEvalStack();
}
to:
boolean interruptedCircle = false;
boolean last_cycle = false;
if(state.IN_CIRCLE) {
interruptedCircle = true;
state.IN_CIRCLE = false;
last_cycle = state.LAST_CYCLE;
state.LAST_CYCLE = false;
state.pushEvalStack();
}
// Call to the compute method
if(interruptedCircle) {
state.IN_CIRCLE = true;
state.LAST_CYCLE = last_cycle;
state.popEvalStack();
}
solves the problem for this case.
Jesper
Jesper MATTSSON, MSc
Software Developer & IT Administrator
Phone direct: +46 73 324 5909
Email: jesper.mattsson_at_modelon.com<mailto:jesper.mattsson_at_modelon.com>
[cid:image001.png_at_01CCD5C6.FFE488F0]
________________________________
Modelon AB
Ideon Science Park
SE-223 70 Lund, Sweden
Phone: +46 46 286 2200
Fax: +46 46 286 2201
Web:
http://www.modelon.com<
http://www.modelon.com/>
From: jastadd-bounces_at_cs.lth.se [mailto:jastadd-bounces_at_cs.lth.se] On Behalf Of Johan Akesson
Sent: den 18 januari 2012 09:39
To: jastadd_at_cs.lth.se
Subject: [Jastadd] Fwd: Possible bug in circular attribute
Dear all,
the potential JastAdd bug reported by Jesper M. on January 2 has turned out to be critical (practically a blocker) for us: <
https://trac.jmodelica.org/ticket/1736>.
Is there any chance that someone can have a look at this to help us understand what is going on?
Best regards
/Johan
Begin forwarded message:
From: Jesper Mattsson <jesper.mattsson_at_modelon.com<mailto:jesper.mattsson_at_modelon.com>>
Date: January 2, 2012 11:01:53 AM GMT+01:00
To: "jastadd_at_cs.lth.se<mailto:jastadd_at_cs.lth.se>" <jastadd_at_cs.lth.se<mailto:jastadd_at_cs.lth.se>>
Subject: [Jastadd] Possible bug in circular attribute
Hi
In the JModelica.org<
http://JModelica.org> compiler, we have a circular attribute InstDot.myInstClassDecl() that under certain circumstances gives strange results. (I have a test case that provokes it, but it is a complicated one.) I think that this is a bug in JastAdd.
The attribute in question is lazy and circular. When the bug occurs, then:
* myInstClassDecl _computed = false
* myInstClassDecl _initialized = false
* myInstClassDecl_visited = -1
* in$Circle = false
* is$Final = true
* result of state() looks like ("Copy Variables" in Eclipse debug):
state ASTNode$State (id=1360)
boundariesCrossed 0 [0x0]
CHANGE false
CIRCLE_INDEX 1053 [0x41d]
circularEvalSet LinkedHashSet<E> (id=1362)
circularEvalStack Stack<E> (id=1369)
capacityIncrement 0 [0x0]
elementCount 4 [0x4]
elementData Object[10] (id=1385)
[0] ASTNode$State$CircularStackEntry (id=1386)
[1] ASTNode$State$CircularStackEntry (id=1387)
[2] ASTNode$State$CircularStackEntry (id=1388)
[3] ASTNode$State$CircularStackEntry (id=1389)
[4] null
...
modCount 63576 [0xf858]
duringConnections 0 [0x0]
duringFlatTypeAnalysis 0 [0x0]
duringInitialTransformations 0 [0x0]
duringInstFunctionBinding 0 [0x0]
duringInstNameClassification 0 [0x0]
duringPredefinedTypes 0 [0x0]
duringScalarization 0 [0x0]
duringTransformCanonical 0 [0x0]
IN_CIRCLE true
LAST_CYCLE true
pos 0 [0x0]
RESET_CYCLE false
stack (id=1402)
This leads to the following code being executed:
if (!myInstClassDecl_initialized) {
myInstClassDecl_initialized = true;
myInstClassDecl_value = unknownInstClassDecl();
}
if (!state.IN_CIRCLE) {
// This is not executed
}
if(myInstClassDecl_visited != state.CIRCLE_INDEX) {
myInstClassDecl_visited = state.CIRCLE_INDEX;
if (state.LAST_CYCLE) {
myInstClassDecl_computed = true;
return myInstClassDecl_compute();
}
Thus myInstClassDecl_value is set to the initialization value, myInstClassDecl _computed is set to true, and the correct value is calculated and returned, but never saved in myInstClassDecl_value.
The next time myInstClassDecl() is called (right after the first call, due to being called from a circular attribute), then the initialization value is returned immediately.
That's all the information I can think of - anything else?
Jesper
Jesper MATTSSON, MSc
Software Developer & IT Administrator
Phone direct: +46 73 324 5909
Email: jesper.mattsson_at_modelon.com<mailto:jesper.mattsson_at_modelon.com>
[cid:image001.png_at_01CCD5C6.FFE488F0]
________________________________
Modelon AB
Ideon Science Park
SE-223 70 Lund, Sweden
Phone: +46 46 286 2200
Fax: +46 46 286 2201
Web:
http://www.modelon.com<
http://www.modelon.com/>
_______________________________________________
JastAdd mailing list
JastAdd_at_cs.lth.se<mailto:JastAdd_at_cs.lth.se>
https://mail1.cs.lth.se/cgi-bin/mailman/listinfo/jastadd
Johan Åkesson, PhD, Assistant Professor
Deptm. of Automatic Control E-mail: johan.akesson_at_control.lth.se<mailto:johan.akesson_at_control.lth.se>
Faculty of Engineering WWW: www.control.lth.se/user/jakesson<
http://www.control.lth.se/user/jakesson>
Lund University Phone: +46 46 2228797
Box 118 Fax: +46 46 138118
221 00 LUND
Received on Wed Jan 18 2012 - 10:05:33 CET