﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
2965	"Information about ""outer output"" declarations needed in backend for variable merging in state machines"	Bernhard Thiele	Bernhard Thiele	"MLS 3.3, ""17.3.5 Merging Variable Definitions"" requires to merge variables in states that have been declared as  **outer output**. However, in the backend that information is lost, thus it can't be implemented.
Quoting from the spec:

  In each state, the outer output variables are solved for and for each such variable a single definition is formed:
  {{{v := if activeState(state1) then expre1 elseif activeState(state2 ) then expre2 elseif ... else last(v) }}}

I tried to recover the needed pieces from what is available in the backend, but didn't succeed so far. Consider example:
{{{
model ConferenceTut1Modified
  inner Integer i(start=0);
  Integer j(start=0), y;
  model State1
    outer output Integer i;
    input Integer j;
    Integer k;
  equation 
    i = previous(i) + 2 - k;
    j = k;
  end State1;
  State1 state1(j=j);
  model State2
    outer output Integer i;
    input Integer j;
    Integer k;
  equation 
    i = previous(i) - 1- k;
    j = k;
  end State2;
  State2 state2(j=j);
equation 
  2 = j;
  y = i;
  initialState(state1);
  transition(state1, state2, i > 10, immediate=false);
  transition(state2,state1, i < 1, immediate=false);
end ConferenceTut1Modified;
}}}

The model flattens to:
{{{
class ConferenceTut1Modified
  Integer i(start = 0);
  Integer j(start = 0);
  Integer y;
  Integer state1.i = i;
  Integer state1.j = j;
  Integer state1.k;
  Integer state2.i = i;
  Integer state2.j = j;
  Integer state2.k;
equation
  state1.i = 2 + previous(state1.i) - state1.k;
  state1.j = state1.k;
  state2.i = -1 + previous(state2.i) - state2.k;
  state2.j = state2.k;
  2 = j;
  y = i;
  initialState(state1);
  transition(state1, state2, i > 10, false, true, false, 1);
  transition(state2, state1, i < 1, false, true, false, 1);
end ConferenceTut1Modified;
}}}
Variable `i` needs to be merged, but variable `j` not. So `i` should get merged like
{{{
i = if activeState(state1) then 2 + previous(i) - state1.k 
    else -1 + previous(i) - state2.k;
}}}

If we could assume that all models are ""correct"", one might be able to figure out that the only way that the model could be correct is that `i` is a ""shared"" variable, but `j` is not. However, one can not safely make that assumption. Hence, additional information about `i` needs to be passed from the frontend to the backend. Or do I miss s.th.?

(Note that #2806 is vaguely related to this ticket, but had the opposite intention of dropping certain information...) 

"	discussion	closed	high	1.9.4	Frontend	trunk	fixed	state machines	Per Östlund Adrian Pop
