From e56974fbff15f77c43e943b31e0b8f935f7eec4c Mon Sep 17 00:00:00 2001 From: paulklint Date: Mon, 5 Jan 2026 15:49:22 +0100 Subject: [PATCH 01/23] Major adaptation to logical ModuleLocations The systematic use of logical locations in TypePal has impact on certain parts of compiler and typechecker. Here are the most relevant points: - All uses of isContainedIn and friends have been reviewed and are usually replaced by calling the Solver version, e.g., s.isContained. - The information organization in the typechcker was ambivalent about the use of a module name or a module location as ky to represent a specific module. This has been fixed: the logical location of a module is used everywhere to identify it, e.g., |rascal+module:///IO|. - A nice side effect of this is that a logical module location also represents the physical module scope, eliminating some extra mappings. - An alias MID (for Module IDentifier) of loc is introduced. The validity of a MID argument of a function is asserted in many places. - As a consequence, many str fields in ModuleStatus have been changed to MID. - Conversions to/from MID/modulename are available. - The best part of all these changes is that the previous, time-consuming, mappings between logical and physical locations have become a thing of the past. TModels now always (either stored in a .tpl file or in memory) use logical locations. --- pom.xml | 2 +- .../lang/rascalcore/check/ADTandGrammar.rsc | 11 +- .../lang/rascalcore/check/Checker.rsc | 200 ++++++----- .../lang/rascalcore/check/CheckerCommon.rsc | 319 ++++++++--------- .../compiler/lang/rascalcore/check/Import.rsc | 324 +++++++++--------- .../lang/rascalcore/check/ModuleLocations.rsc | 1 + .../lang/rascalcore/check/RascalConfig.rsc | 48 +-- .../rascalcore/check/tests/AliasTCTests.rsc | 2 +- .../check/tests/BinaryDependencyTests.rsc | 4 +- .../check/tests/DeclarationTCTests.rsc | 2 +- .../check/tests/StaticTestingUtils.rsc | 8 +- .../compile/Examples/IncompatibleModules.rsc | 4 +- .../lang/rascalcore/compile/Examples/Tst4.rsc | 17 +- .../lang/rascalcore/compile/Examples/Tst5.rsc | 5 + .../lang/rascalcore/compile/Examples/Tst6.rsc | 24 +- .../Rascal2muRascal/ConcreteSyntax.rsc | 4 +- .../Rascal2muRascal/RascalDeclaration.rsc | 16 +- .../compile/Rascal2muRascal/RascalModule.rsc | 2 +- .../compile/Rascal2muRascal/RascalPattern.rsc | 2 +- .../compile/Rascal2muRascal/TypeUtils.rsc | 6 +- .../lang/rascalcore/compile/ShowTPL.rsc | 134 -------- .../compile/muRascal2Java/CodeGen.rsc | 8 +- .../compile/muRascal2Java/JGenie.rsc | 46 +-- .../compile/muRascal2Java/Resolvers.rsc | 26 +- .../lang/rascalcore/compile/util/Names.rsc | 12 +- src/org/rascalmpl/library/Grammar.rsc | 2 +- 26 files changed, 548 insertions(+), 681 deletions(-) create mode 100644 src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst5.rsc delete mode 100644 src/org/rascalmpl/compiler/lang/rascalcore/compile/ShowTPL.rsc diff --git a/pom.xml b/pom.xml index dc9a0fb7b76..38c16dba941 100644 --- a/pom.xml +++ b/pom.xml @@ -458,7 +458,7 @@ org.rascalmpl typepal - 0.15.3 + 0.15.6-SNAPSHOT compile diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/ADTandGrammar.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/ADTandGrammar.rsc index 9d75d2d38cf..c6aaabc657f 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/ADTandGrammar.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/ADTandGrammar.rsc @@ -165,19 +165,20 @@ list[&T <: node ] unsetRec(list[&T <: node] args) = [unsetRec(a) | a <- args]; bool isManualLayout(AProduction p) = (p has attributes && atag("manual"()) in p.attributes); -tuple[TModel, ModuleStatus] addGrammar(str qualifiedModuleName, set[str] imports, set[str] extends, map[str,TModel] transient_tms, ModuleStatus ms){ +tuple[TModel, ModuleStatus] addGrammar(MID moduleId, set[MID] imports, set[MID] extends, map[MID,TModel] transient_tms, ModuleStatus ms){ try { rel[AType,AProduction] definedProductions = {}; allStarts = {}; - for(m <- {qualifiedModuleName, *imports, *extends}){ + qualifiedModuleName = moduleId2moduleName(moduleId); + for(m <- {moduleId, *imports, *extends}){ TModel tm1; if(transient_tms[m]?){ tm1 = transient_tms[m]; } else { = getTModelForModule(m, ms); if(!found) { - msg = error("Cannot add grammar, tmodel for not found", ms.moduleLocs[qualifiedModuleName] ? |unknown:///|); - ms.messages[qualifiedModuleName] ? {} += { msg }; + msg = error("Cannot add grammar, tmodel for not found", ms.moduleLocs[moduleId] ? |unknown:///|); + ms.messages[moduleId] ? {} += { msg }; tm1 = tmodel(modelName=qualifiedModuleName, messages=[msg]); return ; } @@ -223,7 +224,7 @@ tuple[TModel, ModuleStatus] addGrammar(str qualifiedModuleName, set[str] imports // Check keyword rules - tm = checkKeywords(allProductions, transient_tms[qualifiedModuleName]); + tm = checkKeywords(allProductions, transient_tms[moduleId]); // Check layout diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/Checker.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/Checker.rsc index c520de35695..4a352230bca 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/Checker.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/Checker.rsc @@ -113,7 +113,7 @@ bool errorsPresent(list[Message] msgs) = !isEmpty([ e | e:error(_,_) <- msgs ]); // Dummy compile function (used when running only the checker) -list[Message] dummy_compile1(str _qualifiedModuleName, lang::rascal::\syntax::Rascal::Module _M, map[str,TModel] _transient_tms, ModuleStatus _ms, RascalCompilerConfig _compilerConfig) +list[Message] dummy_compile1(MID _moduleId, lang::rascal::\syntax::Rascal::Module _M, map[MID,TModel] _transient_tms, ModuleStatus _ms, RascalCompilerConfig _compilerConfig) = []; // rascalTModelForLocs is the basic work horse @@ -123,7 +123,7 @@ list[Message] dummy_compile1(str _qualifiedModuleName, lang::rascal::\syntax::Ra ModuleStatus rascalTModelForLocs( list[loc] mlocs, RascalCompilerConfig compilerConfig, - list[Message](str qualifiedModuleName, lang::rascal::\syntax::Rascal::Module M, map[str,TModel] transient_tms, ModuleStatus ms, RascalCompilerConfig compilerConfig) codgen + list[Message](MID moduleId, lang::rascal::\syntax::Rascal::Module M, map[MID,TModel] transient_tms, ModuleStatus ms, RascalCompilerConfig compilerConfig) codgen ){ pcfg = compilerConfig.typepalPathConfig; @@ -135,11 +135,18 @@ ModuleStatus rascalTModelForLocs( set[Message] msgs = validatePathConfigForChecker(pcfg, mlocs[0]); - mnames = + list[str] mnames = []; + mids = for(mloc <- mlocs){ + if(isLogicalLoc(mloc)){ + mnames += moduleId2moduleName(mloc); + append mloc; + } else if(exists(mloc)){ try { - append getRascalModuleName(mloc, pcfg); + mname = getRascalModuleName(mloc, pcfg); + mnames += mname; + append moduleName2moduleId(mname); } catch e: { msgs += error("No module name found for ", mloc); } @@ -149,8 +156,8 @@ ModuleStatus rascalTModelForLocs( }; if(size(mlocs) != size(mnames)){ // not all mlocs could be mapped to a module - for(mn <- mnames){ - ms.messages[mn] = msgs; + for(mid <- mids){ + ms.messages[mid] = msgs; } if(errorsPresent(msgs)){ pcfg.messages += toList(msgs); @@ -160,11 +167,11 @@ ModuleStatus rascalTModelForLocs( return ms; } - = libraryDependenciesAreCompatible(mlocs, ms); + = libraryDependenciesAreCompatible(mids, ms); if(compatibleLibs && uptodateTPls(mlocs, mnames, pcfg)){ - for (i <- index(mlocs)) { - = getTModelForModule(mnames[i], ms, convert=true); + for (i <- index(mids)) { + = getTModelForModule(mids[i], ms); if(!found){ throw "TModel for not found (no changes)"; } @@ -173,49 +180,50 @@ ModuleStatus rascalTModelForLocs( } for (int i <- index(mlocs)) { + mid = mids[i]; mloc = mlocs[i]; mname = mnames[i]; - if(isModuleLocationInLibs(mname, mloc, pcfg)){ - ms.status[mname] ? {} += {rsc_not_found()}; + if(isModuleLocationInLibs(mloc, pcfg)){ + ms.status[mloc] ? {} += {rsc_not_found()}; } - ms.moduleLocs[mname] = mloc; - msgs += (ms.messages[mname] ? {}); + ms.moduleLocs[mid] = mloc; + msgs += (ms.messages[mid] ? {}); } str jobName = ""; - ms.changedModules = topModuleNames = toSet(mnames); + ms.changedModules = topModuleIds = toSet(mids); + topModuleNames = mnames; try { - ms = getImportAndExtendGraph(topModuleNames, ms); + ms = getImportAndExtendGraph(topModuleIds, ms); // if(/error(_,_) := ms.messages){ - // return clearTModelCache(ms); // } - imports_and_extends = ms.strPaths<0,2>; + imports_and_extends = ms.paths<0,2>; = stronglyConnectedComponentsAndTopSort(imports_and_extends); - map[str, set[str]] module2component = (m : c | c <- components, m <- c); + map[MID, set[MID]] module2component = (m : c | c <- components, m <- c); - list[str] ordered = []; + list[MID] ordered = []; if(isEmpty(sorted)){ - ordered = toList(topModuleNames); - for(str topModuleName <- topModuleNames){ - module2component[topModuleName] = {topModuleName}; + ordered = toList(topModuleIds); + for(MID topModuleId <- topModuleIds){ + module2component[topModuleId] = {topModuleId}; } } else { ordered = reverse(sorted); - singletons = toList(topModuleNames - toSet(ordered)); + singletons = toList(topModuleIds - toSet(ordered)); ordered += singletons; - for(str singleton <- singletons){ + for(MID singleton <- singletons){ module2component[singleton] = {singleton}; } } - map[str, loc] moduleScopes = (); - map[str,str] path2module = (ms.moduleLocs[mname].path : mname | mname <- ms.moduleLocs); + // map[loc, loc] moduleScopes = (); + //map[str,loc] path2module = (ms.moduleLocs[mname].path : mname | mname <- ms.moduleLocs); mi = 0; nmodules = size(ordered); @@ -226,7 +234,8 @@ ModuleStatus rascalTModelForLocs( component = module2component[ordered[mi]]; sizeComponent = size(component); - jobStep(jobName, intercalate(" + ", [*component]), work=size(component)); + componentNames = [moduleId2moduleName(c) | c <- component]; + jobStep(jobName, intercalate(" + ", [*componentNames]), work=size(componentNames)); recheck = !all(m <- component, m in ms.status, (tpl_uptodate() in ms.status[m] || checked() in ms.status[m])); for(m <- component){ @@ -237,7 +246,7 @@ ModuleStatus rascalTModelForLocs( mi += 1; if(!recheck){ if(tpl_uptodate() notin ms.status[m]){ - = getTModelForModule(m, ms, convert=sizeComponent>1); + = getTModelForModule(m, ms); if(found){ ms.status[m] += {tpl_uptodate(), checked()}; } @@ -255,7 +264,7 @@ ModuleStatus rascalTModelForLocs( } else { for(m <- component){ m_compatible = false; - = getTModelForModule(m, ms, convert=sizeComponent>1); + = getTModelForModule(m, ms); if(found && !tplOutdated(m, pcfg)){ imports_extends_m = imports_and_extends[m]; @@ -283,19 +292,20 @@ ModuleStatus rascalTModelForLocs( // } = rascalTModelComponent(component, ms); - moduleScopes += getModuleScopes(tm); + // moduleScopes += getModuleScopes(tm); map[str,TModel] tmodels_for_component = (); - map[str,set[str]] m_imports = (); - map[str,set[str]] m_extends = (); + map[MID,set[MID]] m_imports = (); + map[MID,set[MID]] m_extends = (); for(m <- component, rsc_not_found() notin ms.status[m], MStatus::ignored() notin ms.status[m]){ - imports = { imp | <- ms.strPaths, m1 == m, MStatus::ignored() notin ms.status[imp]}; + imports = { imp | <- ms.paths, m1 == m, MStatus::ignored() notin ms.status[imp]}; m_imports[m] = imports; - extends = { ext | <- ms.strPaths, m1 == m, MStatus::ignored() notin ms.status[ext] }; + extends = { ext | <- ms.paths, m1 == m, MStatus::ignored() notin ms.status[ext] }; m_extends[m] = extends; - invertedExtends = ms.strPaths<2,0>; + invertedExtends = ms.paths<2,0>; if(compilerConfig.warnUnused){ // Look for unused imports or extends - usedModules = {path2module[l.path] | loc l <- range(tm.useDef), tm.definitions[l].idRole == moduleId(), path2module[l.path]?}; + //usedModules = {path2module[l.path] | loc l <- range(tm.useDef), tm.definitions[l].idRole == moduleId(), path2module[l.path]?}; + usedModules = {l | loc l <- range(tm.useDef), tm.definitions[l].idRole == moduleId()}; usedModules += {*invertedExtends[um] | um <- usedModules}; // use of an extended module via import list[Message] imsgs = []; = getModuleParseTree(m, ms); @@ -306,20 +316,21 @@ ModuleStatus rascalTModelForLocs( check_imports: for(imod <- pt.header.imports, imod has \module){ iname = unescape(""); - if(!ms.status[iname]?){ - ms.status[iname] = {}; + inameId = moduleName2moduleId(iname); + if(!ms.status[inameId]?){ + ms.status[inameId] = {}; } - if(iname notin usedModules){ + if(inameId notin usedModules){ if(iname == "ParseTree" && implicitlyUsesParseTree(ms.moduleLocs[m].path, tm)){ continue check_imports; } - if(ms.moduleLocs[iname]? && ms.moduleLocs[m]? && implicitlyUsesLayoutOrLexical(ms.moduleLocs[m].path, ms.moduleLocs[iname].path, tm)){ + if(ms.moduleLocs[inameId]? && ms.moduleLocs[m]? && implicitlyUsesLayoutOrLexical(ms.moduleLocs[m].path, ms.moduleLocs[inameId].path, tm)){ continue check_imports; } - if(ms.moduleLocs[iname]? && ms.moduleLocs[m]? && usesOrExtendsADT(ms.moduleLocs[m].path, ms.moduleLocs[iname].path, tm)){ + if(ms.moduleLocs[inameId]? && ms.moduleLocs[m]? && usesOrExtendsADT(ms.moduleLocs[m].path, ms.moduleLocs[inameId].path, tm)){ continue check_imports; } - if((iname in component || checked() in ms.status[iname]) && rsc_not_found() notin ms.status[iname]){ + if((inameId in component || checked() in ms.status[inameId]) && rsc_not_found() notin ms.status[inameId]){ if(imod is \default){ imsgs += warning("Unused import of ``", imod@\loc); } //else { //TODO: maybe add option to turn off info messages? @@ -343,11 +354,11 @@ ModuleStatus rascalTModelForLocs( } // prepare the TModels of the modules in this component for compilation - = prepareForCompilation(component, m_imports, m_extends, ms, moduleScopes, tm); + = prepareForCompilation(component, m_imports, m_extends, ms, tm); // generate code for the modules in this component - for(str m <- component, MStatus::ignored() notin ms.status[m]){ + for(MID m <- component, MStatus::ignored() notin ms.status[m]){ = getModuleParseTree(m, ms); if(success){ lmsgs = codgen(m, pt, transient_tms, ms, compilerConfig); @@ -355,7 +366,7 @@ ModuleStatus rascalTModelForLocs( ms.status[m] += errorsPresent(lmsgs) ? {code_generation_error()} : {code_generated()}; } } - ms = doSaveModule(component, m_imports, m_extends, ms, moduleScopes, transient_tms, compilerConfig); + ms = doSaveModule(component, m_imports, m_extends, ms, transient_tms, compilerConfig); for(m <- component){ ms.status[m] -= {rsc_changed()}; ms.status[m] += {tpl_uptodate()}; @@ -367,16 +378,16 @@ ModuleStatus rascalTModelForLocs( } } } catch ParseError(loc src): { - for(str mname <- topModuleNames){ - ms.messages[mname] = { error("Parse error", src) }; + for(MID mid <- topModuleIds){ + ms.messages[mid] = { error("Parse error", src) }; } } catch rascalTplVersionError(str txt):{ - for(str mname <- topModuleNames){ - ms.messages[mname] = { error("", ms.moduleLocs[mname] ? |unknown:///|) }; + for(MID mid <- topModuleIds){ + ms.messages[mid] = { error("", ms.moduleLocs[mid] ? |unknown:///|) }; } } catch Message msg: { - for(str mname <- topModuleNames){ - ms.messages[mname] = { error("During type checking: ", msg.at) }; + for(MID mid <- topModuleIds){ + ms.messages[mid] = { error("During type checking: ", msg.at) }; } } @@ -401,13 +412,13 @@ bool usesOrExtendsADT(str modulePath, str importPath, TModel tm){ return res; } -tuple[set[str], ModuleStatus] loadImportsAndExtends(set[str] moduleNames, ModuleStatus ms, Collector c, set[str] added){ +tuple[set[MID], ModuleStatus] loadImportsAndExtends(set[MID] moduleIds, ModuleStatus ms, Collector c, set[MID] added){ pcfg = ms.pathConfig; - for( <- ms.strPaths, from in moduleNames){ - if(imp notin added, imp notin moduleNames){ + for( <- ms.paths, from in moduleIds){ + if(imp notin added, imp notin moduleIds){ if(tpl_uptodate() in ms.status[imp]){ added += imp; - = getTModelForModule(imp, ms, convert=true); + = getTModelForModule(imp, ms); try { if(pathRole == importPath()){ tm.defines = {d | d <- tm.defines, d.idRole == moduleVariableId() ==> d.defInfo.vis == publicVis() }; @@ -422,54 +433,55 @@ tuple[set[str], ModuleStatus] loadImportsAndExtends(set[str] moduleNames, Module return ; } -tuple[TModel, ModuleStatus] rascalTModelComponent(set[str] moduleNames, ModuleStatus ms){ - +tuple[TModel, ModuleStatus] rascalTModelComponent(set[MID] moduleIds, ModuleStatus ms){ pcfg = ms.pathConfig; compilerConfig = ms.compilerConfig; - modelName = intercalate(" + ", toList(moduleNames)); - map[str, Module] namedTrees = (); - for(str nm <- moduleNames){ - ms.status[nm] = {}; - //ms.messages[nm] = {}; - ms = removeTModel(nm, ms); + modelNames = [moduleId2moduleName(moduleId) | moduleId <- moduleIds]; + modelName = intercalate(" + ", modelNames); + map[MID, Module] idTrees = (); + for(MID mid <- moduleIds){ + mname = moduleId2moduleName(mid); + ms.status[mid] = {}; + //ms.messages[mid] = {}; + ms = removeTModel(mid, ms); mloc = |unknown:///|(0,0,<0,0>,<0,0>); try { - mloc = getRascalModuleLocation(nm, ms); + mloc = getRascalModuleLocation(mid, ms); } catch Message err: { - ms.messages[nm] = { err }; - ms.status[nm] += { rsc_not_found() }; - tm = tmodel(modelName=nm, messages=[ err ]); - ms = addTModel(nm, tm, ms); + ms.messages[mid] = { err }; + ms.status[mid] += { rsc_not_found() }; + tm = tmodel(modelName=mname, messages=[ err ]); + ms = addTModel(mid, tm, ms); return ; } - if(mloc.extension != "rsc" || isModuleLocationInLibs(nm, mloc, pcfg)){ + if(!isLogicalLoc(mloc) && (mloc.extension != "rsc" || isModuleLocationInLibs(mloc, pcfg))){ continue; } - = getModuleParseTree(nm, ms); + = getModuleParseTree(mid, ms); if(success){ tagsMap = getTags(pt.header.tags); if(ignoreCompiler(tagsMap)) { - ms.messages[nm] ? {} += { Message::info("Ignoring module ", pt@\loc) }; - ms.status[nm] += MStatus::ignored(); + ms.messages[mid] ? {} += { Message::info("Ignoring module ", pt@\loc) }; + ms.status[mid] += MStatus::ignored(); } - namedTrees[nm] = pt; + idTrees[mid] = pt; } //else { - // ms.messages[nm] += error("Cannot get parse tree for module ``", ms.moduleLocs[nm]); + // ms.messages[mid] += error("Cannot get parse tree for module ``", ms.moduleLocs[mid]); //} } - if(!isEmpty(namedTrees)){ + if(!isEmpty(idTrees)){ if(compilerConfig.verbose) { println("Checking ... "); } start_check = cpuTime(); resetClosureCounter(); + namedTrees = (moduleId2moduleName(mid) : idTrees[mid] | mid <- idTrees); c = newCollector(modelName, namedTrees, compilerConfig); c.push(key_pathconfig, pcfg); rascalPreCollectInitialization(namedTrees, c); - - = loadImportsAndExtends(moduleNames, ms, c, {}); + = loadImportsAndExtends(domain(idTrees), ms, c, {}); for(str nm <- namedTrees){ collect(namedTrees[nm], c); } @@ -481,9 +493,9 @@ tuple[TModel, ModuleStatus] rascalTModelComponent(set[str] moduleNames, ModuleSt s = newSolver(namedTrees, tm); tm = s.run(); } - tm.usesPhysicalLocs = true; - for(mname <- moduleNames){ - ms.messages[mname] ? {} += toSet(tm.messages); + + for(mid <- moduleIds){ + ms.messages[mid] ? {} += toSet(tm.messages); } //iprintln(tm.messages); @@ -492,19 +504,18 @@ tuple[TModel, ModuleStatus] rascalTModelComponent(set[str] moduleNames, ModuleSt if(compilerConfig.verbose) { println("Checked .... in ms"); } return ; } else { - ms.status[modelName]? {} += { tpl_saved() }; - = getTModelForModule(modelName, ms, convert=false); + oneOfComponent = getOneFrom(moduleIds); + ms.status[oneOfComponent]? {} += { tpl_saved() }; // TODO check this, when is this executed? + = getTModelForModule(oneOfComponent, ms); return ; } } - - // ---- rascalTModelForName a checker version that works on module names ModuleStatus rascalTModelForNames(list[str] moduleNames, RascalCompilerConfig compilerConfig, - list[Message] (str qualifiedModuleName, lang::rascal::\syntax::Rascal::Module M, map[str,TModel] transient_tms, ModuleStatus ms, RascalCompilerConfig compilerConfig) codgen){ + list[Message] (MID moduleId, lang::rascal::\syntax::Rascal::Module M, map[MID,TModel] transient_tms, ModuleStatus ms, RascalCompilerConfig compilerConfig) codgen){ pcfg = compilerConfig.typepalPathConfig; mlocs = []; @@ -513,7 +524,7 @@ ModuleStatus rascalTModelForNames(list[str] moduleNames, mlocs += [ getRascalModuleLocation(moduleName, pcfg) ]; } catch Message err: { ms = newModuleStatus(compilerConfig); - ms.messages[moduleName] = { err }; + ms.messages[moduleName2moduleId(moduleName)] = { err }; return ms; } } @@ -531,18 +542,17 @@ bool uptodateTPls(list[loc] candidates, list[str] mnames, PathConfig pcfg){ return true; } -tuple[bool, ModuleStatus] libraryDependenciesAreCompatible(list[loc] candidates, ModuleStatus ms){ +tuple[bool, ModuleStatus] libraryDependenciesAreCompatible(list[MID] candidates, ModuleStatus ms){ pcfg = ms.pathConfig; for(candidate <- candidates){ - mname = getRascalModuleName(candidate, pcfg); - = getTModelForModule(mname, ms, convert=false); - //if(found){ - imports_and_extends = ms.strPaths<0,2>[mname]; + = getTModelForModule(candidate, ms); + if(found){ // TODO: needed? + imports_and_extends = ms.paths<0,2>[candidate]; = importsAndExtendsAreBinaryCompatible(tm, imports_and_extends, ms); if(!compatible){ return ; } - //} + } } return ; } @@ -564,9 +574,9 @@ list[ModuleMessages] check(list[loc] moduleLocs, RascalCompilerConfig compilerCo } list[ModuleMessages] reportModuleMessages(ModuleStatus ms){ - moduleNames = domain(ms.moduleLocs); - messagesNoModule = {*ms.messages[mname] | mname <- ms.messages, (mname notin moduleNames || mname notin ms.moduleLocs)} + toSet(ms.pathConfig.messages); - msgs = [ program(ms.moduleLocs[mname], (ms.messages[mname] ? {}) + messagesNoModule) | mname <- moduleNames ]; + moduleIds = domain(ms.moduleLocs); + messagesNoModule = {*ms.messages[mid] | MID mid <- ms.messages, (mid notin moduleIds || mid notin ms.moduleLocs)} + toSet(ms.pathConfig.messages); + msgs = [ program(ms.moduleLocs[mid], (ms.messages[mid] ? {}) + messagesNoModule) | MID mid <- moduleIds ]; if(isEmpty(msgs) && !isEmpty(messagesNoModule)){ msgs = [ program(|unknown:///|, messagesNoModule) ]; } diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc index 0dc88807197..6ba9918d7e6 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc @@ -67,6 +67,21 @@ void checkSupportedByParserGenerator(Tree t, Collector c){ }); } +alias MID = loc; // module identification + +bool isModuleId(loc l) = l.scheme == "rascal+module"; + +MID moduleName2moduleId(str mname){ + return |rascal+module:///|; +} + +str moduleId2moduleName(loc mloc){ + assert mloc.scheme == "rascal+module" : "moduleId2moduleName: "; + path = mloc.path; + if(path[0] == "/") path = path[1..]; + return replaceAll(path, "/", "::"); +} + data MStatus = rsc_not_found() | tpl_not_found() @@ -86,26 +101,38 @@ data MStatus = data ModuleStatus = moduleStatus( - rel[str, PathRole, str] strPaths, - rel[loc, PathRole, loc] paths, - map[str, Module] parseTrees, - list[str] parseTreeLIFO, - map[str, TModel] tmodels, - list[str] tmodelLIFO, - set[str] changedModules, - map[str,loc] moduleLocs, - map[str,datetime] moduleLastModified, - map[str, set[Message]] messages, - map[str, set[MStatus]] status, + rel[MID, PathRole, MID] paths, + map[MID, Module] parseTrees, + list[MID] parseTreeLIFO, + map[MID, TModel] tmodels, + list[MID] tmodelLIFO, + set[MID] changedModules, + map[MID,loc] moduleLocs, + map[MID,datetime] moduleLastModified, + map[MID, set[Message]] messages, + map[MID, set[MStatus]] status, PathConfig pathConfig, RascalCompilerConfig compilerConfig ); -ModuleStatus newModuleStatus(RascalCompilerConfig ccfg) = moduleStatus({}, {}, (), [], (), [], {}, (), (), (), (), ccfg.typepalPathConfig, ccfg); - -bool isModuleLocationInLibs(str mname, loc l, PathConfig pcfg){ +// void checkMS(ModuleStatus ms){ +// for( <- ms.paths) assert isModuleId(f) && isModuleId(t); +// for(mid <- domain(ms.parseTrees)) assert isModuleId(mid); +// for(mid <- ms.parseTreeLIFO) assert isModuleId(mid); +// for(mid <- domain(ms.tmodels)) assert isModuleId(mid); +// for(mid <- ms.tmodelLIFO) assert isModuleId(mid); +// for(mid <- ms.changedModules) assert isModuleId(mid); +// for(mid <- domain(ms.moduleLocs)) assert isModuleId(mid); +// for(mid <- domain(ms.moduleLastModified)) assert isModuleId(mid); +// for(mid <- domain(ms.messages)) assert isModuleId(mid); +// for(mid <- domain(ms.status)) assert isModuleId(mid); +// } + +ModuleStatus newModuleStatus(RascalCompilerConfig ccfg) = moduleStatus({}, (), [], (), [], {}, (), (), (), (), ccfg.typepalPathConfig, ccfg); + +bool isModuleLocationInLibs(loc l, PathConfig pcfg){ + assert !isModuleId(l); res = l.extension == "tpl" || !isEmpty(pcfg.libs) && any(lib <- pcfg.libs, l.scheme == lib.scheme && l.path == lib.path); - //println("isModuleLocationInLibs: , ==\> "); return res; } @@ -113,17 +140,20 @@ bool traceTPL = false; bool traceParseTreeCache = false; bool traceTModelCache = false; -tuple[bool,loc] getTPLReadLoc(str qualifiedModuleName, PathConfig pcfg){ - parts = split("::", qualifiedModuleName); +tuple[bool,loc] getTPLReadLoc(str qualifiedModuleName, PathConfig pcfg) + = getTPLReadLoc(moduleName2moduleId(qualifiedModuleName), pcfg); + +tuple[bool,loc] getTPLReadLoc(MID moduleId, PathConfig pcfg){ + assert isModuleId(moduleId) : "getTPLReadLoc: "; + parts = split("/", moduleId.path); parts = parts[0 .. size(parts)-1] + "$"; - res = intercalate("/", parts); fileName = intercalate("/", parts) + ".tpl"; - dirName = makeDirName(qualifiedModuleName); + dirName = makeDirName(parts); for(loc dir <- [pcfg.generatedResources, pcfg.bin] + pcfg.libs){ // In a bin or lib directory? - fileLoc = dir + "" + fileName; + fileLoc = dir + "" + fileName; if(exists(fileLoc)){ - if(traceTPL) println("getTPLReadLoc: =\> "); + if(traceTPL) println("getTPLReadLoc: =\> "); return ; } else { ;// if(traceTPL) @@ -133,7 +163,9 @@ tuple[bool,loc] getTPLReadLoc(str qualifiedModuleName, PathConfig pcfg){ return ; } -tuple[bool,loc] getTPLWriteLoc(str qualifiedModuleName, PathConfig pcfg){ +tuple[bool,loc] getTPLWriteLoc(MID moduleId, PathConfig pcfg){ + assert isModuleId(moduleId) : "getTPLWriteLoc: "; + qualifiedModuleName = moduleId2moduleName(moduleId); fileName = ".tpl"; tplLoc = getGeneratedResourcesDir(qualifiedModuleName, pcfg) + fileName; return ; @@ -141,13 +173,14 @@ tuple[bool,loc] getTPLWriteLoc(str qualifiedModuleName, PathConfig pcfg){ datetime startOfEpoch = $2000-01-01T00:00:00.000+00:00$; -datetime getLastModified(str qualifiedModuleName, map[str, datetime] moduleLastModified, PathConfig pcfg){ - qualifiedModuleName = unescape(qualifiedModuleName); - try { - return moduleLastModified[qualifiedModuleName]; - } catch NoSuchKey(_): { +datetime getLastModified(MID moduleId, ModuleStatus ms){ + assert isModuleId(moduleId) : "getLastModified: "; + qualifiedModuleName = moduleId2moduleName(moduleId); + if(moduleId in ms.moduleLastModified){ + return ms.moduleLastModified[moduleId]; + } else { try { - mloc = getRascalModuleLocation(qualifiedModuleName, pcfg); + mloc = getRascalModuleLocation(moduleId, ms); return lastModified(mloc); } catch value _: { return startOfEpoch; @@ -156,11 +189,10 @@ datetime getLastModified(str qualifiedModuleName, map[str, datetime] moduleLastM } // Check if a module is modified compared to a given timestamp in BOM -tuple[bool,ModuleStatus] isModuleModified(str qualifiedModuleName, datetime timestamp, PathRole pathRole, ModuleStatus ms){ - qualifiedModuleName = unescape(qualifiedModuleName); +tuple[bool,ModuleStatus] isModuleModified(MID moduleId, datetime timestamp, PathRole pathRole, ModuleStatus ms){ pcfg = ms.pathConfig; try { - mloc = getRascalModuleLocation(qualifiedModuleName, pcfg); + mloc = getRascalModuleLocation(moduleId, ms); bool modifiedChanged = lastModified(mloc) != timestamp; if(pathRole == importPath()){ return ; @@ -169,10 +201,10 @@ tuple[bool,ModuleStatus] isModuleModified(str qualifiedModuleName, datetime time // TODO: in the case of deep extend chains this might become inefficient since we are // yoyo-ing up and down through the extend chains. // Potential solution: maintain set of changed modules in ModuleStatus - = getTModelForModule(qualifiedModuleName, ms, convert=false); + = getTModelForModule(moduleId, ms); if(found && tm.store[key_bom]? && rel[str,datetime,PathRole] bom := tm.store[key_bom]){ for( <- bom){ - = isModuleModified(m, timestampInBom, pathRole, ms); + = isModuleModified(moduleName2moduleId(m), timestampInBom, pathRole, ms); if(mchanged){ return ; } @@ -186,8 +218,9 @@ tuple[bool,ModuleStatus] isModuleModified(str qualifiedModuleName, datetime time } } -bool tplOutdated(str qualifiedModuleName, PathConfig pcfg){ +bool tplOutdated(MID moduleId, PathConfig pcfg){ try { + qualifiedModuleName = moduleId2moduleName(moduleId); mloc = getRascalModuleLocation(qualifiedModuleName, pcfg); = getTPLReadLoc(qualifiedModuleName, pcfg); lmMloc = lastModified(mloc); @@ -202,76 +235,75 @@ bool tplOutdated(str qualifiedModuleName, PathConfig pcfg){ int parseTreeCacheSize = 20; -tuple[bool, Module, ModuleStatus] getModuleParseTree(str qualifiedModuleName, ModuleStatus ms){ +tuple[bool, Module, ModuleStatus] getModuleParseTree(MID moduleId, ModuleStatus ms){ + assert isModuleId(moduleId) : "getModuleParseTree: "; pcfg = ms.pathConfig; - if(ms.parseTrees[qualifiedModuleName]?){ - if(traceParseTreeCache) println("*** using cached parse tree for "); - return ; + qualifiedModuleName = moduleId2moduleName(moduleId); + if(ms.parseTrees[moduleId]?){ + if(traceParseTreeCache) println("*** using cached parse tree for "); + return ; } else { - if(!ms.status[qualifiedModuleName]?){ - ms.status[qualifiedModuleName] = {}; + if(!ms.status[moduleId]?){ + ms.status[moduleId] = {}; } - if(parse_error() notin ms.status[qualifiedModuleName]){ + if(parse_error() notin ms.status[moduleId]){ if(size(ms.parseTreeLIFO) >= parseTreeCacheSize){ ms.parseTrees = delete(ms.parseTrees, ms.parseTreeLIFO[-1]); if(traceParseTreeCache) println("*** deleting parse tree "); ms.parseTreeLIFO = ms.parseTreeLIFO[..-1]; } - ms.parseTreeLIFO = [qualifiedModuleName, *ms.parseTreeLIFO]; - mloc = |unknown:///|; + ms.parseTreeLIFO = [moduleId, *ms.parseTreeLIFO]; + mloc = moduleId; try { - mloc = getRascalModuleLocation(qualifiedModuleName, ms); + mloc = getRascalModuleLocation(moduleId, ms); // Make sure we found a real source module (as opposed to a tpl module in a library - if(isModuleLocationInLibs(qualifiedModuleName, mloc, pcfg)) { - ms.status[qualifiedModuleName] += {rsc_not_found()}; + if(isModuleLocationInLibs(mloc, pcfg)) { + ms.status[moduleId] += {rsc_not_found()}; throw "No src or library module"; } - } catch _: { - ms.messages[qualifiedModuleName] ? {} += {error("Module not found", mloc)}; + } catch e: { + println(e); + ms.messages[moduleId] ? {} += {error("Module not found", mloc)}; mpt = [Module] "module "; - //ms.parseTrees[qualifiedModuleName] = mpt; - ms.moduleLocs[qualifiedModuleName] = mloc; + ms.moduleLocs[moduleId] = mloc; return ; } - if(traceParseTreeCache) println("*** parsing from "); + if(traceParseTreeCache) println("*** parsing from "); try { pt = parseModuleWithSpaces(mloc.top).top; - ms.parseTrees[qualifiedModuleName] = pt; + ms.parseTrees[moduleId] = pt; newLoc = getLoc(pt); - if(qualifiedModuleName in ms.moduleLocs){ - ms = updatePaths(ms.moduleLocs[qualifiedModuleName], newLoc, ms); - } - ms.moduleLocs[qualifiedModuleName] = newLoc; - ms.status[qualifiedModuleName] ? {} += {parsed()}; + ms.moduleLocs[moduleId] = newLoc; + ms.status[moduleId] ? {} += {parsed()}; return ; - } catch _: {//ParseError(loc src): { - ms.messages[qualifiedModuleName] ? {} = {error("Parse error in ", mloc)}; - ms.moduleLocs[qualifiedModuleName] = mloc; - ms.status[qualifiedModuleName] += parse_error(); + } catch ParseError(loc src): { + ms.messages[moduleId] ? {} = {error("Parse error in ", src)}; + ms.moduleLocs[moduleId] = mloc; + ms.status[moduleId] += parse_error(); return ", ms>; } } mpt = [Module] "module "; - ms.parseTrees[qualifiedModuleName] = mpt; + ms.parseTrees[moduleId] = mpt; return ; } } -loc getRascalModuleLocation(str qualifiedModuleName, ModuleStatus ms){ - return qualifiedModuleName in ms.moduleLocs - ? ms.moduleLocs[qualifiedModuleName] - : getRascalModuleLocation(qualifiedModuleName, ms.pathConfig); +loc getRascalModuleLocation(MID moduleId, ModuleStatus ms){ + if(moduleId in ms.moduleLocs){ + loc l = ms.moduleLocs[moduleId]; + if(!isLogicalLoc(l)) return l; + } + return getRascalModuleLocation(moduleId2moduleName(moduleId), ms.pathConfig); } /* * We implement a caching mechanism for TModels with the following properties: * - tmodelCacheSize tmodels are cached. - * - TModels on file (.tpl) physical locations have been replaced by logical locations where possible. - * - When a TModel is read in, physical locations are NOT YET converted by logical logical locations - * and only do that when absolutely needed - * - The policy is to keep TModels in the cache in this unconverted logical form as long as possible. + * - In TModels on file (.tpl) physical locations have been replaced by logical locations where possible. + * - The policy is to always keep TModels in the cache in this logical form. * - During its presence in the cache, the BOM of a TModel may get updated. - * - When a TModel has to be removed from the cache, it is converted back to the logical form (if needed) and written back to file. + * - When a TModel has to be removed from the cache, it is written back to file (if needed). */ int tmodelCacheSize = 30; // should be > 0 @@ -289,39 +321,40 @@ ModuleStatus clearTModelCache(ModuleStatus ms){ return ms; } -rel[str,datetime,PathRole] makeBom(str qualifiedModuleName, ModuleStatus ms){ - map[str,datetime] moduleLastModified = ms.moduleLastModified; +rel[str,datetime,PathRole] makeBom(MID moduleId, ModuleStatus ms){ + map[MID,datetime] moduleLastModified = ms.moduleLastModified; pcfg = ms.pathConfig; - imports = ms.strPaths[qualifiedModuleName,importPath()]; - extends = ms.strPaths[qualifiedModuleName, extendPath()]; - return { < m, getLastModified(m, moduleLastModified, pcfg), importPath() > | m <- imports } - + { < m, getLastModified(m, moduleLastModified, pcfg), extendPath() > | m <- extends } - + { }; + qualifiedModuleName = moduleId2moduleName(moduleId); + imports = ms.paths[moduleId,importPath()]; + extends = ms.paths[moduleId, extendPath()]; + return { < mname, getLastModified(m, ms), importPath() > | m <- imports, mname := moduleId2moduleName(m) } + + { < mname, getLastModified(m, ms), extendPath() > | m <- extends, mname := moduleId2moduleName(m) } + + { }; } -ModuleStatus updateBOM(str qualifiedModuleName, ModuleStatus ms){ - if(rsc_not_found() in ms.status[qualifiedModuleName]){ +ModuleStatus updateBOM(MID moduleId, ModuleStatus ms){ + if(rsc_not_found() in ms.status[moduleId]){ return ms; } - = getTModelForModule(qualifiedModuleName, ms, convert=false); + = getTModelForModule(moduleId, ms); if(found){ - newBom = makeBom(qualifiedModuleName, - ms); + newBom = makeBom(moduleId, ms); if(newBom != tm.store[key_bom]){ tm.store[key_bom] = newBom; - ms.status[qualifiedModuleName] -= tpl_saved(); - ms = addTModel(qualifiedModuleName, tm, ms); + ms.status[moduleId] -= tpl_saved(); + ms = addTModel(moduleId, tm, ms); - if(ms.compilerConfig.logWrittenFiles) println("Updated BOM: "); + if(ms.compilerConfig.logWrittenFiles) println("Updated BOM: "); } } else{ - println("Could not update BOM of "); + println("Could not update BOM of "); } return ms; } -ModuleStatus removeTModel(str candidate, ModuleStatus ms, bool updateBOMneeded = false){ +ModuleStatus removeTModel(MID candidate, ModuleStatus ms, bool updateBOMneeded = false){ + assert isModuleId(candidate) : "removeTModel: "; if(candidate in ms.tmodels && ms.status[candidate]? && tpl_saved() notin ms.status[candidate] && rsc_not_found() notin ms.status[candidate]){ pcfg = ms.pathConfig; if(updateBOMneeded){ @@ -331,8 +364,7 @@ ModuleStatus removeTModel(str candidate, ModuleStatus ms, bool updateBOMneeded = } = getTPLWriteLoc(candidate, pcfg); tm = ms.tmodels[candidate]; - tm.messages = toList(toSet(tm.messages) + ms.messages[candidate]); - tm = convertTModel2LogicalLocs(tm, ms.tmodels); + tm.messages = toList(toSet(tm.messages) + ms.messages[candidate]); // TODO needed ? ms.status[candidate] += tpl_saved(); if(ms.compilerConfig.verbose) println("Saving tmodel for before removing from cache"); try { @@ -357,13 +389,13 @@ ModuleStatus removeOldestTModelFromCache(ModuleStatus ms, bool updateBOMneeded = return ms; } -ModuleStatus addTModel (str qualifiedModuleName, TModel tm, ModuleStatus ms){ - if(traceTModelCache) println("addTModel: "); +ModuleStatus addTModel (MID moduleId, TModel tm, ModuleStatus ms){ + if(traceTModelCache) println("addTModel: "); if(tmodelCacheSize > 0){ - ms.tmodels[qualifiedModuleName] = tm; - if(qualifiedModuleName notin ms.tmodelLIFO){ - ms.tmodelLIFO = [qualifiedModuleName, *ms.tmodelLIFO]; - while(size(ms.tmodels) >= tmodelCacheSize && size(ms.tmodelLIFO) > 0 && ms.tmodelLIFO[-1] != qualifiedModuleName){ + ms.tmodels[moduleId] = tm; + if(moduleId notin ms.tmodelLIFO){ + ms.tmodelLIFO = [moduleId, *ms.tmodelLIFO]; + while(size(ms.tmodels) >= tmodelCacheSize && size(ms.tmodelLIFO) > 0 && ms.tmodelLIFO[-1] != moduleId){ ms = removeOldestTModelFromCache(ms); } } @@ -373,67 +405,52 @@ ModuleStatus addTModel (str qualifiedModuleName, TModel tm, ModuleStatus ms){ private type[TModel] ReifiedTModel = #TModel; // precomputed for efficiency -tuple[bool, TModel, ModuleStatus] getTModelForModule(str qualifiedModuleName, ModuleStatus ms, bool convert = true){ - if(traceTModelCache) println("getTModelForModule: "); +tuple[bool, TModel, ModuleStatus] getTModelForModule(str moduleName, ModuleStatus ms) + = getTModelForModule(moduleName2moduleId(moduleName), ms); + +tuple[bool, TModel, ModuleStatus] getTModelForModule(MID moduleId, ModuleStatus ms){ + assert isModuleId(moduleId) : "getTModelForModule: "; + if(traceTModelCache) println("getTModelForModule: "); pcfg = ms.pathConfig; - if(qualifiedModuleName in ms.tmodels){ - tm = ms.tmodels[qualifiedModuleName]; - if(convert && !tm.usesPhysicalLocs){ - tm = convertTModel2PhysicalLocs(tm); - ms.moduleLocs += tm.moduleLocs; - ms.tmodels[qualifiedModuleName] = tm; - } + if(moduleId in ms.tmodels){ + tm = ms.tmodels[moduleId]; return ; } - while(size(ms.tmodels) >= tmodelCacheSize && size(ms.tmodelLIFO) > 0 && ms.tmodelLIFO[-1] != qualifiedModuleName){ + while(size(ms.tmodels) >= tmodelCacheSize && size(ms.tmodelLIFO) > 0 && ms.tmodelLIFO[-1] != moduleId){ ms = removeOldestTModelFromCache(ms); } - = getTPLReadLoc(qualifiedModuleName, pcfg); + = getTPLReadLoc(moduleId, pcfg); if(found){ if(traceTPL) println("*** reading tmodel "); try { tm = readBinaryValueFile(ReifiedTModel, tplLoc); if(tm.rascalTplVersion? && isValidRascalTplVersion(tm.rascalTplVersion)){ - tm.usesPhysicalLocs = false; // temporary - if(convert){ - tm = convertTModel2PhysicalLocs(tm); + ms.tmodels[moduleId] = tm; + mloc = getRascalModuleLocation(moduleId, ms); + if(isModuleLocationInLibs(mloc, pcfg)){ + ms.status[moduleId] ? {} += {rsc_not_found()}; } - ms.tmodels[qualifiedModuleName] = tm; - mloc = getRascalModuleLocation(qualifiedModuleName, ms); - if(isModuleLocationInLibs(qualifiedModuleName, mloc, pcfg)){ - ms.status[qualifiedModuleName] ? {} += {rsc_not_found()}; - } - ms.status[qualifiedModuleName] ? {} += {tpl_uptodate(), tpl_saved()}; - ms.messages[qualifiedModuleName] = toSet(tm.messages); - ms.tmodelLIFO = [qualifiedModuleName, *ms.tmodelLIFO]; + ms.status[moduleId] ? {} += {tpl_uptodate(), tpl_saved()}; + ms.messages[moduleId] = toSet(tm.messages); + ms.tmodelLIFO = [moduleId, *ms.tmodelLIFO]; return ; } } catch e: { - return : ", tplLoc)]), ms>; + qualifiedModuleName = moduleId2moduleName(moduleId); + return : ", tplLoc)]), ms>; } msg = " has outdated or missing Rascal TPL version (required: )"; println("INFO: )"); throw rascalTplVersionError(msg); } + qualifiedModuleName = moduleId2moduleName(moduleId); return ", tplLoc)]), ms>; } -rel[str from, PathRole r, str to] getStrPaths(rel[loc from, PathRole r, loc to] paths, PathConfig pcfg){ - strPaths = {}; - for( <- paths){ - try { - mfrom = getRascalModuleName(from, pcfg); - mto = getRascalModuleName(to, pcfg); - strPaths += ; - } catch _: ;/* ignore non-existing module */ - } - return strPaths; -} - -rel[loc from, PathRole r, loc to] getPaths(rel[str from, PathRole r, str to] strPaths, ModuleStatus ms){ +rel[loc from, PathRole r, loc to] getPaths(rel[MID from, PathRole r, MID to] paths, ModuleStatus ms){ paths = {}; - for( <- strPaths){ + for( <- paths){ try { mfrom = getRascalModuleLocation(from, ms); mto = getRascalModuleLocation(to, ms); @@ -443,42 +460,6 @@ rel[loc from, PathRole r, loc to] getPaths(rel[str from, PathRole r, str to] str return paths; } -// Update locations in paths when new module locations is known -ModuleStatus updatePaths(loc oldModuleLoc, loc newModuleLoc, ModuleStatus ms){ - if(oldModuleLoc == newModuleLoc) return ms; - ms.paths = visit(ms.paths){ case oldModuleLoc => newModuleLoc }; - return ms; -} - -ModuleStatus consolidatePaths(ModuleStatus ms){ - set[loc] locs = {lc| /loc lc := ms.paths}; - map[loc,loc] lprops = (); - rel[loc,PathRole,loc] paths = ms.paths; - for(loc l <- locs){ - if(l.top in lprops && loc r := lprops[l.top] && r != l){ - if(l.length? && !r.length?){ - paths = visit(paths) { case r: { insert l; }}; - } else if(!l.length? && r.length?){ - paths = visit(paths) { case l: { insert r; }}; - } else { - mname = getRascalModuleName(l, ms.pathConfig); - causes = [info("Module location for : ", x) | x <- [l, r]]; - ms.messages[mname] ? {} += { error("Conflicting module locations found for ", l, causes=causes) }; - } - } - lprops[l.top] = l; - } - ms.paths = paths; - - // strPaths = getStrPaths(ms.paths, ms.pathConfig); - // if(strPaths != ms.strPaths){ - // println("ms.strPaths:"); iprintln(ms.strPaths); - // println("ms.paths:"); iprintln(ms.paths); - // throw "ms.strPaths and ms.paths are incompatible"; - // } - return ms; -} - int closureCounter = 0; int nextClosure(){ diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc index 2e7d0ac7ea8..3c2f1638da0 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc @@ -55,41 +55,40 @@ import lang::rascalcore::compile::util::Names; // TODO: refactor, this is an und ModuleStatus reportSelfImport(rel[loc, PathRole, loc] paths, ModuleStatus ms){ for( <- paths){ - mname = getRascalModuleName(from, ms.pathConfig); - ms.messages[mname] ? {} += {error("Self import not allowed", from)}; - ms.status[mname] ? {} += {check_error()}; + // mname = getRascalModuleName(from, ms.pathConfig); + ms.messages[from] ? {} += {error("Self import not allowed", from)}; + ms.status[from] ? {} += {check_error()}; } return ms; } -ModuleStatus reportCycles(rel[loc, PathRole, loc]paths, rel[loc,loc] extendPlus, ModuleStatus ms){ +ModuleStatus reportCycles(rel[MID, PathRole, MID]paths, rel[MID,MID] extendPlus, ModuleStatus ms){ extendCycle = { m | <- extendPlus }; if(size(extendCycle) > 0){ - for(mloc <- extendCycle){ - mname = getRascalModuleName(mloc, ms.pathConfig); - causes = [ info("Part of extend cycle ", eloc) | eloc <- extendCycle ]; - ms.messages[mname] ? {} += {error("Extend cycle not allowed", mloc, causes=causes)}; - ms.status[mname] ? {} += {check_error()}; + for(mid <- extendCycle){ + mname = getRascalModuleName(mid, ms.pathConfig); + causes = [ info("Part of extend cycle ", emid) | emid <- extendCycle ]; + ms.messages[mid] ? {} += {error("Extend cycle not allowed", mid, causes=causes)}; + ms.status[mid] ? {} += {check_error()}; } } pathsPlus = { | <- paths}+; - cyclicMixed = { mloc1, mloc2 - | <- pathsPlus, mloc1 != mloc2, - ( in paths && in paths - || in paths && in paths + cyclicMixed = { mid1, mid2 + | <- pathsPlus, mid1 != mid2, + ( in paths && in paths + || in paths && in paths ) }; - for(mloc <- cyclicMixed){ - set[loc] cycle = { mloc2 | <- pathsPlus, mloc1 == mloc, mloc2 in cyclicMixed } + - { mloc1 | <- pathsPlus, mloc2 == mloc , mloc1 in cyclicMixed }; + for(mid <- cyclicMixed){ + set[loc] cycle = { mid2 | <- pathsPlus, mid1 == mid, mid2 in cyclicMixed } + + { mid1 | <- pathsPlus, mid2 == mid , mid1 in cyclicMixed }; if(size(cycle) > 0){ - mname = getRascalModuleName(mloc, ms.pathConfig); causes = [ info("Part of mixed import/extend cycle ", eloc) | eloc <- cycle ]; - ms.messages[mname] ? {} += { error("Mixed import/extend cycle not allowed", mloc, causes=causes) }; - ms.status[mname] ? {} += {check_error()}; + ms.messages[mid] ? {} += { error("Mixed import/extend cycle not allowed", mid, causes=causes) }; + ms.status[mid] ? {} += {check_error()}; } } return ms; @@ -100,119 +99,118 @@ ModuleStatus reportCycles(rel[loc, PathRole, loc]paths, rel[loc,loc] extendPlus, //- by checking circular dependencies // TODO: reuse enhancePathRelation from RascalConfig here ModuleStatus completeModuleStatus(ModuleStatus ms){ - ms = consolidatePaths(ms); - paths = ms.paths + getPaths(ms.strPaths, ms); + paths = ms.paths; ms = reportSelfImport(paths, ms); - imports = { | <- paths}; - extendPlus = { | <- paths}+; - paths += { | <- extendPlus }; + imports = { | <- paths}; + extendPlus = { | <- paths}+; + paths += { | <- extendPlus }; ms = reportCycles(paths, extendPlus, ms); paths += { *{ | a <- extendPlus[b], c != a} - | < loc c, loc b> <- imports + | < MID c, MID b> <- imports }; - ms.paths = paths; // sync ms.paths with paths - ms.strPaths = getStrPaths(ms.paths, ms.pathConfig); // sync ms.strPaths with ms.paths - + ms.paths = paths; return ms; } -ModuleStatus getImportAndExtendGraph(set[str] qualifiedModuleNames, RascalCompilerConfig ccfg){ - return completeModuleStatus((newModuleStatus(ccfg) | getImportAndExtendGraph(qualifiedModuleName, it) | qualifiedModuleName <- qualifiedModuleNames)); +ModuleStatus getImportAndExtendGraph(set[MID] moduleIds, RascalCompilerConfig ccfg){ + return completeModuleStatus((newModuleStatus(ccfg) | getImportAndExtendGraph(moduleId, it) | moduleId <- moduleIds)); } -ModuleStatus getImportAndExtendGraph(set[str] qualifiedModuleNames, ModuleStatus ms){ - return completeModuleStatus((ms | getImportAndExtendGraph(qualifiedModuleName, it) | qualifiedModuleName <- qualifiedModuleNames)); +ModuleStatus getImportAndExtendGraph(set[MID] moduleIds, ModuleStatus ms){ + return completeModuleStatus((ms | getImportAndExtendGraph(moduleId, it) | moduleId <- moduleIds)); } -ModuleStatus getImportAndExtendGraph(str qualifiedModuleName, RascalCompilerConfig ccfg){ - return completeModuleStatus(getImportAndExtendGraph(qualifiedModuleName, newModuleStatus(ccfg))); +ModuleStatus getImportAndExtendGraph(MID moduleId, RascalCompilerConfig ccfg){ + return completeModuleStatus(getImportAndExtendGraph(moduleId, newModuleStatus(ccfg))); } -ModuleStatus getImportAndExtendGraph(str qualifiedModuleName, ModuleStatus ms){ -//println("getImportAndExtendGraph: "); +ModuleStatus getImportAndExtendGraph(MID moduleId, ModuleStatus ms){ + assert isModuleId(moduleId): "getImportAndExtendGraph: "; pcfg = ms.pathConfig; - qualifiedModuleName = unescape(qualifiedModuleName); + qualifiedModuleName = moduleId2moduleName(moduleId); - if(!ms.status[qualifiedModuleName]?){ - ms.status[qualifiedModuleName] = {}; + if(!ms.status[moduleId]?){ + ms.status[moduleId] = {}; } - if(module_dependencies_extracted() in ms.status[qualifiedModuleName]){ + if(module_dependencies_extracted() in ms.status[moduleId]){ return ms; } - ms.status[qualifiedModuleName] += module_dependencies_extracted(); + ms.status[moduleId] += module_dependencies_extracted(); - = getTModelForModule(qualifiedModuleName, ms, convert=true); + = getTModelForModule(moduleId, ms); if(found){ allImportsAndExtendsValid = true; - rel[str, PathRole] localImportsAndExtends = {}; + rel[loc, PathRole] localImportsAndExtends = {}; - if(!ms.moduleLastModified[qualifiedModuleName]?){ - ms.moduleLastModified[qualifiedModuleName] = getLastModified(qualifiedModuleName, ms.moduleLastModified, pcfg); + if(!ms.moduleLastModified[moduleId]?){ + ms.moduleLastModified[moduleId] = getLastModified(moduleId, ms); } if(tm.store[key_bom]? && rel[str,datetime,PathRole] bom := tm.store[key_bom]){ for( <- bom){ - if(!ms.status[m]?){ - ms.status[m] = {}; + mid = moduleName2moduleId(m); + if(!ms.status[mid]?){ + ms.status[mid] = {}; } - if(m != qualifiedModuleName){ - localImportsAndExtends += ; + if(mid != moduleId){ + localImportsAndExtends += ; } - dependencyChanged = (m != qualifiedModuleName) && !isEmpty(ms.changedModules & range(ms.strPaths[m])); + dependencyChanged = (mid != moduleId) && !isEmpty(ms.changedModules & range(ms.paths[mid])); //if(dependencyChanged) println("processing BOM of and consider , dependencyChanged: "); - = isModuleModified(m, timestampInBom, pathRole, ms); + = isModuleModified(mid, timestampInBom, pathRole, ms); if(dependencyChanged || mchanged){ allImportsAndExtendsValid = false; - ms.status[m] += rsc_changed(); - ms.status[m] -= {tpl_uptodate(), checked()}; - ms.status[qualifiedModuleName] -= tpl_saved(); - ms.messages[qualifiedModuleName] = {}; + ms.status[mid] += rsc_changed(); + ms.status[mid] -= {tpl_uptodate(), checked()}; + ms.status[moduleId] -= tpl_saved(); + ms.messages[moduleId] = {}; if(ms.compilerConfig.verbose){ - println("--- using (most recent) version of , - ' older version was used in previous check of "); + println("--- using (most recent) version of , + ' older version was used in previous check of "); } } } } else { - throw "No bill-of-materials found for "; + throw "No bill-of-materials found for "; } if(!allImportsAndExtendsValid){ // Check that the source code of qualifiedModuleName is available mloc = |unknown:///|(0,0,<0,0>,<0,0>); try { try { - mloc = getRascalModuleLocation(qualifiedModuleName, ms); + mloc = getRascalModuleLocation(moduleId, ms); } catch Message err: { - ms.messages[qualifiedModuleName] = { err }; - tm = tmodel(modelName=qualifiedModuleName, messages=[ err ]); - ms = addTModel(qualifiedModuleName, tm, ms); - ms.status[qualifiedModuleName] += { rsc_not_found() }; + ms.messages[moduleId] = { err }; + tm = tmodel(modelName=moduleId2moduleName(moduleId), messages=[ err ]); + ms = addTModel(moduleId, tm, ms); + ms.status[moduleId] += { rsc_not_found() }; return ms; } - if(mloc.extension != "rsc" || isModuleLocationInLibs(qualifiedModuleName, mloc, pcfg)) throw "No src or library module 1"; //There is only a tpl file available + if(!isLogicalLoc(mloc) && (mloc.extension != "rsc" || isModuleLocationInLibs(mloc, pcfg))) throw "No src or library module 1"; //There is only a tpl file available } catch value _:{ = isCompatibleBinaryLibrary(tm, ms); + incompatibleNames = [ getModuleNameFromAnyLogical(imod) | MID imod <- incompatible ]; if(!isEmpty(incompatible)){ - causes = [ info("Module is incompatible with ", getRascalModuleLocation(iname, ms)) | iname <- incompatible ]; - txt = "Review of dependencies, reconfiguration or recompilation needed: binary module `` depends (indirectly) on incompatible module(s) "; + causes = [ info("Module is incompatible with ", incomp) | incomp <- incompatible ]; + txt = "Review of dependencies, reconfiguration or recompilation needed: binary module `` depends (indirectly) on incompatible module(s) "; msg = error(txt, mloc, causes=causes); tm.messages += [msg]; - ms.messages[qualifiedModuleName] ? {} += { msg }; + ms.messages[moduleId] ? {} += { msg }; txt2 = "Review of dependencies, reconfiguration or recompilation needed: imported/extended binary module `` depends (indirectly) on incompatible module(s)"; - usingModules = {user | <- ms.strPaths<0,2>*}; + usingModules = {user | <- ms.paths<0,2>*}; for(user <- usingModules){ mloc = getRascalModuleLocation(user, ms); - if(!isModuleLocationInLibs(user, mloc, pcfg)){ + if(!isModuleLocationInLibs(mloc, pcfg)){ msg2 = error(txt2, mloc, causes=causes); ms.messages[user] ? {} += { msg2 }; } @@ -226,12 +224,12 @@ ModuleStatus getImportAndExtendGraph(str qualifiedModuleName, ModuleStatus ms){ } } if(allImportsAndExtendsValid){ - ms.status[qualifiedModuleName] += {tpl_uptodate(), checked()}; //TODO: maybe check existence of generated java files - ms.moduleLocs += tm.moduleLocs; + ms.status[moduleId] += {tpl_uptodate(), checked()}; //TODO: maybe check existence of generated java files + ms.moduleLocs += (moduleName2moduleId(mname) : tm.moduleLocs[mname] | mname <- tm.moduleLocs); // TODO: or not? ms.paths += tm.paths; - ms.strPaths += { | <- localImportsAndExtends }; - ms.status[qualifiedModuleName] += module_dependencies_extracted(); - ms.messages[qualifiedModuleName] ? {} += toSet(tm.messages); + // ms.strPaths += { | <- localImportsAndExtends }; + ms.status[moduleId] += module_dependencies_extracted(); + ms.messages[moduleId] ? {} += toSet(tm.messages); for( <- localImportsAndExtends, isEmpty({module_dependencies_extracted()} & ms.status[imp]) ){ ms.status[imp] -= tpl_saved(); ms = getImportAndExtendGraph(imp, ms); @@ -240,20 +238,19 @@ ModuleStatus getImportAndExtendGraph(str qualifiedModuleName, ModuleStatus ms){ } } - if(rsc_not_found() in ms.status[qualifiedModuleName]){ + if(rsc_not_found() in ms.status[moduleId]){ return ms; } - = getModuleParseTree(qualifiedModuleName, ms); + = getModuleParseTree(moduleId, ms); if(success){ - = getModulePathsAsStr(pt, ms); + = getModulePaths(pt, ms); for(<_, kind, imp> <- imports_and_extends, rsc_not_found() notin ms.status[imp]){ - ms.strPaths += {}; ms = getImportAndExtendGraph(imp, ms); } } else { - ms.status[qualifiedModuleName] += rsc_not_found(); + ms.status[moduleId] += rsc_not_found(); } return ms; @@ -266,23 +263,23 @@ ModuleStatus getInlineImportAndExtendGraph(Tree pt, RascalCompilerConfig ccfg){ header = m.header; body = m.body; qualifiedModuleName = prettyPrintName(header.name); - ms.moduleLocs[qualifiedModuleName] = getLoc(m); - = getModulePathsAsStr(m, ms); + ms.moduleLocs[moduleName2moduleId(qualifiedModuleName)] = getLoc(m); + = getModulePaths(m, ms); } } return completeModuleStatus(ms); } // Is binary library module compatible with its dependencies (originating from imports and extends)? -tuple[list[str], ModuleStatus] isCompatibleBinaryLibrary(TModel lib, ModuleStatus ms){ +tuple[list[MID], ModuleStatus] isCompatibleBinaryLibrary(TModel lib, ModuleStatus ms){ libName = lib.modelName; set[loc] libLogical = domain(lib.logical2physical); - set[loc] libDefines = { l | l <- libLogical, getModuleFromLogical(l) == libName }; + set[loc] libDefines = { l | l <- libLogical, getModuleNameFromAnyLogical(l) == libName }; set[loc] libDependsOn = libLogical - libDefines; - set[str] libDependsOnModules = { getModuleFromLogical(l) | l <- libDependsOn }; + set[str] libDependsOnModules = { getModuleNameFromAnyLogical(l) | l <- libDependsOn }; set[loc] dependentsProvide = {}; for(m <- libDependsOnModules){ - = getTModelForModule(m, ms, convert=false); + = getTModelForModule(m, ms); if(found){ dependentsProvide += domain(tm.logical2physical); } @@ -301,33 +298,33 @@ tuple[list[str], ModuleStatus] isCompatibleBinaryLibrary(TModel lib, ModuleStatu "); println("isCompatibleBinaryLibrary, unsatisfied ()"); - incompatibleModules = { getModuleFromLogical(u) | u <- unsatisfied }; - return ; + //incompatibleModuleNames = { moduleId2moduleName(u) | u <- unsatisfied }; + return ; } } // Example: |rascal+function:///util/Math/round$d80e373d64c01979| ==> util::Math // Example: |rascal+module:///lang/rascal/syntax/Rascal| -> lang::rascal::syntax::Rascal -str getModuleFromLogical(loc l){ +str getModuleNameFromAnyLogical(loc l){ i = findLast(l.path[1..], "/"); res = (l.scheme == "rascal+module" || i < 0) ? l.path[1..] : l.path[1..i+1]; res = replaceAll(res, "/", "::"); - //println("getModuleFromLogical: -\> "); + //println("getModuleNameFromAnyLogical: -\> "); return res; } -tuple[bool, ModuleStatus] importsAndExtendsAreBinaryCompatible(TModel tm, set[str] importsAndExtends, ModuleStatus ms){ +tuple[bool, ModuleStatus] importsAndExtendsAreBinaryCompatible(TModel tm, set[MID] importsAndExtends, ModuleStatus ms){ moduleName = tm.modelName; physical2logical = invertUnique(tm.logical2physical); modRequires = { lg | l <- range(tm.useDef), physical2logical[l]?, lg := physical2logical[l], - moduleName !:= getModuleFromLogical(lg) }; + moduleName !:= getModuleNameFromAnyLogical(lg) }; provided = {}; if(!isEmpty(modRequires)){ for(m <- importsAndExtends){ - = getTModelForModule(m, ms, convert=false); + = getTModelForModule(m, ms); if(found){ provided += domain(tm.logical2physical); } @@ -345,23 +342,25 @@ tuple[bool, ModuleStatus] importsAndExtendsAreBinaryCompatible(TModel tm, set[st } } -tuple[ModuleStatus, rel[str, PathRole, str]] getModulePathsAsStr(Module m, ModuleStatus ms){ +tuple[ModuleStatus, rel[loc, PathRole, loc]] getModulePaths(Module m, ModuleStatus ms){ moduleName = unescape(""); + MID moduleId = moduleName2moduleId(moduleName); imports_and_extends = {}; for(imod <- m.header.imports, imod has \module){ iname = unescape(""); - imports_and_extends += ; - ms.status[iname] = ms.status[iname] ? {}; - try { - mloc = getRascalModuleLocation(iname, ms); - ms.paths += {}; - } catch Message err: { - err.at = imod@\loc; - ms.messages[moduleName] ? {} += { err }; - ms.status[iname] += { rsc_not_found() }; - } + inameId = moduleName2moduleId(iname); + imports_and_extends += ; + ms.status[inameId] = ms.status[inameId] ? {}; + // try { + // // mloc = getRascalModuleLocation(iname, ms); + // ms.paths += {}; + // } catch Message err: { + // err.at = imod@\loc; + // ms.messages[moduleId] ? {} += { err }; + // ms.status[inameId] += { rsc_not_found() }; + // } } - ms.strPaths += imports_and_extends; + ms.paths += imports_and_extends; return ; } @@ -370,46 +369,45 @@ tuple[ModuleStatus, rel[str, PathRole, str]] getModulePathsAsStr(Module m, Modul map[str, loc] getModuleScopes(TModel tm) = (id: defined | <- tm.defines); -loc getModuleScope(str qualifiedModuleName, map[str, loc] moduleScopes, PathConfig pcfg){ - if(moduleScopes[qualifiedModuleName]?){ - return moduleScopes[qualifiedModuleName]; - } - for(l <- range(moduleScopes)){ - if(getRascalModuleName(l, pcfg) == qualifiedModuleName){ - return l; - } - } - throw "No module scope found for "; -} - -tuple[map[str,TModel], ModuleStatus] prepareForCompilation(set[str] component, map[str,set[str]] m_imports, map[str,set[str]] m_extends, ModuleStatus ms, map[str,loc] moduleScopes, TModel tm){ +// loc getModuleScope(str qualifiedModuleName, map[str, loc] moduleScopes, PathConfig pcfg){ +// if(moduleScopes[qualifiedModuleName]?){ +// return moduleScopes[qualifiedModuleName]; +// } +// for(l <- range(moduleScopes)){ +// if(getRascalModuleName(l, pcfg) == qualifiedModuleName){ +// return l; +// } +// } +// throw "No module scope found for "; +// } + +tuple[map[MID,TModel], ModuleStatus] prepareForCompilation(set[MID] component, map[MID,set[MID]] m_imports, map[MID,set[MID]] m_extends, ModuleStatus ms, TModel tm){ //map[str,TModel] tmodels = (); //ms.tmodels; pcfg = ms.pathConfig; dependencies_ok = true; for(m <- component, rsc_not_found() notin ms.status[m], MStatus::ignored() notin ms.status[m]){ if(parse_error() in ms.status[m]){ - return <(m : tmodel(modelName=m,messages=toList(ms.messages[m]))) ,ms>; + return <(m : tmodel(modelName=moduleId2moduleName(m),messages=toList(ms.messages[m]))) ,ms>; } for(imp <- m_imports[m] + m_extends[m], rsc_not_found() notin ms.status[imp], MStatus::ignored() notin ms.status[m]){ imp_status = ms.status[imp]; if(parse_error() in imp_status || checked() notin imp_status){ dependencies_ok = false; cause = (rsc_not_found() in imp_status) ? "module not found" : "due to syntax error"; - ms.messages[m] = (ms.messages[imp] ? {}) + error(" module could not be checked ()", moduleScopes[m]); + ms.messages[m] = (ms.messages[imp] ? {}) + error(" module could not be checked ()", m); } } if(!dependencies_ok){ - return <(m: tmodel(modelName=m,messages=toList(ms.messages[m]))), ms>; + return <(m: tmodel(modelName=moduleId2moduleName(m),messages=toList(ms.messages[m]))), ms>; } } transient_tms = (m : tm | m <- component); org_tm = tm; - for(m <- component, rsc_not_found() notin ms.status[m], MStatus::ignored() notin ms.status[m]){ + for(MID m <- component, rsc_not_found() notin ms.status[m], MStatus::ignored() notin ms.status[m]){ tm = org_tm; - tm.modelName = m; - mScope = getModuleScope(m, moduleScopes, pcfg); - tm.moduleLocs = (m : mScope); + mname = moduleId2moduleName(m); + tm.modelName = mname; tm.definitions = ( def.defined : def | Define def <- tm.defines); @@ -421,61 +419,61 @@ tuple[map[str,TModel], ModuleStatus] prepareForCompilation(set[str] component, m return ; } -ModuleStatus doSaveModule(set[str] component, map[str,set[str]] m_imports, map[str,set[str]] m_extends, ModuleStatus ms, map[str,loc] moduleScopes, map[str, TModel] transient_tms, RascalCompilerConfig compilerConfig){ +ModuleStatus doSaveModule(set[MID] component, map[MID,set[MID]] m_imports, map[MID,set[MID]] m_extends, ModuleStatus ms, map[MID, TModel] transient_tms, RascalCompilerConfig compilerConfig){ pcfg = ms.pathConfig; component = { m | m <- component, MStatus::ignored() notin ms.status[m] }; if(isEmpty(component)) return ms; //println("doSaveModule: , , , "); - component_scopes = { getModuleScope(qualifiedModuleName, moduleScopes, pcfg) | qualifiedModuleName <- component }; - set[loc] filteredModuleScopes = {}; + component_scopes = component; //{ getModuleScope(mid, moduleScopes, pcfg) | MID mid <- component }; + set[MID] filteredModuleScopes = {}; loc2moduleName = invertUnique(ms.moduleLocs); - bool isContainedInComponentScopes(loc inner){ - return any(cs <- component_scopes, isContainedIn(inner, cs)); + bool isContainedInComponentScopes(loc inner, map[loc,loc] m){ + return any(cs <- component_scopes, isContainedIn(inner, cs, m)); }; - bool isContainedInFilteredModuleScopes(loc inner){ - return any(cs <- filteredModuleScopes, isContainedIn(inner, cs)); + bool isContainedInFilteredModuleScopes(loc inner, map[loc,loc] m){ + return any(cs <- filteredModuleScopes, isContainedIn(inner, cs, m)); }; - for(qualifiedModuleName <- component){ + for(currentModule <- component){ start_save = cpuTime(); - tm = transient_tms[qualifiedModuleName]; - mscope = getModuleScope(qualifiedModuleName, moduleScopes, pcfg); - = getTPLWriteLoc(qualifiedModuleName, pcfg); + tm = transient_tms[currentModule]; + = getTPLWriteLoc(currentModule, pcfg); - imports = m_imports[qualifiedModuleName]; - extends = m_extends[qualifiedModuleName]; + imports = m_imports[currentModule]; + extends = m_extends[currentModule]; - bom = makeBom(qualifiedModuleName, ms); + bom = makeBom(currentModule, 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 = {m | MID m <- extends, checked() in ms.status[m]}; + extendedModuleScopes += {*tm.paths[ems,importPath()] | MID ems <- extendedModuleScopes}; // add imports of extended modules + filteredModuleScopes = {m | MID m <- (currentModule + imports), checked() in ms.status[m]} + extendedModuleScopes; TModel m1 = tmodel(); m1.rascalTplVersion = compilerConfig.rascalTplVersion; - m1.modelName = qualifiedModuleName; - m1.moduleLocs = (qualifiedModuleName : mscope); + m1.modelName = moduleId2moduleName(currentModule); + m1.moduleLocs = (m1.modelName : currentModule); - m1.facts = (key : tm.facts[key] | key <- tm.facts, isContainedInFilteredModuleScopes(key)); + m1.facts = (key : tm.facts[key] | key <- tm.facts, isContainedInFilteredModuleScopes(key, tm.logical2physical)); - m1.specializedFacts = (key : tm.specializedFacts[key] | key <- tm.specializedFacts, isContainedInComponentScopes(key), any(fms <- filteredModuleScopes, isContainedIn(key, fms))); + m1.specializedFacts = (key : tm.specializedFacts[key] | key <- tm.specializedFacts, isContainedInComponentScopes(key, tm.logical2physical), any(fms <- filteredModuleScopes, isContainedIn(key, fms))); m1.facts += m1.specializedFacts; - m1.messages = [ msg | msg <- tm.messages, msg.at.path == mscope.path || msg is error ]; - ms.messages[qualifiedModuleName] = toSet(m1.messages); + // m1.messages = [ msg | msg <- tm.messages, msg.at.path == currentModule.path || msg is error ]; + m1.messages = tm.messages; + ms.messages[currentModule] = toSet(m1.messages); filteredModuleScopePaths = {ml.path |loc ml <- filteredModuleScopes}; - - m1.scopes - = ( inner : tm.scopes[inner] - | loc inner <- tm.scopes, - inner.path in filteredModuleScopePaths, - isContainedInComponentScopes(inner) - ); + m1.scopes = tm.scopes; + // m1.scopes + // = ( inner : tm.scopes[inner] + // | loc inner <- tm.scopes, + // inner.path in filteredModuleScopePaths, + // (tm.scopes[inner] == |global-scope:///| || isContainedInComponentScopes(inner, tm.logical2physical)) + // ); m1.store = (key_bom : bom); @@ -487,23 +485,23 @@ ModuleStatus doSaveModule(set[str] component, map[str,set[str]] m_imports, map[s 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[MID from, PathRole pathRole, MID to] tup <- tm.paths, tup.from == currentModule || tup.from in filteredModuleScopes /*|| tup.from in filteredModuleScopePaths*/ }; keepRoles = variableRoles + keepInTModelRoles; m1.useDef = { | <- tm.useDef, - isContainedIn(u, mscope) + isContainedIn(u, currentModule, tm.logical2physical) || (tm.definitions[d]? && tm.definitions[d].idRole in keepRoles) }; // Filter model for current module and replace functions in defType by their defined type defs = for(tup: <- tm.defines){ - if( ( idRole in variableRoles ? ( isContainedInComponentScopes(defined) + if( ( idRole in variableRoles ? ( isContainedInComponentScopes(defined, tm.logical2physical) ) : ( idRole in keepInTModelRoles - && ( isContainedInComponentScopes(defined) - || isContainedInFilteredModuleScopes(defined) + && ( isContainedInComponentScopes(defined, tm.logical2physical) + || isContainedInFilteredModuleScopes(defined, tm.logical2physical) ) ) ) @@ -520,12 +518,10 @@ ModuleStatus doSaveModule(set[str] component, map[str,set[str]] m_imports, map[s case kwField(AType atype, str fieldName, str definingModule, Expression _defaultExp) => kwField(atype, fieldName, definingModule) case loc l : if(!isEmpty(l.fragment)) insert l[fragment=""]; }; - log2phys = tm.logical2physical; m1.logical2physical = tm.logical2physical; - m1.usesPhysicalLocs = true; - ms.status[qualifiedModuleName] -= {tpl_saved()}; - ms = addTModel(qualifiedModuleName, m1, ms); - // println("TModel for :"); iprintln(m1); + ms.status[currentModule] -= {tpl_saved()}; + ms = addTModel(currentModule, m1, ms); + // println("TModel for :"); iprintln(m1); } return ms; } \ No newline at end of file diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/ModuleLocations.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/ModuleLocations.rsc index d69f92cafb1..02f5701baf5 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/ModuleLocations.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/ModuleLocations.rsc @@ -57,6 +57,7 @@ loc getSearchPathLoc(str filePath, PathConfig pcfg){ @synopsis{Get the location of a named module, search for `src` in srcs and `tpl` in libs} loc getRascalModuleLocation(str qualifiedModuleName, PathConfig pcfg){ + fileName = makeFileName(qualifiedModuleName, extension="rsc"); for(loc dir <- pcfg.srcs){ fileLoc = dir + fileName; diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc index 8031643e163..432433fc99f 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc @@ -40,7 +40,7 @@ import lang::rascalcore::check::CheckerCommon; import lang::rascalcore::check::BasicRascalConfig; import lang::rascalcore::check::ModuleLocations; -import Location; +import LogicalLocation; import util::FileSystem; import util::Reflective; import lang::rascalcore::compile::util::Names; @@ -134,23 +134,23 @@ set[IdRole] defBeforeUseRoles = {variableId(), moduleVariableId(), formalId(), k Accept rascalIsAcceptableSimple(loc def, Use use, Solver s){ //println("rascalIsAcceptableSimple: *** *** def=, use="); Define d = s.getDefine(def); - if(isBefore(use.occ, def)){ + if(s.isBefore(use.occ, def)){ if(moduleVariableId() == d.idRole){ // Module variables should adhere to def before use, unless they are used inside a function. for(some_def <- s.getAllDefines(), some_def.idRole == functionId()){ - if(isContainedIn(use.occ, some_def.defined)){ + if(s.isContainedIn(use.occ, some_def.defined)){ return acceptBinding(); } } return ignoreContinue(); } else if(!isEmpty(use.idRoles & defBeforeUseRoles) // If we encounter a use before def - && isContainedIn(def, use.scope) // in an idRole that requires def before use + && s.isContainedIn(def, use.scope) // in an idRole that requires def before use ){ // and the definition is in the same scope as the use // then only allow this when inside explicitly defined areas (typically the result part of a comprehension) if(lrel[loc,loc] allowedParts := s.getStack(key_allow_use_before_def)){ list[loc] parts = allowedParts[use.scope]; - return !isEmpty(parts) && any(part <- parts, isContainedIn(use.occ, part)) ? acceptBinding() : ignoreContinue(); + return !isEmpty(parts) && any(part <- parts, s.isContainedIn(use.occ, part)) ? acceptBinding() : ignoreContinue(); } else { throw "Inconsistent value stored for : "; } @@ -158,7 +158,7 @@ Accept rascalIsAcceptableSimple(loc def, Use use, Solver s){ } // Uses of a keyword formal inside its initializing expression are rejected - if(d.idRole == keywordFormalId() && isContainedIn(use.occ, d.defined)){ + if(d.idRole == keywordFormalId() && s.isContainedIn(use.occ, d.defined)){ return ignoreContinue(); } return acceptBinding(); @@ -166,16 +166,22 @@ Accept rascalIsAcceptableSimple(loc def, Use use, Solver s){ Accept rascalIsAcceptableQualified(loc def, Use use, Solver s){ // println("rascalIsAcceptableQualified: , "); - atype = s.getType(def); + + // defPath = def.path; + // qualAsPath = replaceAll(use.ids[0], "::", "/") + ".rsc"; - defPath = def.path; - qualAsPath = replaceAll(use.ids[0], "::", "/") + ".rsc"; + path = def.path; + if(path[0] == "/") path = path[1..]; + defPath = split("/", path)[0..-1]; + qualAsPath = split("::", use.ids[0]); // qualifier and proposed definition are the same? - if(endsWith(defPath, qualAsPath)){ + if(defPath == qualAsPath){ + // if(endsWith(defPath, qualAsPath)){ return acceptBinding(); } + atype = s.getType(def); // Qualifier is a ADT name? if(acons(aadt(adtName, _, _), list[AType] _fields, list[Keyword] _kwFields) := atype){ @@ -192,7 +198,7 @@ Accept rascalIsAcceptableQualified(loc def, Use use, Solver s){ extendedStarBy = { | <- s.getPaths()}*; - if(!isEmpty(extendedStarBy) && any(p <- extendedStarBy[defPath]?{}, endsWith(p, defPath))){ + if(!isEmpty(extendedStarBy) && any(p <- extendedStarBy[path]?{}, endsWith(p, path))){ //TODO check this return acceptBinding(); } @@ -316,7 +322,7 @@ bool rascalReportUnused(loc def, TModel tm){ if(!definitions[def]? || !tm.moduleLocs[tm.modelName]?) return false; - if(!isContainedIn(definitions[def].defined, tm.moduleLocs[tm.modelName])){ + if(!isContainedIn(definitions[def].defined, tm.moduleLocs[tm.modelName], tm.logical2physical)){ return false; } @@ -377,13 +383,13 @@ bool rascalReportUnused(loc def, TModel tm){ // Extend the path relation by // - adding transitive edges for extend // - adding imports via these extends -rel[loc, PathRole,loc] enhancePathRelation(rel[loc, PathRole,loc] paths){ - extendPlus = { | <- paths}+; - paths += { | <- extendPlus}; +rel[loc, PathRole,loc] enhancePathRelation(rel[MID, PathRole,MID] paths){ + extendPlus = { | <- paths}+; + paths += { | <- extendPlus}; - imports = { | <- paths}; + imports = { | <- paths}; delta = { - | <- extendPlus o imports, + | <- extendPlus o imports, notin paths, from != to2 }; @@ -471,8 +477,8 @@ void checkOverloading(map[str,Tree] namedTrees, Solver s){ allDefs = { d.defined | d <- defs }; for(d1 <- defs, d2 <- defs, d1.defined != d2.defined, - t1 := facts[d1.defined]?acons(aadt("***DUMMY***", [], dataSyntax()),[],[]), - t2 := facts[d2.defined]?acons(aadt("***DUMMY***", [], dataSyntax()),[],[]), + d1.defined in facts, t1 := facts[d1.defined], + d2.defined in facts, t2 := facts[d2.defined], comparableList(t1.fields, t2.fields), ! (isSyntaxType(t1) && isSyntaxType(t2))){ @@ -529,7 +535,7 @@ void rascalPostSolver(map[str,Tree] namedTrees, Solver s){ // bool isLogicalLoc(loc l) // = startsWith(l.scheme, "rascal+"); -loc rascalCreateLogicalLoc(Define def, str _modelName, PathConfig pcfg){ +loc rascalCreateLogicalLoc(Define def, str modelName, PathConfig pcfg){ if(def.idRole in keepInTModelRoles){ if(isLogicalLoc(def.defined)) return def.defined; moduleName = getRascalModuleName(def.defined, pcfg); @@ -576,7 +582,7 @@ list[str] rascalSimilarNames(Use u, TModel tm){ similar = similarWords(w, domain(longNames), tm.config.cutoffForNameSimilarity)[0..10]; return sort({*longNames[s] | s <- similar }, bool (str a, str b) { return size(a) < size(b); }); } else { - vocabulary = { d.orgId | d <- tm.defines, d.idRole in idRoles, isContainedIn(u.occ, d.scope) }; + vocabulary = { d.orgId | d <- tm.defines, d.idRole in idRoles, isContainedIn(u.occ, d.scope, tm.logical2physical) }; similar = similarWords(w, vocabulary, tm.config.cutoffForNameSimilarity)[0..10]; return sort(similar, bool (str a, str b) { return a < b; }); } diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/AliasTCTests.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/AliasTCTests.rsc index 5d02d8f6f90..d80024d1bc7 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/AliasTCTests.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/AliasTCTests.rsc @@ -93,6 +93,6 @@ test bool CircularAliasError4() = unexpectedDeclarationInModule(" test bool Issue504() = redeclaredVariableInModule(" module Issue504 alias INT = int; - alias INT = int; + alias INT = rat; "); diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/BinaryDependencyTests.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/BinaryDependencyTests.rsc index 31511550942..4aaecb4c68e 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/BinaryDependencyTests.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/BinaryDependencyTests.rsc @@ -175,7 +175,7 @@ bool checkExpectErrors(str mname, list[str] expected, PathConfig pcfg, list[Proj TModel check(str mname, RascalCompilerConfig cfg){ ModuleStatus ms = rascalTModelForNames([mname], cfg, dummy_compile1); - = getTModelForModule(mname, ms); + = getTModelForModule(moduleName2moduleId(mname), ms); if(found) return tm; throw "check: no TModel found for "; } @@ -359,7 +359,7 @@ test bool incompatibleWithBinaryLibraryAfterChange(){ */ test bool incompatibleVersionsOfBinaryLibrary(){ - clearMemory() ; + clearMemory(); rascalName = "rascal"; rascal = createProject(rascalName, diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/DeclarationTCTests.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/DeclarationTCTests.rsc index 6da8d323fc2..58d81e033ee 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/DeclarationTCTests.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/DeclarationTCTests.rsc @@ -97,7 +97,7 @@ test bool RedeclaredVarDeclaration(){ test bool ModuleVarReDeclaration(){ writeModule("module MMM public int n = 1; - public int n = 2;"); + public str n = \"a\";"); return redeclaredVariableInModule(" module ModuleVarReDeclaration import MMM; diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/StaticTestingUtils.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/StaticTestingUtils.rsc index ac07ef5394b..1db014b9710 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/StaticTestingUtils.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/StaticTestingUtils.rsc @@ -36,7 +36,7 @@ module lang::rascalcore::check::tests::StaticTestingUtils import IO; import String; -import Location; +import LogicalLocation; import Message; import Set; import util::Reflective; @@ -46,7 +46,7 @@ import lang::rascalcore::check::RascalConfig; import lang::rascalcore::check::Checker; import lang::rascal::\syntax::Rascal; -bool verbose = false; +bool verbose = true; PathConfig pathConfigForTesting() { return getDefaultTestingPathConfig(); @@ -189,7 +189,7 @@ bool checkModuleOK(str moduleText, PathConfig pathConfig = pathConfigForTesting( } bool validateUseDefs(str moduleName, map[str, tuple[int, set[int]]] usedefs, ModuleStatus ms){ - = getModuleParseTree(moduleName, ms); + = getModuleParseTree(moduleName2moduleId(moduleName), ms); map[str,list[loc]] names = (); top-down-break visit(pt){ case Name nm: @@ -217,7 +217,7 @@ bool validateUseDefs(str moduleName, map[str, tuple[int, set[int]]] usedefs, Mod potentialDefs = foundUseDefs[occ[u]]; // We us containement here, give how the type chcker works at the moment. // An equality test would be better. - if(isEmpty(potentialDefs) || !any(d <- potentialDefs, isContainedIn(occ[def], d))){ + if(isEmpty(potentialDefs) || !any(d <- potentialDefs, isContainedIn(occ[def], d, tm.logical2physical))){ throw "Missing def for use of "; } } diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/IncompatibleModules.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/IncompatibleModules.rsc index 17ca8075460..a3382a1e8db 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/IncompatibleModules.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/IncompatibleModules.rsc @@ -44,9 +44,9 @@ void main() { tuple[list[str], ModuleStatus] isCompatibleBinaryLibrary(TModel lib, ModuleStatus ms){ libName = lib.modelName; set[loc] libLogical = domain(lib.logical2physical); - set[loc] libDefines = { l | l <- libLogical, getModuleFromLogical(l) == libName }; + set[loc] libDefines = { l | l <- libLogical, getModuleNameFromAnyLogical(l) == libName }; set[loc] libDependsOn = libLogical - libDefines; - set[str] libDependsOnModules = { getModuleFromLogical(l) | l <- libDependsOn }; + set[str] libDependsOnModules = { getModuleNameFromAnyLogical(l) | l <- libDependsOn }; set[loc] dependentsProvide = {}; for(m <- libDependsOnModules){ = getTModelForModule(m, ms, convert=false); diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst4.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst4.rsc index a4db5fcfb4a..a6ba4073a7c 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst4.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst4.rsc @@ -24,9 +24,14 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. } -module lang::rascalcore::compile::Examples::Tst4 -import lang::rascalcore::compile::Examples::Tst2; - -void main(){ - N = "a"; -} \ No newline at end of file +module lang::rascalcore::compile::Examples::Tst4 + +import lang::rascalcore::compile::Examples::Tst5; + +// int M = lang::rascalcore::compile::Examples::Tst5::N + 2; + +//AB xxx = AB::ab(); + +value f() = AB::ab(); + + \ No newline at end of file diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst5.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst5.rsc new file mode 100644 index 00000000000..b6ab4c939be --- /dev/null +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst5.rsc @@ -0,0 +1,5 @@ +module lang::rascalcore::compile::Examples::Tst5 + +//extend lang::rascalcore::compile::Examples::Tst6; + +data AB = ab(); \ No newline at end of file diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst6.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst6.rsc index a2edc2e3167..86ee83a2ebd 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst6.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst6.rsc @@ -26,23 +26,7 @@ POSSIBILITY OF SUCH DAMAGE. } @bootstrapParser module lang::rascalcore::compile::Examples::Tst6 -import IO; -import ParseTree; -import lang::rascal::grammar::storage::ModuleParserStorage; - -lexical W = [\ ]; -layout L = W*; -lexical A = [A]; -start syntax As = A+; - -value main() { //test bool storeParserNonModule() { - storeParsers(#As, |home://test-tmp/parsersA.jar|); - p = loadParsers(|home://test-tmp/parsersA.jar|); - println("p1"); - p1 = p(type(sort("As"), ()), "A A", |origin:///|); - println("p1 = "); - println("p2"); - p2 = parse(#As, "A A", |origin:///|); - println("p2 = "); - return p1 == p2; -} + +data Symbol + = \label(str name, Symbol symbol); + diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/ConcreteSyntax.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/ConcreteSyntax.rsc index dc7059e6956..258c5af6de6 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/ConcreteSyntax.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/ConcreteSyntax.rsc @@ -37,7 +37,7 @@ import ParseTree; import Message; import String; import IO; -import Location; +import LogicalLocation; // WARNING: this module is sensitive to bootstrapping dependencies and implicit contracts: // @@ -72,7 +72,7 @@ tuple[Tree, TModel] parseConcreteFragments(Tree M, TModel tm, AGrammar gr) { M = top-down-break visit(M) { case Tree t:appl(p:prod(label("concrete",sort(/Expression|Pattern/)), _, _),[Tree concrete]) => appl(p, [parseFragment(concrete)])[@\loc=t@\loc] - when !any(loc ign <- ignoredFunctionLocs, isContainedIn(t@\loc, ign)) + when !any(loc ign <- ignoredFunctionLocs, isContainedIn(t@\loc, ign, tm.logical2physical)) } return ; diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalDeclaration.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalDeclaration.rsc index 1a448b1b4db..0f404e7bb83 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalDeclaration.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalDeclaration.rsc @@ -31,7 +31,7 @@ import IO; import Map; import List; import ListRelation; -import Location; +import LogicalLocation; import Node; import Set; import String; @@ -112,16 +112,16 @@ public void translateDecl(d: (Declaration) ` <- conses, isContainedIn(getLoc(consType.kwFields[0].defaultExp), module_scope) + | <- conses, isContainedIn(getLoc(consType.kwFields[0].defaultExp), module_scope, l2p) ] + failCode ); @@ -200,7 +200,7 @@ private void generateGettersForAdt(AType adtType, loc module_scope, set[AType] c * Create getters for common keyword fields of this data type */ seen = {}; - for(Keyword kw <- common_keyword_fields, kw has defaultExp, kw.fieldType notin seen, isContainedIn(kw.defaultExp@\loc, module_scope)){ + for(Keyword kw <- common_keyword_fields, kw has defaultExp, kw.fieldType notin seen, isContainedIn(kw.defaultExp@\loc, module_scope, l2p)){ kwType = kw.fieldType; defaultExp = kw.defaultExp; seen += kwType; diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalModule.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalModule.rsc index 3d36b7775f8..d014ee16f29 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalModule.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalModule.rsc @@ -92,7 +92,7 @@ tuple[TModel, MuModule] r2mu(lang::rascal::\syntax::Rascal::Module M, TModel tmo translateModule(M); - generateAllFieldGetters(module_scope); + generateAllFieldGetters(module_scope, tmodel.logical2physical); modName = replaceAll("","\\",""); diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalPattern.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalPattern.rsc index 78aa39a2c91..76d20620cb7 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalPattern.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalPattern.rsc @@ -1623,7 +1623,7 @@ private bool isDefinition(Pattern pat){ private bool isDefinedOutsidePat(loc def, Pattern container){ try { defined = getDefinition(def); - return !isContainedIn(defined, container@\loc); + return !isContainedIn(defined, container@\loc); // TODO: adapt } catch: { return false; } diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/TypeUtils.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/TypeUtils.rsc index 3bb031072ef..368290c3812 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/TypeUtils.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/TypeUtils.rsc @@ -269,7 +269,7 @@ private loc findContainer(Define d){ } str findDefiningModule(loc l){ - for(ms <- module_scopes,isContainedIn(l, ms)){ + for(ms <- module_scopes,isContainedIn(l, ms, current_tmodel.logical2physical)){ return definitions[ms].id; } throw "No module found for "; @@ -644,11 +644,11 @@ tuple[str fuid, int pos] getVariableScope(str name, loc l) { else { bool found = false; for(c <- functions){ - if(isContainedIn(l, c)){ container = c; found = true; break; } + if(isContainedIn(l, c, current_tmodel.logical2physical)){ container = c; found = true; break; } } if(!found){ for(c <- module_scopes){ - if(isContainedIn(l, c)){ container = c; found = true; break; } + if(isContainedIn(l, c, current_tmodel.logical2physical)){ container = c; found = true; break; } } } if(!found) throw "No container found for , "; diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/ShowTPL.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/ShowTPL.rsc deleted file mode 100644 index 6778d6cd479..00000000000 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/ShowTPL.rsc +++ /dev/null @@ -1,134 +0,0 @@ -@license{ -Copyright (c) 2018-2025, NWO-I CWI, Swat.engineering and Paul Klint -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, -this list of conditions and the following disclaimer in the documentation -and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE -LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. -} -module lang::rascalcore::compile::ShowTPL - -import IO; -import ValueIO; -import String; -import lang::rascalcore::check::CheckerCommon; -loc tplLoc = |file:///Users/paulklint/git/compiled-rascal/src/main/java/rascal/lang/rascalcore/compile/Examples/$C.tpl|; -TModel tm = tmodel(); // {try return readBinaryValueFile(#TModel, tplLoc); catch _: return tmodel();}; - -void main() { - setTPL(tplLoc); -} - -void setTPL(loc tpl){ - tplLoc = tpl; - tm = readBinaryValueFile(#TModel, tplLoc); -} - -void showAll(){ - iprintln(tm, lineLimit=10000); -} - -void saveAll(loc destination){ - iprintToFile(destination, tm); -} - -void saveAll(loc tmLoc, loc destination){ - if(endsWith(tmLoc.path, ".tpl")){ - tm = readBinaryValueFile(#TModel, tmLoc); - iprintToFile(destination, tm); - } else { - throw "Not a tpl file: "; - } -} - -void defines(str search = ""){ - if(search?){ - for(def <- tm.defines){ - if(def.id == search) println(def); - } - } else { - iprintln(tm.defines, lineLimit=10000); - } -} - -void scopes(){ - iprintln(tm.scopes, lineLimit=10000); -} - -void paths(){ - iprintln(tm.paths, lineLimit=10000); -} - -void referPaths(){ - iprintln(tm.referPaths, lineLimit=10000); -} - -void uses(){ - iprintln(tm.uses, lineLimit=10000); -} - -void definesMap(){ - iprintln(tm.definesMap, lineLimit=10000); -} - -void modelName(){ - iprintln(tm.modelName, lineLimit=10000); -} - -void moduleLocs(){ - iprintln(tm.moduleLocs, lineLimit=10000); -} - -void facts(){ - iprintln(tm.facts, lineLimit=10000); -} - -void specializedFacts(){ - iprintln(tm.specializedFacts, lineLimit=10000); -} - -void useDef(){ - iprintln(tm.useDef, lineLimit=10000); -} - -void messages(){ - iprintln(tm.messages, lineLimit=10000); -} - -void store(){ - iprintln(tm.store, lineLimit=10000); -} - -void definintions(){ - iprintln(tm.definitions, lineLimit=10000); -} - -void logical2physical(){ - iprintln(tm.logical2physical, lineLimit=10000); -} - -void usesPhysicalLocs(){ - iprintln(tm.usesPhysicalLocs, lineLimit=10000); -} - -void config(){ - iprintln(tm.config, lineLimit=10000); -} \ No newline at end of file diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/CodeGen.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/CodeGen.rsc index 198cdd10662..8d7085dd521 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/CodeGen.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/CodeGen.rsc @@ -35,7 +35,7 @@ import lang::rascalcore::compile::muRascal::AST; extend lang::rascalcore::check::CheckerCommon; -import Location; +import LogicalLocation; import List; import Relation; import Set; @@ -108,7 +108,7 @@ tuple[JCode, JCode, JCode, list[value]] muRascal2Java(MuModule m, ModuleStatus m resolvers = generateResolvers(moduleName, loc2muFunction, imports, extends, tmodels, moduleLocs, pcfg, jg); map[loc,AType] facts = tm.facts; - cons_in_module = { def.defInfo.atype | Define def <-range(tm.definitions), def.idRole == constructorId(), isContainedIn(def.scope, module_scope) } + cons_in_module = { def.defInfo.atype | Define def <-range(tm.definitions), def.idRole == constructorId(), jg.isContainedIn(def.scope, module_scope) } + { t | loc k <- facts, /AType t:acons(AType adt, list[AType] fields, list[Keyword] kwFields) := facts[k], !isEmpty(adt.parameters), any(p <- adt.parameters, !isTypeParameter(p)) }; @@ -465,7 +465,7 @@ str getMemoCache(MuFunction fun) tuple[str constantKwpDefaults, str constantKwpDefaultsInit, JCode jcode] trans(MuFunction fun, JGenie jg){ //iprintln(fun); // print function - if(!isContainedIn(fun.src, jg.getModuleLoc())) return <"", "", "">; + if(!jg.isContainedIn(fun.src, jg.getModuleLoc())) return <"", "", "">; if(ignoreCompiler(fun.tags)) return <"", "", "">; @@ -996,7 +996,7 @@ JCode trans(muOCall(MuExp fun, AType ftype, list[MuExp] largs, lrel[str kwpName, externalRefs = jg.getExternalRefs(uid); externals = [ varName(var, jg) | var <- sort(externalRefs), !isVarDeclaredInFun(var, jg.getFunction())/*, var notin fun.formals*/]; - if(isContainedIn(uid, jg.getModuleLoc())){ + if(jg.isContainedIn(uid, jg.getModuleLoc())){ fn = loc2muFunction[uid]; kwactuals1 = jg.collectKwpFormals(fn); if(isEmpty(kwactuals) && !isEmpty(kwactuals1)) kwactuals = ["$kwpActuals"]; diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/JGenie.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/JGenie.rsc index 32b93ce549f..2cf86daa064 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/JGenie.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/JGenie.rsc @@ -29,7 +29,7 @@ module lang::rascalcore::compile::muRascal2Java::JGenie import IO; import List; -import Location; +import LogicalLocation; import Map; import Node; import Set; @@ -80,7 +80,8 @@ data JGenie str(str prefix) newTmp, void(str) addImportedLibrary, list[str] () getImportedLibraries, - bool (tuple[str name, AType funType, str scope, list[loc] ofunctions, list[loc] oconstructors] overloads) usesLocalFunctions + bool (tuple[str name, AType funType, str scope, list[loc] ofunctions, list[loc] oconstructors] overloads) usesLocalFunctions, + bool (loc,loc) isContainedIn ) ; @@ -90,7 +91,7 @@ JGenie makeJGenie(MuModule m, map[str, MuFunction] muFunctions){ map[str,loc] allModuleLocs = moduleLocs; - map[loc,str] allLocs2Module = invertUnique(moduleLocs); + map[loc,str] allLocs2Module = invertUnique((mname : moduleLocs[mname].top | mname <- moduleLocs)); MuModule currentModule = m; str moduleName = m.name; map[AType, map[str,AType]] commonKeywordFieldsNameAndType = m.commonKeywordFields; @@ -126,9 +127,9 @@ JGenie makeJGenie(MuModule m, allPaths = { *(tmodels[mname].paths) | mname <- tmodels}; - extendScopesCurrentModule = { mscope | <- allPaths }; - importScopesCurrentModule = { mscope | <- allPaths} ; - flattenedImportScopes = importScopesCurrentModule + { mscope | imp <- importScopesCurrentModule, <- allPaths }; + extendScopesCurrentModule = { mscope.top | <- allPaths }; + importScopesCurrentModule = { mscope.top | <- allPaths} ; + flattenedImportScopes = importScopesCurrentModule + { mscope.top | imp <- importScopesCurrentModule, <- allPaths }; importAndExtendScopes = flattenedImportScopes + extendScopesCurrentModule; extends = { | <- allPaths, a in importAndExtendScopes, b in importAndExtendScopes}+; @@ -137,9 +138,12 @@ JGenie makeJGenie(MuModule m, bool(loc a, loc b) { return a != b && in extends /*|| in allPaths*/; }); JGenie thisJGenie; + bool _isContainedIn(loc inner, loc outer) + = isContainedIn(inner, outer, currentTModel.logical2physical); + loc findDefiningModuleForDef(loc def){ for(ms <- sortedImportAndExtendScopes){ - if(isContainedIn(def, ms)){ + if(_isContainedIn(def, ms)){ return ms; } } @@ -214,9 +218,8 @@ JGenie makeJGenie(MuModule m, } for(ms <- sortedImportAndExtendScopes){ for(Define def <- found_defs){ - //println("def: "); - if(isContainedIn(def.scope, ms)){ - defMod = allLocs2Module[ms]; + if(_isContainedIn(def.scope, ms)){ + defMod = allLocs2Module[ms.top]; res = defMod == moduleName ? "" : "<_getImportViaExtend(ms, defMod)>."; if(b)println("getTypeAccessor() =\> )"); return res; @@ -239,7 +242,7 @@ JGenie makeJGenie(MuModule m, bool importFromSameModule(list[loc] srcs){ fst = srcs[0].top; - return all(src <- srcs, fst == src.top) && any(imp <- importScopesCurrentModule, isContainedIn(srcs[0], imp)); + return all(src <- srcs, fst == src.top) && any(imp <- importScopesCurrentModule, _isContainedIn(srcs[0], imp)); } @memo @@ -255,7 +258,7 @@ JGenie makeJGenie(MuModule m, if(isSyntheticFunctionName(def.id)){ return baseName; - } else if(isContainedIn(def.defined, currentModuleScope)){ + } else if(_isContainedIn(def.defined, currentModuleScope)){ if(def.scope != currentModuleScope){ // inner function fun = muFunctionsByLoc[def.defined]; return isEmpty(fun.scopeIn) ? baseName : "_"; @@ -277,7 +280,7 @@ JGenie makeJGenie(MuModule m, if(isSyntheticFunctionName(baseName)){ return baseName; } - if(isContainedIn(def.defined, currentModuleScope)){ + if(_isContainedIn(def.defined, currentModuleScope)){ return baseName; } else { return def.scope in extendScopesCurrentModule ? "$me." @@ -312,10 +315,10 @@ JGenie makeJGenie(MuModule m, return "_"; } - if(any(d <- srcs, isContainedIn(d, currentModuleScope))){ + if(any(d <- srcs, _isContainedIn(d, currentModuleScope))){ return "$me."; } - alternative_defined_in_extended_module = any(d <- srcs, ms <- extendScopesCurrentModule, isContainedIn(d, ms)); + alternative_defined_in_extended_module = any(d <- srcs, ms <- extendScopesCurrentModule, _isContainedIn(d, ms)); if(alternative_defined_in_extended_module){ return "$me."; } @@ -326,7 +329,7 @@ JGenie makeJGenie(MuModule m, str definedInInnerScope(list[loc] srcs){ scopeIn = ""; for(d <- srcs){ - if(isContainedIn(d, currentModuleScope)){ + if(_isContainedIn(d, currentModuleScope)){ if(muFunctionsByLoc[d]?){ fun = muFunctionsByLoc[d]; if(fun.scopeIn == "") return ""; @@ -352,7 +355,7 @@ JGenie makeJGenie(MuModule m, list[MuExp] _getExternalRefs(loc src){ if(fun2externals[src]?){ fun = muFunctionsByLoc[src]; - evars = isContainedIn(src, currentModuleScope) ? fun2externals[src] : {}; + evars = _isContainedIn(src, currentModuleScope) ? fun2externals[src] : {}; return sort([var | var <- evars, var.pos >= 0, var notin fun.formals, !isVarDeclaredInFun(var, fun) ]); } return []; @@ -360,7 +363,7 @@ JGenie makeJGenie(MuModule m, bool _isDefinedInCurrentFunction(MuExp var){ map[loc, Define] definitions = currentTModel.definitions; - for(d <- definitions, def := definitions[d], var.name == def.id, isContainedIn(def.scope, function.src), def.idRole in variableRoles){ + for(d <- definitions, def := definitions[d], var.name == def.id, _isContainedIn(def.scope, function.src), def.idRole in variableRoles){ return true; } return false; @@ -719,8 +722,8 @@ JGenie makeJGenie(MuModule m, } bool _usesLocalFunctions(tuple[str name, AType funType, str scope, list[loc] ofunctions, list[loc] oconstructors] overloads){ - return any(of <- overloads.ofunctions, isContainedIn(currentTModel.definitions[of].defined, currentModuleScope)) - || any(oc <- overloads.oconstructors, isContainedIn(currentTModel.definitions[oc].defined, currentModuleScope)); + return any(of <- overloads.ofunctions, _isContainedIn(currentTModel.definitions[of].defined, currentModuleScope)) + || any(oc <- overloads.oconstructors, _isContainedIn(currentTModel.definitions[oc].defined, currentModuleScope)); } thisJGenie = @@ -757,7 +760,8 @@ JGenie makeJGenie(MuModule m, _newTmp, _addImportedLibrary, _getImportedLibraries, - _usesLocalFunctions + _usesLocalFunctions, + _isContainedIn ); //thisJGenie.shareType(anode([])); // Add types that can be implicitly defined by lubbing overloaded functions diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Resolvers.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Resolvers.rsc index 9cfda02bd34..8bf70a20ae6 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Resolvers.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Resolvers.rsc @@ -52,7 +52,7 @@ alias Name_Arity = tuple[str name, int arity]; // Get all functions and constructors from a given tmodel -rel[Name_Arity, Define] getFunctionsAndConstructors(TModel tmodel, set[loc] module_and_extend_scopes, PathConfig pcfg){ +rel[Name_Arity, Define] getFunctionsAndConstructors(TModel tmodel, set[loc] module_and_extend_scopes, PathConfig pcfg, JGenie jg){ if(!tmodel.moduleLocs[tmodel.modelName]?){ iprintln(tmodel); throw "getFunctionsAndConstructors"; @@ -60,7 +60,7 @@ rel[Name_Arity, Define] getFunctionsAndConstructors(TModel tmodel, set[loc] modu mname = tmodel.modelName; // mscope = tmodel.moduleLocs[tmodel.modelName]; - overloads0 = {*{ ov | tuple[loc def, IdRole idRole, AType atype] ov <- ovl.overloads,(ov.idRole == functionId() || ov.idRole == constructorId()) } | loc u <- tmodel.facts, getRascalModuleName(u, pcfg) == mname/*isContainedIn(u, mscope)*/, /ovl:overloadedAType(rel[loc def, IdRole idRole, AType atype] overloads) := tmodel.facts[u] }; + overloads0 = {*{ ov | tuple[loc def, IdRole idRole, AType atype] ov <- ovl.overloads,(ov.idRole == functionId() || ov.idRole == constructorId()) } | loc u <- tmodel.facts, getRascalModuleName(u, pcfg) == mname/*jg.isContainedIn(u, mscope)*/, /ovl:overloadedAType(rel[loc def, IdRole idRole, AType atype] overloads) := tmodel.facts[u] }; overloads_used_in_module = {<, def> | tuple[loc def, IdRole idRole, AType atype] ov <- overloads0, (ov.idRole == functionId() || ov.idRole == constructorId()), @@ -74,7 +74,7 @@ rel[Name_Arity, Define] getFunctionsAndConstructors(TModel tmodel, set[loc] modu { <, def> | Define def <- tmodel.defines, defType(AType tp) := def.defInfo, - (def.idRole == functionId() && any(me_scope <- module_and_extend_scopes, isContainedIn(def.defined, me_scope))) || def.idRole == constructorId(), + (def.idRole == functionId() && any(me_scope <- module_and_extend_scopes, jg.isContainedIn(def.defined, me_scope))) || def.idRole == constructorId(), !(acons(AType adt, list[AType] _, list[Keyword] _) := tp && isNonTerminalAType(adt)) }; return overloads_used_in_module + overloads_created_in_module; @@ -158,7 +158,7 @@ str generateResolvers(str moduleName, map[loc, MuFunction] loc2muFunction, set[s module_and_extend_scopes = module_scope + extend_scopes; - rel[Name_Arity, Define] functions_and_constructors = { *getFunctionsAndConstructors(tmodels[mname], module_and_extend_scopes, pcfg) | mname <- tmodels }; + rel[Name_Arity, Define] functions_and_constructors = { *getFunctionsAndConstructors(tmodels[mname], module_and_extend_scopes, pcfg, jg) | mname <- tmodels }; resolvers = ""; for( <- domain(functions_and_constructors), !isClosureName(fname)){ @@ -206,9 +206,9 @@ list[MuExp] getExternalRefs(set[Define] relevant_fun_defs, map[loc, MuFunction] return sort({ *getExternalRefs(fun_def, loc2muFunction) | fun_def <- relevant_fun_defs }); } -tuple[bool,loc] findImplementingModule(set[Define] fun_defs, set[loc] import_scopes, set[loc] extend_scopes){ +tuple[bool,loc] findImplementingModule(set[Define] fun_defs, set[loc] import_scopes, set[loc] extend_scopes, JGenie jg){ for(s <- import_scopes + extend_scopes){ - if(all(fd <- fun_defs, isContainedIn(fd.defined, s))){ + if(all(fd <- fun_defs, jg.isContainedIn(fd.defined, s))){ return ; } } @@ -222,12 +222,12 @@ str generateResolver(str moduleName, str functionName, set[Define] fun_defs, map module_scopes = domain(loc2module); - set[Define] local_fun_defs = {def | def <- fun_defs, /**/isContainedIn(def.defined, module_scope)/*, "test" notin loc2muFunction[def.defined].modifiers*/ }; + set[Define] local_fun_defs = {def | def <- fun_defs, /**/jg.isContainedIn(def.defined, module_scope)/*, "test" notin loc2muFunction[def.defined].modifiers*/ }; nonlocal_fun_defs0 = for(def <- fun_defs){ - if(!isEmpty(extend_scopes) && any(ext <- extend_scopes, isContainedIn(def.defined, ext))) append def; - if(!isEmpty(import_scopes) && any(imp <- import_scopes, isContainedIn(def.defined, imp))) append def; + if(!isEmpty(extend_scopes) && any(ext <- extend_scopes, jg.isContainedIn(def.defined, ext))) append def; + if(!isEmpty(import_scopes) && any(imp <- import_scopes, jg.isContainedIn(def.defined, imp))) append def; }; nonlocal_fun_defs = toSet(nonlocal_fun_defs0); set[Define] relevant_fun_defs = local_fun_defs + nonlocal_fun_defs; @@ -235,7 +235,7 @@ str generateResolver(str moduleName, str functionName, set[Define] fun_defs, map implementing_module = ""; if(isEmpty(local_fun_defs)){ - = findImplementingModule(relevant_fun_defs, import_scopes, extend_scopes); + = findImplementingModule(relevant_fun_defs, import_scopes, extend_scopes, jg); if(found){ implementing_module = loc2module[im]; } @@ -266,7 +266,7 @@ str generateResolver(str moduleName, str functionName, set[Define] fun_defs, map inner_scope = ""; if(all(def <- relevant_fun_defs, def in local_fun_defs, def.scope notin module_scopes)){ - for(def <- relevant_fun_defs, getRascalModuleName(def.defined, pcfg) == moduleName/*isContainedIn(def.defined, module_scope)*/){ + for(def <- relevant_fun_defs, getRascalModuleName(def.defined, pcfg) == moduleName/*jg.isContainedIn(def.defined, module_scope)*/){ fun = loc2muFunction[def.defined]; inner_scope = "_"; break; @@ -439,7 +439,7 @@ str generateResolver(str moduleName, str functionName, set[Define] fun_defs, map call_code = base_call = ""; cst = resolver_returns_void ? "" : "()"; if(isFunctionAType(def_type)){ - if(isContainedIn(def.defined, module_scope)){ + if(jg.isContainedIn(def.defined, module_scope)){ pref = ""; if(def.scope != module_scope){ for(odef <- fun_defs){ @@ -449,7 +449,7 @@ str generateResolver(str moduleName, str functionName, set[Define] fun_defs, map } } call_code = "()"; - } else if(/*isContainedIn(def.defined, def.scope),*/ loc2module[def.scope]?){ + } else if(/*jg.isContainedIn(def.defined, def.scope),*/ loc2module[def.scope]?){ call_code = ".()"; // was uniqueName } else { return; //do nothing diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/util/Names.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/util/Names.rsc index a909e8e4b75..263619fbc39 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/util/Names.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/util/Names.rsc @@ -75,8 +75,10 @@ str prefixLast(str pref, str qname){ return res; } +str getCompiledPackage() = "rascal"; + str getCompiledPackage(str _qname, PathConfig _pcfg) - = "rascal"; + = getCompiledPackage(); str asClassRef(str qname, PathConfig pcfg){ //return prefixLast("$", qname); @@ -117,6 +119,11 @@ str makeDirName(str qualifiedModuleName){ return isEmpty(parts) ? "" : intercalate("/", parts[0..-1]); } +str makeDirName(list[str] parts){ + parts = escapeJavaKeywords(normalize(parts)); + return isEmpty(parts) ? "" : intercalate("/", parts[0..-1]); +} + str asBaseClassName(str qname){ qname = normalizeQName(qname); n = findLast(qname, "."); @@ -213,4 +220,5 @@ bool isEqualModule(str name1, name2){ res = endsWith(name1a, name2a) || endsWith(name2a, name1a); //println("isEqualModule(, ) =\> "); return res; -} \ No newline at end of file +} + diff --git a/src/org/rascalmpl/library/Grammar.rsc b/src/org/rascalmpl/library/Grammar.rsc index 599cd4d403b..fd97e7d49ec 100644 --- a/src/org/rascalmpl/library/Grammar.rsc +++ b/src/org/rascalmpl/library/Grammar.rsc @@ -11,7 +11,7 @@ @synopsis{A simple but effective internal format for the representation of context-free grammars.} module Grammar - + extend ParseTree; From 2719929165b8a8351bdf06a3696e9968fd43756c Mon Sep 17 00:00:00 2001 From: paulklint Date: Mon, 5 Jan 2026 17:22:20 +0100 Subject: [PATCH 02/23] Updated TypePal dependency --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 38c16dba941..1735be0be56 100644 --- a/pom.xml +++ b/pom.xml @@ -458,7 +458,7 @@ org.rascalmpl typepal - 0.15.6-SNAPSHOT + 0.15.6 compile From a6d85c456b99ac86bea7dfa524773e683f4f6c35 Mon Sep 17 00:00:00 2001 From: paulklint Date: Mon, 5 Jan 2026 19:27:59 +0100 Subject: [PATCH 03/23] Fixed two minor errors --- src/org/rascalmpl/compiler/lang/rascalcore/check/Checker.rsc | 2 +- .../rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/Checker.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/Checker.rsc index 4a352230bca..0967669f317 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/Checker.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/Checker.rsc @@ -311,7 +311,7 @@ ModuleStatus rascalTModelForLocs( = getModuleParseTree(m, ms); if(success){ if(compilerConfig.infoModuleChecked){ - imsgs += [info("Checked ", pt.header.name@\loc)]; + imsgs += [info("Checked ", pt.header.name@\loc)]; } check_imports: for(imod <- pt.header.imports, imod has \module){ diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc index 6ba9918d7e6..1aa539c08c0 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc @@ -366,7 +366,7 @@ ModuleStatus removeTModel(MID candidate, ModuleStatus ms, bool updateBOMneeded = tm = ms.tmodels[candidate]; tm.messages = toList(toSet(tm.messages) + ms.messages[candidate]); // TODO needed ? ms.status[candidate] += tpl_saved(); - if(ms.compilerConfig.verbose) println("Saving tmodel for before removing from cache"); + if(ms.compilerConfig.verbose) println("Saving tmodel for before removing from cache"); try { writeBinaryValueFile(tplLoc, tm); if(traceTPL) println("Written "); From 4c797a1b5f4160d414bc9e9626b1d9cb26a20d45 Mon Sep 17 00:00:00 2001 From: paulklint Date: Tue, 6 Jan 2026 12:47:57 +0100 Subject: [PATCH 04/23] Added (for bootstrapping reasons) a copy of LogicallLocations --- src/org/rascalmpl/library/LogicalLocation.rsc | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/org/rascalmpl/library/LogicalLocation.rsc diff --git a/src/org/rascalmpl/library/LogicalLocation.rsc b/src/org/rascalmpl/library/LogicalLocation.rsc new file mode 100644 index 00000000000..19814879343 --- /dev/null +++ b/src/org/rascalmpl/library/LogicalLocation.rsc @@ -0,0 +1,39 @@ +module LogicalLocation + +// Note: this is a duplicate of LogicalLocation in typepal +// TODO: remove the one in TypePal + +extend Location; + +bool isLexicallyLess(loc l, loc r, map[loc,loc] m) + = isLexicallyLess(l in m ? m[l] : l, r in m ? m[r] : r); + +bool isStrictlyContainedIn(loc inner, loc outer, map[loc,loc] m) + = isStrictlyContainedIn(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); + +bool isContainedIn(loc inner, loc outer, map[loc,loc] m) + = isContainedIn(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); + +// bool beginsBefore(loc inner, loc outer, map[loc,loc] m) +// = beginsBefore(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); + +bool isBefore(loc inner, loc outer, map[loc,loc] m) + = isBefore(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); + +bool isImmediatelyBefore(loc inner, loc outer, map[loc,loc] m) + = isImmediatelyBefore(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); + + bool beginsAfter(loc inner, loc outer, map[loc,loc] m) + = beginsAfter(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); + +bool isAfter(loc inner, loc outer, map[loc,loc] m) + = beginsAfter(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); + +bool isImmediatelyAfter(loc inner, loc outer, map[loc,loc] m) + = isImmediatelyAfter(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); + +bool isOverlapping(loc inner, loc outer, map[loc,loc] m) + = isOverlapping(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); + +loc cover(list[loc] locs, map[loc,loc] m) + = cover([l in m ? m[l] : l | l <- locs]); From 86596ece739f6d1840914d51abf67edd0dc1c683 Mon Sep 17 00:00:00 2001 From: paulklint Date: Tue, 6 Jan 2026 13:23:50 +0100 Subject: [PATCH 05/23] Moved contents of LogicalLocation to Location --- .../lang/rascalcore/check/RascalConfig.rsc | 2 +- .../check/tests/StaticTestingUtils.rsc | 2 +- .../Rascal2muRascal/ConcreteSyntax.rsc | 2 +- .../Rascal2muRascal/RascalDeclaration.rsc | 2 +- .../compile/muRascal2Java/CodeGen.rsc | 2 +- .../compile/muRascal2Java/JGenie.rsc | 2 +- src/org/rascalmpl/library/Location.rsc | 37 +++++++++++++++++++ 7 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc index 432433fc99f..fa529dc3a0e 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc @@ -40,7 +40,7 @@ import lang::rascalcore::check::CheckerCommon; import lang::rascalcore::check::BasicRascalConfig; import lang::rascalcore::check::ModuleLocations; -import LogicalLocation; +import Location; import util::FileSystem; import util::Reflective; import lang::rascalcore::compile::util::Names; diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/StaticTestingUtils.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/StaticTestingUtils.rsc index 1db014b9710..e642c97d2e2 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/StaticTestingUtils.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/StaticTestingUtils.rsc @@ -36,7 +36,7 @@ module lang::rascalcore::check::tests::StaticTestingUtils import IO; import String; -import LogicalLocation; +import Location; import Message; import Set; import util::Reflective; diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/ConcreteSyntax.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/ConcreteSyntax.rsc index 258c5af6de6..3029d44c684 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/ConcreteSyntax.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/ConcreteSyntax.rsc @@ -37,7 +37,7 @@ import ParseTree; import Message; import String; import IO; -import LogicalLocation; +import Location; // WARNING: this module is sensitive to bootstrapping dependencies and implicit contracts: // diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalDeclaration.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalDeclaration.rsc index 0f404e7bb83..c2a3e590370 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalDeclaration.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalDeclaration.rsc @@ -31,7 +31,7 @@ import IO; import Map; import List; import ListRelation; -import LogicalLocation; +import Location; import Node; import Set; import String; diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/CodeGen.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/CodeGen.rsc index 8d7085dd521..0116b36237b 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/CodeGen.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/CodeGen.rsc @@ -35,7 +35,7 @@ import lang::rascalcore::compile::muRascal::AST; extend lang::rascalcore::check::CheckerCommon; -import LogicalLocation; +import Location; import List; import Relation; import Set; diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/JGenie.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/JGenie.rsc index 2cf86daa064..6fdc46e5334 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/JGenie.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/JGenie.rsc @@ -29,7 +29,7 @@ module lang::rascalcore::compile::muRascal2Java::JGenie import IO; import List; -import LogicalLocation; +import Location; import Map; import Node; import Set; diff --git a/src/org/rascalmpl/library/Location.rsc b/src/org/rascalmpl/library/Location.rsc index c812df006e3..fe165676dd3 100644 --- a/src/org/rascalmpl/library/Location.rsc +++ b/src/org/rascalmpl/library/Location.rsc @@ -212,3 +212,40 @@ loc cover(list[loc] locs){ } } } + +// Note: this is a duplicate of LogicalLocation in typepal +// TODO: remove the one in TypePal + +bool isLexicallyLess(loc l, loc r, map[loc,loc] m) + = isLexicallyLess(l in m ? m[l] : l, r in m ? m[r] : r); + +bool isStrictlyContainedIn(loc inner, loc outer, map[loc,loc] m) + = isStrictlyContainedIn(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); + +bool isContainedIn(loc inner, loc outer, map[loc,loc] m) + = isContainedIn(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); + +// bool beginsBefore(loc inner, loc outer, map[loc,loc] m) +// = beginsBefore(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); + +bool isBefore(loc inner, loc outer, map[loc,loc] m) + = isBefore(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); + +bool isImmediatelyBefore(loc inner, loc outer, map[loc,loc] m) + = isImmediatelyBefore(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); + + bool beginsAfter(loc inner, loc outer, map[loc,loc] m) + = beginsAfter(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); + +bool isAfter(loc inner, loc outer, map[loc,loc] m) + = beginsAfter(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); + +bool isImmediatelyAfter(loc inner, loc outer, map[loc,loc] m) + = isImmediatelyAfter(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); + +bool isOverlapping(loc inner, loc outer, map[loc,loc] m) + = isOverlapping(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); + +loc cover(list[loc] locs, map[loc,loc] m) + = cover([l in m ? m[l] : l | l <- locs]); + From d658d267fb9f1639917e336d7fc1fc118d4611b4 Mon Sep 17 00:00:00 2001 From: paulklint Date: Tue, 6 Jan 2026 14:21:41 +0100 Subject: [PATCH 06/23] Forgot to remove old LogicalLocation file --- src/org/rascalmpl/library/LogicalLocation.rsc | 39 ------------------- 1 file changed, 39 deletions(-) delete mode 100644 src/org/rascalmpl/library/LogicalLocation.rsc diff --git a/src/org/rascalmpl/library/LogicalLocation.rsc b/src/org/rascalmpl/library/LogicalLocation.rsc deleted file mode 100644 index 19814879343..00000000000 --- a/src/org/rascalmpl/library/LogicalLocation.rsc +++ /dev/null @@ -1,39 +0,0 @@ -module LogicalLocation - -// Note: this is a duplicate of LogicalLocation in typepal -// TODO: remove the one in TypePal - -extend Location; - -bool isLexicallyLess(loc l, loc r, map[loc,loc] m) - = isLexicallyLess(l in m ? m[l] : l, r in m ? m[r] : r); - -bool isStrictlyContainedIn(loc inner, loc outer, map[loc,loc] m) - = isStrictlyContainedIn(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); - -bool isContainedIn(loc inner, loc outer, map[loc,loc] m) - = isContainedIn(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); - -// bool beginsBefore(loc inner, loc outer, map[loc,loc] m) -// = beginsBefore(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); - -bool isBefore(loc inner, loc outer, map[loc,loc] m) - = isBefore(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); - -bool isImmediatelyBefore(loc inner, loc outer, map[loc,loc] m) - = isImmediatelyBefore(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); - - bool beginsAfter(loc inner, loc outer, map[loc,loc] m) - = beginsAfter(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); - -bool isAfter(loc inner, loc outer, map[loc,loc] m) - = beginsAfter(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); - -bool isImmediatelyAfter(loc inner, loc outer, map[loc,loc] m) - = isImmediatelyAfter(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); - -bool isOverlapping(loc inner, loc outer, map[loc,loc] m) - = isOverlapping(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); - -loc cover(list[loc] locs, map[loc,loc] m) - = cover([l in m ? m[l] : l | l <- locs]); From abe0b17c94d651539f1201e0881e9696444888a9 Mon Sep 17 00:00:00 2001 From: paulklint Date: Tue, 6 Jan 2026 17:38:08 +0100 Subject: [PATCH 07/23] Fixed error in typepal dependency --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1735be0be56..5a7d4fbb34a 100644 --- a/pom.xml +++ b/pom.xml @@ -458,7 +458,7 @@ org.rascalmpl typepal - 0.15.6 + 0.15.6-RC1 compile From c63510bb35d03e30a2207052def88d72b441f817 Mon Sep 17 00:00:00 2001 From: paulklint Date: Tue, 6 Jan 2026 17:44:47 +0100 Subject: [PATCH 08/23] Exclude target from search --- .vscode/launch.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.vscode/launch.json b/.vscode/launch.json index fa9529bef36..973c0fc1c57 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -3,6 +3,9 @@ // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", + "search.exclude": { + "/target/": true, + }, "configurations": [ { "type": "java", From 505d06c5c9352b374776a716c14f9b289d3f36ca Mon Sep 17 00:00:00 2001 From: paulklint Date: Tue, 6 Jan 2026 17:53:07 +0100 Subject: [PATCH 09/23] Revert "Exclude target from search" This reverts commit c63510bb35d03e30a2207052def88d72b441f817. --- .vscode/launch.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 973c0fc1c57..fa9529bef36 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -3,9 +3,6 @@ // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", - "search.exclude": { - "/target/": true, - }, "configurations": [ { "type": "java", From 39f5f4aee15cd2d29e0f7c7c996ff1d6a28008cf Mon Sep 17 00:00:00 2001 From: paulklint Date: Tue, 6 Jan 2026 17:54:17 +0100 Subject: [PATCH 10/23] Bumped typepal version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5a7d4fbb34a..2e88a446fb1 100644 --- a/pom.xml +++ b/pom.xml @@ -458,7 +458,7 @@ org.rascalmpl typepal - 0.15.6-RC1 + 0.16.0-RC1 compile From ecde7f7bafca31a7dc205fe483c65de2ed95222c Mon Sep 17 00:00:00 2001 From: paulklint Date: Wed, 7 Jan 2026 11:44:04 +0100 Subject: [PATCH 11/23] Started propagating switch to logical locations to remainder of compiler --- .../lang/rascalcore/compile/Compile.rsc | 13 +++++----- .../compile/Rascal2muRascal/TypeUtils.rsc | 2 +- .../compile/muRascal2Java/CodeGen.rsc | 25 ++++++++++--------- .../compile/muRascal2Java/Interface.rsc | 10 ++++---- .../compile/muRascal2Java/JGenie.rsc | 15 +++++------ .../compile/muRascal2Java/Resolvers.rsc | 12 +++++---- 6 files changed, 41 insertions(+), 36 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Compile.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Compile.rsc index ddcf0117539..d75c854d432 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Compile.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Compile.rsc @@ -48,10 +48,11 @@ import lang::rascalcore::compile::util::Names; data ModuleStatus; -list[Message] compile1(str qualifiedModuleName, lang::rascal::\syntax::Rascal::Module M, map[str,TModel] transient_tms, ModuleStatus ms, RascalCompilerConfig compilerConfig){ +list[Message] compile1(MID moduleId, lang::rascal::\syntax::Rascal::Module M, map[MID,TModel] transient_tms, ModuleStatus ms, RascalCompilerConfig compilerConfig){ + qualifiedModuleName = moduleId2moduleName(moduleId); pcfg = ms.pathConfig; // = getTModelForModule(qualifiedModuleName, ms); - tm = transient_tms[qualifiedModuleName]; + tm = transient_tms[moduleId]; //iprintln(tm, lineLimit=10000); if(errorsPresent(tm)){ return tm.messages; @@ -87,8 +88,8 @@ list[Message] compile1(str qualifiedModuleName, lang::rascal::\syntax::Rascal::M return tm.messages; } - imports = { imp | <- ms.strPaths, m1 == qualifiedModuleName }; - extends = { ext | <- ms.strPaths, m1 == qualifiedModuleName }; + imports = { imp | <- ms.paths, m1 == moduleId }; + extends = { ext | <- ms.paths, m1 == moduleId }; tmodels = (); for(m <- imports + extends, tpl_uptodate() in ms.status[m]){ if(m in transient_tms){ @@ -99,7 +100,7 @@ list[Message] compile1(str qualifiedModuleName, lang::rascal::\syntax::Rascal::M } } // tmodels[qualifiedModuleName] = tm; - ms = addTModel(qualifiedModuleName, tm, ms); + ms = addTModel(moduleId, tm, ms); = muRascal2Java(muMod, ms); // = muRascal2Java(muMod, tmodels, ms.moduleLocs, pcfg); @@ -160,7 +161,7 @@ list[Message] compile(list[str] qualifiedModuleNames, RascalCompilerConfig compi comp_time = (cpuTime() - start_comp)/1000000; if(compilerConfig.verbose) { println("Compiled ... in ms [total]"); } - return [*(ms.messages[m] ? {}) | m <- qualifiedModuleNames]; + return [*(ms.messages[moduleName2moduleId(m)] ? {}) | m <- qualifiedModuleNames]; } int main( diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/TypeUtils.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/TypeUtils.rsc index 368290c3812..7b20617c20a 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/TypeUtils.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/TypeUtils.rsc @@ -294,7 +294,7 @@ list[AType] dummyFormalsInType(AType t){ // extractScopes: extract and convert type information from the TModel delivered by the type checker. void extractScopes(TModel tm){ - tm = convertTModel2PhysicalLocs(tm); + //tm = convertTModel2PhysicalLocs(tm); current_tmodel = tm; physical2logical = invertUnique(tm.logical2physical); diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/CodeGen.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/CodeGen.rsc index 0116b36237b..a06930f9629 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/CodeGen.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/CodeGen.rsc @@ -63,7 +63,7 @@ bool debug = false; // ---- globals --------------------------------------------------------------- -map[str, MuFunction] muFunctions = (); +map[MID, MuFunction] muFunctions = (); map[loc, MuFunction] loc2muFunction = (); int naux = 0; @@ -73,20 +73,21 @@ int naux = 0; // Generate code and test class for a single Rascal module tuple[JCode, JCode, JCode, list[value]] muRascal2Java(MuModule m, ModuleStatus ms){ - map[str,TModel] tmodels = ms.tmodels; - map[str,loc] moduleLocs = ms .moduleLocs; + map[MID,TModel] tmodels = ms.tmodels; + map[MID,loc] moduleLocs = ms .moduleLocs; PathConfig pcfg = ms.pathConfig; naux = 0; moduleName = m.name; + MID moduleId = moduleName2moduleId(moduleName); locsModule = invertUnique(moduleLocs); - module_scope = moduleLocs[moduleName]; - = getTModelForModule(moduleName, ms, convert=true); - - strPaths = { | <- tm.paths }; - - extends = { mname | <- strPaths }; - imports = { mname | <- strPaths }; - imports += { mname | imp <- imports, <- strPaths}; + module_scope = moduleLocs[moduleId]; + = getTModelForModule(moduleId, ms); + + //strPaths = { | <- tm.paths }; + paths = tm.paths; + extends = { mname | <- paths }; + imports = { mname | <- paths }; + imports += { mname | imp <- imports, <- paths}; loc2muFunction = (f.src : f | f <- m.functions); @@ -105,7 +106,7 @@ tuple[JCode, JCode, JCode, list[value]] muRascal2Java(MuModule m, ModuleStatus m muFunctions = (f.uniqueName : f | f <- m.functions); jg = makeJGenie(m, tmodels, moduleLocs, muFunctions); - resolvers = generateResolvers(moduleName, loc2muFunction, imports, extends, tmodels, moduleLocs, pcfg, jg); + resolvers = generateResolvers(moduleId, loc2muFunction, imports, extends, tmodels, moduleLocs, pcfg, jg); map[loc,AType] facts = tm.facts; cons_in_module = { def.defInfo.atype | Define def <-range(tm.definitions), def.idRole == constructorId(), jg.isContainedIn(def.scope, module_scope) } diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Interface.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Interface.rsc index 2557a7a9965..048fedbf5fb 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Interface.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Interface.rsc @@ -44,7 +44,7 @@ import String; // Generate an interface for a Rascal module -str generateInterface(str moduleName, str packageName, list[MuFunction] functions, set[str] imports, set[str] extends, map[str,TModel] tmodels, PathConfig pcfg, JGenie _jg){ +str generateInterface(str moduleName, str packageName, list[MuFunction] functions, set[MID] imports, set[MID] extends, map[MID,TModel] tmodels, PathConfig pcfg, JGenie _jg){ return "package ;<}> 'import io.usethesource.vallang.*; 'import org.rascalmpl.runtime.function.*; @@ -55,11 +55,11 @@ str generateInterface(str moduleName, str packageName, list[MuFunction] function '}"; } -lrel[str, AType] getInterfaceSignature(str moduleName, list[MuFunction] functions, set[str] _imports, set[str] extends, map[str,TModel] tmodels, PathConfig pcfg){ - +lrel[str, AType] getInterfaceSignature(str moduleName, list[MuFunction] functions, set[MID] _imports, set[MID] extends, map[MID,TModel] tmodels, PathConfig pcfg){ + MID moduleId = moduleName2moduleId(moduleName); lrel[str, AType] result = []; rel[str, int, AType] signatures = {}; - mscope = tmodels[moduleName].moduleLocs[moduleName]; + mscope = tmodels[moduleId].moduleLocs[moduleName]; for(f <- functions, isEmpty(f.scopeIn), isContainedIn(f.src, mscope), @@ -101,7 +101,7 @@ lrel[str, AType] getInterfaceSignature(str moduleName, list[MuFunction] function return sort(result); } -str generateInterfaceMethods(str moduleName, list[MuFunction] functions, set[str] imports, set[str] extends, map[str,TModel] tmodels, PathConfig pcfg){ +str generateInterfaceMethods(str moduleName, list[MuFunction] functions, set[MID] imports, set[MID] extends, map[MID,TModel] tmodels, PathConfig pcfg){ interface_signature = getInterfaceSignature(moduleName, functions, imports, extends, tmodels, pcfg); methods = [generateInterfaceMethod(name, tp) | <- interface_signature]; return intercalate("\n", methods); diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/JGenie.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/JGenie.rsc index 6fdc46e5334..31cfdf9e47a 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/JGenie.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/JGenie.rsc @@ -86,14 +86,15 @@ data JGenie ; JGenie makeJGenie(MuModule m, - map[str,TModel] tmodels, - map[str,loc] moduleLocs, - map[str, MuFunction] muFunctions){ + map[MID,TModel] tmodels, + map[MID,loc] moduleLocs, + map[MID, MuFunction] muFunctions){ - map[str,loc] allModuleLocs = moduleLocs; - map[loc,str] allLocs2Module = invertUnique((mname : moduleLocs[mname].top | mname <- moduleLocs)); + map[MID,loc] allModuleLocs = moduleLocs; + map[loc,MID] allLocs2Module = invertUnique((mname : moduleLocs[mname].top | mname <- moduleLocs)); MuModule currentModule = m; str moduleName = m.name; + MID moduleId = moduleName2moduleId(moduleName); map[AType, map[str,AType]] commonKeywordFieldsNameAndType = m.commonKeywordFields; map[value,int] constant2idx = (); map[int,value] idx2constant = (); @@ -115,9 +116,9 @@ JGenie makeJGenie(MuModule m, checkAllTypesAvailable(tmodels[mname]); } - TModel currentTModel = tmodels[moduleName]; + TModel currentTModel = tmodels[moduleId]; checkAllTypesAvailable(currentTModel); // TODO: remove - loc currentModuleScope = moduleLocs[moduleName]; + loc currentModuleScope = moduleLocs[moduleId]; str functionName = "$UNKNOWN"; MuFunction function = muFunction("", "*unknown", avalue(), [], [], [], "", false, true, false, {}, {}, {}, currentModuleScope, [], (), muBlock([])); diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Resolvers.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Resolvers.rsc index 8bf70a20ae6..80a8d4e32d8 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Resolvers.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Resolvers.rsc @@ -148,8 +148,9 @@ public set[set[Define]] mygroup(set[Define] input, bool (Define a, Define b) sim // Generate all resolvers for a given module -str generateResolvers(str moduleName, map[loc, MuFunction] loc2muFunction, set[str] imports, set[str] extends, map[str,TModel] tmodels, map[str,loc] module2loc, PathConfig pcfg, JGenie jg){ - module_scope = module2loc[moduleName]; +str generateResolvers(MID moduleId, map[loc, MuFunction] loc2muFunction, set[MID] imports, set[MID] extends, map[MID,TModel] tmodels, map[MID,loc] module2loc, PathConfig pcfg, JGenie jg){ + moduleName = moduleId2moduleName(moduleId); + module_scope = module2loc[moduleId]; loc2module = invertUnique(module2loc); module_scopes = domain(loc2module); @@ -158,7 +159,8 @@ str generateResolvers(str moduleName, map[loc, MuFunction] loc2muFunction, set[s module_and_extend_scopes = module_scope + extend_scopes; - rel[Name_Arity, Define] functions_and_constructors = { *getFunctionsAndConstructors(tmodels[mname], module_and_extend_scopes, pcfg, jg) | mname <- tmodels }; + + rel[Name_Arity, Define] functions_and_constructors = { *getFunctionsAndConstructors(tmodels[mid], module_and_extend_scopes, pcfg, jg) | mid <- tmodels }; resolvers = ""; for( <- domain(functions_and_constructors), !isClosureName(fname)){ @@ -175,7 +177,7 @@ str generateResolvers(str moduleName, map[loc, MuFunction] loc2muFunction, set[s for(sdefs <- defs_in_disjoint_scopes){ if(any(d <- sdefs, d.scope notin module_scopes)){ // All local functions trated samw wrt keyword parameters - resolvers += generateResolver(moduleName, fname, sdefs, loc2muFunction, module_scope, import_scopes, extend_scopes, tmodels[moduleName].paths, tmodels[moduleName], loc2module, pcfg, jg); + resolvers += generateResolver(moduleName, fname, sdefs, loc2muFunction, module_scope, import_scopes, extend_scopes, tmodels[moduleId].paths, tmodels[moduleId], loc2module, pcfg, jg); } else { // For global functions we differentiate wrt keyword oarameters @@ -217,7 +219,7 @@ tuple[bool,loc] findImplementingModule(set[Define] fun_defs, set[loc] import_sco } // Generate a resolver for a specific function -str generateResolver(str moduleName, str functionName, set[Define] fun_defs, map[loc, MuFunction] loc2muFunction, loc module_scope, set[loc] import_scopes, set[loc] extend_scopes, Paths paths, TModel tm, map[loc, str] loc2module, PathConfig pcfg, JGenie jg){ +str generateResolver(str moduleName, str functionName, set[Define] fun_defs, map[loc, MuFunction] loc2muFunction, loc module_scope, set[loc] import_scopes, set[loc] extend_scopes, Paths paths, TModel tm, map[loc, MID] loc2module, PathConfig pcfg, JGenie jg){ //println("generate resolver for , "); module_scopes = domain(loc2module); From d255f53c5799e14cc3f21d7c0c0492483e79b108 Mon Sep 17 00:00:00 2001 From: paulklint Date: Wed, 7 Jan 2026 11:47:33 +0100 Subject: [PATCH 12/23] Updated TypePal dependency --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2e88a446fb1..44e1527d192 100644 --- a/pom.xml +++ b/pom.xml @@ -458,7 +458,7 @@ org.rascalmpl typepal - 0.16.0-RC1 + 0.16.0-RC2 compile From 074ca0bbde9b375e2327b3250bfbf1a3cc966ff1 Mon Sep 17 00:00:00 2001 From: paulklint Date: Thu, 8 Jan 2026 11:19:39 +0100 Subject: [PATCH 13/23] Removed duplicate license --- .../compiler/lang/rascalcore/check/ATypeUtils.rsc | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc index 6616a2f29ab..77a0703b6c6 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc @@ -24,17 +24,6 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. } -@license{ - Copyright (c) 2009-2015 CWI - All rights reserved. This program and the accompanying materials - are made available under the terms of the Eclipse Public License v1.0 - which accompanies this distribution, and is available at - http://www.eclipse.org/legal/epl-v10.html -} -@contributor{Jurgen J. Vinju - Jurgen.Vinju@cwi.nl - CWI} -@contributor{Mark Hills - Mark.Hills@cwi.nl (CWI)} -@contributor{Paul Klint - Paul.Klint@cwi.nl (CWI)} -@contributor{Anastasia Izmaylova - Anastasia.Izmaylova@cwi.nl (CWI)} @bootstrapParser module lang::rascalcore::check::ATypeUtils From 95371790b521c07397225365ca38c13e0b3d05d8 Mon Sep 17 00:00:00 2001 From: paulklint Date: Thu, 8 Jan 2026 11:20:17 +0100 Subject: [PATCH 14/23] Fixed error in filterOverloads related to varargs and constructors Case in point: ``` data Symbol = label(str lbl, Symbol sym); void label(value vals...) { } ``` was not handled correctly --- .../rascalcore/check/CollectExpression.rsc | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectExpression.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectExpression.rsc index 2a458f25d69..7403133a2cb 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectExpression.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectExpression.rsc @@ -750,10 +750,27 @@ void reportMissingNonTerminalCases(Expression current, rel[loc def, IdRole idRol // } private tuple[rel[loc, IdRole, AType], list[bool]] filterOverloads(rel[loc, IdRole, AType] overloads, int arity){ + // println("filterOverloads: , "); rel[loc, IdRole, AType] filteredOverloads = {}; list[AType] prevFormals = []; list[bool] identicalFormals = [true | int _ <- [0 .. arity]]; + // Filter constructors first to avoid issues with vararg functions + for(ovl:<_, _, tp> <- overloads){ + if(acons(aadt(_, list[AType] _,_), list[AType] fields, list[Keyword] _) := tp){ + if(size(fields) == arity){ + filteredOverloads += ovl; + if(isEmpty(prevFormals)){ + prevFormals = fields; //<1>; + } else { + for(int i <- index(fields)) { + identicalFormals[i] = identicalFormals[i] && (comparable(prevFormals[i], fields[i]/*.fieldType*/)); + } + } + } + } + } + for(ovl:<_, _, tp> <- overloads){ if(ft:afunc(AType _, list[AType] formals, list[Keyword] _) := tp){ if(ft.varArgs ? (arity >= size(formals) - 1) : (arity == size(formals))) { @@ -769,18 +786,7 @@ private tuple[rel[loc, IdRole, AType], list[bool]] filterOverloads(rel[loc, IdRo } } } - else if(acons(aadt(_, list[AType] _,_), list[AType] fields, list[Keyword] _) := tp){ - if(size(fields) == arity){ - filteredOverloads += ovl; - if(isEmpty(prevFormals)){ - prevFormals = fields; //<1>; - } else { - for(int i <- index(fields)) { - identicalFormals[i] = identicalFormals[i] && (comparable(prevFormals[i], fields[i]/*.fieldType*/)); - } - } - } - } + } return ; } From c30d403b7fabc0775f3f58773d50d56d962fa686 Mon Sep 17 00:00:00 2001 From: paulklint Date: Thu, 8 Jan 2026 11:22:05 +0100 Subject: [PATCH 15/23] Show physical locs in messages --- .../compiler/lang/rascalcore/check/Import.rsc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc index 3c2f1638da0..0ebc12e1cb4 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc @@ -172,8 +172,8 @@ ModuleStatus getImportAndExtendGraph(MID moduleId, ModuleStatus ms){ ms.status[moduleId] -= tpl_saved(); ms.messages[moduleId] = {}; if(ms.compilerConfig.verbose){ - println("--- using (most recent) version of , - ' older version was used in previous check of "); + println("--- using (most recent) version of , + ' older version was used in previous check of "); } } } @@ -291,12 +291,12 @@ tuple[list[MID], ModuleStatus] isCompatibleBinaryLibrary(TModel lib, ModuleStatu //println("isCompatibleBinaryLibrary : satisfied"); return <[], ms>; } else { - println("BOM of :"); iprintln(lib.store[key_bom]); - println("libDependsOn: - 'dependentsProvide: - 'unstatisfied: - "); - println("isCompatibleBinaryLibrary, unsatisfied ()"); + // println("BOM of :"); iprintln(lib.store[key_bom]); + // println("libDependsOn: + // 'dependentsProvide: + // 'unstatisfied: + // "); + // println("isCompatibleBinaryLibrary, unsatisfied ()"); //incompatibleModuleNames = { moduleId2moduleName(u) | u <- unsatisfied }; return ; From 6b68b80f9ec34d17df923bd1bc1d1622a02db39a Mon Sep 17 00:00:00 2001 From: paulklint Date: Fri, 9 Jan 2026 15:34:32 +0100 Subject: [PATCH 16/23] Fixed type error --- src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc index 77a0703b6c6..4243ece11cc 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/ATypeUtils.rsc @@ -355,7 +355,7 @@ AType symbol2atype1(Symbol::\cons(Symbol \adt, str name, list[Symbol] parameters AType symbol2atype1(Symbol::sort(str name)) = aadt(name, [], contextFreeSyntax()); AType symbol2atype1(Symbol::lex(str name)) = aadt(name, [], lexicalSyntax()); AType symbol2atype1(Symbol::keywords(str name)) = aadt(name, [], keywordSyntax()); -AType symbol2atype1(Symbol::layouts(str name)) = AType::layouts(name); +AType symbol2atype1(Symbol::layouts(str name)) = aadt(name, [], layoutSyntax()); AType symbol2atype1(Symbol::\parameterized-sort(str name, list[Symbol] parameters)) = aadt(name, symbol2atype(parameters), contextFreeSyntax()); From 778d915389f30259cbffc49003783ff4ce3b3a73 Mon Sep 17 00:00:00 2001 From: paulklint Date: Fri, 9 Jan 2026 15:35:07 +0100 Subject: [PATCH 17/23] Removed warnings --- .../compiler/lang/rascalcore/check/RascalConfig.rsc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc index fa529dc3a0e..2835cd956ba 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc @@ -165,11 +165,8 @@ Accept rascalIsAcceptableSimple(loc def, Use use, Solver s){ } Accept rascalIsAcceptableQualified(loc def, Use use, Solver s){ - // println("rascalIsAcceptableQualified: , "); + // println("rascalIsAcceptableQualified: , "); - // defPath = def.path; - // qualAsPath = replaceAll(use.ids[0], "::", "/") + ".rsc"; - path = def.path; if(path[0] == "/") path = path[1..]; defPath = split("/", path)[0..-1]; @@ -177,7 +174,6 @@ Accept rascalIsAcceptableQualified(loc def, Use use, Solver s){ // qualifier and proposed definition are the same? if(defPath == qualAsPath){ - // if(endsWith(defPath, qualAsPath)){ return acceptBinding(); } @@ -197,7 +193,8 @@ Accept rascalIsAcceptableQualified(loc def, Use use, Solver s){ // Is there another acceptable qualifier via an extend? extendedStarBy = { | <- s.getPaths()}*; - + // println("path = "); + // println("extendedStarBy");iprintln(extendedStarBy); if(!isEmpty(extendedStarBy) && any(p <- extendedStarBy[path]?{}, endsWith(p, path))){ //TODO check this return acceptBinding(); } From 65ab24d2caf1c575d0c7fc573a04553d2f406c31 Mon Sep 17 00:00:00 2001 From: paulklint Date: Fri, 9 Jan 2026 15:35:46 +0100 Subject: [PATCH 18/23] Minor cleanup --- src/org/rascalmpl/compiler/lang/rascalcore/compile/Compile.rsc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Compile.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Compile.rsc index d75c854d432..3ec511c2e30 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Compile.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Compile.rsc @@ -51,7 +51,6 @@ data ModuleStatus; list[Message] compile1(MID moduleId, lang::rascal::\syntax::Rascal::Module M, map[MID,TModel] transient_tms, ModuleStatus ms, RascalCompilerConfig compilerConfig){ qualifiedModuleName = moduleId2moduleName(moduleId); pcfg = ms.pathConfig; - // = getTModelForModule(qualifiedModuleName, ms); tm = transient_tms[moduleId]; //iprintln(tm, lineLimit=10000); if(errorsPresent(tm)){ From 963c98b0c24262238eaabdf436e6d869ebccf275 Mon Sep 17 00:00:00 2001 From: paulklint Date: Fri, 9 Jan 2026 15:36:07 +0100 Subject: [PATCH 19/23] Removed warnings --- .../compiler/lang/rascalcore/check/CheckerCommon.rsc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc index 1aa539c08c0..739660341d6 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc @@ -228,7 +228,7 @@ bool tplOutdated(MID moduleId, PathConfig pcfg){ res = !found || lmMloc > lmTpl; //println("tplOutdated : ; mloc: \> tpl: : lmTpl>, (, )"); return res; - } catch e: { + } catch _: { return false; } } @@ -322,7 +322,6 @@ ModuleStatus clearTModelCache(ModuleStatus ms){ } rel[str,datetime,PathRole] makeBom(MID moduleId, ModuleStatus ms){ - map[MID,datetime] moduleLastModified = ms.moduleLastModified; pcfg = ms.pathConfig; qualifiedModuleName = moduleId2moduleName(moduleId); imports = ms.paths[moduleId,importPath()]; @@ -455,7 +454,7 @@ rel[loc from, PathRole r, loc to] getPaths(rel[MID from, PathRole r, MID to] pat mfrom = getRascalModuleLocation(from, ms); mto = getRascalModuleLocation(to, ms); paths += ; - } catch e: ;/* ignore non-existing module */ + } catch _: ;/* ignore non-existing module */ } return paths; } From 1674ccfe6267cd1c4924257c4548ea54b94359de Mon Sep 17 00:00:00 2001 From: paulklint Date: Fri, 9 Jan 2026 15:36:36 +0100 Subject: [PATCH 20/23] Started adapting backend --- .../compile/Rascal2muRascal/RascalModule.rsc | 10 ++++++---- .../rascalcore/compile/Rascal2muRascal/TypeUtils.rsc | 1 - 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalModule.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalModule.rsc index d014ee16f29..e47d2374159 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalModule.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalModule.rsc @@ -67,11 +67,13 @@ import lang::rascalcore::compile::Rascal2muRascal::RascalExpression; tuple[TModel, MuModule] r2mu(lang::rascal::\syntax::Rascal::Module M, TModel tmodel, RascalCompilerConfig compilerConfig){ try { resetModuleInfo(compilerConfig); - module_scope = M@\loc; - setModuleScope(module_scope); - //setModuleScope(convert2fuid(module_scope)); - M_module_name = ""; + + M_module_name = unescape(""); setModuleName(M_module_name); + + module_scope = moduleName2ModuleId(M_module_name); + setModuleScope(module_scope); + mtags = translateTags(M.header.tags); setModuleTags(mtags); if(ignoreTest(mtags)){ diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/TypeUtils.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/TypeUtils.rsc index 7b20617c20a..fd3936d6b3d 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/TypeUtils.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/TypeUtils.rsc @@ -294,7 +294,6 @@ list[AType] dummyFormalsInType(AType t){ // extractScopes: extract and convert type information from the TModel delivered by the type checker. void extractScopes(TModel tm){ - //tm = convertTModel2PhysicalLocs(tm); current_tmodel = tm; physical2logical = invertUnique(tm.logical2physical); From 4d4c849f0ca234007fafeb9bc2e7a6a9c1f51bc5 Mon Sep 17 00:00:00 2001 From: paulklint Date: Fri, 9 Jan 2026 23:36:48 +0100 Subject: [PATCH 21/23] Optimizing tpl file saving --- .../lang/rascalcore/check/Checker.rsc | 8 ++++---- .../lang/rascalcore/check/CheckerCommon.rsc | 20 +++++++++++-------- .../compiler/lang/rascalcore/check/Import.rsc | 2 +- .../lang/rascalcore/check/RascalConfig.rsc | 8 ++++---- .../lang/rascalcore/compile/Examples/Tst4.rsc | 7 ++++++- .../lang/rascalcore/compile/Examples/Tst5.rsc | 5 ++++- 6 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/Checker.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/Checker.rsc index 0967669f317..29758a7d5cb 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/Checker.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/Checker.rsc @@ -372,9 +372,9 @@ ModuleStatus rascalTModelForLocs( ms.status[m] += {tpl_uptodate()}; } } else { - for(m <- component){ - ms.status[m] += bom_update_needed(); - } + ;// for(m <- component){ + // ms.status[m] += bom_update_needed(); + // } } } } catch ParseError(loc src): { @@ -441,7 +441,7 @@ tuple[TModel, ModuleStatus] rascalTModelComponent(set[MID] moduleIds, ModuleStat map[MID, Module] idTrees = (); for(MID mid <- moduleIds){ mname = moduleId2moduleName(mid); - ms.status[mid] = {}; + //ms.status[mid] = {}; //ms.messages[mid] = {}; ms = removeTModel(mid, ms); mloc = |unknown:///|(0,0,<0,0>,<0,0>); diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc index 739660341d6..702a6f4ec5e 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc @@ -311,11 +311,11 @@ int tmodelCacheSize = 30; // should be > 0 ModuleStatus clearTModelCache(ModuleStatus ms){ todo = { mname | mname <- ms.status, bom_update_needed() in ms.status[mname]}; for(candidate <- ms.tmodelLIFO){ - ms = removeOldestTModelFromCache(ms, updateBOMneeded=true); + ms = removeOldestTModelFromCache(ms/*, updateBOMneeded=true*/); todo -= candidate; } for(candidate <- todo){ - ms = removeTModel(candidate, ms, updateBOMneeded=true); + ms = removeTModel(candidate, ms/*, updateBOMneeded=true*/); ms.status[candidate] -= bom_update_needed(); } return ms; @@ -341,7 +341,7 @@ ModuleStatus updateBOM(MID moduleId, ModuleStatus ms){ newBom = makeBom(moduleId, ms); if(newBom != tm.store[key_bom]){ tm.store[key_bom] = newBom; - ms.status[moduleId] -= tpl_saved(); + ms.status[moduleId] -= {tpl_saved(), bom_update_needed()}; ms = addTModel(moduleId, tm, ms); if(ms.compilerConfig.logWrittenFiles) println("Updated BOM: "); @@ -354,13 +354,17 @@ ModuleStatus updateBOM(MID moduleId, ModuleStatus ms){ ModuleStatus removeTModel(MID candidate, ModuleStatus ms, bool updateBOMneeded = false){ assert isModuleId(candidate) : "removeTModel: "; - if(candidate in ms.tmodels && ms.status[candidate]? && tpl_saved() notin ms.status[candidate] && rsc_not_found() notin ms.status[candidate]){ + if( updateBOMneeded + || ( candidate in ms.tmodels + && candidate in ms.status + && tpl_saved() notin ms.status[candidate] + && rsc_not_found() notin ms.status[candidate]) + ){ pcfg = ms.pathConfig; if(updateBOMneeded){ ms = updateBOM(candidate, ms); - } else { - ms.status[candidate] += bom_update_needed(); - } + } + ms.status[candidate] -= bom_update_needed(); = getTPLWriteLoc(candidate, pcfg); tm = ms.tmodels[candidate]; tm.messages = toList(toSet(tm.messages) + ms.messages[candidate]); // TODO needed ? @@ -409,7 +413,7 @@ tuple[bool, TModel, ModuleStatus] getTModelForModule(str moduleName, ModuleStatu tuple[bool, TModel, ModuleStatus] getTModelForModule(MID moduleId, ModuleStatus ms){ assert isModuleId(moduleId) : "getTModelForModule: "; - if(traceTModelCache) println("getTModelForModule: "); + if(traceTModelCache) println("getTModelForModule: "); pcfg = ms.pathConfig; if(moduleId in ms.tmodels){ tm = ms.tmodels[moduleId]; diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc index 0ebc12e1cb4..3ee53b325c3 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc @@ -224,7 +224,7 @@ ModuleStatus getImportAndExtendGraph(MID moduleId, ModuleStatus ms){ } } if(allImportsAndExtendsValid){ - ms.status[moduleId] += {tpl_uptodate(), checked()}; //TODO: maybe check existence of generated java files + ms.status[moduleId] += {tpl_uptodate(), checked(), tpl_saved()}; //TODO: maybe check existence of generated java files ms.moduleLocs += (moduleName2moduleId(mname) : tm.moduleLocs[mname] | mname <- tm.moduleLocs); // TODO: or not? ms.paths += tm.paths; // ms.strPaths += { | <- localImportsAndExtends }; diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc index 2835cd956ba..07e005a10d5 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc @@ -165,7 +165,7 @@ Accept rascalIsAcceptableSimple(loc def, Use use, Solver s){ } Accept rascalIsAcceptableQualified(loc def, Use use, Solver s){ - // println("rascalIsAcceptableQualified: , "); + // println("rascalIsAcceptableQualified: , "); path = def.path; if(path[0] == "/") path = path[1..]; @@ -173,7 +173,7 @@ Accept rascalIsAcceptableQualified(loc def, Use use, Solver s){ qualAsPath = split("::", use.ids[0]); // qualifier and proposed definition are the same? - if(defPath == qualAsPath){ + if(defPath[-size(qualAsPath)..] == qualAsPath){ return acceptBinding(); } @@ -181,13 +181,13 @@ Accept rascalIsAcceptableQualified(loc def, Use use, Solver s){ // Qualifier is a ADT name? if(acons(aadt(adtName, _, _), list[AType] _fields, list[Keyword] _kwFields) := atype){ - return use.ids[0] == adtName ? acceptBinding() : ignoreContinue(); + return use.ids[0] == adtName ? acceptBinding() : ignoreContinue(); } // Qualifier is a Production? if(aprod(prod(aadt(adtName, _, _), list[AType] _atypes)) := atype){ - return use.ids[0] == adtName ? acceptBinding() : ignoreContinue(); + return use.ids[0] == adtName ? acceptBinding() : ignoreContinue(); } // Is there another acceptable qualifier via an extend? diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst4.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst4.rsc index a6ba4073a7c..b0a178cfa02 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst4.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst4.rsc @@ -32,6 +32,11 @@ import lang::rascalcore::compile::Examples::Tst5; //AB xxx = AB::ab(); -value f() = AB::ab(); +// value f() = AB::ab(); + +void main(){ + lang::rascalcore::compile::Examples::Tst5::bla::empty(); +} + \ No newline at end of file diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst5.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst5.rsc index b6ab4c939be..ce3403882dd 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst5.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst5.rsc @@ -1,5 +1,8 @@ module lang::rascalcore::compile::Examples::Tst5 //extend lang::rascalcore::compile::Examples::Tst6; +data Tst5= txt(str s); -data AB = ab(); \ No newline at end of file +Tst5 empty() = txt(""); + + \ No newline at end of file From 8838f1a507820af31c2f613ad63df3e964d09cc1 Mon Sep 17 00:00:00 2001 From: paulklint Date: Sat, 10 Jan 2026 14:34:04 +0100 Subject: [PATCH 22/23] Introduced new kinds of logical locations in separate module --- .../rascalcore/check/LogicalLocations.rsc | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/org/rascalmpl/compiler/lang/rascalcore/check/LogicalLocations.rsc diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/LogicalLocations.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/LogicalLocations.rsc new file mode 100644 index 00000000000..bbb1ed218a6 --- /dev/null +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/LogicalLocations.rsc @@ -0,0 +1,31 @@ +module lang::rascalcore::check::LogicalLocations + +import String; +import lang::rascalcore::check::ATypeUtils; + +alias MODID = loc; // module identification + +bool isModuleId(loc l) = l.scheme == "rascal+module"; + +MODID moduleName2moduleId(str mname){ + return |rascal+module:///|; +} + +str moduleId2moduleName(loc mloc){ + assert mloc.scheme == "rascal+module" : "moduleId2moduleName: "; + path = mloc.path; + if(path[0] == "/") path = path[1..]; + return replaceAll(path, "/", "::"); +} + +alias FUNID = loc; // function identification + +bool isFunctionId(loc l) = l.scheme == "rascal+function"; + +alias CONSID = loc; // constructor identification + +bool isConstructorId(loc l) = l.scheme == "rascal+constructor"; + +alias FLDID = loc; // field identification + +bool isFieldId(loc l) = l.scheme == "rascal+field"; \ No newline at end of file From 428ffed8711bdcbf37ec255ea03c01d7d575be52 Mon Sep 17 00:00:00 2001 From: paulklint Date: Sat, 10 Jan 2026 14:35:01 +0100 Subject: [PATCH 23/23] Some renamings; undone early changes to backend --- .../lang/rascalcore/check/ADTandGrammar.rsc | 2 +- .../lang/rascalcore/check/Checker.rsc | 40 ++++++------ .../lang/rascalcore/check/CheckerCommon.rsc | 62 ++++++++----------- .../compiler/lang/rascalcore/check/Import.rsc | 44 ++++++------- .../lang/rascalcore/check/RascalConfig.rsc | 10 +-- .../lang/rascalcore/compile/Compile.rsc | 2 +- .../compile/Rascal2muRascal/RascalModule.rsc | 4 +- .../compile/muRascal2Java/CodeGen.rsc | 18 +++--- .../compile/muRascal2Java/Interface.rsc | 9 ++- .../compile/muRascal2Java/JGenie.rsc | 23 ++++--- .../compile/muRascal2Java/Resolvers.rsc | 13 ++-- 11 files changed, 110 insertions(+), 117 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/ADTandGrammar.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/ADTandGrammar.rsc index c6aaabc657f..46578396ce4 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/ADTandGrammar.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/ADTandGrammar.rsc @@ -165,7 +165,7 @@ list[&T <: node ] unsetRec(list[&T <: node] args) = [unsetRec(a) | a <- args]; bool isManualLayout(AProduction p) = (p has attributes && atag("manual"()) in p.attributes); -tuple[TModel, ModuleStatus] addGrammar(MID moduleId, set[MID] imports, set[MID] extends, map[MID,TModel] transient_tms, ModuleStatus ms){ +tuple[TModel, ModuleStatus] addGrammar(MODID moduleId, set[MODID] imports, set[MODID] extends, map[MODID,TModel] transient_tms, ModuleStatus ms){ try { rel[AType,AProduction] definedProductions = {}; allStarts = {}; diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/Checker.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/Checker.rsc index 29758a7d5cb..0b63696da40 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/Checker.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/Checker.rsc @@ -113,7 +113,7 @@ bool errorsPresent(list[Message] msgs) = !isEmpty([ e | e:error(_,_) <- msgs ]); // Dummy compile function (used when running only the checker) -list[Message] dummy_compile1(MID _moduleId, lang::rascal::\syntax::Rascal::Module _M, map[MID,TModel] _transient_tms, ModuleStatus _ms, RascalCompilerConfig _compilerConfig) +list[Message] dummy_compile1(MODID _moduleId, lang::rascal::\syntax::Rascal::Module _M, map[MODID,TModel] _transient_tms, ModuleStatus _ms, RascalCompilerConfig _compilerConfig) = []; // rascalTModelForLocs is the basic work horse @@ -123,7 +123,7 @@ list[Message] dummy_compile1(MID _moduleId, lang::rascal::\syntax::Rascal::Modul ModuleStatus rascalTModelForLocs( list[loc] mlocs, RascalCompilerConfig compilerConfig, - list[Message](MID moduleId, lang::rascal::\syntax::Rascal::Module M, map[MID,TModel] transient_tms, ModuleStatus ms, RascalCompilerConfig compilerConfig) codgen + list[Message](MODID moduleId, lang::rascal::\syntax::Rascal::Module M, map[MODID,TModel] transient_tms, ModuleStatus ms, RascalCompilerConfig compilerConfig) codgen ){ pcfg = compilerConfig.typepalPathConfig; @@ -204,20 +204,20 @@ ModuleStatus rascalTModelForLocs( imports_and_extends = ms.paths<0,2>; = stronglyConnectedComponentsAndTopSort(imports_and_extends); - map[MID, set[MID]] module2component = (m : c | c <- components, m <- c); + map[MODID, set[MODID]] module2component = (m : c | c <- components, m <- c); - list[MID] ordered = []; + list[MODID] ordered = []; if(isEmpty(sorted)){ ordered = toList(topModuleIds); - for(MID topModuleId <- topModuleIds){ + for(MODID topModuleId <- topModuleIds){ module2component[topModuleId] = {topModuleId}; } } else { ordered = reverse(sorted); singletons = toList(topModuleIds - toSet(ordered)); ordered += singletons; - for(MID singleton <- singletons){ + for(MODID singleton <- singletons){ module2component[singleton] = {singleton}; } } @@ -294,8 +294,8 @@ ModuleStatus rascalTModelForLocs( = rascalTModelComponent(component, ms); // moduleScopes += getModuleScopes(tm); map[str,TModel] tmodels_for_component = (); - map[MID,set[MID]] m_imports = (); - map[MID,set[MID]] m_extends = (); + map[MODID,set[MODID]] m_imports = (); + map[MODID,set[MODID]] m_extends = (); for(m <- component, rsc_not_found() notin ms.status[m], MStatus::ignored() notin ms.status[m]){ imports = { imp | <- ms.paths, m1 == m, MStatus::ignored() notin ms.status[imp]}; m_imports[m] = imports; @@ -358,7 +358,7 @@ ModuleStatus rascalTModelForLocs( // generate code for the modules in this component - for(MID m <- component, MStatus::ignored() notin ms.status[m]){ + for(MODID m <- component, MStatus::ignored() notin ms.status[m]){ = getModuleParseTree(m, ms); if(success){ lmsgs = codgen(m, pt, transient_tms, ms, compilerConfig); @@ -378,15 +378,15 @@ ModuleStatus rascalTModelForLocs( } } } catch ParseError(loc src): { - for(MID mid <- topModuleIds){ + for(MODID mid <- topModuleIds){ ms.messages[mid] = { error("Parse error", src) }; } } catch rascalTplVersionError(str txt):{ - for(MID mid <- topModuleIds){ + for(MODID mid <- topModuleIds){ ms.messages[mid] = { error("", ms.moduleLocs[mid] ? |unknown:///|) }; } } catch Message msg: { - for(MID mid <- topModuleIds){ + for(MODID mid <- topModuleIds){ ms.messages[mid] = { error("During type checking: ", msg.at) }; } } @@ -412,7 +412,7 @@ bool usesOrExtendsADT(str modulePath, str importPath, TModel tm){ return res; } -tuple[set[MID], ModuleStatus] loadImportsAndExtends(set[MID] moduleIds, ModuleStatus ms, Collector c, set[MID] added){ +tuple[set[MODID], ModuleStatus] loadImportsAndExtends(set[MODID] moduleIds, ModuleStatus ms, Collector c, set[MODID] added){ pcfg = ms.pathConfig; for( <- ms.paths, from in moduleIds){ if(imp notin added, imp notin moduleIds){ @@ -433,13 +433,13 @@ tuple[set[MID], ModuleStatus] loadImportsAndExtends(set[MID] moduleIds, ModuleSt return ; } -tuple[TModel, ModuleStatus] rascalTModelComponent(set[MID] moduleIds, ModuleStatus ms){ +tuple[TModel, ModuleStatus] rascalTModelComponent(set[MODID] moduleIds, ModuleStatus ms){ pcfg = ms.pathConfig; compilerConfig = ms.compilerConfig; modelNames = [moduleId2moduleName(moduleId) | moduleId <- moduleIds]; modelName = intercalate(" + ", modelNames); - map[MID, Module] idTrees = (); - for(MID mid <- moduleIds){ + map[MODID, Module] idTrees = (); + for(MODID mid <- moduleIds){ mname = moduleId2moduleName(mid); //ms.status[mid] = {}; //ms.messages[mid] = {}; @@ -515,7 +515,7 @@ tuple[TModel, ModuleStatus] rascalTModelComponent(set[MID] moduleIds, ModuleStat ModuleStatus rascalTModelForNames(list[str] moduleNames, RascalCompilerConfig compilerConfig, - list[Message] (MID moduleId, lang::rascal::\syntax::Rascal::Module M, map[MID,TModel] transient_tms, ModuleStatus ms, RascalCompilerConfig compilerConfig) codgen){ + list[Message] (MODID moduleId, lang::rascal::\syntax::Rascal::Module M, map[MODID,TModel] transient_tms, ModuleStatus ms, RascalCompilerConfig compilerConfig) codgen){ pcfg = compilerConfig.typepalPathConfig; mlocs = []; @@ -542,7 +542,7 @@ bool uptodateTPls(list[loc] candidates, list[str] mnames, PathConfig pcfg){ return true; } -tuple[bool, ModuleStatus] libraryDependenciesAreCompatible(list[MID] candidates, ModuleStatus ms){ +tuple[bool, ModuleStatus] libraryDependenciesAreCompatible(list[MODID] candidates, ModuleStatus ms){ pcfg = ms.pathConfig; for(candidate <- candidates){ = getTModelForModule(candidate, ms); @@ -575,8 +575,8 @@ list[ModuleMessages] check(list[loc] moduleLocs, RascalCompilerConfig compilerCo list[ModuleMessages] reportModuleMessages(ModuleStatus ms){ moduleIds = domain(ms.moduleLocs); - messagesNoModule = {*ms.messages[mid] | MID mid <- ms.messages, (mid notin moduleIds || mid notin ms.moduleLocs)} + toSet(ms.pathConfig.messages); - msgs = [ program(ms.moduleLocs[mid], (ms.messages[mid] ? {}) + messagesNoModule) | MID mid <- moduleIds ]; + messagesNoModule = {*ms.messages[mid] | MODID mid <- ms.messages, (mid notin moduleIds || mid notin ms.moduleLocs)} + toSet(ms.pathConfig.messages); + msgs = [ program(ms.moduleLocs[mid], (ms.messages[mid] ? {}) + messagesNoModule) | MODID mid <- moduleIds ]; if(isEmpty(msgs) && !isEmpty(messagesNoModule)){ msgs = [ program(|unknown:///|, messagesNoModule) ]; } diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc index 702a6f4ec5e..9b8fc280183 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/CheckerCommon.rsc @@ -40,6 +40,7 @@ extend analysis::typepal::FailMessage; extend lang::rascalcore::check::BasicRascalConfig; extend lang::rascalcore::check::ModuleLocations; extend lang::rascalcore::CompilerPathConfig; +extend lang::rascalcore::check::LogicalLocations; extend analysis::typepal::Collector; @@ -67,20 +68,7 @@ void checkSupportedByParserGenerator(Tree t, Collector c){ }); } -alias MID = loc; // module identification -bool isModuleId(loc l) = l.scheme == "rascal+module"; - -MID moduleName2moduleId(str mname){ - return |rascal+module:///|; -} - -str moduleId2moduleName(loc mloc){ - assert mloc.scheme == "rascal+module" : "moduleId2moduleName: "; - path = mloc.path; - if(path[0] == "/") path = path[1..]; - return replaceAll(path, "/", "::"); -} data MStatus = rsc_not_found() @@ -101,16 +89,16 @@ data MStatus = data ModuleStatus = moduleStatus( - rel[MID, PathRole, MID] paths, - map[MID, Module] parseTrees, - list[MID] parseTreeLIFO, - map[MID, TModel] tmodels, - list[MID] tmodelLIFO, - set[MID] changedModules, - map[MID,loc] moduleLocs, - map[MID,datetime] moduleLastModified, - map[MID, set[Message]] messages, - map[MID, set[MStatus]] status, + rel[MODID, PathRole, MODID] paths, + map[MODID, Module] parseTrees, + list[MODID] parseTreeLIFO, + map[MODID, TModel] tmodels, + list[MODID] tmodelLIFO, + set[MODID] changedModules, + map[MODID,loc] moduleLocs, + map[MODID,datetime] moduleLastModified, + map[MODID, set[Message]] messages, + map[MODID, set[MStatus]] status, PathConfig pathConfig, RascalCompilerConfig compilerConfig ); @@ -143,7 +131,7 @@ bool traceTModelCache = false; tuple[bool,loc] getTPLReadLoc(str qualifiedModuleName, PathConfig pcfg) = getTPLReadLoc(moduleName2moduleId(qualifiedModuleName), pcfg); -tuple[bool,loc] getTPLReadLoc(MID moduleId, PathConfig pcfg){ +tuple[bool,loc] getTPLReadLoc(MODID moduleId, PathConfig pcfg){ assert isModuleId(moduleId) : "getTPLReadLoc: "; parts = split("/", moduleId.path); parts = parts[0 .. size(parts)-1] + "$"; @@ -163,7 +151,7 @@ tuple[bool,loc] getTPLReadLoc(MID moduleId, PathConfig pcfg){ return ; } -tuple[bool,loc] getTPLWriteLoc(MID moduleId, PathConfig pcfg){ +tuple[bool,loc] getTPLWriteLoc(MODID moduleId, PathConfig pcfg){ assert isModuleId(moduleId) : "getTPLWriteLoc: "; qualifiedModuleName = moduleId2moduleName(moduleId); fileName = ".tpl"; @@ -173,7 +161,7 @@ tuple[bool,loc] getTPLWriteLoc(MID moduleId, PathConfig pcfg){ datetime startOfEpoch = $2000-01-01T00:00:00.000+00:00$; -datetime getLastModified(MID moduleId, ModuleStatus ms){ +datetime getLastModified(MODID moduleId, ModuleStatus ms){ assert isModuleId(moduleId) : "getLastModified: "; qualifiedModuleName = moduleId2moduleName(moduleId); if(moduleId in ms.moduleLastModified){ @@ -189,7 +177,7 @@ datetime getLastModified(MID moduleId, ModuleStatus ms){ } // Check if a module is modified compared to a given timestamp in BOM -tuple[bool,ModuleStatus] isModuleModified(MID moduleId, datetime timestamp, PathRole pathRole, ModuleStatus ms){ +tuple[bool,ModuleStatus] isModuleModified(MODID moduleId, datetime timestamp, PathRole pathRole, ModuleStatus ms){ pcfg = ms.pathConfig; try { mloc = getRascalModuleLocation(moduleId, ms); @@ -218,7 +206,7 @@ tuple[bool,ModuleStatus] isModuleModified(MID moduleId, datetime timestamp, Path } } -bool tplOutdated(MID moduleId, PathConfig pcfg){ +bool tplOutdated(MODID moduleId, PathConfig pcfg){ try { qualifiedModuleName = moduleId2moduleName(moduleId); mloc = getRascalModuleLocation(qualifiedModuleName, pcfg); @@ -235,7 +223,7 @@ bool tplOutdated(MID moduleId, PathConfig pcfg){ int parseTreeCacheSize = 20; -tuple[bool, Module, ModuleStatus] getModuleParseTree(MID moduleId, ModuleStatus ms){ +tuple[bool, Module, ModuleStatus] getModuleParseTree(MODID moduleId, ModuleStatus ms){ assert isModuleId(moduleId) : "getModuleParseTree: "; pcfg = ms.pathConfig; qualifiedModuleName = moduleId2moduleName(moduleId); @@ -289,7 +277,7 @@ tuple[bool, Module, ModuleStatus] getModuleParseTree(MID moduleId, ModuleStatus } } -loc getRascalModuleLocation(MID moduleId, ModuleStatus ms){ +loc getRascalModuleLocation(MODID moduleId, ModuleStatus ms){ if(moduleId in ms.moduleLocs){ loc l = ms.moduleLocs[moduleId]; if(!isLogicalLoc(l)) return l; @@ -321,7 +309,7 @@ ModuleStatus clearTModelCache(ModuleStatus ms){ return ms; } -rel[str,datetime,PathRole] makeBom(MID moduleId, ModuleStatus ms){ +rel[str,datetime,PathRole] makeBom(MODID moduleId, ModuleStatus ms){ pcfg = ms.pathConfig; qualifiedModuleName = moduleId2moduleName(moduleId); imports = ms.paths[moduleId,importPath()]; @@ -331,7 +319,7 @@ rel[str,datetime,PathRole] makeBom(MID moduleId, ModuleStatus ms){ + { }; } -ModuleStatus updateBOM(MID moduleId, ModuleStatus ms){ +ModuleStatus updateBOM(MODID moduleId, ModuleStatus ms){ if(rsc_not_found() in ms.status[moduleId]){ return ms; } @@ -352,7 +340,7 @@ ModuleStatus updateBOM(MID moduleId, ModuleStatus ms){ return ms; } -ModuleStatus removeTModel(MID candidate, ModuleStatus ms, bool updateBOMneeded = false){ +ModuleStatus removeTModel(MODID candidate, ModuleStatus ms, bool updateBOMneeded = false){ assert isModuleId(candidate) : "removeTModel: "; if( updateBOMneeded || ( candidate in ms.tmodels @@ -392,7 +380,7 @@ ModuleStatus removeOldestTModelFromCache(ModuleStatus ms, bool updateBOMneeded = return ms; } -ModuleStatus addTModel (MID moduleId, TModel tm, ModuleStatus ms){ +ModuleStatus addTModel (MODID moduleId, TModel tm, ModuleStatus ms){ if(traceTModelCache) println("addTModel: "); if(tmodelCacheSize > 0){ ms.tmodels[moduleId] = tm; @@ -411,7 +399,7 @@ private type[TModel] ReifiedTModel = #TModel; // precomputed for efficiency tuple[bool, TModel, ModuleStatus] getTModelForModule(str moduleName, ModuleStatus ms) = getTModelForModule(moduleName2moduleId(moduleName), ms); -tuple[bool, TModel, ModuleStatus] getTModelForModule(MID moduleId, ModuleStatus ms){ +tuple[bool, TModel, ModuleStatus] getTModelForModule(MODID moduleId, ModuleStatus ms){ assert isModuleId(moduleId) : "getTModelForModule: "; if(traceTModelCache) println("getTModelForModule: "); pcfg = ms.pathConfig; @@ -451,9 +439,9 @@ tuple[bool, TModel, ModuleStatus] getTModelForModule(MID moduleId, ModuleStatus return ", tplLoc)]), ms>; } -rel[loc from, PathRole r, loc to] getPaths(rel[MID from, PathRole r, MID to] paths, ModuleStatus ms){ +rel[loc from, PathRole r, loc to] getPaths(rel[MODID from, PathRole r, MODID to] paths, ModuleStatus ms){ paths = {}; - for( <- paths){ + for( <- paths){ try { mfrom = getRascalModuleLocation(from, ms); mto = getRascalModuleLocation(to, ms); diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc index 3ee53b325c3..ae78e61512b 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc @@ -62,7 +62,7 @@ ModuleStatus reportSelfImport(rel[loc, PathRole, loc] paths, ModuleStatus ms){ return ms; } -ModuleStatus reportCycles(rel[MID, PathRole, MID]paths, rel[MID,MID] extendPlus, ModuleStatus ms){ +ModuleStatus reportCycles(rel[MODID, PathRole, MODID]paths, rel[MODID,MODID] extendPlus, ModuleStatus ms){ extendCycle = { m | <- extendPlus }; if(size(extendCycle) > 0){ for(mid <- extendCycle){ @@ -103,33 +103,33 @@ ModuleStatus completeModuleStatus(ModuleStatus ms){ ms = reportSelfImport(paths, ms); - imports = { | <- paths}; - extendPlus = { | <- paths}+; - paths += { | <- extendPlus }; + imports = { | <- paths}; + extendPlus = { | <- paths}+; + paths += { | <- extendPlus }; ms = reportCycles(paths, extendPlus, ms); paths += { *{ | a <- extendPlus[b], c != a} - | < MID c, MID b> <- imports + | < MODID c, MODID b> <- imports }; ms.paths = paths; return ms; } -ModuleStatus getImportAndExtendGraph(set[MID] moduleIds, RascalCompilerConfig ccfg){ +ModuleStatus getImportAndExtendGraph(set[MODID] moduleIds, RascalCompilerConfig ccfg){ return completeModuleStatus((newModuleStatus(ccfg) | getImportAndExtendGraph(moduleId, it) | moduleId <- moduleIds)); } -ModuleStatus getImportAndExtendGraph(set[MID] moduleIds, ModuleStatus ms){ +ModuleStatus getImportAndExtendGraph(set[MODID] moduleIds, ModuleStatus ms){ return completeModuleStatus((ms | getImportAndExtendGraph(moduleId, it) | moduleId <- moduleIds)); } -ModuleStatus getImportAndExtendGraph(MID moduleId, RascalCompilerConfig ccfg){ +ModuleStatus getImportAndExtendGraph(MODID moduleId, RascalCompilerConfig ccfg){ return completeModuleStatus(getImportAndExtendGraph(moduleId, newModuleStatus(ccfg))); } -ModuleStatus getImportAndExtendGraph(MID moduleId, ModuleStatus ms){ +ModuleStatus getImportAndExtendGraph(MODID moduleId, ModuleStatus ms){ assert isModuleId(moduleId): "getImportAndExtendGraph: "; pcfg = ms.pathConfig; qualifiedModuleName = moduleId2moduleName(moduleId); @@ -196,7 +196,7 @@ ModuleStatus getImportAndExtendGraph(MID moduleId, ModuleStatus ms){ if(!isLogicalLoc(mloc) && (mloc.extension != "rsc" || isModuleLocationInLibs(mloc, pcfg))) throw "No src or library module 1"; //There is only a tpl file available } catch value _:{ = isCompatibleBinaryLibrary(tm, ms); - incompatibleNames = [ getModuleNameFromAnyLogical(imod) | MID imod <- incompatible ]; + incompatibleNames = [ getModuleNameFromAnyLogical(imod) | MODID imod <- incompatible ]; if(!isEmpty(incompatible)){ causes = [ info("Module is incompatible with ", incomp) | incomp <- incompatible ]; txt = "Review of dependencies, reconfiguration or recompilation needed: binary module `` depends (indirectly) on incompatible module(s) "; @@ -271,7 +271,7 @@ ModuleStatus getInlineImportAndExtendGraph(Tree pt, RascalCompilerConfig ccfg){ } // Is binary library module compatible with its dependencies (originating from imports and extends)? -tuple[list[MID], ModuleStatus] isCompatibleBinaryLibrary(TModel lib, ModuleStatus ms){ +tuple[list[MODID], ModuleStatus] isCompatibleBinaryLibrary(TModel lib, ModuleStatus ms){ libName = lib.modelName; set[loc] libLogical = domain(lib.logical2physical); set[loc] libDefines = { l | l <- libLogical, getModuleNameFromAnyLogical(l) == libName }; @@ -314,7 +314,7 @@ str getModuleNameFromAnyLogical(loc l){ } -tuple[bool, ModuleStatus] importsAndExtendsAreBinaryCompatible(TModel tm, set[MID] importsAndExtends, ModuleStatus ms){ +tuple[bool, ModuleStatus] importsAndExtendsAreBinaryCompatible(TModel tm, set[MODID] importsAndExtends, ModuleStatus ms){ moduleName = tm.modelName; physical2logical = invertUnique(tm.logical2physical); @@ -344,7 +344,7 @@ tuple[bool, ModuleStatus] importsAndExtendsAreBinaryCompatible(TModel tm, set[MI tuple[ModuleStatus, rel[loc, PathRole, loc]] getModulePaths(Module m, ModuleStatus ms){ moduleName = unescape(""); - MID moduleId = moduleName2moduleId(moduleName); + MODID moduleId = moduleName2moduleId(moduleName); imports_and_extends = {}; for(imod <- m.header.imports, imod has \module){ iname = unescape(""); @@ -381,7 +381,7 @@ map[str, loc] getModuleScopes(TModel tm) // throw "No module scope found for "; // } -tuple[map[MID,TModel], ModuleStatus] prepareForCompilation(set[MID] component, map[MID,set[MID]] m_imports, map[MID,set[MID]] m_extends, ModuleStatus ms, TModel tm){ +tuple[map[MODID,TModel], ModuleStatus] prepareForCompilation(set[MODID] component, map[MODID,set[MODID]] m_imports, map[MODID,set[MODID]] m_extends, ModuleStatus ms, TModel tm){ //map[str,TModel] tmodels = (); //ms.tmodels; pcfg = ms.pathConfig; @@ -404,7 +404,7 @@ tuple[map[MID,TModel], ModuleStatus] prepareForCompilation(set[MID] component, m } transient_tms = (m : tm | m <- component); org_tm = tm; - for(MID m <- component, rsc_not_found() notin ms.status[m], MStatus::ignored() notin ms.status[m]){ + for(MODID m <- component, rsc_not_found() notin ms.status[m], MStatus::ignored() notin ms.status[m]){ tm = org_tm; mname = moduleId2moduleName(m); tm.modelName = mname; @@ -419,15 +419,15 @@ tuple[map[MID,TModel], ModuleStatus] prepareForCompilation(set[MID] component, m return ; } -ModuleStatus doSaveModule(set[MID] component, map[MID,set[MID]] m_imports, map[MID,set[MID]] m_extends, ModuleStatus ms, map[MID, TModel] transient_tms, RascalCompilerConfig compilerConfig){ +ModuleStatus doSaveModule(set[MODID] component, map[MODID,set[MODID]] m_imports, map[MODID,set[MODID]] m_extends, ModuleStatus ms, map[MODID, TModel] transient_tms, RascalCompilerConfig compilerConfig){ pcfg = ms.pathConfig; component = { m | m <- component, MStatus::ignored() notin ms.status[m] }; if(isEmpty(component)) return ms; //println("doSaveModule: , , , "); - component_scopes = component; //{ getModuleScope(mid, moduleScopes, pcfg) | MID mid <- component }; - set[MID] filteredModuleScopes = {}; + component_scopes = component; //{ getModuleScope(mid, moduleScopes, pcfg) | MODID mid <- component }; + set[MODID] filteredModuleScopes = {}; loc2moduleName = invertUnique(ms.moduleLocs); bool isContainedInComponentScopes(loc inner, map[loc,loc] m){ @@ -448,9 +448,9 @@ ModuleStatus doSaveModule(set[MID] component, map[MID,set[MID]] m_imports, map[M bom = makeBom(currentModule, ms); - extendedModuleScopes = {m | MID m <- extends, checked() in ms.status[m]}; - extendedModuleScopes += {*tm.paths[ems,importPath()] | MID ems <- extendedModuleScopes}; // add imports of extended modules - filteredModuleScopes = {m | MID m <- (currentModule + imports), checked() in ms.status[m]} + extendedModuleScopes; + extendedModuleScopes = {m | MODID m <- extends, checked() in ms.status[m]}; + extendedModuleScopes += {*tm.paths[ems,importPath()] | MODID ems <- extendedModuleScopes}; // add imports of extended modules + filteredModuleScopes = {m | MODID m <- (currentModule + imports), checked() in ms.status[m]} + extendedModuleScopes; TModel m1 = tmodel(); m1.rascalTplVersion = compilerConfig.rascalTplVersion; @@ -485,7 +485,7 @@ ModuleStatus doSaveModule(set[MID] component, map[MID,set[MID]] m_imports, map[M m1.store[key_common_keyword_fields] = tm.store[key_common_keyword_fields] ? []; - m1.paths = { tup | tuple[MID from, PathRole pathRole, MID 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 <- tm.paths, tup.from == currentModule || tup.from in filteredModuleScopes /*|| tup.from in filteredModuleScopePaths*/ }; keepRoles = variableRoles + keepInTModelRoles; m1.useDef = { diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc index 07e005a10d5..6b936db1344 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc @@ -380,13 +380,13 @@ bool rascalReportUnused(loc def, TModel tm){ // Extend the path relation by // - adding transitive edges for extend // - adding imports via these extends -rel[loc, PathRole,loc] enhancePathRelation(rel[MID, PathRole,MID] paths){ - extendPlus = { | <- paths}+; - paths += { | <- extendPlus}; +rel[loc, PathRole,loc] enhancePathRelation(rel[MODID, PathRole,MODID] paths){ + extendPlus = { | <- paths}+; + paths += { | <- extendPlus}; - imports = { | <- paths}; + imports = { | <- paths}; delta = { - | <- extendPlus o imports, + | <- extendPlus o imports, notin paths, from != to2 }; diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Compile.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Compile.rsc index 3ec511c2e30..f70913380eb 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Compile.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Compile.rsc @@ -48,7 +48,7 @@ import lang::rascalcore::compile::util::Names; data ModuleStatus; -list[Message] compile1(MID moduleId, lang::rascal::\syntax::Rascal::Module M, map[MID,TModel] transient_tms, ModuleStatus ms, RascalCompilerConfig compilerConfig){ +list[Message] compile1(MODID moduleId, lang::rascal::\syntax::Rascal::Module M, map[MODID,TModel] transient_tms, ModuleStatus ms, RascalCompilerConfig compilerConfig){ qualifiedModuleName = moduleId2moduleName(moduleId); pcfg = ms.pathConfig; tm = transient_tms[moduleId]; diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalModule.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalModule.rsc index e47d2374159..422f0f71e30 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalModule.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalModule.rsc @@ -41,6 +41,8 @@ import lang::rascalcore::compile::muRascal::AST; //extend lang::rascalcore::check::Checker; extend analysis::typepal::TypePal; import lang::rascalcore::check::RascalConfig; +import lang::rascalcore::check::LogicalLocations; + import lang::rascalcore::compile::Rascal2muRascal::ModuleInfo; import lang::rascalcore::compile::Rascal2muRascal::TmpAndLabel; @@ -71,7 +73,7 @@ tuple[TModel, MuModule] r2mu(lang::rascal::\syntax::Rascal::Module M, TModel tmo M_module_name = unescape(""); setModuleName(M_module_name); - module_scope = moduleName2ModuleId(M_module_name); + module_scope = moduleName2moduleId(M_module_name); setModuleScope(module_scope); mtags = translateTags(M.header.tags); diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/CodeGen.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/CodeGen.rsc index a06930f9629..1542d7e804c 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/CodeGen.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/CodeGen.rsc @@ -63,7 +63,7 @@ bool debug = false; // ---- globals --------------------------------------------------------------- -map[MID, MuFunction] muFunctions = (); +map[str, MuFunction] muFunctions = (); map[loc, MuFunction] loc2muFunction = (); int naux = 0; @@ -73,20 +73,20 @@ int naux = 0; // Generate code and test class for a single Rascal module tuple[JCode, JCode, JCode, list[value]] muRascal2Java(MuModule m, ModuleStatus ms){ - map[MID,TModel] tmodels = ms.tmodels; - map[MID,loc] moduleLocs = ms .moduleLocs; + map[str,TModel] tmodels = (moduleId2moduleName(mid) : ms.tmodels[mid] | mid <- ms.tmodels); + map[str,loc] moduleLocs = (moduleId2moduleName(mid) : ms.moduleLocs[mid] | mid <- ms.moduleLocs); PathConfig pcfg = ms.pathConfig; naux = 0; moduleName = m.name; - MID moduleId = moduleName2moduleId(moduleName); + MODID moduleId = moduleName2moduleId(moduleName); locsModule = invertUnique(moduleLocs); - module_scope = moduleLocs[moduleId]; + module_scope = moduleLocs[moduleName]; = getTModelForModule(moduleId, ms); //strPaths = { | <- tm.paths }; - paths = tm.paths; - extends = { mname | <- paths }; - imports = { mname | <- paths }; + paths = { | <- tm.paths}; + extends = { mname | <- paths }; + imports = { mname | <- paths }; imports += { mname | imp <- imports, <- paths}; loc2muFunction = (f.src : f | f <- m.functions); @@ -106,7 +106,7 @@ tuple[JCode, JCode, JCode, list[value]] muRascal2Java(MuModule m, ModuleStatus m muFunctions = (f.uniqueName : f | f <- m.functions); jg = makeJGenie(m, tmodels, moduleLocs, muFunctions); - resolvers = generateResolvers(moduleId, loc2muFunction, imports, extends, tmodels, moduleLocs, pcfg, jg); + resolvers = generateResolvers(moduleName, loc2muFunction, imports, extends, tmodels, moduleLocs, pcfg, jg); map[loc,AType] facts = tm.facts; cons_in_module = { def.defInfo.atype | Define def <-range(tm.definitions), def.idRole == constructorId(), jg.isContainedIn(def.scope, module_scope) } diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Interface.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Interface.rsc index 048fedbf5fb..c6908c66a6f 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Interface.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Interface.rsc @@ -44,7 +44,7 @@ import String; // Generate an interface for a Rascal module -str generateInterface(str moduleName, str packageName, list[MuFunction] functions, set[MID] imports, set[MID] extends, map[MID,TModel] tmodels, PathConfig pcfg, JGenie _jg){ +str generateInterface(str moduleName, str packageName, list[MuFunction] functions, set[str] imports, set[str] extends, map[str,TModel] tmodels, PathConfig pcfg, JGenie _jg){ return "package ;<}> 'import io.usethesource.vallang.*; 'import org.rascalmpl.runtime.function.*; @@ -55,11 +55,10 @@ str generateInterface(str moduleName, str packageName, list[MuFunction] function '}"; } -lrel[str, AType] getInterfaceSignature(str moduleName, list[MuFunction] functions, set[MID] _imports, set[MID] extends, map[MID,TModel] tmodels, PathConfig pcfg){ - MID moduleId = moduleName2moduleId(moduleName); +lrel[str, AType] getInterfaceSignature(str moduleName, list[MuFunction] functions, set[str] _imports, set[str] extends, map[str,TModel] tmodels, PathConfig pcfg){ lrel[str, AType] result = []; rel[str, int, AType] signatures = {}; - mscope = tmodels[moduleId].moduleLocs[moduleName]; + mscope = tmodels[moduleName].moduleLocs[moduleName]; for(f <- functions, isEmpty(f.scopeIn), isContainedIn(f.src, mscope), @@ -101,7 +100,7 @@ lrel[str, AType] getInterfaceSignature(str moduleName, list[MuFunction] function return sort(result); } -str generateInterfaceMethods(str moduleName, list[MuFunction] functions, set[MID] imports, set[MID] extends, map[MID,TModel] tmodels, PathConfig pcfg){ +str generateInterfaceMethods(str moduleName, list[MuFunction] functions, set[str] imports, set[str] extends, map[str,TModel] tmodels, PathConfig pcfg){ interface_signature = getInterfaceSignature(moduleName, functions, imports, extends, tmodels, pcfg); methods = [generateInterfaceMethod(name, tp) | <- interface_signature]; return intercalate("\n", methods); diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/JGenie.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/JGenie.rsc index 31cfdf9e47a..09099adbe7f 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/JGenie.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/JGenie.rsc @@ -86,15 +86,20 @@ data JGenie ; JGenie makeJGenie(MuModule m, - map[MID,TModel] tmodels, - map[MID,loc] moduleLocs, - map[MID, MuFunction] muFunctions){ - - map[MID,loc] allModuleLocs = moduleLocs; - map[loc,MID] allLocs2Module = invertUnique((mname : moduleLocs[mname].top | mname <- moduleLocs)); + map[str,TModel] tmodels, + map[str,loc] moduleLocs, + map[str, MuFunction] muFunctions){ + + // // temporary glue code + // map[str,TModel] tmodels = (moduleId2moduleName(mid) : tmodels[mid] | mid <- tmodels0); + // map[str,loc] moduleLocs = (moduleId2moduleName(mid) : moduleLocs[mid] | mid <- moduleLocs0); + // map[str,loc] moduleLocs = (moduleId2moduleName(mid) : muFunctions0[mid] | mid <- muFunctions0); + + map[str,loc] allModuleLocs = moduleLocs; + map[loc,str] allLocs2Module = invertUnique((mname : moduleLocs[mname].top | mname <- moduleLocs)); MuModule currentModule = m; str moduleName = m.name; - MID moduleId = moduleName2moduleId(moduleName); + MODID moduleId = moduleName2moduleId(moduleName); map[AType, map[str,AType]] commonKeywordFieldsNameAndType = m.commonKeywordFields; map[value,int] constant2idx = (); map[int,value] idx2constant = (); @@ -116,9 +121,9 @@ JGenie makeJGenie(MuModule m, checkAllTypesAvailable(tmodels[mname]); } - TModel currentTModel = tmodels[moduleId]; + TModel currentTModel = tmodels[moduleName]; checkAllTypesAvailable(currentTModel); // TODO: remove - loc currentModuleScope = moduleLocs[moduleId]; + loc currentModuleScope = moduleLocs[moduleName]; str functionName = "$UNKNOWN"; MuFunction function = muFunction("", "*unknown", avalue(), [], [], [], "", false, true, false, {}, {}, {}, currentModuleScope, [], (), muBlock([])); diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Resolvers.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Resolvers.rsc index 80a8d4e32d8..44c350b552d 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Resolvers.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Resolvers.rsc @@ -148,9 +148,8 @@ public set[set[Define]] mygroup(set[Define] input, bool (Define a, Define b) sim // Generate all resolvers for a given module -str generateResolvers(MID moduleId, map[loc, MuFunction] loc2muFunction, set[MID] imports, set[MID] extends, map[MID,TModel] tmodels, map[MID,loc] module2loc, PathConfig pcfg, JGenie jg){ - moduleName = moduleId2moduleName(moduleId); - module_scope = module2loc[moduleId]; +str generateResolvers(str moduleName, map[loc, MuFunction] loc2muFunction, set[str] imports, set[str] extends, map[str,TModel] tmodels, map[str,loc] module2loc, PathConfig pcfg, JGenie jg){ + module_scope = module2loc[moduleName]; loc2module = invertUnique(module2loc); module_scopes = domain(loc2module); @@ -177,7 +176,7 @@ str generateResolvers(MID moduleId, map[loc, MuFunction] loc2muFunction, set[MID for(sdefs <- defs_in_disjoint_scopes){ if(any(d <- sdefs, d.scope notin module_scopes)){ // All local functions trated samw wrt keyword parameters - resolvers += generateResolver(moduleName, fname, sdefs, loc2muFunction, module_scope, import_scopes, extend_scopes, tmodels[moduleId].paths, tmodels[moduleId], loc2module, pcfg, jg); + resolvers += generateResolver(moduleName, fname, sdefs, loc2muFunction, module_scope, import_scopes, extend_scopes, tmodels[moduleName].paths, tmodels[moduleName], loc2module, pcfg, jg); } else { // For global functions we differentiate wrt keyword oarameters @@ -219,7 +218,7 @@ tuple[bool,loc] findImplementingModule(set[Define] fun_defs, set[loc] import_sco } // Generate a resolver for a specific function -str generateResolver(str moduleName, str functionName, set[Define] fun_defs, map[loc, MuFunction] loc2muFunction, loc module_scope, set[loc] import_scopes, set[loc] extend_scopes, Paths paths, TModel tm, map[loc, MID] loc2module, PathConfig pcfg, JGenie jg){ +str generateResolver(str moduleName, str functionName, set[Define] fun_defs, map[loc, MuFunction] loc2muFunction, loc module_scope, set[loc] import_scopes, set[loc] extend_scopes, Paths paths, TModel tm, map[loc, str] loc2module, PathConfig pcfg, JGenie jg){ //println("generate resolver for , "); module_scopes = domain(loc2module); @@ -228,8 +227,8 @@ str generateResolver(str moduleName, str functionName, set[Define] fun_defs, map nonlocal_fun_defs0 = for(def <- fun_defs){ - if(!isEmpty(extend_scopes) && any(ext <- extend_scopes, jg.isContainedIn(def.defined, ext))) append def; - if(!isEmpty(import_scopes) && any(imp <- import_scopes, jg.isContainedIn(def.defined, imp))) append def; + if(!isEmpty(extend_scopes) && any(ext <- extend_scopes, jg.isContainedIn(def.defined, moduleName2moduleId(ext)))) append def; + if(!isEmpty(import_scopes) && any(imp <- import_scopes, jg.isContainedIn(def.defined, moduleId2moduleName(imp)))) append def; }; nonlocal_fun_defs = toSet(nonlocal_fun_defs0); set[Define] relevant_fun_defs = local_fun_defs + nonlocal_fun_defs;