Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit

Permalink
Merge branch 'shallow-incremental-checking'
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulKlint committed Nov 23, 2024
2 parents f3f5cce + 884d5b0 commit 087a363
Show file tree
Hide file tree
Showing 15 changed files with 373 additions and 143 deletions.
5 changes: 4 additions & 1 deletion src/org/rascalmpl/core/library/CheckTestSources.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void checkTestSources(list[str] cmdLineArgs) {
println("PathConfig for type checking test sources:\n");
iprintln(testConfig);

testCompilerConfig = rascalCompilerConfig(testConfig)[logPathConfig=false][forceCompilationTopModule=false];
testCompilerConfig = rascalCompilerConfig(testConfig)[logPathConfig=false];
total = 0;

println(readFile(|lib://rascal/META-INF/MANIFEST.MF|));
Expand Down Expand Up @@ -128,6 +128,9 @@ tuple[str, int] safeCheck(str \module, RascalCompilerConfig compilerConfig) {
//iprintln(result.tmodels[\module].facts);
<found, tm, result> = getTModelForModule(\module, result);
if(found && !isEmpty(tm.messages)){
if(/error(_,_) := tm.messages){
println("*** ERRORS ***");
}
iprintln(tm.messages);
}
return <"", cpuTime()-start_time>;
Expand Down
2 changes: 1 addition & 1 deletion src/org/rascalmpl/core/library/CompileTestSources.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void compileTestSources(PathConfig pcfg) {
println("PathConfig for compiling test sources:\n");
iprintln(testConfig);

testCompilerConfig = getRascalCoreCompilerConfig(testConfig)[logPathConfig=false][forceCompilationTopModule=false];
testCompilerConfig = getRascalCoreCompilerConfig(testConfig)[logPathConfig=false];
total = 0;

println(readFile(|lib://rascal/META-INF/MANIFEST.MF|));
Expand Down
2 changes: 1 addition & 1 deletion src/org/rascalmpl/core/library/GenerateTestSources.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void generateTestSources(list[str] cmdLineArgs) {
libs = [ ]
);

testCompilerConfig = getRascalCoreCompilerConfig(testConfig)[logPathConfig=false][forceCompilationTopModule=false];
testCompilerConfig = getRascalCoreCompilerConfig(testConfig)[logPathConfig=false];

map[str,int] durations = ();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ extend lang::rascalcore::grammar::definition::Characters;

import Node;
import Set;
//import IO;

// ---- asubtype --------------------------------------------------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ data AType (str alabel = "")
| avalue()
;

@memo{expireAfter(minutes=5).maximumSize(1000)}
@memo{expireAfter(minutes=5),maximumSize(1000)}
AType overloadedAType(rel[loc, IdRole, AType] overloads){
if(all(<loc _, IdRole _, AType t> <- overloads, aadt(_, _, _) := t)){
str adtName = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,5 @@ data TypePalConfig(
bool logPathConfig = false, // log PathConfig that is used

bool optimizeVisit = true, // Options for compiler developer
bool enableAsserts = true,
bool forceCompilationTopModule = false
bool enableAsserts = true
);
119 changes: 73 additions & 46 deletions src/org/rascalmpl/core/library/lang/rascalcore/check/Checker.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -121,43 +121,50 @@ ModuleStatus rascalTModelForLocs(
list[Message](str qualifiedModuleName, lang::rascal::\syntax::Rascal::Module M, map[str,TModel] transient_tms, ModuleStatus ms, RascalCompilerConfig compilerConfig) codgen
){
pcfg = compilerConfig.typepalPathConfig;

if(compilerConfig.logPathConfig) { iprintln(pcfg); }

msgs = validatePathConfigForChecker(pcfg, mlocs[0]);

ModuleStatus ms = newModuleStatus(compilerConfig);
topModuleNames = {};

if(!otherModulesWithOutdatedTpls(mlocs, pcfg)){
if(uptodateTPls(mlocs, pcfg)){
for (mloc <- mlocs) {
m = getModuleName(mloc, pcfg);
<found, tm, ms> = getTModelForModule(m, ms);
if(!found){
throw "TModel for <m> not found (no changes)";
}
}
return ms;
}
}

for (mloc <- mlocs) {
m = getModuleName(mloc, pcfg);
if(isModuleLocationInLibs(m, mloc, pcfg)){
ms.status[m] ? {} += {rsc_not_found()};
}
topModuleNames += {m};
ms.moduleLocs[m] = mloc;
msgs += ms.messages[m] ? [];
msgs += toList(ms.messages[m] ? {});
}

str jobName = "";

try {
ms = getImportAndExtendGraph(topModuleNames, compilerConfig);
ms = getImportAndExtendGraph(topModuleNames, ms);

if(/error(_,_) := ms.messages){
return clearTModelCache(ms);
}
if(compilerConfig.forceCompilationTopModule){
for(str nm <- topModuleNames){
ms.status[nm] = {};
}
}
// if(/error(_,_) := ms.messages){

// return clearTModelCache(ms);
// }

imports_and_extends = ms.strPaths<0,2>;
<components, sorted> = stronglyConnectedComponentsAndTopSort(imports_and_extends);
//println("strong: <components>, Ambiguity: <ms.status["analysis::grammars::Ambiguity"] ? {}>");
map[str, set[str]] module2component = (m : c | c <- components, m <- c);

list[str] ordered = [];
Expand Down Expand Up @@ -185,7 +192,9 @@ ModuleStatus rascalTModelForLocs(
jobStart(jobName, totalWork=nmodules);

while(mi < nmodules) {

component = module2component[ordered[mi]];
//println("while: <component>, Ambiguity: <ms.status["analysis::grammars::Ambiguity"] ? {}>");
jobStep(jobName, intercalate(" + ", [*component]), work=size(component));

recheck = !all(m <- component, ms.status[m]?, (tpl_uptodate() in ms.status[m] || checked() in ms.status[m]));
Expand All @@ -205,11 +214,12 @@ ModuleStatus rascalTModelForLocs(
for(m <- component){
m_compatible = false;
<found, tm, ms> = getTModelForModule(m, ms);
if(found){
if(found && !tplOutdated(m, pcfg)){
imports_extends_m = imports_and_extends[m];

<m_compatible, ms> = importsAndExtendsAreBinaryCompatible(tm, imports_extends_m, ms);
if(m_compatible){
ms.status[m] += {tpl_uptodate(), checked()};
ms.status[m] += {tpl_uptodate(), checked(), bom_update_needed()};
}
}
compatible_with_all_imports = compatible_with_all_imports && m_compatible;
Expand Down Expand Up @@ -244,11 +254,11 @@ ModuleStatus rascalTModelForLocs(
// Look for unused imports or exports
usedModules = {path2module[l.path] | loc l <- range(tm.useDef), tm.definitions[l].idRole != moduleId(), path2module[l.path]?};
usedModules += {*invertedExtends[um] | um <- usedModules}; // use of an extended module via import
msgs = [];
list[Message] imsgs = [];
<success, pt, ms> = getModuleParseTree(m, ms);
if(success){
if(compilerConfig.infoModuleChecked){
msgs += [info("Checked <m>", pt.header.name@\loc)];
imsgs += [info("Checked <m>", pt.header.name@\loc)];
}
check_imports:
for(imod <- pt.header.imports, imod has \module){
Expand All @@ -268,20 +278,20 @@ ModuleStatus rascalTModelForLocs(
}
if(checked() in ms.status[iname] && rsc_not_found() notin ms.status[iname]){
if(imod is \default){
msgs += warning("Unused import of `<iname>`", imod@\loc);
imsgs += warning("Unused import of `<iname>`", imod@\loc);
} //else { //TODO: maybe add option to turn off info messages?
//msgs += info("Extended module `<iname>` is unused in the current module", imod@\loc);
//imsgs += info("Extended module `<iname>` is unused in the current module", imod@\loc);
//}
}
}
}
tm.messages += msgs;
tm.messages += imsgs;
}
}
if(ms.messages[m]?){
tm.messages += ms.messages[m];
tm.messages += toList(ms.messages[m]);
}
ms.messages[m] ? [] += tm.messages;
ms.messages[m] ? {} += toSet(tm.messages);

ms.status[m] += {tpl_uptodate(), checked()};
if(!isEmpty([ e | e:error(_,_) <- ms.messages[m] ])){
Expand All @@ -298,7 +308,7 @@ ModuleStatus rascalTModelForLocs(
<success, pt, ms> = getModuleParseTree(m, ms);
if(success){
msgs = codgen(m, pt, transient_tms, ms, compilerConfig);
ms.messages[m] += msgs;
ms.messages[m] += toSet(msgs);
ms.status[m] += {code_generated()};
}
}
Expand All @@ -308,31 +318,26 @@ ModuleStatus rascalTModelForLocs(
ms.status[m] += {tpl_uptodate()};
}
} else {
for(m <- component){
// imports = { imp | <m1, importPath(), imp> <- ms.strPaths, m1 == m };
// extends = { ext | <m1, extendPath(), ext > <- ms.strPaths, m1 == m };
imports = ms.strPaths[m,importPath()];
extends = ms.strPaths[m,extendPath()];
updateBOM(m, imports, extends, ms);
for(m <- component){
ms.status[m] += bom_update_needed();
}
}
}
} catch ParseError(loc src): {
for(str mname <- topModuleNames){
ms.messages[mname] = [ error("Parse error", src) ];
ms.messages[mname] = { error("Parse error", src) };
}
} catch rascalTplVersionError(str txt):{
for(str mname <- topModuleNames){
ms.messages[mname] = [error("<txt>", ms.moduleLocs[mname] ? |unknown:///|)];
ms.messages[mname] = { error("<txt>", ms.moduleLocs[mname] ? |unknown:///|) };
}
} catch Message msg: {
for(str mname <- topModuleNames){
ms.messages[mname] = [error("During type checking: <msg>", msg.at)];
ms.messages[mname] = { error("During type checking: <msg>", msg.at) };
}
} catch rascalBinaryNeedsRecompilation(str txt): {
for(str mname <- topModuleNames){
ms.messages[mname] = [error("Binary module `<txt>` needs recompilation", |unknown:///|)];
ms.messages[mname] = { error("Binary module `<txt>` needs recompilation", |unknown:///|) };
}
}

Expand Down Expand Up @@ -368,7 +373,7 @@ tuple[set[str], ModuleStatus] loadImportsAndExtends(str moduleName, ModuleStatus
try {
c.addTModel(tm);
} catch wrongTplVersion(str reason): {
ms.messages[imp] ? [] += [ Message::error(reason, ms.moduleLocs[imp]) ];
ms.messages[imp] ? {} += { Message::error(reason, ms.moduleLocs[imp]) };
}
}
}
Expand All @@ -383,8 +388,8 @@ tuple[TModel, ModuleStatus] rascalTModelComponent(set[str] moduleNames, ModuleSt
modelName = intercalate(" + ", toList(moduleNames));
map[str, Module] namedTrees = ();
for(str nm <- moduleNames){
ms.status[nm] = {};
ms.messages[nm] = [];
//ms.status[nm] = {};
ms.messages[nm] = {};
mloc = getModuleLocation(nm, pcfg);
if(mloc.extension != "rsc" || isModuleLocationInLibs(nm, mloc, pcfg)){
continue;
Expand All @@ -394,7 +399,7 @@ tuple[TModel, ModuleStatus] rascalTModelComponent(set[str] moduleNames, ModuleSt
tagsMap = getTags(pt.header.tags);

if(ignoreCompiler(tagsMap)) {
ms.messages[nm] ? [] += [ Message::info("Ignoring module <nm>", pt@\loc) ];
ms.messages[nm] ? {} += { Message::info("Ignoring module <nm>", pt@\loc) };
ms.status[nm] += MStatus::ignored();
} else {
namedTrees[nm] = pt;
Expand Down Expand Up @@ -432,6 +437,9 @@ tuple[TModel, ModuleStatus] rascalTModelComponent(set[str] moduleNames, ModuleSt
tm = s.run();
}
tm.usesPhysicalLocs = true;
// for(mname <- moduleNames){
// ms.messages[mname] = tm.messages;
// }
//iprintln(tm.messages);

check_time = (cpuTime() - start_check)/1000000;
Expand All @@ -451,7 +459,6 @@ ModuleStatus rascalTModelForNames(list[str] moduleNames,
RascalCompilerConfig compilerConfig,
list[Message] (str qualifiedModuleName, lang::rascal::\syntax::Rascal::Module M, map[str,TModel] transient_tms, ModuleStatus ms, RascalCompilerConfig compilerConfig) codgen){
pcfg = compilerConfig.typepalPathConfig;
mlocs = [];
for(moduleName <- moduleNames){
Expand All @@ -460,24 +467,47 @@ ModuleStatus rascalTModelForNames(list[str] moduleNames,
} catch value e: {
mloc = |unknown:///|(0,0,<0,0>,<0,0>);
ms = newModuleStatus(compilerConfig);
ms.messages[moduleName] = [ error("<e>", mloc) ];
ms.messages[moduleName] = { error("<e>", mloc) };
return ms;
}
}
return rascalTModelForLocs(mlocs, compilerConfig, codgen);
}
bool uptodateTPls(list[loc] candidates, PathConfig pcfg){
for(mloc <- candidates){
mname = getModuleName(mloc, pcfg);
<found, tpl> = getTPLReadLoc(mname, pcfg);
if(!found || lastModified(mloc) > lastModified(tpl)){
return false;
}
}
return true;
}
bool otherModulesWithOutdatedTpls(list[loc] candidates, PathConfig pcfg){
for(srcdir <- pcfg.srcs){
for(loc mloc <- find(srcdir, "rsc")){
mname = getModuleName(mloc, pcfg);
<found, tpl> = getTPLReadLoc(mname, pcfg);
if(found && (mloc notin candidates) && (lastModified(mloc) > lastModified(tpl))){
return true;
}
}
}
return false;
}
// ---- checker functions for IDE
// name of the production has to mirror the Kernel compile result
data ModuleMessages = program(loc src, set[Message] messages);
list[ModuleMessages] check(list[loc] moduleLocs, RascalCompilerConfig compilerConfig){
pcfg1 = compilerConfig.typepalPathConfig; pcfg1.classloaders = []; pcfg1.javaCompilerPath = [];
compilerConfig.typepalPathConfig = pcfg1;
ms = rascalTModelForLocs(moduleLocs, compilerConfig, dummy_compile1);
return [ program(ms.moduleLocs[mname] ? |unknown:///|, toSet(ms.messages[mname])) | mname <- ms.messages ];
return [ program(ms.moduleLocs[mname] ? |unknown:///|, ms.messages[mname]) | mname <- ms.messages ];
}

list[ModuleMessages] checkAll(loc root, RascalCompilerConfig compilerConfig){
Expand All @@ -488,10 +518,7 @@ list[ModuleMessages] checkAll(loc root, RascalCompilerConfig compilerConfig){

map[str, list[Message]] checkModules(list[str] moduleNames, RascalCompilerConfig compilerConfig) {
ModuleStatus ms = rascalTModelForNames(moduleNames, compilerConfig, dummy_compile1);
tmodels = ms.tmodels;
tmMsgs = (mname : tmodels[mname].messages | mname <- tmodels, !isEmpty(tmodels[mname].messages));
return //(mname : tmodels[mname].messages | mname <- tmodels, !isEmpty(tmodels[mname].messages))
(mname : ms.messages[mname] + (tmMsgs[mname] ? []) | mname <- ms.messages, !isEmpty(ms.messages[mname]));
return (mname : toList(msgs) | mname <- ms.messages, msgs := ms.messages[mname], !isEmpty(msgs));
}

// -- calculate rename changes
Expand Down
Loading

0 comments on commit 087a363

Please sign in to comment.