Skip to content

Commit

Permalink
Merge branch 'master' into demo-first-quickfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Nov 5, 2024
2 parents b267526 + 42ff021 commit fca67a1
Show file tree
Hide file tree
Showing 13 changed files with 181 additions and 140 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
<errorsAsWarnings>false</errorsAsWarnings>
<proceedOnError />
<properties>${project.basedir}/.settings/org.eclipse.jdt.core.prefs</properties>
</compilerArguments>
</compilerArguments>
</configuration>
<dependencies>
<dependency>
Expand Down Expand Up @@ -173,7 +173,7 @@
</execution>
</executions>
-->
</plugin>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
Expand Down Expand Up @@ -238,7 +238,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version>
<version>5.8.2</version>
</dependency>
<dependency>
<groupId>org.rascalmpl</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public AProduction choice(AType s, set[AProduction] choices){
if(any(choice(AType _, set[AProduction] _) <- choices)){
// TODO: this does not work in interpreter and typechecker crashes on it (both related to the splicing)
//return choice(s, { *(choice(Symbol t, set[AProduction] b) := ch ? b : {ch}) | ch <- choices });
changed = false;
bool changed = false;
new_choices = {};
for(ch <- choices){
if(choice(AType _, set[AProduction] b) := ch){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,13 @@ ModuleStatus rascalTModelForLocs(
}
any_rsc_changed = any(m <- component, rsc_changed() in ms.status[m]);
any_from_lib = any(m <- component, rsc_not_found() in ms.status[m]);
all_tmodels_uptodate = true;
for(m <- component){
if(tpl_uptodate() notin ms.status[m] && checked() notin ms.status[m])
all_tmodels_uptodate = false;
}
recheckCond = !compatible_with_all_imports || any_rsc_changed || !all_tmodels_uptodate;
recheckCond = !any_from_lib && (!compatible_with_all_imports || any_rsc_changed || !all_tmodels_uptodate);
if(recheckCond){
if(ms.compilerConfig.verbose){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ ModuleStatus clearTModelCache(ModuleStatus ms){
}

ModuleStatus removeTModel(str candidate, ModuleStatus ms){
if(tpl_saved() notin ms.status[candidate] && rsc_not_found() notin ms.status[candidate]){
if(ms.status[candidate]? && tpl_saved() notin ms.status[candidate] && rsc_not_found() notin ms.status[candidate]){
pcfg = ms.pathConfig;
if(ms.compilerConfig.verbose) println("Save <candidate> before removing from cache <ms.status[candidate]>");
tm = ms.tmodels[candidate];
Expand Down Expand Up @@ -287,11 +287,11 @@ tuple[bool, TModel, ModuleStatus] getTModelForModule(str qualifiedModuleName, Mo
if(found){
if(traceTPL) println("*** reading tmodel <tplLoc>");
try {
tpl = readBinaryValueFile(#TModel, tplLoc);
if(tpl.rascalTplVersion? && isValidRascalTplVersion(tpl.rascalTplVersion)){
tpl.convertedToPhysical = false; // temporary
tpl = convertTModel2PhysicalLocs(tpl);
ms.tmodels[qualifiedModuleName] = tpl;
tm = readBinaryValueFile(#TModel, tplLoc);
if(tm.rascalTplVersion? && isValidRascalTplVersion(tm.rascalTplVersion)){
tm.usesPhysicalLocs = false; // temporary
tm = convertTModel2PhysicalLocs(tm);
ms.tmodels[qualifiedModuleName] = tm;
mloc = getModuleLocation(qualifiedModuleName, pcfg);
if(isModuleLocationInLibs(qualifiedModuleName, mloc, pcfg)){
ms.status[qualifiedModuleName] ? {} += rsc_not_found();
Expand All @@ -300,7 +300,7 @@ tuple[bool, TModel, ModuleStatus] getTModelForModule(str qualifiedModuleName, Mo
if(qualifiedModuleName notin hardwired){
ms.tmodelLIFO = [qualifiedModuleName, *ms.tmodelLIFO];
}
return <true, tpl, ms>;
return <true, tm, ms>;
}
} catch e: {
//ms.status[qualifiedModuleName] ? {} += rsc_not_found();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ import util::IDEServices;

// ---- Rascal declarations ---------------------------------------------------

int localFunCounter = 0;
int localFunctionCounter = 0;

void collect(Module current: (Module) `<Header header> <Body body>`, Collector c){

dataCounter = 0;
variantCounter = 0;
nalternatives = 0;
syndefCounter = 0;
localFunCounter = 0;
localFunctionCounter = 0;

mloc = getLoc(current);
mname = prettyPrintName(header.name);
Expand Down Expand Up @@ -241,12 +241,19 @@ void collect(current: (FunctionDeclaration) `<FunctionDeclaration decl>`, Collec
c.report(info(current, "Ignoring function declaration for `<decl.signature.name>`"));
return;
}
// Make md5hash of nested functions unique with counter
if(size(c.getStack(currentFunction)) > 0){
localFunCounter += 1;
// Make md5hash of nested functions unique by using all surrounding signatures
c.push(currentFunction, current);
allSignatures = "";
fstk = c.getStack(currentFunction);

for(FunctionDeclaration outerFun <- fstk){
allSignatures += md5Contrib4signature(outerFun.signature);
}
md5Contrib = "<md5Contrib4Tags(decl.tags)><decl.visibility><allSignatures>";
if(size(fstk) > 1){
localFunctionCounter += 1;
md5Contrib += "-<localFunctionCounter>";
}
c.push(currentFunction, ppfname);
md5Contrib = "<md5Contrib4Tags(decl.tags)><decl.visibility><md5Contrib4signature(signature)>-<localFunCounter>";

<expected, expectedTagString> = getExpected(decl.tags);
if(expected){
Expand Down Expand Up @@ -387,16 +394,14 @@ void collect(current: (FunctionDeclaration) `<FunctionDeclaration decl>`, Collec
endUseBoundedTypeParameters(c);
surroundingFuns = c.getStack(currentFunction);
dt.md5 = md5Hash(size(surroundingFuns) == 1 ? md5Contrib : "<intercalate("/", surroundingFuns)><md5Contrib>");
dt.md5 = md5Hash(md5Contrib);
c.defineInScope(parentScope, prettyPrintName(fname), functionId(), current, dt);
// println("<md5Contrib> =\> <dt.md5>");
c.leaveScope(decl);
c.pop(currentFunction);
if(size(c.getStack(currentFunction)) == 0){
localFunCounter = 0;
if(isEmpty(fstk)){
localFunctionCounter = 0;
}
}
void collect(current: (FunctionBody) `{ <Statement* statements> }`, Collector c){
Expand Down
116 changes: 55 additions & 61 deletions src/org/rascalmpl/core/library/lang/rascalcore/check/Import.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,11 @@ str getModuleFromLogical(loc l){

// Is what library module lib provides compatible with all uses in the modules libUsers?
tuple[bool, ModuleStatus] isCompatibleBinaryLibrary(TModel lib, set[str] libUsers, ModuleStatus ms){

libName = lib.modelName;
libProvides = domain(lib.logical2physical);
libProvidesModules = { getModuleFromLogical(l) | l <- libProvides };
usersRequire = {};
set[loc] libProvides = domain(lib.logical2physical);
set[str] libProvidesModules = { getModuleFromLogical(l) | l <- libProvides };
set[loc] usersRequire = {};
for(m <- libUsers){
<found, tm, ms> = getTModelForModule(m, ms);
if(found){
Expand Down Expand Up @@ -331,6 +332,7 @@ rel[str,datetime,PathRole] makeBom(str qualifiedModuleName, set[str] imports, se
+ { < m, getLastModified(m, moduleLastModified, pcfg), extendPath() > | m <- extends }
+ { <qualifiedModuleName, getLastModified(qualifiedModuleName, moduleLastModified, pcfg), importPath() > };
}

void updateBOM(str qualifiedModuleName, set[str] imports, set[str] extends, ModuleStatus ms){
if(rsc_not_found() in ms.status[qualifiedModuleName]){
return;
Expand Down Expand Up @@ -374,95 +376,87 @@ ModuleStatus doSaveModule(set[str] component, map[str,set[str]] m_imports, map[s
for(qualifiedModuleName <- component){
start_save = cpuTime();
tm = transient_tms[qualifiedModuleName];
//try {
mscope = getModuleScope(qualifiedModuleName, moduleScopes, pcfg);
<found, tplLoc> = getTPLWriteLoc(qualifiedModuleName, pcfg);
mscope = getModuleScope(qualifiedModuleName, moduleScopes, pcfg);
<found, tplLoc> = getTPLWriteLoc(qualifiedModuleName, pcfg);

imports = m_imports[qualifiedModuleName];
extends = m_extends[qualifiedModuleName];
imports = m_imports[qualifiedModuleName];
extends = m_extends[qualifiedModuleName];

bom = makeBom(qualifiedModuleName, imports, extends, ms);
bom = makeBom(qualifiedModuleName, imports, extends, ms);

extendedModuleScopes = {getModuleScope(m, moduleScopes, pcfg) | str m <- extends, checked() in ms.status[m]};
extendedModuleScopes += {*tm.paths[ems,importPath()] | ems <- extendedModuleScopes}; // add imports of extended modules
filteredModuleScopes = {getModuleScope(m, moduleScopes, pcfg) | str m <- (qualifiedModuleName + imports), checked() in ms.status[m]} + extendedModuleScopes;
extendedModuleScopes = {getModuleScope(m, moduleScopes, pcfg) | str m <- extends, checked() in ms.status[m]};
extendedModuleScopes += {*tm.paths[ems,importPath()] | ems <- extendedModuleScopes}; // add imports of extended modules
filteredModuleScopes = {getModuleScope(m, moduleScopes, pcfg) | str m <- (qualifiedModuleName + imports), checked() in ms.status[m]} + extendedModuleScopes;

TModel m1 = tmodel();
m1.rascalTplVersion = compilerConfig.rascalTplVersion;
m1.modelName = qualifiedModuleName;
m1.moduleLocs = (qualifiedModuleName : mscope);
TModel m1 = tmodel();
m1.rascalTplVersion = compilerConfig.rascalTplVersion;
m1.modelName = qualifiedModuleName;
m1.moduleLocs = (qualifiedModuleName : mscope);

m1.facts = (key : tm.facts[key] | key <- tm.facts, isContainedInComponentScopes(key));
m1.facts = (key : tm.facts[key] | key <- tm.facts, isContainedInComponentScopes(key));

m1.specializedFacts = (key : tm.specializedFacts[key] | key <- tm.specializedFacts, isContainedInComponentScopes(key), any(fms <- filteredModuleScopes, isContainedIn(key, fms)));
m1.facts += m1.specializedFacts;
m1.specializedFacts = (key : tm.specializedFacts[key] | key <- tm.specializedFacts, isContainedInComponentScopes(key), any(fms <- filteredModuleScopes, isContainedIn(key, fms)));
m1.facts += m1.specializedFacts;

m1.messages = sort( { msg | msg <- tm.messages, msg.at.path == mscope.path}, bool(Message a, Message b){ return a.at.begin.line < b.at.begin.line; });
ms.messages[qualifiedModuleName] = m1.messages;
m1.messages = sort( { msg | msg <- tm.messages, msg.at.path == mscope.path}, bool(Message a, Message b){ return a.at.begin.line < b.at.begin.line; });
ms.messages[qualifiedModuleName] = m1.messages;

filteredModuleScopePaths = {ml.path |loc ml <- filteredModuleScopes};
filteredModuleScopePaths = {ml.path |loc ml <- filteredModuleScopes};

//println("tm.scopes:"); iprintln(tm.scopes);
//m1.scopes = tm.scopes;
m1.scopes
m1.scopes
= ( inner : tm.scopes[inner]
| loc inner <- tm.scopes,
inner.path in filteredModuleScopePaths,
isContainedInComponentScopes(inner)
);

m1.store
m1.store
= (key_bom : bom);
m1.store[key_grammar]
m1.store[key_grammar]
= tm.store[key_grammar] ? grammar({}, ());

m1.store[key_ADTs]
m1.store[key_ADTs]
= tm.store[key_ADTs] ? {};
m1.store[key_common_keyword_fields]
m1.store[key_common_keyword_fields]
= tm.store[key_common_keyword_fields] ? [];

m1.paths = { tup | tuple[loc from, PathRole pathRole, loc to] tup <- tm.paths, tup.from == mscope || tup.from in filteredModuleScopes /*|| tup.from in filteredModuleScopePaths*/ };
m1.paths = { tup | tuple[loc from, PathRole pathRole, loc to] tup <- tm.paths, tup.from == mscope || tup.from in filteredModuleScopes /*|| tup.from in filteredModuleScopePaths*/ };

keepRoles = variableRoles + keepInTModelRoles;
m1.useDef = { <u, d>
| <u, d> <- tm.useDef,
isContainedIn(u, mscope)
|| (tm.definitions[d]? && tm.definitions[d].idRole in keepRoles)
};
keepRoles = variableRoles + keepInTModelRoles;
m1.useDef = { <u, d>
| <u, d> <- tm.useDef,
isContainedIn(u, mscope)
|| (tm.definitions[d]? && tm.definitions[d].idRole in keepRoles)
};

// Filter model for current module and replace functions in defType by their defined type
// Filter model for current module and replace functions in defType by their defined type

defs = for(tup:<loc _scope, str _id, str _orgId, IdRole idRole, loc defined, DefInfo _defInfo> <- tm.defines){
if( ( idRole in variableRoles ? isContainedInComponentScopes(defined)
: ( idRole in keepInTModelRoles
&& ( isContainedInComponentScopes(defined)
|| isContainedInFilteredModuleScopes(defined)
)
defs = for(tup:<loc _scope, str _id, str _orgId, IdRole idRole, loc defined, DefInfo _defInfo> <- tm.defines){
if( ( idRole in variableRoles ? isContainedInComponentScopes(defined)
: ( idRole in keepInTModelRoles
&& ( isContainedInComponentScopes(defined)
|| isContainedInFilteredModuleScopes(defined)
)
)
){
)
)
){
append tup;
}
};
}
};

m1.defines = toSet(defs);
m1.defines = toSet(defs);

m1.definitions = ( def.defined : def | Define def <- m1.defines); // TODO this is derived info, can we derive it later?
// Remove default expressions and fragments
m1 = visit(m1) {
m1.definitions = ( def.defined : def | Define def <- m1.defines); // TODO this is derived info, can we derive it later?
// Remove default expressions and fragments
m1 = visit(m1) {
case kwField(AType atype, str fieldName, str definingModule, Expression _defaultExp) => kwField(atype, fieldName, definingModule)
case loc l : if(!isEmpty(l.fragment)) insert l[fragment=""];
};

m1.convertedToPhysical = false;
ms.status[qualifiedModuleName] -= {tpl_saved()};
ms = addTModel(qualifiedModuleName, m1, ms);
//println("doSaveModule"); iprintln(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>))];
// return ms;
// }
log2phys = tm.logical2physical;
m1.logical2physical = tm.logical2physical;
m1.usesPhysicalLocs = true;
ms.status[qualifiedModuleName] -= {tpl_saved()};
ms = addTModel(qualifiedModuleName, m1, ms);
}
return ms;
}
Loading

0 comments on commit fca67a1

Please sign in to comment.