Skip to content

Commit

Permalink
Reduce memory consumption
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund committed Apr 16, 2016
1 parent 2ac963a commit 2aca7e4
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 56 deletions.
5 changes: 1 addition & 4 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -3293,7 +3293,7 @@ algorithm
if SCode.finalBool(final_prefix) then
m = InstUtil.traverseModAddFinal(m);
end if;
comp = SCode.COMPONENT(name, prefixes, attr, ts, m, comment, cond, info);
comp = if referenceEq(el.modifications, m) then el else SCode.COMPONENT(name, prefixes, attr, ts, m, comment, cond, info);

// Fails if multiple decls not identical
already_declared = InstUtil.checkMultiplyDeclared(cache, env, mods, pre, ci_state, (comp, cmod), inst_dims, impl);
Expand Down Expand Up @@ -4125,9 +4125,6 @@ algorithm

// If first part of ident is a class, e.g StateSelect.None, nothing to update
case (cache,env,ih,_,_,_,_,_,_,_)
equation
_ = Absyn.crefFirstIdent(cref);
// (cache,_,_) = Lookup.lookupClass(cache,env, Absyn.IDENT(id));
then
(cache,env,ih,inUpdatedComps);
// report an error!
Expand Down
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/InstExtends.mo
Expand Up @@ -1533,7 +1533,7 @@ algorithm
equation
id = Absyn.crefFirstIdent(cref);
//print("Try lookupC " + id + "\n");
(_,c,denv) = Lookup.lookupClass(arrayGet(cache,1),env,Absyn.IDENT(id));
(_,c,denv) = Lookup.lookupClassIdent(arrayGet(cache,1),env,id);
// isOutside = FGraph.graphPrefixOf(denv, env);
// id might come from named import, make sure you use the actual class name!
id = SCode.getElementName(c);
Expand Down
62 changes: 25 additions & 37 deletions Compiler/FrontEnd/InstUtil.mo
Expand Up @@ -3560,7 +3560,7 @@ algorithm
false = FGraph.isTopScope(inNewEnv);
id = FNode.refName(FGraph.lastScopeRef(inNewEnv));
(rest, _) = FGraph.stripLastScopeRef(inNewEnv);
(_, cls, _) = Lookup.lookupClass(inCache, rest, Absyn.IDENT(id));
(_, cls, _) = Lookup.lookupClassIdent(inCache, rest, id);
ci_state = ClassInf.start(SCode.getClassRestriction(cls), FGraph.getGraphName(inNewEnv));
then
ci_state;
Expand Down Expand Up @@ -6618,30 +6618,29 @@ end extractCorrectClassMod2;

public function traverseModAddFinal
"Helper function for traverseModAddFinal"
input SCode.Mod mod;
output SCode.Mod mod2;
input output SCode.Mod mod;
algorithm
mod2 := matchcontinue(mod)
mod := matchcontinue(mod)
local
SCode.Element element;
SCode.Element element1,element2;
SCode.Each each_;
list<SCode.SubMod> subs;
list<SCode.SubMod> subs1,subs2;
Option<Absyn.Exp> eq;
SourceInfo info;
SCode.Final f;

case(SCode.NOMOD()) then SCode.NOMOD();
case SCode.NOMOD() then mod;

case(SCode.REDECL(eachPrefix = each_, element = element))
case SCode.REDECL(eachPrefix = each_, element = element1)
equation
element = traverseModAddFinal3(element);
then
SCode.REDECL(SCode.FINAL(),each_,element);
element2 = traverseModAddFinal3(element1);
then if referenceEq(element1,element2) then mod else SCode.REDECL(SCode.FINAL(),each_,element2);

case(SCode.MOD(_,each_,subs,eq,info))
case(SCode.MOD(f,each_,subs1,eq,info))
equation
subs = traverseModAddFinal4(subs);
subs2 = List.mapCheckReferenceEq(subs1, traverseModAddFinal4);
then
SCode.MOD(SCode.FINAL(),each_,subs,eq,info);
if valueEq(SCode.FINAL(),f) and referenceEq(subs1, subs2) then mod else SCode.MOD(SCode.FINAL(),each_,subs2,eq,info);

else
equation
Expand Down Expand Up @@ -6674,15 +6673,15 @@ algorithm
equation
mod = traverseModAddFinal(oldmod);
then
SCode.COMPONENT(name,prefixes,attr,tySpec,mod,cmt,cond,info);
if referenceEq(oldmod,mod) then inElement else SCode.COMPONENT(name,prefixes,attr,tySpec,mod,cmt,cond,info);

case SCode.IMPORT() then inElement;
case SCode.CLASS() then inElement;

case SCode.EXTENDS(p,vis,mod,ann,info)
case SCode.EXTENDS(p,vis,oldmod,ann,info)
equation
mod = traverseModAddFinal(mod);
then SCode.EXTENDS(p,vis,mod,ann,info);
mod = traverseModAddFinal(oldmod);
then if referenceEq(oldmod,mod) then inElement else SCode.EXTENDS(p,vis,mod,ann,info);

else
equation
Expand All @@ -6695,25 +6694,14 @@ end traverseModAddFinal3;

protected function traverseModAddFinal4
"Helper function for traverseModAddFinal2"
input list<SCode.SubMod> subs;
output list<SCode.SubMod> osubs;
algorithm osubs:= matchcontinue(subs)
local
String ident;
SCode.Mod mod;
list<Absyn.Subscript> intList;
list<SCode.SubMod> rest;
case({}) then {};
case((SCode.NAMEMOD(ident,mod))::rest )
equation
rest = traverseModAddFinal4(rest);
mod = traverseModAddFinal(mod);
then
SCode.NAMEMOD(ident,mod)::rest;
else
equation print(" we failed with traverseModAddFinal4\n");
then fail();
end matchcontinue;
input output SCode.SubMod sub;
protected
SCode.Mod mod;
algorithm
mod := traverseModAddFinal(sub.mod);
if not referenceEq(sub.mod, mod) then
sub.mod := mod;
end if;
end traverseModAddFinal4;

public function traverseModAddDims
Expand Down
22 changes: 17 additions & 5 deletions Compiler/FrontEnd/Lookup.mo
Expand Up @@ -425,6 +425,18 @@ algorithm
// print("Lookup C2: " + " outenv: " + FGraph.printGraphPathStr(outEnv) + "\n");
end lookupClass;

public function lookupClassIdent "Like lookupClass, but takes a String as ident for input (avoids Absyn.IDENT() creation)"
input FCore.Cache inCache;
input FCore.Graph inEnv "Where to look";
input String ident;
input Option<SourceInfo> inInfo = NONE();
output FCore.Cache outCache;
output SCode.Element outClass;
output FCore.Graph outEnv;
algorithm
(outCache,outClass,outEnv) := lookupClassInEnv(inCache, inEnv, ident, {}, Util.makeStatefulBoolean(false), inInfo);
end lookupClassIdent;

protected function lookupClass1 "help function to lookupClass, does all the work."
input FCore.Cache inCache;
input FCore.Graph inEnv;
Expand Down Expand Up @@ -547,7 +559,7 @@ algorithm
// Qualified names in package and non-package
case (cache,env,_,_,NONE(),_)
equation
(cache,c,env,prevFrames) = lookupClass2(cache,env,Absyn.IDENT(id),{},inState,inInfo);
(cache,c,env,prevFrames) = lookupClassInEnv(cache,env,id,{},inState,inInfo);
(optFrame,prevFrames) = lookupPrevFrames(id,prevFrames);
(cache,c,env,prevFrames) = lookupClassQualified2(cache,env,path,c,optFrame,prevFrames,inState,inInfo);
then
Expand Down Expand Up @@ -870,7 +882,7 @@ algorithm
Util.setStatefulBoolean(inState,true);
r::prevFrames = listReverse(FGraph.currentScope(env));
env = FGraph.setScope(env, {r});
(cache,c,env_1,prevFrames) = lookupClass2(cache,env,Absyn.IDENT(id),prevFrames,Util.makeStatefulBoolean(false),inInfo);
(cache,c,env_1,prevFrames) = lookupClassInEnv(cache,env,id,prevFrames,Util.makeStatefulBoolean(false),inInfo);
then
(cache,c,env_1,prevFrames);

Expand Down Expand Up @@ -1012,7 +1024,7 @@ algorithm
Inst.partialInstClassIn(cache, env2, InnerOuter.emptyInstHierarchy,
mod, Prefix.NOPRE(), ci_state, c, SCode.PUBLIC(), {}, 0);
// Restrict import to the imported scope only, not its parents, thus {f} below
(cache,c_1,env2,prevFrames) = lookupClass2(cache,env2,Absyn.IDENT(ident),prevFrames,Util.makeStatefulBoolean(true),inInfo) "Restrict import to the imported scope only, not its parents..." ;
(cache,c_1,env2,prevFrames) = lookupClassInEnv(cache,env2,ident,prevFrames,Util.makeStatefulBoolean(true),inInfo) "Restrict import to the imported scope only, not its parents..." ;
(cache,more) = moreLookupUnqualifiedImportedClassInFrame(cache, rest, env, ident);
unique = boolNot(more);
then
Expand Down Expand Up @@ -1410,9 +1422,9 @@ algorithm
case (NONE())
equation
(cache,(c as SCode.CLASS(name=n,encapsulatedPrefix=encflag,restriction=r)),env2,prevFrames) =
lookupClass2(cache,
lookupClassInEnv(cache,
env,
Absyn.IDENT(id),
id,
prevFrames,
Util.makeStatefulBoolean(true), // In order to use the prevFrames, we need to make sure we can't instantiate one of the classes too soon!
NONE());
Expand Down
14 changes: 10 additions & 4 deletions Compiler/FrontEnd/SCode.mo
Expand Up @@ -5260,16 +5260,22 @@ algorithm
SourceInfo i1, i2;
Mod m;

case (NOMOD(), _) then inOldMod;
case (_, NOMOD()) then inNewMod;
case (NOMOD(), _) then inOldMod;
case (REDECL(), _) then inNewMod;

case (MOD(f1, e1, sl1, b1, i1),
MOD(_, _, sl2, b2, _))
MOD(f2, e2, sl2, b2, _))
equation
b = mergeBindings(b1, b2);
sl = mergeSubMods(sl1, sl2);
m = MOD(f1, e1, sl, b, i1);
if referenceEq(b, b1) and referenceEq(sl, sl1) then
m = inNewMod;
elseif referenceEq(b, b2) and referenceEq(sl, sl2) and valueEq(f1, f2) and valueEq(e1, e2) then
m = inOldMod;
else
m = MOD(f1, e1, sl, b, i1);
end if;
then
m;

Expand Down Expand Up @@ -5324,7 +5330,7 @@ algorithm
list<Subscript> idxs1, idxs2;
SubMod s;

case (_, {}) then {};
case (_, {}) then inOld;

case (NAMEMOD(ident = id1), NAMEMOD(ident = id2)::rest)
equation
Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -7508,7 +7508,7 @@ algorithm
case (cache,env,fn,args,nargs,impl,_,st,pre,_,_)
equation
(cache,cl as SCode.CLASS(restriction = SCode.R_PACKAGE()),_) =
Lookup.lookupClass(cache, env, Absyn.IDENT("GraphicalAnnotationsProgram____"));
Lookup.lookupClassIdent(cache, env, "GraphicalAnnotationsProgram____");
(cache,cl as SCode.CLASS( restriction = SCode.R_RECORD(_)),env_1) = Lookup.lookupClass(cache, env, fn);
(cache,cl,env_2) = Lookup.lookupRecordConstructorClass(cache, env_1 /* env */, fn);
(_,_::names) = SCode.getClassComponents(cl); // remove the fist one as it is the result!
Expand Down Expand Up @@ -12680,7 +12680,7 @@ algorithm

case () // not a class or OpenModelica, continue
equation
failure((_,_,_) = Lookup.lookupClass(cache, env, Absyn.IDENT(id)));
failure((_,_,_) = Lookup.lookupClassIdent(cache, env, id));
(_,dexp,prop,_) = elabExpInExpression(cache,env,exp,false,st,false,Prefix.NOPRE(),info);
then
();
Expand Down
6 changes: 3 additions & 3 deletions Compiler/Script/Interactive.mo
Expand Up @@ -11567,7 +11567,7 @@ algorithm
// adrpo: handle the case for model extends baseClassName end baseClassName;
case (Absyn.CLASS(body = Absyn.CLASS_EXTENDS(baseClassName, _, _, parts = parts)),env)
equation
(_,_,cenv) = Lookup.lookupClass(FCore.emptyCache(), env, Absyn.IDENT(baseClassName), SOME(inClass.info));
(_,_,cenv) = Lookup.lookupClassIdent(FCore.emptyCache(), env, baseClassName, SOME(inClass.info));
SOME(envpath) = FGraph.getScopePath(cenv);
p1 = Absyn.joinPaths(envpath, Absyn.IDENT(baseClassName));
cref = Absyn.pathToCref(p1);
Expand Down Expand Up @@ -12922,7 +12922,7 @@ algorithm
algorithm
(cache, env, _, outCache) := buildEnvForGraphicProgram(outCache, mod);

(cache, c, env2) := Lookup.lookupClass(cache, inEnv, Absyn.IDENT(ann_name));
(cache, c, env2) := Lookup.lookupClassIdent(cache, inEnv, ann_name);
smod := SCodeUtil.translateMod(SOME(Absyn.CLASSMOD(mod,
Absyn.NOMOD())), SCode.NOT_FINAL(), SCode.NOT_EACH(), info);
(cache, dmod) := Mod.elabMod(cache, env, InnerOuter.emptyInstHierarchy, Prefix.NOPRE(),
Expand All @@ -12946,7 +12946,7 @@ algorithm
algorithm
(cache, _, _, outCache) := buildEnvForGraphicProgram(outCache, {});

(cache, c, env) := Lookup.lookupClass(cache, inEnv, Absyn.IDENT(ann_name));
(cache, c, env) := Lookup.lookupClassIdent(cache, inEnv, ann_name);
c := SCode.classSetPartial(c, SCode.NOT_PARTIAL());
(_, _, _, _, dae) := Inst.instClass(cache, env, InnerOuter.emptyInstHierarchy,
UnitAbsyn.noStore, DAE.NOMOD(), Prefix.NOPRE(), c, {}, false,
Expand Down

0 comments on commit 2aca7e4

Please sign in to comment.