Skip to content

Commit

Permalink
Replace CREF with ComponentPrefix in ElementSource
Browse files Browse the repository at this point in the history
It takes time to calculate a cref in elementsource and the only real
usage of cref is in StateMachineFeatures (but it could just as well
use hashing on the prefix; this is not done yet).

Also removed generation of the _info.xml (replaced by the JSON file
which has been the default for a long time).
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed Apr 21, 2016
1 parent 077a6e6 commit 86399e4
Show file tree
Hide file tree
Showing 18 changed files with 163 additions and 648 deletions.
4 changes: 2 additions & 2 deletions Compiler/BackEnd/BackendVariable.mo
Expand Up @@ -1426,7 +1426,7 @@ algorithm

case (_) guard(ComponentReference.traverseCref(inCref, ComponentReference.crefIsRec, false)) equation
DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(path), source=typeLst) = inType;
source = DAE.SOURCE(Absyn.dummyInfo, {}, NONE(), {}, path::typeLst, {}, {});
source = DAE.SOURCE(Absyn.dummyInfo, {}, Prefix.NOCOMPPRE(), {}, path::typeLst, {}, {});
varKind = if Types.isDiscreteType(inType) then BackendDAE.DISCRETE() else BackendDAE.VARIABLE();
outVar = BackendDAE.VAR(inCref, varKind, DAE.BIDIR(), DAE.NON_PARALLEL(), inType, NONE(), NONE(), {}, source, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), true);
then outVar;
Expand Down Expand Up @@ -1506,7 +1506,7 @@ algorithm

case (_) guard(ComponentReference.traverseCref(inCref, ComponentReference.crefIsRec, false)) equation
DAE.T_COMPLEX(complexClassType=ClassInf.RECORD(path), source=typeLst) = inType;
source = DAE.SOURCE(Absyn.dummyInfo, {}, NONE(), {}, path::typeLst, {}, {});
source = DAE.SOURCE(Absyn.dummyInfo, {}, Prefix.NOCOMPPRE(), {}, path::typeLst, {}, {});
varKind = if Types.isDiscreteType(inType) then BackendDAE.DISCRETE() else BackendDAE.VARIABLE();
outVar = BackendDAE.VAR(inCref, varKind, DAE.BIDIR(), DAE.NON_PARALLEL(), inType, NONE(), NONE(), inArryDim, source, NONE(), NONE(), NONE(), DAE.NON_CONNECTOR(), DAE.NOT_INNER_OUTER(), true);
then outVar;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/BackEnd/IndexReduction.mo
Expand Up @@ -1638,7 +1638,7 @@ algorithm
(mulAdstates,_) := Expression.extendArrExp(mulAdstates,false);
expset := if b then DAE.ARRAY(DAE.T_ARRAY(DAE.T_REAL_DEFAULT,{DAE.DIM_INTEGER(rang)},DAE.emptyTypeSource),true,expcrset) else listHead(expcrset);
expderset := if b then DAE.ARRAY(DAE.T_ARRAY(DAE.T_REAL_DEFAULT,{DAE.DIM_INTEGER(rang)},DAE.emptyTypeSource),true,expcrdset) else listHead(expcrdset);
source := DAE.SOURCE(SOURCEINFO("stateselection",false,0,0,0,0,0.0),{},NONE(),{},{},{},{});
source := DAE.SOURCE(SOURCEINFO("stateselection",false,0,0,0,0,0.0),{},Prefix.NOCOMPPRE(),{},{},{},{});
// set.x = set.A*set.statecandidates
eqn := if b then BackendDAE.ARRAY_EQUATION({rang},expset,mulAstates,source,BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC)
else BackendDAE.EQUATION(expset,mulAstates,source,BackendDAE.EQ_ATTR_DEFAULT_DYNAMIC);
Expand Down
16 changes: 10 additions & 6 deletions Compiler/BackEnd/StateMachineFeatures.mo
Expand Up @@ -52,6 +52,7 @@ protected import HashSet;
protected import BaseHashSet;
protected import HashTableSM;
protected import Array;
protected import PrefixUtil;
protected import ExpressionDump;
protected import ValuesUtil;
protected import DAEDump;
Expand Down Expand Up @@ -1518,6 +1519,7 @@ protected
Mode mode;
DAE.ComponentRef cref;
DAE.ElementSource source "origin of variable";
Prefix.ComponentPrefix instance;
algorithm
try
(SOME(var), mt) := inVarModeTable;
Expand All @@ -1530,7 +1532,8 @@ algorithm
end match;

BackendDAE.VAR(source=source) := var;
DAE.SOURCE(instanceOpt=SOME(cref)) := source;
DAE.SOURCE(instance=instance) := source;
cref := PrefixUtil.prefixToCref(Prefix.PREFIX(instance,Prefix.CLASSPRE(SCode.PARAM())));
mode := BaseHashTable.get(cref, mt);
mode := match mode
case MODE()
Expand Down Expand Up @@ -1572,13 +1575,15 @@ protected
Option<SCode.Comment> comment "this contains the comment and annotation from Absyn";
DAE.ConnectorType connectorType "flow, stream, unspecified or not connector.";
DAE.VarInnerOuter io;
Prefix.ComponentPrefix instance;
algorithm
try
(SOME(var), mt) := inVarModeTable;
BackendDAE.VAR(varName, varKind, DAE.OUTPUT(), varParallelism, varType, bindExp,
bindValue, arryDim, source, values, tearingSelectOption, comment, connectorType, DAE.OUTER()) := var;

DAE.SOURCE(instanceOpt=SOME(cref)) := source;
DAE.SOURCE(instance=instance as Prefix.PRE()) := source;
cref := PrefixUtil.prefixToCref(Prefix.PREFIX(instance,Prefix.CLASSPRE(SCode.PARAM())));
mode := BaseHashTable.get(cref, mt);
mode := match mode
case MODE()
Expand Down Expand Up @@ -1607,6 +1612,7 @@ protected
Option<BackendDAE.Equation> eqOpt;
ModeTable modeTable;
Option<DAE.ElementSource> sourceOpt "origin of equation";
Prefix.ComponentPrefix instance;
Option<DAE.ComponentRef> instanceOpt "the instance(s) this element is part of";
Option<tuple<DAE.ComponentRef,TransitionType>> transitionOpt "transition statement";
Option<Mode> optMode;
Expand Down Expand Up @@ -1662,7 +1668,7 @@ algorithm
Option<DAE.ComponentRef> crefOpt;
DAE.ComponentRef cref;
case (_, SOME((cref,_))) then SOME(cref);
case (SOME(DAE.SOURCE(instanceOpt=crefOpt)), NONE()) then crefOpt;
case (SOME(DAE.SOURCE(instance=instance)), NONE()) then SOME(PrefixUtil.prefixToCref(Prefix.PREFIX(instance,Prefix.CLASSPRE(SCode.PARAM()))));
else NONE();
end match;

Expand Down Expand Up @@ -2639,9 +2645,7 @@ algorithm
sBindExp := Util.getOptionOrDefault(s1, "");
s2 := Util.applyOption(bindValue, ValuesUtil.valString);
sBindValue := Util.getOptionOrDefault(s2, "");
DAE.SOURCE(instanceOpt=crefOpt) := source;
s3 := Util.applyOption(crefOpt, ComponentReference.crefStr);
sInstanceOpt := Util.getOptionOrDefault(s3, "NONE()");
sInstanceOpt := PrefixUtil.printComponentPrefixStr(source.instance);
sIo := match io
case DAE.INNER() then "inner";
case DAE.OUTER() then "outer";
Expand Down
7 changes: 4 additions & 3 deletions Compiler/FrontEnd/CheckModel.mo
Expand Up @@ -50,6 +50,7 @@ protected import Expression;
protected import Flags;
protected import HashSet;
protected import List;
protected import PrefixUtil;
protected import Util;
protected import Error;

Expand Down Expand Up @@ -297,13 +298,13 @@ algorithm
DAE.ComponentRef cr;
list<DAE.ComponentRef> crefLst;

case (_, DAE.SOURCE(instanceOpt = NONE()), _)
case (_, DAE.SOURCE(instance = Prefix.NOCOMPPRE()), _)
then algorithmOutputs(inAlgorithm, inCrefExpansionRule);

// the algorithm came from a component that is member of an array or not
case (_, DAE.SOURCE(instanceOpt = SOME(cr)), _)
case (_, DAE.SOURCE(), _)
then
if ComponentReference.crefHaveSubs(cr)
if PrefixUtil.haveSubs(inSource.instance)
then algorithmOutputs(inAlgorithm, DAE.NOT_EXPAND())
else algorithmOutputs(inAlgorithm, inCrefExpansionRule);

Expand Down
5 changes: 3 additions & 2 deletions Compiler/FrontEnd/DAE.mo
Expand Up @@ -45,6 +45,7 @@ import Absyn;
import BaseAvlTree;
import ClassInf;
import SCode;
import Prefix;
import Values;

protected
Expand Down Expand Up @@ -106,15 +107,15 @@ uniontype ElementSource "gives information about the origin of the element"
record SOURCE
SourceInfo info "the line and column numbers of the equations and algorithms this element came from";
list<Absyn.Within> partOfLst "the model(s) this element came from";
Option<ComponentRef> instanceOpt "the instance(s) this element is part of";
Prefix.ComponentPrefix instance "the instance(s) this element is part of";
list<tuple<ComponentRef, ComponentRef>> connectEquationOptLst "this element came from this connect(s)";
list<Absyn.Path> typeLst "the classes where the type(s) of the element is defined";
list<SymbolicOperation> operations "the symbolic operations used to end up with the final state of the element";
list<SCode.Comment> comment;
end SOURCE;
end ElementSource;

public constant ElementSource emptyElementSource = SOURCE(Absyn.dummyInfo,{},NONE(),{},{},{},{});
public constant ElementSource emptyElementSource = SOURCE(Absyn.dummyInfo,{},Prefix.NOCOMPPRE(),{},{},{},{});

public uniontype SymbolicOperation
record FLATTEN "From one equation/statement to an element"
Expand Down
63 changes: 33 additions & 30 deletions Compiler/FrontEnd/ElementSource.mo
@@ -1,6 +1,7 @@
encapsulated package ElementSource "A package for recording symbolic operations (used by the debugger) as well as other operations recording where an equation came from"

import DAE;
import Prefix;

protected

Expand All @@ -22,7 +23,7 @@ algorithm
local
SourceInfo info;
list<Absyn.Within> partOfLst1,partOfLst2,p;
Option<DAE.ComponentRef> instanceOpt1,instanceOpt2,i;
Prefix.ComponentPrefix instanceOpt1,instanceOpt2,i;
list<tuple<DAE.ComponentRef, DAE.ComponentRef>> connectEquationOptLst1,connectEquationOptLst2,c;
list<Absyn.Path> typeLst1,typeLst2,t;
list<DAE.SymbolicOperation> o,operations1,operations2;
Expand All @@ -31,7 +32,7 @@ algorithm
DAE.SOURCE(_ /* Discard */, partOfLst2, instanceOpt2, connectEquationOptLst2, typeLst2, operations2, comment2))
equation
p = List.union(partOfLst1, partOfLst2);
i = if isSome(instanceOpt1) then instanceOpt1 else instanceOpt2;
i = match instanceOpt1 case Prefix.NOCOMPPRE() then instanceOpt2; else instanceOpt1; end match;
c = List.union(connectEquationOptLst1, connectEquationOptLst2);
t = List.union(typeLst1, typeLst2);
o = listAppend(operations1, operations2);
Expand All @@ -41,25 +42,24 @@ algorithm
end mergeSources;

function addCommentToSource
input DAE.ElementSource src1;
input output DAE.ElementSource source;
input Option<SCode.Comment> commentIn;
output DAE.ElementSource mergedSrc;
algorithm
mergedSrc := match(src1,commentIn)
source := match(source,commentIn)
local
SourceInfo info;
list<Absyn.Within> partOfLst1;
Option<DAE.ComponentRef> instanceOpt1;
Prefix.ComponentPrefix instanceOpt1;
list<tuple<DAE.ComponentRef, DAE.ComponentRef>> connectEquationOptLst1;
list<Absyn.Path> typeLst1;
list<DAE.SymbolicOperation> operations1;
list<SCode.Comment> comment1,comment2;
SCode.Comment comment;
case (DAE.SOURCE(info, partOfLst1, instanceOpt1, connectEquationOptLst1, typeLst1, operations1, comment1),SOME(comment))
equation
comment2 = comment::comment1;
then DAE.SOURCE(info,partOfLst1,instanceOpt1,connectEquationOptLst1,typeLst1, operations1,comment2);
else src1;
algorithm
source.comment := comment::source.comment;
then source;
else source;
end match;
end addCommentToSource;

Expand All @@ -68,18 +68,21 @@ function createElementSource
set the various sources of the element"
input SourceInfo fileInfo;
input Option<Absyn.Path> partOf "the model(s) this element came from";
input Option<DAE.ComponentRef> instanceOpt "the instance(s) this element is part of";
input Prefix.Prefix prefix "the instance(s) this element is part of";
input tuple<DAE.ComponentRef, DAE.ComponentRef> connectEquation=(DAE.emptyCref, DAE.emptyCref) "this element came from this connect(s)";
output DAE.ElementSource source;
protected
Absyn.Path path;
algorithm
// TODO: Optimize this to only do 1 allocation?
source := addElementSourceFileInfo(DAE.emptyElementSource, fileInfo);
source := addElementSourcePartOfOpt(source, partOf);
source := addElementSourceInstanceOpt(source, instanceOpt);
source := match connectEquation
case (DAE.CREF_IDENT(ident=""),_) then source;
else addElementSourceConnect(source, connectEquation);
end match;
source := DAE.SOURCE(
fileInfo,
match partOf case NONE() then {}; case SOME(path) then {Absyn.WITHIN(path)}; end match,
match prefix case Prefix.NOPRE() then Prefix.NOCOMPPRE(); case Prefix.PREFIX() then prefix.compPre; end match,
match connectEquation case (DAE.CREF_IDENT(ident=""),_) then {}; else {connectEquation}; end match,
{},
{},
{}
);
end createElementSource;

function addAdditionalComment
Expand All @@ -92,7 +95,7 @@ algorithm
SourceInfo info "the line and column numbers of the equations and algorithms this element came from";
list<Absyn.Path> typeLst "the absyn type of the element" ;
list<Absyn.Within> partOfLst "the models this element came from" ;
Option<DAE.ComponentRef> instanceOpt "the instance this element is part of" ;
Prefix.ComponentPrefix instanceOpt "the instance this element is part of" ;
list<tuple<DAE.ComponentRef, DAE.ComponentRef>> connectEquationOptLst "this element came from this connect" ;
list<DAE.SymbolicOperation> operations;
list<SCode.Comment> comment;
Expand Down Expand Up @@ -120,7 +123,7 @@ algorithm
SourceInfo info "the line and column numbers of the equations and algorithms this element came from";
list<Absyn.Path> typeLst "the absyn type of the element" ;
list<Absyn.Within> partOfLst "the models this element came from" ;
Option<DAE.ComponentRef> instanceOpt "the instance this element is part of" ;
Prefix.ComponentPrefix instanceOpt "the instance this element is part of" ;
list<tuple<DAE.ComponentRef, DAE.ComponentRef>> connectEquationOptLst "this element came from this connect" ;
list<DAE.SymbolicOperation> operations;
list<SCode.Comment> commentLst;
Expand Down Expand Up @@ -159,7 +162,7 @@ algorithm
SourceInfo info "the line and column numbers of the equations and algorithms this element came from";
list<Absyn.Path> typeLst "the absyn type of the element" ;
list<Absyn.Within> partOfLst "the models this element came from" ;
Option<DAE.ComponentRef> instanceOpt "the instance this element is part of" ;
Prefix.ComponentPrefix instanceOpt "the instance this element is part of" ;
list<tuple<DAE.ComponentRef, DAE.ComponentRef>> connectEquationOptLst "this element came from this connect" ;
list<DAE.SymbolicOperation> operations;
DAE.Exp h1,t1,t2;
Expand Down Expand Up @@ -227,7 +230,7 @@ algorithm
SourceInfo info "the line and column numbers of the equations and algorithms this element came from";
list<Absyn.Path> typeLst "the absyn type of the element" ;
list<Absyn.Within> partOfLst "the models this element came from" ;
Option<DAE.ComponentRef> instanceOpt "the instance this element is part of" ;
Prefix.ComponentPrefix instanceOpt "the instance this element is part of" ;
list<tuple<DAE.ComponentRef, DAE.ComponentRef>> connectEquationOptLst "this element came from this connect" ;
list<DAE.SymbolicOperation> operations;
DAE.Exp h1,t1,t2;
Expand Down Expand Up @@ -429,9 +432,9 @@ function getElementSourceInstances
"@author: adrpo
retrieves the paths from the DAE.ElementSource.SOURCE.instanceOpt"
input DAE.ElementSource source "the source of the element";
output Option<DAE.ComponentRef> instanceOpt;
output Prefix.ComponentPrefix instanceOpt;
algorithm
instanceOpt := source.instanceOpt;
instanceOpt := source.instance;
end getElementSourceInstances;

function getElementSourceConnects
Expand Down Expand Up @@ -497,7 +500,7 @@ algorithm
local
SourceInfo info "the line and column numbers of the equations and algorithms this element came from";
list<Absyn.Within> partOfLst "the models this element came from" ;
Option<DAE.ComponentRef> instanceOpt "the instance this element is part of" ;
Prefix.ComponentPrefix instanceOpt "the instance this element is part of" ;
list<tuple<DAE.ComponentRef, DAE.ComponentRef>> connectEquationOptLst "this element came from this connect" ;
list<Absyn.Path> typeLst "the classes where the type of the element is defined" ;
list<DAE.SymbolicOperation> operations;
Expand All @@ -521,7 +524,7 @@ algorithm
SourceInfo info "the line and column numbers of the equations and algorithms this element came from";
list<Absyn.Path> typeLst "the absyn type of the element" ;
list<Absyn.Within> partOfLst "the models this element came from" ;
Option<DAE.ComponentRef> instanceOpt "the instance this element is part of" ;
Prefix.ComponentPrefix instanceOpt "the instance this element is part of" ;
list<tuple<DAE.ComponentRef, DAE.ComponentRef>> connectEquationOptLst "this element came from this connect" ;
list<DAE.SymbolicOperation> operations;
list<SCode.Comment> comment;
Expand All @@ -535,7 +538,7 @@ protected

function addElementSourceInstanceOpt
input DAE.ElementSource inSource;
input Option<DAE.ComponentRef> instanceOpt;
input Prefix.ComponentPrefix instanceOpt;
output DAE.ElementSource outSource;
algorithm
outSource := match(inSource, instanceOpt)
Expand All @@ -549,9 +552,9 @@ algorithm
DAE.ComponentRef cr;

// a NONE() means top level (equivalent to NO_PRE, SOME(cref) means subcomponent
case (_, NONE())
case (_, Prefix.NOCOMPPRE())
then inSource;
case (DAE.SOURCE(info,partOfLst,_,connectEquationOptLst,typeLst,operations,comment), SOME(cr))
case (DAE.SOURCE(info,partOfLst,_,connectEquationOptLst,typeLst,operations,comment), _)
then DAE.SOURCE(info,partOfLst,instanceOpt,connectEquationOptLst,typeLst,operations,comment);
end match;
end addElementSourceInstanceOpt;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Inst.mo
Expand Up @@ -2086,7 +2086,7 @@ algorithm
// If we are currently instantiating a connector, add all flow variables
// in it as inside connectors.
zero_dims = InstUtil.instDimsHasZeroDims(inst_dims);
elementSource = ElementSource.createElementSource(info, FGraph.getScopePath(env3), PrefixUtil.prefixToCrefOpt(pre));
elementSource = ElementSource.createElementSource(info, FGraph.getScopePath(env3), pre);
csets1 = ConnectUtil.addConnectorVariablesFromDAE(zero_dims, ci_state1, pre, vars, info, elementSource, csets);

// Reorder the connect equations to have non-expandable connect first:
Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/InstFunction.mo
Expand Up @@ -370,7 +370,7 @@ algorithm
env_1 = FGraph.mkTypeNode(env_1, n, ty1);

// set the source of this element
source = ElementSource.createElementSource(info, FGraph.getScopePath(env), PrefixUtil.prefixToCrefOpt(pre));
source = ElementSource.createElementSource(info, FGraph.getScopePath(env), pre);
inlineType = InstUtil.isInlineFunc(c);
partialPrefixBool = SCode.partialBool(partialPrefix);

Expand Down Expand Up @@ -413,7 +413,7 @@ algorithm
(cache,ih,extdecl) = instExtDecl(cache, tempenv,ih, n, parts, true, pre,info) "impl" ;

// set the source of this element
source = ElementSource.createElementSource(info, FGraph.getScopePath(env), PrefixUtil.prefixToCrefOpt(pre));
source = ElementSource.createElementSource(info, FGraph.getScopePath(env), pre);
partialPrefixBool = SCode.partialBool(partialPrefix);
InstUtil.checkExternalFunction(daeElts,extdecl,Absyn.pathString(fpath));
then
Expand Down

0 comments on commit 86399e4

Please sign in to comment.