Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ tuple[bool, TModel, ModuleStatus] addGrammar(MODID moduleId, set[MODID] imports,
<found, tm1, ms> = getTModelForModule(m, ms);
if(!found) {
msg = error("Cannot add grammar or tmodel since `<moduleId2moduleName(m)>` is not found", ms.moduleLocs[moduleId] ? |unknown:///|);
println(msg); // TODO: Just to record this event; this should probably go to a log file
//println(msg); // TODO: Just to record this event; this should probably go to a log file
ms.messages[moduleId] ? {} += { msg };
tm1 = tmodel(modelName=qualifiedModuleName, messages=[msg]);
return <false, tm1, ms>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ bool uptodateTPls(list[loc] candidates, list[str] mnames, PathConfig pcfg){
for(int i <- index(candidates)){
mloc = candidates[i];
<found, tpl> = getTPLReadLoc(mnames[i], pcfg);
if(!found || lastModified(mloc) > lastModified(tpl)){
if(!found || lastModified(mloc) >= lastModified(tpl)){
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ bool tplOutdated(MODID moduleId, PathConfig pcfg){
lmMloc = lastModified(mloc);
lmTpl = lastModified(tpl);
res = !found || lmMloc > lmTpl;
//println("tplOutdated <qualifiedModuleName>: <res>; mloc: <lmMloc> \> tpl: <lmTpl>: <lmMloc > lmTpl>, (<mloc>, <tpl>)");
// println("tplOutdated <qualifiedModuleName>: <res>; mloc: <lmMloc> \> tpl: <lmTpl>: <lmMloc > lmTpl>, (<mloc>, <tpl>)");
return res;
} catch _: {
return false;
Expand Down
11 changes: 5 additions & 6 deletions src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,11 @@ str getModuleNameFromAnyLogical(loc l){
tuple[bool, ModuleStatus] importsAndExtendsAreBinaryCompatible(TModel tm, set[MODID] importsAndExtends, ModuleStatus ms){
moduleName = tm.modelName;
physical2logical = invertUnique(tm.logical2physical);

modRequires = { lg | l <- range(tm.useDef),
physical2logical[l]?, lg := physical2logical[l],
moduleName !:= getModuleNameFromAnyLogical(lg) };
modRequires = {lg | l <- range(tm.useDef),
l in physical2logical,
lg := physical2logical[l],
moduleName != getModuleNameFromAnyLogical(lg)
};
provided = {};
if(!isEmpty(modRequires)){
for(m <- importsAndExtends){
Expand All @@ -342,8 +343,6 @@ tuple[bool, ModuleStatus] importsAndExtendsAreBinaryCompatible(TModel tm, set[MO
}
}

//println("<moduleName> requires <modRequires>");

if(isEmpty(modRequires - provided)){
//println("importsAndExtendsAreBinaryCompatible <moduleName>: satisfied");
return <true, ms>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import String;
import lang::rascalcore::check::ModuleLocations;
import util::FileSystem;
import util::SemVer;
import lang::rascalcore::check::tests::StaticTestingUtils;


// ---- Utilities for test setup ----------------------------------------------
Expand Down Expand Up @@ -99,6 +100,9 @@ str writeModule(str mname, str mtext){
throw "Parse error in <msrc>";
}

loc getModuleLoc(str mname, Project pd)
= src(pd.name) + "<mname>.rsc";

PathConfig createPathConfig(str pname){
return pathConfig(
srcs=[src(pname)],
Expand All @@ -111,22 +115,28 @@ PathConfig createPathConfig(str pname){

Project addModule(str mname, str mtext, Project pd){
pd.modules[mname] = writeModule(mname, mtext);
writeFile(src(pd.name) + "<mname>.rsc", pd.modules[mname]);
mloc = getModuleLoc(mname, pd);
writeFile(mloc, pd.modules[mname]);
assert exists(mloc) : "<mloc> does not exist after write";
return pd;
}

Project changeModule(str mname, str mtext, Project pd){
if(!pd.modules[mname]?) throw "Module <mname> does not exist in <pd.name>";

pd.modules[mname] = writeModule(mname, mtext);
writeFile(src(pd.name) + "<mname>.rsc", pd.modules[mname]);
mloc = getModuleLoc(mname, pd);
writeFile(mloc, pd.modules[mname]);
assert exists(mloc) : "<mloc> does not exist after write";
return pd;
}

Project removeSourceOfModule(str mname, Project pd){
if(!pd.modules[mname]?) throw "Cannot remove non-existing module <mname>";
pd.modules = delete(pd.modules, mname);
remove(src(pd.name) + "<mname>.rsc", recursive=true);
mloc = getModuleLoc(mname, pd);
remove(mloc, recursive=true);
assert !exists(mloc): "<mloc> not removed";
return pd;
}

Expand Down Expand Up @@ -533,7 +543,7 @@ test bool incompatibleVersionsOfBinaryLibrary(){

// Important: we do not recompile TP (and thus it will contain the outdated version of IO)

// Update Checks' modification time to make sure it will rechecked
// Update Checks' modification time to make sure it will be rechecked
touch(getRascalModuleLocation("Check", core.pcfg));
// Recompile Check and discover the error
return checkExpectErrors("Check", ["Review of dependencies, reconfiguration or recompilation needed: binary module `TP` depends (indirectly) on incompatible module(s)"], core.pcfg, remove = [rascal, typepal, core]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,29 @@ test bool breakingChange1(){
return expectReChecks(D, ["C", "D"]);
}

test bool fixedErrorsDisappearCompact() {
clearMemory();
pcfg = getDefaultTestingPathConfig();

mlocs = writeModules("
module ParserBase
");

assert checkModulesOK(mlocs, pathConfig=pcfg) : "Precondition failed: no errors expected!";

// Introduce a type error (import of module that does not exist)
l = writeModule("
module ParserBase

import vis::ParseTree; // module does not exist -\> error

");

assert missingModuleInModule(l, pathConfig=pcfg) : "Precondition failed: expected at least one error, but got none!";

return true;
}

test bool fixedErrorsDisappear() { // ht @toinehartman
clearMemory();
pcfg = getReleasedStandardLibraryTestingPathConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private void runChecker(PathConfig pcfg, list[str] mnames) {

test bool packagerRewritesTModelsCorrectly () {
println("**** Checking List");
tplRoot = |memory:///|;
tplRoot = |memory://packager-test/|;
originalBin = tplRoot + "rascal-lib";
rewrittenBin = tplRoot + "rascal-lib-rewritten";
rascalLibPcfg =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import Relation;
import Set;
import util::Reflective;
import ParseTree;
import util::FileSystem;
import lang::rascalcore::check::RascalConfig;

import lang::rascalcore::check::Checker;
Expand Down Expand Up @@ -104,6 +105,19 @@ void removeModule(str mname){
remove(pcfg.generatedResources + "<name>.tpl");
}

void printModules(){
println("\<\<\<\<");
for(f <- find(testRoot, "rsc")){
println("<f> <lastModified(f)>:
'<readFile(f)>");
}
for(f <- find(testRoot, "tpl")){
println("<f>: <lastModified(f)>");
}
println("\>\>\>\>");
}


set[Message] getErrorMessages(ModuleStatus r)
= { m | m <- getAllMessages(r), m is error };

Expand Down
41 changes: 30 additions & 11 deletions src/org/rascalmpl/uri/libraries/MemoryResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.nio.file.NoSuchFileException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicLong;

import org.checkerframework.checker.nullness.qual.Nullable;
import org.rascalmpl.uri.FileAttributes;
import org.rascalmpl.uri.ISourceLocationInputOutput;
Expand Down Expand Up @@ -62,16 +64,41 @@
*/

public class MemoryResolver implements ISourceLocationInputOutput {


private static class MemoryEntry extends FSEntry {
/** keep track of the timestamp across entries */
private static final AtomicLong now = new AtomicLong(System.currentTimeMillis());

/**
* Every time we're called, we get a new timestamp, to make sure file written at roughly the same
* time don't get the same modification timestamp
* @return
*/
private static long timestamp() {
return now.accumulateAndGet(System.currentTimeMillis(), (now, prev) -> {
if (now > prev) {
return now;
}
if (now == prev) {
return now + 1;
}
// else : prev > now
return prev + 1;
});
}
private final @Nullable byte[] contents;

public MemoryEntry() {
this(null);
}

public MemoryEntry(@Nullable byte[] contents) {
this(System.currentTimeMillis(), System.currentTimeMillis(), contents);
this(timestamp(), contents);
}

private MemoryEntry(long created, @Nullable byte[] contents) {
this(created, created, contents);
}

public MemoryEntry(long created, long lastModified) {
Expand All @@ -83,19 +110,11 @@ public MemoryEntry(long created, long lastModified, @Nullable byte[] contents) {
}

public MemoryEntry newContents(byte[] newContents) {
long newTimestamp = System.currentTimeMillis();
if (newTimestamp <= getLastModified()) {
newTimestamp = getLastModified() + 1;
}
return new MemoryEntry(getCreated(), newTimestamp, newContents);
return new MemoryEntry(getCreated(), timestamp(), newContents);
}

public MemoryEntry copy() {
long newTimestamp = System.currentTimeMillis();
if (newTimestamp <= getLastModified()) {
newTimestamp = getLastModified() + 1;
}
return new MemoryEntry(newTimestamp, newTimestamp, contents);
return new MemoryEntry(timestamp(), contents);
}
}

Expand Down
Loading