Skip to content

Commit

Permalink
Structural parameters as HashSet instead of Table
Browse files Browse the repository at this point in the history
The FCore.Cache stores the structural parameters as a HashTable, but
does not use the value. This changes the structure to a HashSet
instead.

Note: This also fixes a bug in a model where the HashTable gets
corrupted (probably due to matchcontinue use). The structure should
possibly be changed to an AvlSet instead (or HashTable/HashSet
changed to be fully mutable).
  • Loading branch information
sjoelund committed Oct 19, 2016
1 parent eae52ab commit 88b6260
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 24 deletions.
12 changes: 6 additions & 6 deletions Compiler/FFrontEnd/FCore.mo
Expand Up @@ -45,10 +45,10 @@ import BaseAvlTree;
import DAE;
import SCode;
import Prefix;
import HashTable;
import HashSet;

protected
import BaseHashTable;
import BaseHashSet;
import DAEUtil;
import Config;

Expand Down Expand Up @@ -406,7 +406,7 @@ public constant Id firstId = 0;
// ************************ Cache structures ***************************
// ************************ Cache structures ***************************

public type StructuralParameters = tuple<HashTable.HashTable,list<list<DAE.ComponentRef>>>;
public type StructuralParameters = tuple<HashSet.HashSet,list<list<DAE.ComponentRef>>>;
public uniontype Cache
record CACHE
Option<Graph> initialGraph "and the initial environment";
Expand Down Expand Up @@ -443,7 +443,7 @@ protected
StructuralParameters ht;
algorithm
instFuncs := arrayCreate(1, DAE.AvlTreePathFunction.Tree.EMPTY());
ht := (HashTable.emptyHashTableSized(BaseHashTable.lowBucketSize),{});
ht := (HashSet.emptyHashSetSized(BaseHashSet.lowBucketSize),{});
cache := CACHE(NONE(),instFuncs,ht,Absyn.IDENT("##UNDEFINED##"),Absyn.dummyProgram);
end emptyCache;

Expand All @@ -464,7 +464,7 @@ algorithm
local
Option<Graph> initialGraph;
array<DAE.FunctionTree> functions;
HashTable.HashTable ht;
HashSet.HashSet ht;
list<list<DAE.ComponentRef>> st;
list<DAE.ComponentRef> crs;
Absyn.Path p;
Expand All @@ -480,7 +480,7 @@ end addEvaluatedCref;

public function getEvaluatedParams
input Cache cache;
output HashTable.HashTable ht;
output HashSet.HashSet ht;
algorithm
CACHE(evaluatedParams=(ht,_)) := cache;
end getEvaluatedParams;
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/Ceval.mo
Expand Up @@ -5379,7 +5379,7 @@ protected
FCore.StructuralParameters structuralParameters;
array<DAE.FunctionTree> functionTree;
algorithm
structuralParameters := (HashTable.emptyHashTableSized(BaseHashTable.lowBucketSize),{});
structuralParameters := (HashSet.emptyHashSetSized(BaseHashSet.lowBucketSize),{});
functionTree := arrayCreate(1,functions);
cache := FCore.CACHE(NONE(), functionTree, structuralParameters, Absyn.IDENT(""), Absyn.dummyProgram);
(_,val,_) := ceval(cache, FGraph.empty(), exp, false, NONE(), Absyn.NO_MSG(),0);
Expand Down
16 changes: 7 additions & 9 deletions Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -5303,7 +5303,7 @@ public function transformationsBeforeBackend
protected
DAE.DAElist dAElist;
list<DAE.Element> elts;
HashTable.HashTable ht;
HashSet.HashSet ht;
algorithm
// Transform Modelica state machines to flat data-flow equations
dAElist := StateMachineFlatten.stateMachineToDataFlow(cache, env, inDAElist);
Expand All @@ -5322,7 +5322,7 @@ algorithm
end transformationsBeforeBackend;

protected function transformationsBeforeBackendNotification
input HashTable.HashTable ht;
input HashSet.HashSet ht;
algorithm
_ := matchcontinue ht
local
Expand All @@ -5331,7 +5331,7 @@ algorithm
String str;
case _
equation
(crs as _::_) = BaseHashTable.hashTableKeyList(ht);
(crs as _::_) = BaseHashSet.hashSetList(ht);
strs = List.map(crs, ComponentReference.printComponentRefStr);
strs = List.sort(strs, Util.strcmpBool);
str = stringDelimitList(strs, ", ");
Expand All @@ -5344,10 +5344,10 @@ end transformationsBeforeBackendNotification;
protected function makeEvaluatedParamFinal "
This function makes all evaluated parameters final."
input DAE.Element inElement;
input HashTable.HashTable ht "evaluated parameters";
input HashSet.HashSet ht "evaluated parameters";
output DAE.Element outElement;
algorithm
outElement := matchcontinue(inElement, ht)
outElement := match (inElement, ht)
local
DAE.ComponentRef cr;
Option<DAE.VariableAttributes> varOpt;
Expand All @@ -5358,17 +5358,15 @@ algorithm
DAE.Element elt;

case (DAE.VAR(componentRef=cr, kind=DAE.PARAM(), variableAttributesOption=varOpt), _) equation
_ = BaseHashTable.get(cr, ht);
// print("Make cr final " + ComponentReference.printComponentRefStr(cr) + "\n");
elt = setVariableAttributes(inElement, setFinalAttr(varOpt, true));
elt = if BaseHashSet.has(cr, ht) then setVariableAttributes(inElement, setFinalAttr(varOpt, true)) else inElement;
then elt;

case (DAE.COMP(id, elts, source, cmt), _) equation
elts = List.map1(elts, makeEvaluatedParamFinal, ht);
then DAE.COMP(id, elts, source, cmt);

else inElement;
end matchcontinue;
end match;
end makeEvaluatedParamFinal;

public function setBindingSource "author: adrpo
Expand Down
9 changes: 4 additions & 5 deletions Compiler/FrontEnd/InstUtil.mo
Expand Up @@ -7721,7 +7721,7 @@ algorithm
local
Option<FCore.Graph> ie;
array<DAE.FunctionTree> f;
HashTable.HashTable ht;
HashSet.HashSet ht;
list<list<DAE.ComponentRef>> crs;
Absyn.Path p;
Absyn.Program program;
Expand All @@ -7740,7 +7740,7 @@ algorithm
local
Option<FCore.Graph> ie;
array<DAE.FunctionTree> f;
HashTable.HashTable ht;
HashSet.HashSet ht;
list<DAE.ComponentRef> crs;
list<list<DAE.ComponentRef>> crss;
Absyn.Path p;
Expand All @@ -7756,14 +7756,13 @@ end popStructuralParameters;
protected function prefixAndAddCrefsToHt
"Cannot be part of Env due to RML issues"
input FCore.Cache cache;
input HashTable.HashTable iht;
input output HashSet.HashSet set;
input Prefix.Prefix pre;
input list<DAE.ComponentRef> icrs;
output HashTable.HashTable oht=iht;
algorithm
for cr in icrs loop
(_,cr) := PrefixUtil.prefixCref(cache, FGraph.empty(), InnerOuter.emptyInstHierarchy, pre, cr);
oht := BaseHashTable.add((cr,1),oht);
set := BaseHashSet.add(cr,set);
end for;
end prefixAndAddCrefsToHt;

Expand Down
1 change: 1 addition & 0 deletions Compiler/SimCode/SimCode.mo
Expand Up @@ -54,6 +54,7 @@ encapsulated package SimCode
import Absyn;
import BackendDAE;
import DAE;
import HashTable;
import HashTableCrILst;
import HashTableCrIListArray;
import HashTableCrefSimVar;
Expand Down
4 changes: 2 additions & 2 deletions Compiler/Util/BaseHashTable.mo
Expand Up @@ -539,9 +539,9 @@ algorithm
then
((n, size, arr));

case ((_, size, _), _, _)
case ((_, size, arr), _, _)
equation
Error.addInternalError("HashTable.valueArraySet(pos="+String(pos)+") size="+String(size)+" failed\n", sourceInfo());
Error.addInternalError("HashTable.valueArraySet(pos="+String(pos)+") size="+String(size)+" arrSize="+String(arrayLength(arr))+" failed\n", sourceInfo());
then
fail();

Expand Down
2 changes: 1 addition & 1 deletion common
Submodule common updated 1 files
+2 −2 m4/qmake.m4

0 comments on commit 88b6260

Please sign in to comment.