Skip to content

Commit

Permalink
Fix bug #2871
Browse files Browse the repository at this point in the history
- as the new env has references and destructive updates we need to clone it when returning it in Builtin.intialGraph


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@22663 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Oct 7, 2014
1 parent da5f753 commit 9615d45
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
15 changes: 10 additions & 5 deletions Compiler/FrontEnd/Builtin.mo
Expand Up @@ -652,6 +652,8 @@ algorithm
// First look for cached version
case (cache) equation
graph = FCore.getCachedInitialGraph(cache);
// we have references in the graph so we need to clone it before giving it away
graph = FGraph.clone(graph);
then (cache,graph);

// then look in the global roots[builtinEnvIndex]
Expand All @@ -671,10 +673,6 @@ algorithm
graph = FGraphBuildEnv.mkCompNode(timeComp, FGraph.top(graph), FCore.BUILTIN(), graph);
graph = FGraph.updateComp(graph, timeVar, FCore.VAR_UNTYPED(), FGraph.empty());

graph = initialGraphOptimica(graph);

graph = initialGraphMetaModelica(graph);

graph = FGraphBuildEnv.mkTypeNode(
{anyNonExpandableConnector2int,
anyExpandableConnector2int},
Expand All @@ -694,6 +692,11 @@ algorithm
// add the ModelicaBuiltin/MetaModelicaBuiltin classes in the initial graph
graph = FGraphBuildEnv.mkProgramGraph(initialProgram, FCore.BUILTIN(), graph);

graph = initialGraphOptimica(graph);
graph = initialGraphMetaModelica(graph);

graph = FGraph.clone(graph); // we have references in the graph so we need to clone it before storing

cache = FCore.setCachedInitialGraph(cache,graph);
_ = getSetInitialGraph(SOME(graph));
then
Expand Down Expand Up @@ -724,8 +727,10 @@ algorithm
case (NONE())
equation
assocLst = getGlobalRoot(Global.builtinGraphIndex);
// we have references in the graph so we need to clone it before giving it away
graph = FGraph.clone(Util.assoc(Flags.getConfigEnum(Flags.GRAMMAR), assocLst));
then
Util.assoc(Flags.getConfigEnum(Flags.GRAMMAR), assocLst);
graph;

case (SOME(graph))
equation
Expand Down
9 changes: 9 additions & 0 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -2415,12 +2415,17 @@ algorithm
(cache, mod_1) = Mod.elabMod(cache, parentEnv, ih, pre, mod, false, Mod.DERIVED(cn), info);
// print("mods: " +& Absyn.pathString(cn) +& " " +& Mod.printModStr(mods_1) +& "\n");
mods_1 = Mod.merge(mods, mod_1, parentEnv, pre);

//print("DEF:--->" +& FGraph.printGraphPathStr(env) +& " = " +& Absyn.pathString(cn) +& " mods: " +& Mod.printModStr(mods_1) +& "\n");
//System.startTimer();
// use instExtends for derived with no array dimensions and no modification (given via the mods_1)
(cache, env, ih, store, dae, csets, ci_state, vars, bc, oDA, eqConstraint, graph) =
instClassdef2(cache, env, ih, store, mods_1, pre, ci_state, className,
SCode.PARTS({SCode.EXTENDS(cn, vis, SCode.NOMOD(), NONE(), info)},{},{},{},{},{},{},NONE()),
re, vis, partialPrefix, encapsulatedPrefix, inst_dims, impl,
callscope, graph, inSets, instSingleCref,comment,info,stopInst);
//System.stopTimer();
//print("DEF:<---" +& FGraph.printGraphPathStr(env) +& " took: " +& realString(System.getTimerIntervalTime()) +& "\n");
oDA = SCode.mergeAttributes(DA,oDA);
then
(cache,env,ih,store,dae,csets,ci_state,vars,bc,oDA,eqConstraint,graph);
Expand Down Expand Up @@ -3090,10 +3095,14 @@ algorithm
mods_1 = Mod.merge(mods, mod_1, parentEnv, pre);

// use instExtends for derived with no array dimensions and no modification (given via the mods_1)
//print("DEP:>>>" +& FGraph.printGraphPathStr(env) +& " = " +& Absyn.pathString(cn) +& " mods: " +& Mod.printModStr(mods_1) +& "\n");
//System.startTimer();
(cache, env, ih, ci_state,vars) =
partialInstClassdef(cache, env, ih, mods_1, pre, ci_state, parentClass,
SCode.PARTS({SCode.EXTENDS(cn, vis, SCode.NOMOD(), NONE(), info)},{},{},{},{},{},{},NONE()),
vis, inst_dims, numIter);
//System.stopTimer();
//print("DEP:<<<" +& FGraph.printGraphPathStr(env) +& " took: " +& realString(System.getTimerIntervalTime()) +& "\n");
then
(cache, env, ih, ci_state, vars);

Expand Down
3 changes: 2 additions & 1 deletion Compiler/Script/Interactive.mo
Expand Up @@ -321,6 +321,7 @@ algorithm
evalfunc = Flags.set(Flags.EVAL_FUNC, false);
keepArrays = Flags.getConfigBool(Flags.KEEP_ARRAYS);
Flags.setConfigBool(Flags.KEEP_ARRAYS, false);
Inst.initInstHashTable();
(str,newst) = evaluateGraphicalApi(stmts, st, partialInst, gen, evalfunc, keepArrays);
str_1 = stringAppend(str, "\n");
then
Expand Down Expand Up @@ -13391,7 +13392,7 @@ algorithm
lineProgram = modelicaAnnotationProgram(Config.getAnnotationVersion());
fargs = createFuncargsFromElementargs(mod);
p_1 = SCodeUtil.translateAbsyn2SCode(lineProgram);
(cache,env) = Inst.makeEnvFromProgram(FCore.emptyCache(),p_1, Absyn.IDENT(""));
(cache,env) = Inst.makeEnvFromProgram(FCore.emptyCache(), p_1, Absyn.IDENT(""));
(_,newexp,prop) = StaticScript.elabGraphicsExp(cache,env, Absyn.CALL(Absyn.CREF_IDENT(annName,{}),fargs), false,Prefix.NOPRE(), info) "impl" ;
(cache, newexp, prop) = Ceval.cevalIfConstant(cache, env, newexp, prop, false, info);
Print.clearErrorBuf() "this is to clear the error-msg generated by the annotations." ;
Expand Down

0 comments on commit 9615d45

Please sign in to comment.