Skip to content

Commit

Permalink
Made md5 hashes less sensitive for irrelevant layout
Browse files Browse the repository at this point in the history
Typical example: Only the contents of javaClass Tag contributes now to
the hash. As a consequence, any change to other Tags (e.g., doc,
synopsis, benefits) has no impact on the hash of the declaration
associated with the Tag.

Visibility is now also properly included in the hash.
  • Loading branch information
PaulKlint committed Jul 15, 2024
1 parent 42e0234 commit de41083
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ void collect(current:(Variant) `<Name name> ( <{TypeArg ","}* arguments> <Keywor

scope = c.getScope();
c.enterScope(current);
args = "<for(arg <- arguments){><arg is typedVariable ? "<arg.\type> <arg.name>" : "<arg>"> <}>";
args = "<for(arg <- arguments){><arg is named ? "<arg.\type> <arg.name>" : "<arg>"> <}>";
md5Contrib = "<currentModuleName><adtName><dataCounter><name><variantCounter>( <args>)";
//println("<current>: <md5Contrib>");
c.defineInScope(adtParentScope, prettyPrintName(name), constructorId(), name, defType(adt + formals + kwFormals + commonKwFormals,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import lang::rascalcore::check::CollectPattern;
import lang::rascal::\syntax::Rascal;
import lang::rascalcore::grammar::definition::Symbols;
import lang::rascalcore::grammar::definition::Attributes;
import lang::rascalcore::check::SyntaxGetters;

import IO;
import List;
Expand Down Expand Up @@ -135,6 +136,7 @@ void collect(current: (Declaration) `<Tags tags> <Visibility visibility> <Type v
c.enterLubScope(var);
dt = defType([varType], makeGetSyntaxType(varType));
dt.vis = getVis(current.visibility, privateVis());
dt.md5 = md5Hash("<md5Contrib4Tags(tags)><visibility><varType><var.name>");
if(!isEmpty(tagsMap)) dt.tags = tagsMap;
vname = prettyPrintName(var.name);
if(isWildCard(vname)){
Expand Down Expand Up @@ -173,7 +175,7 @@ void collect(current: (Declaration) `<Tags tags> <Visibility visibility> anno <T

dt = defType([annoType, onType], AType(Solver s) { return aanno(pname, s.getType(onType), s.getType(annoType)); });
dt.vis = getVis(current.visibility, publicVis());
dt.md5 = md5Hash("<current>");
dt.md5 = md5Hash("<md5Contrib4Tags(tags)><visibility><annoType><onType><name>");
if(!isEmpty(tagsMap)) dt.tags = tagsMap;
if(isWildCard(pname)){
c.report(error(name, "Cannot declare annotation name starting with `_`"));
Expand Down Expand Up @@ -226,8 +228,8 @@ void collect(current: (FunctionDeclaration) `<FunctionDeclaration decl>`, Collec
return;
}
c.push(currentFunction, ppfname);
md5Contrib = md5Contrib4signature(signature);
md5Contrib = "<md5Contrib4Tags(decl.tags)><decl.visibility><md5Contrib4signature(signature)>";

<expected, expectedTagString> = getExpected(decl.tags);
if(expected){
expectedName = expectedTagString.contents;
Expand Down Expand Up @@ -363,7 +365,7 @@ void collect(current: (FunctionDeclaration) `<FunctionDeclaration decl>`, Collec
dt.md5 = md5Hash(size(surroundingFuns) == 1 ? md5Contrib : "<intercalate("/", surroundingFuns)><md5Contrib>");
c.defineInScope(parentScope, prettyPrintName(fname), functionId(), current, dt);
// println("<md5Contrib> =\> <dt.md5>");
c.leaveScope(decl);
c.pop(currentFunction);
}
Expand All @@ -373,7 +375,7 @@ void collect(current: (FunctionBody) `{ <Statement* statements> }`, Collector c)
}
str md5Contrib4signature(Signature signature){
fs = "<for(f <- signature.parameters.formals.formals){><f is typeVariable ? "<f.\type> <f.name>" : "<f>"> <}>";
fs = "<for(f <- signature.parameters.formals.formals){><f is typedVariable ? "<f.\type> <f.name>" : "<f>"> <}>";
res = "<signature.modifiers><signature.\type> <signature.name>( <fs>)";
//println("<signature> =\> <res>");
return res;
Expand Down Expand Up @@ -644,7 +646,7 @@ void collect (current: (Declaration) `<Tags tags> <Visibility visibility> alias
c.report(error(name, "Cannot declare alias name starting with `_`"));
}
c.define(aliasName, aliasId(), current, defType([base], AType(Solver s) { return s.getType(base); })[md5 = md5Hash("<current>")]);
c.define(aliasName, aliasId(), current, defType([base], AType(Solver s) { return s.getType(base); })[md5 = md5Hash("<md5Contrib4Tags(tags)><visibility><name><base>")]);
c.enterScope(current);
collect(tags, base, c);
c.leaveScope(current);
Expand Down Expand Up @@ -679,7 +681,7 @@ void collect (current: (Declaration) `<Tags tags> <Visibility visibility> alias
}
return aalias(aliasName, params, s.getType(base));
})[md5 = md5Hash("<current>")]);
})[md5 = md5Hash("<md5Contrib4Tags(tags)><visibility><name><parameters><base>")]);
collect(tags, c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ list[KeywordFormal] getCommonKwFormals(Declaration decl)
= decl.commonKeywordParameters is present ? [kwf | kwf <- decl.commonKeywordParameters.keywordFormalList] : [];
str md5Contrib4Tags(Tags tags){
for(tg <- tags.tags){
if("<tg.name>" == "javaClass"){
if(tg has contents){
return"<tg.contents.contents>";
} else {
return "";
}
}
}
return "";
}
map[str,str] getTags(Tags tags){
res = ();
for(tg <- tags.tags){
Expand Down

0 comments on commit de41083

Please sign in to comment.