Skip to content

Commit

Permalink
New round of improvements in md5Hash computations
Browse files Browse the repository at this point in the history
- Less order dependent
- More detailed (and layout insensitive) for grammars
  • Loading branch information
PaulKlint committed Jul 19, 2024
1 parent 7afd24b commit d09833e
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 33 deletions.
10 changes: 5 additions & 5 deletions src/org/rascalmpl/core/library/lang/rascalcore/check/Checker.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ public PathConfig getRascalCorePathConfigDev() {
|project://rascal/src/org/rascalmpl/library|,
|std:///|,
|project://rascal-core/src/org/rascalmpl/core/library|,
|project://typepal/src|,
|project://rascal-tutor/src|,
|project://flybytes/src|,
|project://salix/src|,
|project://rascal-lsp/src/main/rascal/|
|project://typepal/src|,
|project://rascal-tutor/src|,
|project://flybytes/src|,
|project://salix/src|,
|project://rascal-lsp/src/main/rascal/|
],
bin = |project://rascal-core/target/test-classes|,
generatedSources = |project://rascal-core/target/generated-test-sources|,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,22 @@ void collect(current:(Variant) `<Name name> ( <{TypeArg ","}* arguments> <Keywor
&& str adtName := "<adt.user.name>"
){
formals = getFormals(current);
consArity = size(formals);
kwFormals = getKwFormals(current);

declaredFieldNames = {};

// Define all fields in the outer scope of the data declaration in order to be easily found there.

for(ta <- formals){
for(int i <- index(formals)){
ta = formals[i];
if(ta is named){
fieldName = prettyPrintName(ta.name);
if(fieldName in declaredFieldNames) c.report(error(ta, "Double declaration of field `%v`", fieldName));
declaredFieldNames += fieldName;
fieldType = ta.\type;
dt = defType([fieldType], makeFieldType(fieldName, fieldType));
dt.md5 = md5Hash("<currentModuleName><adtName><dataCounter><variantCounter><fieldType> <fieldName>");
dt.md5 = md5Hash("<currentModuleName><adtName><dataCounter><name><consArity><i><fieldType> <fieldName>");
c.define(fieldName, fieldId(), ta.name, dt);
}
}
Expand All @@ -100,16 +102,15 @@ void collect(current:(Variant) `<Name name> ( <{TypeArg ","}* arguments> <Keywor
declaredFieldNames += fieldName;
kwfType = kwf.\type;
dt = defType([kwfType], makeFieldType(fieldName, kwfType));
dt.md5 = md5Hash("<currentModuleName><adtName><dataCounter><variantCounter><kwfType><fieldName>");
dt.md5 = md5Hash("<currentModuleName><adtName><dataCounter><name><consArity><kwfType><fieldName>");
c.define(fieldName, keywordFieldId(), kwf.name, dt);
c.requireSubType(kwf.expression, kwfType, error(kwf, "Default expression of type %t expected, found %t", kwfType, kwf.expression));
}

scope = c.getScope();
c.enterScope(current);
args = "<for(arg <- arguments){><arg is named ? "<arg.\type> <arg.name>" : "<arg>"> <}>";
md5Contrib = "<currentModuleName><adtName><dataCounter><name><variantCounter>( <args>)";
//println("<current>: <md5Contrib>");
md5Contrib = "<currentModuleName><adtName><dataCounter><name>( <args>)";
c.defineInScope(adtParentScope, prettyPrintName(name), constructorId(), name, defType(adt + formals + kwFormals + commonKwFormals,
AType(Solver s){
adtType = s.getType(adt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public int nalternatives = 0;
public int syndefCounter = 0;

void declareSyntax(SyntaxDefinition current, SyntaxRole syntaxRole, IdRole idRole, Collector c, Vis vis=publicVis()){
//println("declareSyntax: <current>");
// println("declareSyntax: <current>");
Sym defined = current.defined;
Prod production = current.production;
nonterminalType = defsym2AType(defined, syntaxRole);
Expand All @@ -53,7 +53,7 @@ void declareSyntax(SyntaxDefinition current, SyntaxRole syntaxRole, IdRole idRol

dt = defType(nonterminalType);
dt.vis = vis;
dt.md5 = md5Hash("<adtName><syndefCounter>");
dt.md5 = md5Hash("<current is language ? current.\start : ""><adtName><syndefCounter><md5ContribSym(defined)>");
syndefCounter += 1;

// Define the syntax symbol itself and all labelled alternatives as constructors
Expand All @@ -77,6 +77,17 @@ void declareSyntax(SyntaxDefinition current, SyntaxRole syntaxRole, IdRole idRol
}
}

// ---- ProdModifier ---------------------------------------------------------

str md5ContribProdMod(Tag \tag)
= "";

default str md5ContribProdMod(ProdModifier pm)
= "<pm>";

str md5ContribProdMods(ProdModifier* pms)
= "<for(pm <- pms){><md5ContribProdMod(pm)><}>";

// ---- Prod ------------------------------------------------------------------

AProduction getProd(AType adtType, Tree tree, Solver s){
Expand All @@ -90,6 +101,9 @@ void collect(current: (Prod) `: <Name referenced>`, Collector c){
c.fact(current, referenced);
}

str md5ContribProd((Prod) `: <Name referenced>`)
= "REF<referenced>";

void requireNonLayout(Tree current, AType u, str msg, Solver s){
if(isLayoutAType(u)) s.report(error(current, "Layout type %t not allowed %v", u, msg));
}
Expand Down Expand Up @@ -165,7 +179,7 @@ void collect(current: (Prod) `<ProdModifier* modifiers> <Name name> : <Sym* syms
//def = \start(sdef) := def ? sdef : unset(def, "alabel");
return acons(def, fields, [], alabel=unescape("<name>"));
} else throw "Unexpected type of production: <ptype>";
})[md5=md5Hash("<adt><current>")]);
})[md5=md5Hash("<adt><md5ContribProd(current)>")]);
beginUseTypeParameters(c,closed=true);
collect(symbols, c);
endUseTypeParameters(c);
Expand All @@ -174,6 +188,9 @@ void collect(current: (Prod) `<ProdModifier* modifiers> <Name name> : <Sym* syms
}
}

str md5ContribProd((Prod) `<ProdModifier* modifiers> <Name name> : <Sym* syms>`)
= "<md5ContribProdMods(modifiers)><unescape("<name>")>C<for(s <- syms){><md5ContribSym(s)><}>";

void collect(current: (Prod) `<ProdModifier* modifiers> <Sym* syms>`, Collector c){
symbols = [sym | sym <- syms];
//typeParametersInSymbols = {*getTypeParameters(sym) | sym <- symbols };
Expand All @@ -195,6 +212,10 @@ void collect(current: (Prod) `<ProdModifier* modifiers> <Sym* syms>`, Collector
}
}

str md5ContribProd(p:(Prod) `<ProdModifier* modifiers> <Sym* syms>`){
return "<md5ContribProdMods(modifiers)><for(s <- syms){><md5ContribSym(s)><}>";
}

private AProduction associativity(AType nt, nothing(), AProduction p) = p;
private default AProduction associativity(AType nt, just(AAssociativity a), AProduction p) = associativity(nt, a, {p});

Expand Down Expand Up @@ -224,6 +245,9 @@ list[Prod] normalizeAlt((Prod) `<Prod lhs> | <Prod rhs>`)

default list[Prod] normalizeAlt(Prod p) = [p];

str md5ContribProd((Prod) `<Assoc ass> ( <Prod group> )`)
= "<ass>L<md5ContribProd(group)>R";

void collect(current: (Prod) `<Prod lhs> | <Prod rhs>`, Collector c){
if(<Tree adt, _, _, _> := c.top(currentAdt)){
alts = normalizeAlt(current);
Expand All @@ -237,13 +261,15 @@ void collect(current: (Prod) `<Prod lhs> | <Prod rhs>`, Collector c){
c.pop(inAlternative);
if(isEmpty(c.getStack(inAlternative))){
nalternatives += 1;
c.define("alternative-<nalternatives>", nonterminalId(), current, defType(current)[md5=md5Hash("<current>")]);
c.define("alternative-<nalternatives>", nonterminalId(), current, defType(current)[md5=md5ContribProd(current)]);
}
} else {
throw "collect alt: currentAdt not found";
}
}

str md5ContribProd((Prod) `<Prod lhs> | <Prod rhs>`)
= "<md5ContribProd(lhs)>A<md5ContribProd(rhs)>";

void collect(current: (Prod) `<Prod lhs> \> <Prod rhs>`, Collector c){
if(<Tree adt, _, _, _> := c.top(currentAdt)){
c.calculate("first production", current, [adt, lhs, rhs],
Expand All @@ -257,6 +283,9 @@ void collect(current: (Prod) `<Prod lhs> \> <Prod rhs>`, Collector c){
}
}

str md5ContribProd((Prod) `<Prod lhs> \> <Prod rhs>`)
= "<md5ContribProd(lhs)>R<md5ContribProd(rhs)>";

//default void collect(Prod current, Collector c){
// throw "collect Prod, missed case <current>";
//}
Loading

0 comments on commit d09833e

Please sign in to comment.