Skip to content

Commit

Permalink
Tuned error handling for version incompatible tpl files
Browse files Browse the repository at this point in the history
Given
	module A
	import B

We have the following possibilities:

B.tpl   /  B.rsc          |  exists      | does not exist
---------------------------------------------------------
up-to-date (0)            | reuse        | reuse
does not exist            | recompile    | ERROR (1)
outdated rascalTplVersion | ERROR (2)    | ERROR (3)

(0) relative to BOM of module A
(1) “Undefined module B”
(2) “.../$B.tpl” has outdated or missing Rascal TPL version”, points to
B.rsc
(3) “.../$B.tpl” has outdated or missing Rascal TPL version”, points to
A.rsc

To summarize, always an error when source is missing or tpl has a wrong
version number.
  • Loading branch information
PaulKlint committed May 9, 2024
1 parent e50d17e commit 7bdbf6e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ ModuleStatus rascalTModelForLocs(
for(mloc <- mlocs){
m = getModuleName(mloc, pcfg);
topModuleNames += {m};
ms.moduleLocs[m] = mloc;
}

try {
Expand Down Expand Up @@ -361,6 +362,14 @@ ModuleStatus rascalTModelForLocs(
for(str mname <- topModuleNames){
ms.messages[mname] = [ error("Parse error", src) ];
}
} catch rascalTplVersionError(str txt):{
for(str mname <- topModuleNames){
ms.messages[mname] = [error("<txt>", ms.moduleLocs[mname] ? |unknown:///|)];
}
} catch rascalSourceMissing(str txt):{
for(str mname <- topModuleNames){
ms.messages[mname] = [error("<msg>", ms.moduleLocs[mname] ? |unknown:///|)];
}
} catch Message msg: {
for(str mname <- topModuleNames){
ms.messages[mname] = [error("During type checking: <msg>", msg.at)];
Expand Down
26 changes: 15 additions & 11 deletions src/org/rascalmpl/core/library/lang/rascalcore/check/Import.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import analysis::graphs::Graph;
import util::Reflective;
import lang::rascalcore::compile::util::Names; // TODO: refactor, this is an undesired dependency on compile

bool traceTPL = false;
bool traceTPL = true;
bool traceCaches = false;

tuple[bool,loc] getTPLReadLoc(str qualifiedModuleName, PathConfig pcfg){
Expand Down Expand Up @@ -192,20 +192,24 @@ tuple[bool, TModel, ModuleStatus] getTModelForModule(str qualifiedModuleName, Mo
ms.tmodels[qualifiedModuleName] = tpl;
ms.status[qualifiedModuleName] += {tpl_uptodate(), tpl_saved()};
return <true, tpl, ms>;
} else {
println("INFO: <tplLoc> has outdated or missing Rascal TPL version (required: <getCurrentRascalTplVersion()>)");
msg = error("<tplLoc> has outdated or missing Rascal TPL version (required: <getCurrentRascalTplVersion()>)", tplLoc);

ms.tmodels[qualifiedModuleName] =
tmodel(modelName=qualifiedModuleName,
messages=[msg]);
return <true, tpl, ms>;
}
}
//else {
// msg = "<tplLoc> has outdated or missing Rascal TPL version (required: <getCurrentRascalTplVersion()>)";
// println("INFO: <msg>)");
// throw rascalTplVersionError(msg);
// //ms.tmodels[qualifiedModuleName] =
// // tmodel(modelName=qualifiedModuleName,
// // messages=[msg]);
// //return <true, tpl, ms>;
//}
} catch e: {
//ms.status[qualifiedModuleName] ? {} += not_found();
return <false, tmodel(modelName=qualifiedModuleName, messages=[error("Cannot read TPL for <qualifiedModuleName>: <e>", tplLoc)]), ms>;
//throw IO("Cannot read tpl for <qualifiedModuleName>: <e>");
}
msg = "<tplLoc> has outdated or missing Rascal TPL version (required: <getCurrentRascalTplVersion()>)";
println("INFO: <msg>)");
throw rascalTplVersionError(msg);
}
//if(qualifiedModuleName notin hardwired){
// ms.tmodelLIFO = ms.tmodelLIFO[1..];
Expand Down Expand Up @@ -322,7 +326,6 @@ ModuleStatus getImportAndExtendGraph(str qualifiedModuleName, ModuleStatus ms){
}

if(tm.store[key_bom]? && rel[str,datetime,PathRole] bom := tm.store[key_bom]){
//println("BOM <qualifiedModuleName>:"); iprintln(bom);
for(<str m, datetime timestampInBom, PathRole pathRole> <- bom){
if(!ms.status[m]?){
ms.status[m] = {};
Expand Down Expand Up @@ -351,6 +354,7 @@ ModuleStatus getImportAndExtendGraph(str qualifiedModuleName, ModuleStatus ms){
} catch value _:{
allImportsAndExtendsValid = true;
println("--- reusing tmodel of <qualifiedModuleName> (source not accessible)");
throw rascalSourceMissing("Source of <qualifiedModuleName> is not accessible");
}
}
if(allImportsAndExtendsValid){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ import Message;
data Exception
= CompileTimeError(Message msg)
| InternalCompilerError(Message msg)
| rascalTplVersionError(str txt)
| rascalSourceMissing(str txt)
;
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module lang::rascalcore::compile::Examples::Tst6

import lang::rascalcore::compile::Examples::Tst5;

value main() = inc(42);
value main() = inc(43);

0 comments on commit 7bdbf6e

Please sign in to comment.