Opened 12 years ago

Closed 12 years ago

Last modified 7 years ago

#1909 closed defect (fixed)

Propagate redeclares correctly

Reported by: Per Östlund Owned by: Per Östlund
Priority: high Milestone: 1.9.4
Component: New Instantiation Version: trunk
Keywords: Cc:

Description

The new instantiation has issues when it comes to propagating redeclares, because it tries to fully qualify redeclares instead of looking them up in the correct environment. This means that models such as this doesn't work:

model A
  replaceable package Medium = PartialMedium;
  Medium.BaseProperties medium;
end A;

model B
  A a(redeclare package Medium = Medium);
  replaceable package Medium = PartialMedium;
end B;

model C
  B b(redeclare package Medium = NonPartialMedium);
end C;

In this case it will use the old declaration of B.Medium when applying the redeclare to a. We need to look up B.Medium so that we get the redeclared declaration.

Change History (10)

comment:1 by Adrian Pop, 12 years ago

Hi. Here is a more complex model that seems to have this issue.
It might be also that redeclares inside redeclare inside redeclare are not all applied.

package Default
  package Medium
    replaceable type K = Integer(quantity = "wrong");
    constant K nXi = 0;
  end Medium;
end Default;

package Other
  package Medium
    replaceable type K = Integer(quantity = "good");
    constant K nXi = 100;
  end Medium;
end Other;

package Extends
  partial model P
    replaceable package Medium = Default.Medium;
    Medium.K m = Medium.nXi;
  end P;

  partial model X
    replaceable P env;
    constant Integer z = env.nXi;
  end X;
end Extends;

model ExtendsTest
  model NewP
    extends Extends.P;
    Medium.K new = Medium.nXi;
  end NewP;

  model X
   extends 
     Extends.X(
       redeclare NewP env(
         redeclare package Medium = Other.Medium(
           redeclare type K = Integer(start=10, quantity="good"))));
  end X;

  X x;

  parameter Integer one = x.env.z;
  parameter Integer two = x.env.new;

end ExtendsTest;

in reply to:  1 comment:2 by Per Östlund, 12 years ago

Replying to adrpo:

Hi. Here is a more complex model that seems to have this issue.
It might be also that redeclares inside redeclare inside redeclare are not all applied.

I've actually already fixed this issue, I just put up the ticket to keep track of what I've done. But your model helped me find a stupid mistake in my code (using the wrong variable), so I guess it was a good idea to create a ticket :)

To my great surprise it actually seems like the redeclares are handled correctly in this model with my fixes, although there are some issues with the dependency analysis which removes Extends.X.z. I want to clean up the code and sprinkle some comments on it before I commit the fix though.

comment:3 by Adrian Pop, 12 years ago

Sounds great.
Please push your changes in as soon as possible as I
really need them to test my translator on bigger models.

Cheers,
Adrian Pop/

comment:4 by Per Östlund, 12 years ago

Resolution: fixed
Status: newclosed

Fixed in r13687.

comment:5 by Hubert Thieriot, 12 years ago

Hi,

With the last version r15135 (probably since 1.9.0Beta4), I face the same problem (though it used to work before).

Actually, the version below works:

model A
  replaceable package Medium = PartialMedium;
  Medium.BaseProperties medium;
end A;

model B
  A a(redeclare package Medium = Medium);
  replaceable package Medium = PartialMedium;
end B;

model C
  B b(redeclare package Medium = NonPartialMedium);
end C;

But if we change package names, it does not work anymore:

model A
  replaceable package MediumA = PartialMedium;
  MediumA.BaseProperties medium;
end A;

model B
  A a(redeclare package MediumA = MediumB);
  replaceable package MediumB = PartialMedium;
end B;

model C
  B b(redeclare package MediumB = NonPartialMedium);
end C;

comment:6 by Adrian Pop, 12 years ago

Have you tried with flag +d=scodeInstShortcut?

in reply to:  6 comment:7 by Hubert Thieriot, 12 years ago

Replying to adrpo:

Have you tried with flag +d=scodeInstShortcut?

I just did. It works with this flag. What exactly does it mean? My model is not well written?

Best regards,

H.

comment:8 by Adrian Pop, 12 years ago

No. Your model is correct.
The old instantiation cannot handle correctly all redeclares.
This flag uses new lookup together with the old instantiation.
It should work for any models that have redeclares and do not
work with the old instantiation.

I'm trying now to get rid of the flag by making it the default.

comment:9 by Dietmar Winkler, 9 years ago

Milestone: Futurepre1.9.4

It doesn't make sense to keep closed ticket in the "Future" milestone that were simply forgotten to assign to the correct milestone in the past.

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

Milestone: pre1.9.41.9.4

Removing the pre1.9.4 milestone in favor of 1.9.4.

Note: See TracTickets for help on using tickets.