Skip to content

Commit

Permalink
Fine tuning of md5 hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulKlint committed Jul 10, 2024
1 parent bd4e97b commit a0fe1d0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ tuple[bool,loc] getTPLWriteLoc(str qualifiedModuleName, PathConfig pcfg){
return <exists(tplLoc), tplLoc>;
}

datetime startOfEpoch = $2000-01-01T00:00:00.000+00:00$;

datetime getLastModified(str qualifiedModuleName, map[str, datetime] moduleLastModified, PathConfig pcfg){
qualifiedModuleName = unescape(qualifiedModuleName);
try {
Expand All @@ -110,7 +112,7 @@ datetime getLastModified(str qualifiedModuleName, map[str, datetime] moduleLastM
//println("getLastModified <mloc> via lastModified: <res>");
return res;
} catch value _: {
return $2000-01-01T00:00:00.000+00:00$;
return startOfEpoch;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void collect(current:(Variant) `<Name name> ( <{TypeArg ","}* arguments> <Keywor
declaredFieldNames += fieldName;
fieldType = ta.\type;
dt = defType([fieldType], makeFieldType(fieldName, fieldType));
dt.md5 = md5Hash("<currentModuleName><adtName><dataCounter><variantCounter><ta>");
dt.md5 = md5Hash("<currentModuleName><adtName><dataCounter><variantCounter><fieldType> <fieldName>");
c.define(fieldName, fieldId(), ta.name, dt);
}
}
Expand All @@ -107,13 +107,16 @@ void collect(current:(Variant) `<Name name> ( <{TypeArg ","}* arguments> <Keywor

scope = c.getScope();
c.enterScope(current);
args = "<for(arg <- arguments){><arg.\type> <arg.name> <}>";
md5Contrib = "<currentModuleName><adtName><dataCounter><name><variantCounter>( <args>)";
//println("<current>: <md5Contrib>");
c.defineInScope(adtParentScope, prettyPrintName(name), constructorId(), name, defType(adt + formals + kwFormals + commonKwFormals,
AType(Solver s){
adtType = s.getType(adt);
kwFormalTypes = [kwField(s.getType(kwf.\type)[alabel=prettyPrintName(kwf.name)], prettyPrintName(kwf.name), currentModuleName, kwf.expression) | kwf <- kwFormals /*+ commonKwFormals*/];
formalTypes = [f is named ? s.getType(f)[alabel=prettyPrintName(f.name)] : s.getType(f) | f <- formals];
return acons(adtType, formalTypes, kwFormalTypes)[alabel=asUnqualifiedName(prettyPrintName(name))];
})[md5 = md5Hash("<currentModuleName><adtName><dataCounter><name><variantCounter>(<arguments>")]);
})[md5 = md5Hash(md5Contrib)]);
variantCounter += 1;
c.fact(current, name);
beginUseTypeParameters(c, closed=false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ void collect(Module current: (Module) `<Header header> <Body body>`, Collector c

dataCounter = 0;
variantCounter = 0;
nalternatives = 0;
syndefCounter = 0;

mloc = getLoc(current);
mname = prettyPrintName(header.name);
Expand Down Expand Up @@ -265,7 +267,6 @@ void collect(current: (FunctionDeclaration) `<FunctionDeclaration decl>`, Collec

if("default" in modifiers){
ft.isDefault = true;
md5Contrib = "default" + md5Contrib;
}

if("test" in modifiers){
Expand Down Expand Up @@ -322,7 +323,7 @@ void collect(current: (FunctionDeclaration) `<FunctionDeclaration decl>`, Collec
c.report(error(decl.signature, "Missing return statement"));
}
if(!alwaysSucceeds){
md5Contrib += "<decl.body>";
md5Contrib += "{<decl.body>}";
}
}
Expand All @@ -339,7 +340,7 @@ void collect(current: (FunctionDeclaration) `<FunctionDeclaration decl>`, Collec
if(decl is conditional){
conditions = [cond | cond <- decl.conditions];
md5Contrib += "<decl.conditions>";
md5Contrib += " when <decl.conditions>";
storeAllowUseBeforeDef(decl, decl.expression, c);
c.require("when conditions", decl.conditions, conditions,
void (Solver s){
Expand All @@ -359,7 +360,7 @@ void collect(current: (FunctionDeclaration) `<FunctionDeclaration decl>`, Collec
endUseBoundedTypeParameters(c);
surroundingFuns = c.getStack(currentFunction);
dt.md5 = md5Hash(size(surroundingFuns) == 1 ? md5Contrib : "<intercalate("/", surroundingFuns)><md5Contrib>");
c.defineInScope(parentScope, prettyPrintName(fname), functionId(), current, dt);
Expand All @@ -372,7 +373,10 @@ void collect(current: (FunctionBody) `{ <Statement* statements> }`, Collector c)
}
str md5Contrib4signature(Signature signature){
return "<signature.\type><signature.name><signature.parameters.formals>";
fs = "<for(f <- signature.parameters.formals.formals){><f.\type> <f.name> <}>";
res = "<signature.modifiers><signature.\type> <signature.name>( <fs>)";
//println("<signature> =\> <res>");
return res;
}
tuple[set[str], rel[str,Type]] collectSignature(Signature signature, Collector c){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ void collect (current: (SyntaxDefinition) `<Start strt> syntax <Sym defined> = <
declareSyntax(current, contextFreeSyntax(), nonterminalId(), c);
}

int nalternatives = 0;
int syndefCounter = 0;
public int nalternatives = 0;
public int syndefCounter = 0;

void declareSyntax(SyntaxDefinition current, SyntaxRole syntaxRole, IdRole idRole, Collector c, Vis vis=publicVis()){
//println("declareSyntax: <current>");
Expand Down
35 changes: 31 additions & 4 deletions src/org/rascalmpl/core/library/lang/rascalcore/check/Import.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ 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");
isCompatible(tm, domain(localImportsAndExtends), ms);
//throw rascalSourceMissing("Source of <qualifiedModuleName> is not accessible");
}
}
if(allImportsAndExtendsValid){
Expand Down Expand Up @@ -185,6 +186,29 @@ ModuleStatus getInlineImportAndExtendGraph(Tree pt, PathConfig pcfg){
return complete(ms);
}

str getModuleFromLogical(loc l){
i = findFirst(l.path[1..], "/");
return i >= 0 ? l.path[1..i+1] : l.path[1..];
}

bool isCompatible(TModel lib, set[str] otherImportsAndExtends, ModuleStatus ms){
provides = {<m , l> | l <- domain(lib.logical2physical), m := getModuleFromLogical(l) };
println("<lib.modelName> provides:"); iprintln(provides);
requires = {};
for(m <- otherImportsAndExtends){
<found, tm, ms> = getTModelForModule(m, ms);
if(found){
println("<m>:"); iprintln(domain(tm.logical2physical));
requires += {<m , l> | l <- domain(tm.logical2physical), m := getModuleFromLogical(l) };
}
}
println("requires:"); iprintln(requires);

println("unstatisfied: <requires - provides>");

return true;
}

rel[str, PathRole, str] getModulePathsAsStr(Module m){
moduleName = unescape("<m.header.name>");
return { <moduleName, imod is \default ? importPath() : extendPath(), unescape("<imod.\module.name>")> | imod <- m.header.imports, imod has \module};
Expand Down Expand Up @@ -389,14 +413,17 @@ ModuleStatus doSaveModule(set[str] component, map[str,set[str]] m_imports, map[s
ms.status[qualifiedModuleName] += tpl_saved();
try {
writeBinaryValueFile(tplLoc, m1);
//if(compilerConfig.logWrittenFiles) println("Written: <tplLoc>");
if(compilerConfig.logWrittenFiles) println("Written: <tplLoc>");
save_time = (cpuTime() - start_save)/1000000;
println("Saved TPL .. <qualifiedModuleName> in <save_time> ms");
if(compilerConfig.verbose) {
save_time = (cpuTime() - start_save)/1000000;
println("Saved TPL .. <qualifiedModuleName> in <save_time> ms");
}
} catch value e: {
throw "Cannot write TPL file <tplLoc>, reason: <e>";
}
ms = addTModel(qualifiedModuleName, m1, ms);
//println("doSaveModule"); iprintln(m1);
//println("doSaveModule"); iprintln(domain(m1.logical2physical));

} catch value e: {
ms.messages[qualifiedModuleName] ? [] += tm.messages + [error("Could not save .tpl file for `<qualifiedModuleName>`, reason: <e>", |unknown:///|(0,0,<0,0>,<0,0>))];
Expand Down

0 comments on commit a0fe1d0

Please sign in to comment.