Skip to content

Commit

Permalink
Don't load libraries when looking for builtin name (#9571)
Browse files Browse the repository at this point in the history
- Don't load libraries when looking for a builtin element during name
  lookup, since that means we're in an encapsulated class and the
  library might already be loaded and should not be loaded again.
- Disable reporting of times when running `checkAllModelsRecursive` in a
  testcase to make it possible to test it.

Fixes #9554
  • Loading branch information
perost committed Oct 21, 2022
1 parent 4cd093e commit 8a273be
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 9 deletions.
7 changes: 4 additions & 3 deletions OMCompiler/Compiler/NFFrontEnd/NFLookup.mo
Expand Up @@ -465,9 +465,10 @@ algorithm
// If we're in an annotation, check in the special scope where
// annotation classes are defined.
cur_scope := InstNode.annotationScope(cur_scope);
elseif not loaded then
// If we haven't already tried, try to load a library with that name
// and then try to look it up in the top scope again.
elseif not loaded and not require_builtin then
// If we haven't already tried and we're not trying to find a
// builtin name, try to load a library with that name and then try
// to look it up in the top scope again.
loaded := true;
loadLibrary(name, cur_scope);
else
Expand Down
17 changes: 12 additions & 5 deletions OMCompiler/Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -6317,7 +6317,7 @@ algorithm
allClassPaths = getAllClassPathsRecursive(className, b, SymbolTable.getAbsyn());
print("Number of classes to check: " + intString(listLength(allClassPaths)) + "\n");
// print ("All paths: \n" + stringDelimitList(List.map(allClassPaths, AbsynUtil.pathString), "\n") + "\n");
failed = checkAll(cache, env, allClassPaths, msg, 0);
failed = checkAll(cache, env, allClassPaths, msg, not Testsuite.isRunning(), 0);
ret = "Number of classes checked / failed: " + intString(listLength(allClassPaths)) + "/" + intString(failed);
then
(cache,Values.STRING(ret));
Expand Down Expand Up @@ -6360,6 +6360,7 @@ function checkAll
input FCore.Graph inEnv;
input list<Absyn.Path> allClasses;
input Absyn.Msg inMsg;
input Boolean reportTimes;
input output Integer failed;
protected
Absyn.Program p;
Expand Down Expand Up @@ -6401,23 +6402,29 @@ algorithm
s = realString(elapsedTime);
(smsg, f) = failOrSuccess(str);
failed = if f then failed + 1 else failed;
print (s + " seconds -> " + smsg + "\n\t");

if reportTimes then
print (s + " seconds -> " + smsg + "\n\t");
else
print(smsg + "\n\t");
end if;

print (System.stringReplace(str, "\n", "\n\t"));
print ("\n");
print ("Error String:\n" + Print.getErrorString() + "\n");
print ("Error Buffer:\n" + ErrorExt.printMessagesStr(false) + "\n");
print ("#" + (if f then "[-]" else "[+]") + ", " +
realString(elapsedTime) + ", " +
(if reportTimes then realString(elapsedTime) + ", " else "") +
AbsynUtil.pathString(className) + "\n");
print ("-------------------------------------------------------------------------\n");
failed = checkAll(cache, env, rest, msg, failed);
failed = checkAll(cache, env, rest, msg, reportTimes, failed);
then ();

case (cache,env,className::rest,msg)
equation
c = InteractiveUtil.getPathedClassInProgram(className, p);
print("Checking skipped: " + Dump.unparseClassAttributesStr(c) + " " + AbsynUtil.pathString(className) + "... \n");
failed = checkAll(cache, env, rest, msg, failed);
failed = checkAll(cache, env, rest, msg, reportTimes, failed);
then
();
end matchcontinue;
Expand Down
3 changes: 2 additions & 1 deletion testsuite/openmodelica/interactive-API/Makefile
Expand Up @@ -17,10 +17,11 @@ Bug3974.mos \
Bug3979.mos \
Bug4209.mos \
Bug4248.mos \
checkAllModelsRecursive1.mos \
choicesAllMatching.mos \
ConvertUnits.mos \
ConversionVersions.mos \
CopyClass.mos \
choicesAllMatching.mos \
DefaultComponentName.mos \
DeleteConnection.mos \
DialogAnnotation.mos \
Expand Down
@@ -0,0 +1,63 @@
// name: checkAllModelsRecursive1
// keywords:
// status: correct
// cflags: -d=newInst
//

loadString("
package TestCheckAll
model A
parameter Modelica.SIunits.Voltage V = 10;
end A;
encapsulated model B
parameter Modelica.SIunits.Current A = 5;
end B;
model C
parameter Modelica.SIunits.Voltage V = 10;
end C;
annotation(uses(Modelica(version = \"3.2.3\")));
end TestCheckAll;
");

checkAllModelsRecursive(TestCheckAll);
getErrorString();

// Result:
// true
// Number of classes to check: 4
// Checking skipped: package TestCheckAll...
// Checking: model TestCheckAll.A... OK
// Check of TestCheckAll.A completed successfully.
// Class TestCheckAll.A has 0 equation(s) and 0 variable(s).
// 0 of these are trivial equation(s).
// Error String:
//
// Error Buffer:
// Notification: Automatically loaded package Modelica 3.2.3 due to uses annotation from TestCheckAll.
// Notification: Automatically loaded package Complex 3.2.3 due to uses annotation from Modelica.
// Notification: Automatically loaded package ModelicaServices 3.2.3 due to uses annotation from Modelica.
//
// #[+], TestCheckAll.A
// -------------------------------------------------------------------------
// Checking: encapsulated model TestCheckAll.B... FAILED!
//
// Error String:
//
// Error Buffer:
// [<interactive>:7:6-7:46:writable] Error: Class Modelica.SIunits.Current not found in scope B.
//
// #[-], TestCheckAll.B
// -------------------------------------------------------------------------
// Checking: model TestCheckAll.C... OK
// Check of TestCheckAll.C completed successfully.
// Class TestCheckAll.C has 0 equation(s) and 0 variable(s).
// 0 of these are trivial equation(s).
// Error String:
//
// Error Buffer:
//
// #[+], TestCheckAll.C
// -------------------------------------------------------------------------
// "Number of classes checked / failed: 4/1"
// ""
// endResult

0 comments on commit 8a273be

Please sign in to comment.