Skip to content

Commit 057735c

Browse files
authored
Merge pull request #2564 from usethesource/fix/better-change-detection-for-extend
Fix/better-change-detection-for-extend
2 parents ee7f5a1 + b0ea5c2 commit 057735c

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

src/org/rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,27 @@ datetime getLastModified(str qualifiedModuleName, map[str, datetime] moduleLastM
155155
}
156156
}
157157
158-
// Check if a module is modified compared to a given timestamp
159-
bool isModuleModified(str qualifiedModuleName, datetime timestamp, PathConfig pcfg){
158+
// Check if a module is modified compared to a given timestamp in BOM
159+
bool isModuleModified(str qualifiedModuleName, datetime timestamp, PathRole pathRole, ModuleStatus ms){
160160
qualifiedModuleName = unescape(qualifiedModuleName);
161+
pcfg = ms.pathConfig;
161162
try {
162163
mloc = getRascalModuleLocation(qualifiedModuleName, pcfg);
163-
return lastModified(mloc) != timestamp;
164+
bool modifiedChanged = lastModified(mloc) != timestamp;
165+
if(pathRole == importPath()){
166+
return modifiedChanged;
167+
} else { // extendPath
168+
<found, tm, ms> = getTModelForModule(qualifiedModuleName, ms, convert=false);
169+
if(found && tm.store[key_bom]? && rel[str,datetime,PathRole] bom := tm.store[key_bom]){
170+
for(<str m, datetime timestampInBom, PathRole pathRole> <- bom){
171+
if(isModuleModified(m, timestampInBom, pathRole, ms)){
172+
return true;
173+
}
174+
}
175+
return false;
176+
}
177+
return false;
178+
}
164179
} catch value _: {
165180
return false;
166181
}

src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ ModuleStatus getImportAndExtendGraph(str qualifiedModuleName, ModuleStatus ms){
167167
168168
dependencyChanged = (m != qualifiedModuleName) && !isEmpty(ms.changedModules & range(ms.strPaths[m]));
169169
//if(dependencyChanged) println("processing BOM of <qualifiedModuleName> and consider <m>, dependencyChanged: <dependencyChanged>");
170-
if(dependencyChanged || isModuleModified(m, timestampInBom, pcfg)){
170+
if(dependencyChanged || isModuleModified(m, timestampInBom, pathRole, ms)){
171171
allImportsAndExtendsValid = false;
172172
ms.status[m] += rsc_changed();
173173
ms.status[m] -= {tpl_uptodate(), checked()};

src/org/rascalmpl/compiler/lang/rascalcore/check/tests/ChangeScenarioTests.rsc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,20 @@ test bool changedExtendedModule(){
597597
return checkModuleOK(ScratchLoc);
598598
}
599599
600+
// Issue #2562, ht @sungshik (Sung-Shik Jongmans)
601+
602+
test bool changedExtendedModules(){
603+
ALoc = writeModule("module A extend B;");
604+
BLoc = writeModule("module B extend C;");
605+
CLoc = writeModule("module C");
606+
607+
assert checkModuleOK(ALoc);
608+
writeModule("module A extend B; "); // extra space
609+
writeModule("module C "); // extra space
610+
611+
return checkModulesOK([ALoc, ALoc]);
612+
}
613+
600614
@ignore{Can no longer test in this way since all "Checked .." messages are preserved}
601615
test bool onlyChangedModulesAreReChecked1(){
602616
clearMemory();

src/org/rascalmpl/compiler/lang/rascalcore/check/tests/StaticTestingUtils.rsc

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ set[Message] getAllMessages(ModuleStatus r)
115115
ModuleStatus checkStatements(str stmts) {
116116
clearMemory();
117117
mloc = composeModule(stmts);
118-
return rascalTModelForLocs([mloc], rascalCompilerConfig(pathConfigForTesting())[infoModuleChecked=true], dummy_compile1);
118+
return rascalTModelForLocs([mloc], rascalCompilerConfig(pathConfigForTesting())[infoModuleChecked=true][verbose=verbose], dummy_compile1);
119119
}
120120
121121
ModuleStatus checkModule(str moduleText){
122122
mloc = writeModule(moduleText);
123-
return rascalTModelForLocs([mloc], rascalCompilerConfig(pathConfigForTesting())[infoModuleChecked=true], dummy_compile1);
123+
return rascalTModelForLocs([mloc], rascalCompilerConfig(pathConfigForTesting())[infoModuleChecked=true][verbose=verbose], dummy_compile1);
124124
}
125125
126126
bool checkStatementsAndFilter(str stmts, list[str] expected) {
@@ -139,7 +139,7 @@ bool checkModuleAndFilter(str moduleText, list[str] expected, bool matchAll = fa
139139
return checkModuleAndFilter([mloc], expected, matchAll=matchAll, errorsAllowed=errorsAllowed, pathConfig=pathConfig);
140140
}
141141
bool checkModuleAndFilter(list[loc] mlocs, list[str] expected, bool matchAll = false, bool errorsAllowed = true, PathConfig pathConfig = pathConfigForTesting()) {
142-
ms = rascalTModelForLocs(mlocs, rascalCompilerConfig(pathConfig)[infoModuleChecked=true], dummy_compile1);
142+
ms = rascalTModelForLocs(mlocs, rascalCompilerConfig(pathConfig)[infoModuleChecked=true][verbose=verbose], dummy_compile1);
143143
msgs = getAllMessages(ms);
144144
if (verbose) {
145145
println(msgs);
@@ -168,7 +168,14 @@ bool checkOK(str stmts) {
168168
}
169169
170170
bool checkModuleOK(loc moduleToCheck, PathConfig pathConfig = pathConfigForTesting()) {
171-
errors = getErrorMessages(rascalTModelForLocs([moduleToCheck], rascalCompilerConfig(pathConfig)[infoModuleChecked=true], dummy_compile1));
171+
errors = getErrorMessages(rascalTModelForLocs([moduleToCheck], rascalCompilerConfig(pathConfig)[infoModuleChecked=true][verbose=verbose], dummy_compile1));
172+
if(size(errors) == 0)
173+
return true;
174+
throw abbrev("<errors>");
175+
}
176+
177+
bool checkModulesOK(list[loc] modulesToCheck, PathConfig pathConfig = pathConfigForTesting()) {
178+
errors = getErrorMessages(rascalTModelForLocs(modulesToCheck, rascalCompilerConfig(pathConfig)[infoModuleChecked=true][verbose=verbose], dummy_compile1));
172179
if(size(errors) == 0)
173180
return true;
174181
throw abbrev("<errors>");
@@ -222,7 +229,7 @@ bool useDefOK(str moduleText, map[str, tuple[int, set[int]]] usedefs, PathConfig
222229
<mname, mbody> = extractModuleNameAndBody(moduleText);
223230
pathConfig.srcs += pathConfigForTesting().srcs;
224231
mloc = writeModule(moduleText);
225-
ms = rascalTModelForLocs([mloc], rascalCompilerConfig(pathConfig), dummy_compile1);
232+
ms = rascalTModelForLocs([mloc], rascalCompilerConfig(pathConfig)[verbose=verbose], dummy_compile1);
226233
227234
errors = getErrorMessages(ms);
228235
if(size(errors) != 0){

0 commit comments

Comments
 (0)