Opened 11 years ago

Closed 3 years ago

Last modified 3 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 Changed 11 years ago by sjoelund.se

  • Component changed from Backend to Frontend
  • Resolution set to invalid
  • Status changed from new to closed

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 Changed 11 years ago by petar

  • Resolution invalid deleted
  • Status changed from closed to reopened

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 Changed 11 years ago by sjoelund.se

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 Changed 10 years ago by sjoelund.se

  • Milestone changed from 1.9.0 to 1.9.1

Postponed until 1.9.1

comment:5 Changed 9 years ago by sjoelund.se

  • Milestone changed from 1.9.1 to 1.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 Changed 9 years ago by sjoelund.se

  • Milestone changed from 1.9.2 to 1.9.3

Milestone changed to 1.9.3 since 1.9.2 was released.

comment:7 Changed 9 years ago by sjoelund.se

  • Milestone changed from 1.9.3 to 1.9.4

Moved to new milestone 1.9.4

comment:8 Changed 8 years ago by sjoelund.se

  • Milestone changed from 1.9.4 to 1.9.5

Milestone pushed to 1.9.5

comment:9 Changed 8 years ago by sjoelund.se

  • Milestone changed from 1.9.5 to 1.10.0

Milestone renamed

comment:10 Changed 7 years ago by sjoelund.se

  • Milestone changed from 1.10.0 to 1.11.0

Ticket retargeted after milestone closed

comment:11 Changed 7 years ago by sjoelund.se

  • Milestone changed from 1.11.0 to 1.12.0

Milestone moved to 1.12.0 due to 1.11.0 already being released.

comment:12 Changed 6 years ago by casella

  • Milestone changed from 1.12.0 to Future

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 Changed 3 years ago by perost

  • Component changed from Frontend to New Instantiation
  • Resolution set to fixed
  • Status changed from reopened to closed

comment:14 Changed 3 years ago by casella

  • Milestone changed from Future to 1.16.0
Note: See TracTickets for help on using tickets.