Opened 12 years ago

Closed 4 years ago

Last modified 4 years ago

#2029 closed defect (fixed)

Incorrect cyclically dependent error, inheritance issue (from MathCore)

Reported by: mikaelf@… Owned by: probably noone
Priority: high Milestone: 1.16.0
Component: New Instantiation Version: trunk
Keywords: Cc:

Description

Problem with inheritance which induces a cyclically dependent constants or parameters error, if however the partial models are included in the model the example works.

package TestCyclic
  model TestModel "Fails to flatten"
    extends TestCyclic.Internal.SetDefinition;
    TestCyclic.FlexModel flexModel1(doSomething = doMoreSpecific);
  end TestModel;
  model FlexModel
    extends TestCyclic.Internal.Base;
    TestCyclic.Internal.Shape shape1 if doMoreSpecific;
  end FlexModel;
  package Internal
    partial model SetDefinition
      parameter Boolean doSomething = true;
      final parameter Boolean doMoreSpecific = doSomething and true and true;
    end SetDefinition;
    model Base
      extends TestCyclic.Internal.SetDefinition;
      TestCyclic.Internal.NullShape nullShape1 if not doMoreSpecific;
    end Base;
    model Shape
    end Shape;
    model NullShape
    end NullShape;
  end Internal;

Without extending partial models

  // Do the same w/o using extends, which works.
  model TestModel2 "Works, includes the code which is extended in TestModel"
    parameter Boolean doSomething = true;
    final parameter Boolean doMoreSpecific = doSomething and true and true;
    TestCyclic.FlexModel2 flexModel1(doSomething = doMoreSpecific);
  end TestModel2;
  model FlexModel2 "Includes the code which is extended in FlexModel"
    parameter Boolean doSomething = true;
    final parameter Boolean doMoreSpecific = doSomething and true and true;
    TestCyclic.Internal.NullShape nullShape1 if not doMoreSpecific;
    TestCyclic.Internal.Shape shape1 if doMoreSpecific;
  end FlexModel2;
end TestCyclic;

Change History (14)

comment:1 by Martin Sjölund, 12 years ago

Component: BackendFrontend
Resolution: invalid
Status: newclosed

In the first model you get

model TestModel
  parameter Boolean doMoreSpecific = doSomething;
  parameter Boolean doSomething = doMoreSpecific and true and true;
end TestModel;

In the second model you get:

model FlexModel2
  parameter Boolean doMoreSpecific = doSomething;
  parameter Boolean doSomething = X; // where X comes from outside, so it won't cause a cycle within the class
end FlexModel2;

The first one should not work (give the error we do right now). The second should work. And after running omc, this is what we do.

class TestCyclic.TestModel2
  parameter Boolean doSomething = true;
  final parameter Boolean doMoreSpecific = doSomething;
  parameter Boolean flexModel1.doSomething = doMoreSpecific;
  final parameter Boolean flexModel1.doMoreSpecific = flexModel1.doSomething;
end TestCyclic.TestModel2;

Look at that model and you see that it is very easy to calculate each of the parameters by going top down.

comment:2 by Peter Aronsson, 12 years ago

Resolution: invalid
Status: closedreopened

I think you are wrong. When I do it manually i get this:

The original model:

package TestCyclic
  model TestModel "Fails to flatten"
    extends TestCyclic.Internal.SetDefinition;
    TestCyclic.FlexModel flexModel1(doSomething = doMoreSpecific);
  end TestModel;
  model FlexModel
    extends TestCyclic.Internal.Base;
    TestCyclic.Internal.Shape shape1 if doMoreSpecific;
  end FlexModel;
  package Internal
    partial model SetDefinition
      parameter Boolean doSomething = true;
      final parameter Boolean doMoreSpecific = doSomething and true and true;
    end SetDefinition;
    model Base
      extends TestCyclic.Internal.SetDefinition;
      TestCyclic.Internal.NullShape nullShape1 if not doMoreSpecific;
    end Base;
    model Shape
    end Shape;
    model NullShape
    end NullShape;
  end Internal;
end TestCyclic; 


Removeflatten inheritance :

package TestCyclic
  model TestModel "Fails to flatten"
    parameter Boolean doSomething = true;  					//Inherited from SetDefinition
    final parameter Boolean doMoreSpecific = doSomething and true and true; 	// Inherited from SetDefinition
    TestCyclic.FlexModel flexModel1(doSomething = doMoreSpecific);
  end TestModel;
  model FlexModel
    parameter Boolean doSomething = true;  					//Inherited from Base->SetDefinition
    final parameter Boolean doMoreSpecific = doSomething and true and true; 	// Inherited from Base->SetDefinition
    TestCyclic.Internal.NullShape nullShape1 if not doMoreSpecific; 		// Inherited from Base
    TestCyclic.Internal.Shape shape1 if doMoreSpecific;
  end FlexModel;
 ...
  end Internal;
 


Flatten out flexModel1 in TestModel and apply modifiers:


model TestModel "Fails to flatten"
    parameter Boolean doSomething = true;  					
    final parameter Boolean doMoreSpecific = doSomething and true and true; 	
    parameter Boolean flexModel1.doSomething = doMoreSpecific;  					
    final parameter Boolean flexModel1.doMoreSpecific = flexModel1.doSomething and true and true; 	
    TestCyclic.Internal.NullShape flexModel1.nullShape1 if not flexModel1.doMoreSpecific; 		
    TestCyclic.Internal.Shape flexModel1.shape1 if flexModel1.doMoreSpecific;
  end TestModel;

This doesn't result in a cyclic dependency. Maybe you got confused about the scoping rules of modifiers?


comment:3 by Martin Sjölund, 12 years ago

Yes, the damn scoping confused me :) Anyway, the new instantiation handles this correctly already...

$ omc a.mo +i=TestCyclic.TestModel +d=scodeInst
/home/marsj/trunk/build/bin/omc 1.9.0 Beta2 (r14687)
class TestModel
  parameter Boolean doSomething = true;
  parameter Boolean doMoreSpecific = true;
  parameter Boolean flexModel1.doSomething = true;
  parameter Boolean flexModel1.doMoreSpecific = true;
end TestModel;

comment:4 by Martin Sjölund, 11 years ago

Milestone: 1.9.01.9.1

Postponed until 1.9.1

comment:5 by Martin Sjölund, 10 years ago

Milestone: 1.9.11.9.2

This ticket was not closed for 1.9.1, which has now been released. It was batch modified for milestone 1.9.2 (but maybe an empty milestone was more appropriate; feel free to change it).

comment:6 by Martin Sjölund, 10 years ago

Milestone: 1.9.21.9.3

Milestone changed to 1.9.3 since 1.9.2 was released.

comment:7 by Martin Sjölund, 9 years ago

Milestone: 1.9.31.9.4

Moved to new milestone 1.9.4

comment:8 by Martin Sjölund, 9 years ago

Milestone: 1.9.41.9.5

Milestone pushed to 1.9.5

comment:9 by Martin Sjölund, 9 years ago

Milestone: 1.9.51.10.0

Milestone renamed

comment:10 by Martin Sjölund, 8 years ago

Milestone: 1.10.01.11.0

Ticket retargeted after milestone closed

comment:11 by Martin Sjölund, 8 years ago

Milestone: 1.11.01.12.0

Milestone moved to 1.12.0 due to 1.11.0 already being released.

comment:12 by Francesco Casella, 7 years ago

Milestone: 1.12.0Future

The milestone of this ticket has been reassigned to "Future".

If you think the issue is still valid and relevant for you, please select milestone 1.13.0 for back-end, code generation and run-time issues, or 2.0.0 for front-end issues.

If you are aware that the problem is no longer present, please select the milestone corresponding to the version of OMC you used to check that, and set the status to "worksforme".

In both cases, a short informative comment would be welcome.

comment:13 by Per Östlund, 4 years ago

Component: FrontendNew Instantiation
Resolution: fixed
Status: reopenedclosed

comment:14 by Francesco Casella, 4 years ago

Milestone: Future1.16.0
Note: See TracTickets for help on using tickets.