Skip to content
Draft
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
48 changes: 32 additions & 16 deletions src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -421,16 +421,20 @@ ModuleStatus doSaveModule(set[MODID] component, map[MODID,set[MODID]] m_imports,
if(isEmpty(component)) return ms;

//println("doSaveModule: <component>, <m_imports>, <m_extends>, <moduleScopes>");
component_scopes = component; //{ getModuleScope(mid, moduleScopes, pcfg) | MODID mid <- component };
set[MODID] componentScopes = component; //{ getModuleScope(mid, moduleScopes, pcfg) | MODID mid <- component };
map[str, MODID] componentScopesByUri = ();
set[MODID] filteredModuleScopes = {};
map[str, MODID] filteredModuleScopesByUri = ();
loc2moduleName = invertUnique(ms.moduleLocs);

bool isContainedInComponentScopes(loc inner, map[loc,loc] m){
return any(cs <- component_scopes, isContainedIn(inner, cs, m));
inner = m[inner] ? inner;
return inner.uri in componentScopesByUri ? isContainedIn(inner, componentScopesByUri[inner.uri]) : false;
};

bool isContainedInFilteredModuleScopes(loc inner, map[loc,loc] m){
return any(cs <- filteredModuleScopes, isContainedIn(inner, cs, m));
inner = m[inner] ? inner;
return inner.uri in filteredModuleScopesByUri ? isContainedIn(inner, filteredModuleScopesByUri[inner.uri]) : false;
};

for(currentModule <- component){
Expand All @@ -443,25 +447,36 @@ ModuleStatus doSaveModule(set[MODID] component, map[MODID,set[MODID]] m_imports,

bom = makeBom(currentModule, ms);

// Lookup fields only once to save interpreter time (significant)
paths = tm.paths;
facts = tm.facts;
specializedFacts = tm.specializedFacts;
useDef = tm.useDef;
logical2physical = tm.logical2physical;
definitions = tm.definitions;

componentScopesByUri = (s.uri: s | loc s <- componentScopes, loc s := logical2physical[s] ? s);

extendedModuleScopes = {m | MODID m <- extends, hasProperty(m, ms, checked())};
extendedModuleScopes += {*tm.paths[ems,importPath()] | MODID ems <- extendedModuleScopes}; // add imports of extended modules
extendedModuleScopes += {*paths[ems,importPath()] | MODID ems <- extendedModuleScopes}; // add imports of extended modules
filteredModuleScopes = {m | MODID m <- (currentModule + imports), hasProperty(m, ms, checked())} + extendedModuleScopes;
filteredModuleScopesByUri = (m.uri: m | loc m <- filteredModuleScopes, loc m := logical2physical[m] ? m);

TModel m1 = tmodel();
m1.version = getCurrentTplVersion();
m1.rascalTplVersion = compilerConfig.rascalTplVersion;
m1.modelName = moduleId2moduleName(currentModule);
m1.moduleLocs = (m1.modelName : currentModule);

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

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

m1.messages = [msg | msg <- tm.messages, isContainedIn(msg.at, currentModule, tm.logical2physical)];
m1.messages = [msg | msg <- tm.messages, isContainedIn(msg.at, currentModule, logical2physical)];
ms.messages[currentModule] = toSet(m1.messages);

filteredModuleScopePaths = {ml.path |loc ml <- filteredModuleScopes};
// filteredModuleScopePaths = {ml.path |loc ml <- filteredModuleScopes};
m1.scopes = tm.scopes;
// m1.scopes
// = ( inner : tm.scopes[inner]
Expand All @@ -480,23 +495,23 @@ ModuleStatus doSaveModule(set[MODID] component, map[MODID,set[MODID]] m_imports,
m1.store[key_common_keyword_fields]
= tm.store[key_common_keyword_fields] ? [];

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

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

// 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, tm.logical2physical)
if( ( idRole in variableRoles ? ( isContainedInComponentScopes(defined, logical2physical)
)
: ( idRole in keepInTModelRoles
&& ( isContainedInComponentScopes(defined, tm.logical2physical)
|| isContainedInFilteredModuleScopes(defined, tm.logical2physical)
&& ( isContainedInComponentScopes(defined, logical2physical)
|| isContainedInFilteredModuleScopes(defined, logical2physical)
)
)
)
Expand All @@ -511,11 +526,12 @@ ModuleStatus doSaveModule(set[MODID] component, map[MODID,set[MODID]] m_imports,
m1.define2id = tm.define2id;

// Remove default expressions and fragments
// (Relatively expensive: can take >50% of the execution time of this function)
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.logical2physical = tm.logical2physical;
m1.logical2physical = logical2physical;
ms = deleteProperty(currentModule, ms, tpl_saved());
ms = addTModel(currentModule, m1, ms);
// println("TModel for <currentModule>:"); iprintln(m1);
Expand Down
Loading