diff --git a/rascal.code-workspace b/rascal.code-workspace index d885fe36eae..785db1bfba2 100644 --- a/rascal.code-workspace +++ b/rascal.code-workspace @@ -5,6 +5,9 @@ }, { "path": "../typepal" + }, + { + "path": "../compiled-rascal" } ], "settings": { diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc index b53b2acf9b2..d3dd8975f0b 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/RascalConfig.rsc @@ -39,6 +39,7 @@ import lang::rascalcore::compile::muRascal::AST; import lang::rascalcore::check::CheckerCommon; import lang::rascalcore::check::BasicRascalConfig; import lang::rascalcore::check::ModuleLocations; +import lang::rascalcore::check::LogicalLocations; import Location; import util::FileSystem; @@ -77,62 +78,15 @@ bool rascalMayOverload(set[loc] defs, map[loc, Define] defines){ } } } - - // oldResult = rascalMayOverloadOld(defs, defines); - // if(result != oldResult){ - // println("rascalMayOverload, new: , old: , for "); - // for(def <- defs){ - // println(defines[def]); + // if(result){ + // scopes = {defines[d].scope | d <- defs}; + // if(size(scopes) != 1){ + // result = all(s <- scopes, s in defines, defines[s].idRole == moduleId()); // } - // throw "rascalMayOverload"; // } return result; } -// // Define the name overloading that is allowed -// bool rascalMayOverloadOld(set[loc] defs, map[loc, Define] defines){ -// bool seenVAR = false; -// bool seenNT = false; -// bool seenLEX = false; -// bool seenLAY = false; -// bool seenKEY = false; -// bool seenALIAS = false; -// bool seenFUNCTION = false; - -// for(def <- defs){ -// // Forbid: -// // - overloading of variables/formals/pattern variables -// // - overloading of incompatible syntax definitions -// // - alias and most other names -// switch(defines[def].idRole){ -// case functionId(): -// { if(seenVAR || seenALIAS) return false; seenFUNCTION = true; } -// case variableId(): -// { if(seenVAR || seenFUNCTION || seenALIAS) return false; seenVAR = true;} -// case moduleVariableId(): -// { if(seenVAR || seenFUNCTION || seenALIAS) return false; seenVAR = true;} -// case formalId(): -// { if(seenVAR || seenFUNCTION || seenALIAS) return false; seenVAR = true;} -// case keywordFormalId(): -// { if(seenVAR || seenFUNCTION || seenALIAS) return false; seenVAR = true;} -// case patternVariableId(): -// { if(seenVAR || seenFUNCTION || seenALIAS) return false; seenVAR = true;} -// case nonterminalId(): -// { if(seenLEX || seenLAY || seenKEY || seenALIAS){ return false; } seenNT = true; } -// case lexicalId(): -// { if(seenNT || seenLAY || seenKEY || seenALIAS) { return false; } seenLEX= true; } -// case layoutId(): -// { if(seenNT || seenLEX || seenKEY || seenALIAS) { return false; } seenLAY = true; } -// case keywordId(): -// { if(seenNT || seenLAY || seenLEX || seenALIAS) { return false; } seenKEY = true; } -// case aliasId(): -// { if(seenALIAS || seenVAR || seenFUNCTION || seenNT || seenLEX || seenLAY || seenKEY) return false; seenALIAS = true; } -// } -// } -// return true; -// } - - // Name resolution filters set[IdRole] defBeforeUseRoles = {variableId(), moduleVariableId(), formalId(), keywordFormalId(), patternVariableId()}; @@ -457,6 +411,8 @@ void checkOverloading(map[str,Tree] namedTrees, Solver s){ facts = s.getFacts(); moduleScopes = { t.src | t <- range(namedTrees) }; + bool definedInReachableModule(loc l) = isModuleId(l) && any(ms <- moduleScopes, s.isContainedIn(l, ms)); + funDefs = { | define <- defines, define.idRole == functionId() }; funIds = domain(funDefs); for(id <- funIds){ @@ -465,7 +421,8 @@ void checkOverloading(map[str,Tree] namedTrees, Solver s){ for(d1 <- defs, d2 <- defs, d1.defined != d2.defined, d1.defined in facts, AType t1 := facts[d1.defined], d2.defined in facts, AType t2 := facts[d2.defined], - d1.scope in moduleScopes, d2.scope in moduleScopes, size(t1.formals) == size(t2.formals) + size(t1.formals) == size(t2.formals), + definedInReachableModule(d1.scope), definedInReachableModule(d2.scope) ){ if(isEmpty(t1.formals)){ msgs = [ error("Nullary function `` should not be overloaded", d1.defined), 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 5456d71eb61..d6798a93feb 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/DeclarationTCTests.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/DeclarationTCTests.rsc @@ -522,12 +522,12 @@ test bool overloadedVoidFunctionInitializerIsRejected() = checkModuleAndFilter(" void main() { int a = f(1); } ", ["Variable initialization should not have type `void`"]); -test bool nonMatchingVoidOverloadInitializerIsAccepted() = checkModuleOK(" - module NonMatchingVoidOverloadInitializerIsAccepted +test bool nonMatchingVoidOverloadInitializerIsNotAccepted() = checkModuleAndFilter(" + module NonMatchingVoidOverloadInitializerIsNotAccepted int f(int x) = x; void f(str x) {} void main() { int a = f(1); } - "); + ", ["Declaration clashes with other declaration of function _ with non-`void` result type"]); test bool voidKeywordParameterDefaultIsRejected() = checkModuleAndFilter(" module VoidKeywordParameterDefaultIsRejected 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 d2b48932338..10a3257fa09 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/StaticTestingUtils.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/StaticTestingUtils.rsc @@ -484,7 +484,8 @@ list[str] unexpectedDeclarationMsgs = [ "Self import not allowed", "Extend cycle not allowed", "Mixed import/extend cycle not allowed", - "Module name _ is incompatible with its file location" + "Module name _ is incompatible with its file location", + "Declaration clashes with other declaration of function _ with non-`void` result type" ]; bool unexpectedDeclarationInModule(str moduleText, PathConfig pathConfig = getDefaultTestingPathConfig()) 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 b27ce947852..d54e6b995a2 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst4.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst4.rsc @@ -26,4 +26,4 @@ POSSIBILITY OF SUCH DAMAGE. } module lang::rascalcore::compile::Examples::Tst4 -void main() { } \ No newline at end of file +void main() { } 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 e1abcea5fb5..9a0aa196b29 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalPattern.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Rascal2muRascal/RascalPattern.rsc @@ -1160,11 +1160,13 @@ MuExp translatePat(p:(Pattern) ` ( <{Pattern ","}* arguments MuExp arg_val = muTmpIValue(nextTmp("arg_"), fuid, avalue()); AType arg_type = getType(lpats[i]); + //TODO: can we really do without this code? // Replace all occurrences of the argument by the var representing its computed value - body = visit(body){ - case muVar(str name, loc fuid, int pos, AType atype, IdRole idRole) => arg_val - when name == arg_type.alabel, arg_type := atype - }; + // body = visit(body){ + // case m:muVar(str name, loc fuid, int pos, AType atype, IdRole idRole) => arg_val + // when name == arg_type.alabel, arg_type := atype, bprintln(" =\> ") + // }; + // iprintln(body); body = muBlock([ muVarInit(arg_val, arg), muIfElse(muValueIsComparable(arg_val, arg_type), @@ -1191,11 +1193,12 @@ MuExp translatePat(p:(Pattern) ` ( <{Pattern ","}* arguments } fun_name = asUnqualifiedName(prettyPrintName(qname)); code = muBlock([subjectInit, muIfElse(muHasNameAndArity(subjectType, expType, muCon(fun_name), size(lpats), subject), body, falseCont)]); - + // iprintln(code); return code; } else if(expression is literal){ // StringConstant fun_name = prettyPrintName(""[1..-1]); //TODO escapes in string code = muBlock([subjectInit, muIfElse(muHasNameAndArity(subjectType, expType, muCon(fun_name), size(lpats), subject), body, falseCont)]); + // iprintln(code); return code; } else { fun_name_subject = muTmpIValue(nextTmp("fun_name_subject"), fuid, expType); @@ -1212,6 +1215,7 @@ MuExp translatePat(p:(Pattern) ` ( <{Pattern ","}* arguments ]); } code = muExists(getEnter(p, btscopes), code); +// iprintln(code); return code; } 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 7c0cbdbd024..7478a92caaa 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/CodeGen.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/CodeGen.rsc @@ -115,9 +115,15 @@ tuple[JCode, JCode, JCode, list[value]] muRascal2Java(MuModule m, ModuleStatus m bool hasMainFunction = false; str mainName = "main"; AType mainType = avoid(); + bool isMainType(AType atype){ + assert isFunctionAType(atype); + argTypes = getFunctionOrConstructorArgumentTypes(atype); + return argTypes == [] || [alist(astr())] := argTypes; + + } MuFunction mainFunction; for(f <- m.functions){ - if(isOuterScopeName(f.scopeIn) && isMainName(f.name)) { + if(isOuterScopeName(f.scopeIn) && isMainName(f.name) && isMainType(f.ftype)) { hasMainFunction = true; mainFunction = f; mainType = f.ftype; @@ -307,9 +313,12 @@ tuple[JCode, JCode, JCode, list[value]] muRascal2Java(MuModule m, ModuleStatus m str newValueRef(str name, str jtype, str code, JGenie jg) = "new ValueRef\<\>(\"\", )"; -str newValueRef(str vname, AType atype, v:muVar(str name, loc _, int pos, AType _, IdRole idRole), JGenie jg) - = jg.isRef(v) ? "new ValueRef\<\>(\"\", .getValue())" : newValueRef(vname, atype2javatype(atype), varName(v, jg), jg) +str newValueRef(str vname, AType atype, v:muVar(str name, loc _, int pos, AType _, IdRole idRole), JGenie jg){ + jtype = atype2javatype(atype); + res = jg.isRef(v) ? "new ValueRef\<\>(\"\", .getValue())" : newValueRef(vname, jtype, varName(v, jg), jg) ; + return res; +} default str newValueRef(str name, AType atype, MuExp exp, JGenie jg) = "new ValueRef\<\>(\"\", )"; @@ -553,7 +562,8 @@ JCode trans(muFun(FUNID uid, AType ftype), JGenie jg){ actuals = intercalate(", ", [")">$_" | i <- [0..nformals]]); if(!isEmpty(ftype.kwFormals)){ - actuals = isEmpty(actuals) ? "$kwpActuals" : ", $kwpActuals"; + // actuals = isEmpty(actuals) ? "$kwpActuals" : ", $kwpActuals"; + actuals = isEmpty(actuals) ? " Util.kwpMap()" : ", Util.kwpMap()"; } // else if(muFunctions[uid]?){ // fun = muFunctions[uid]; @@ -607,13 +617,15 @@ JCode trans(muOFun(list[FUNID] funIds, AType ftype), JGenie jg){ fun = muFunctions[funId]; fun_kwFormals += fun.ftype.kwFormals; if(!isEmpty(fun.externalRefs)){ - ext_actuals += [varName(v, jg) | v <- fun.externalRefs]; + //ext_actuals += [varName(v, jg) | v <- fun.externalRefs]; + ext_actuals += [newValueRef(varName(v, jg), getType(v), v, jg) | v <- fun.externalRefs]; } } } if(!isEmpty(fun_kwFormals)){ - actualsWithCast += ["$kwpActuals"]; + // actualsWithCast += ["$kwpActuals"]; + actualsWithCast += ["Util.kwpMap()"]; } actualsWithCast += ext_actuals; @@ -621,7 +633,8 @@ JCode trans(muOFun(list[FUNID] funIds, AType ftype), JGenie jg){ formalsAsStr = intercalate(", ", formals); actualsWithCastAsStr = intercalate(", ", actualsWithCast); - return "(() -\> { return (); }, )"; + res = "(() -\> { return (); }, )"; + return res; } // ---- muComposedFun --------------------------------------------------------- @@ -779,10 +792,8 @@ JCode trans(muVarInit(v: muVar(str name, loc fuid, int pos, AType atype, IdRole } else if(isSameVarModuloRole(v, exp)) { return ""; } else { - x = varName(v, jg); - y = newValueRef(name, atype, exp, jg); return jg.isRef(v) ? "final ValueRef\<\> = ;\n" //new ValueRef\<\>();\n" - : " = ;\n"; + : " = ();\n"; } } @@ -824,11 +835,11 @@ JCode trans(muVarInit(var: muTmpNative(str name, loc fuid, NativeKind nkind), Mu if(isSameVarModuloRole(v, exp)){ return ""; } - jtype = atype2javatype(atype); + jtype = atype2javatype(alub(atype, getType(exp))); if(jg.isRef(v)){ return "final ValueRef\<\> = ;\n"; //new ValueRef\<\>();\n"; } - return " = ;\n"; + return " = ();\n"; } JCode trans(muConInit(v:muTmpIValue(str name, loc fuid, AType atype), MuExp exp), JGenie jg){ @@ -992,9 +1003,9 @@ JCode trans(muOCall(MuExp fun, AType ftype, list[MuExp] largs, lrel[str kwpName, if(jg.isContainedIn(uid, jg.getModuleLoc())){ fn = muFunctions[uid]; arg_list = "()"; - + fun_name = isGlobalScope(fn.scopeIn) - ? "$me." + ? (isMainName(fn.name) ? fn.name : "$me.") : (isClosureName(fn.name) ? fn.name : jg.getFunctionNameInContext(fn.scopeIn, fn.name) @@ -1041,7 +1052,8 @@ JCode trans(muReturnFirstSucceeds(list[str] formals, list[MuExp] exps), JGenie j // ---- muGetKwField ------------------------------------------------------ str prefix(str moduleName, JGenie jg){ - res = (isEmpty(moduleName) || isEqualModule(moduleName, jg.getModuleName())) ? "" : (module2field(moduleName) + "."); + mn = jg.getModuleName(); + res = (isEmpty(moduleName) || moduleName == jg.getModuleName()) ? "" : (module2field(moduleName) + "."); return res; } JCode trans(muGetKwField(AType resultType, adtType:aadt(_,_,_), MuExp cons, str fieldName, str moduleName), JGenie jg){ @@ -1386,7 +1398,7 @@ JCode trans(muHasKwp(MuExp exp, str kwName), JGenie jg) JCode trans(muGetKwp(MuExp exp, AType atype, str kwpName), JGenie jg){ if(acons(AType adtType, list[AType] _, list[Keyword] _) := atype){ adtName = getUniqueADTName(adtType); - return "$getkw__()"; + return "$getkw__()"; } else if(anode(_) := atype){ return ".asWithKeywordParameters().getParameter(\"\")"; } else if(a: aadt(str _, list[AType] _, SyntaxRole _) := atype){ 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 db23c7411e6..d1885bc24e0 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Resolvers.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/muRascal2Java/Resolvers.rsc @@ -425,7 +425,7 @@ str generateResolver(MODID moduleId, str functionName, set[Define] fun_defs, map call_actuals += "() $P"; } - actuals_text = intercalate(", ", call_actuals); + actuals_base = intercalate(", ", call_actuals); activeKwpFormals = []; if(def in relevant_fun_defs /*local_fun_defs*/){ @@ -436,22 +436,24 @@ str generateResolver(MODID moduleId, str functionName, set[Define] fun_defs, map activeKwpFormals += tp.kwFormals; } } + + actuals_with_kwp = actuals_base; if(hasKeywordParameters(def_type) /*|| (def.scope notin module_scopes && !isEmpty(activeKwpFormals))*/){ - actuals_text = isEmpty(actuals_text) ? "$kwpActuals" : ", $kwpActuals"; + actuals_with_kwp = isEmpty(actuals_base) ? "$kwpActuals" : ", $kwpActuals"; } if(!onlyGlobalFuns){ externalRefs = getExternalRefs(def, fid2muFunction); if(!isEmpty(externalRefs)){ - actuals_text += (isEmpty(actuals_text) ? "" : ", ") + intercalate(", ", [ varName(var) | var <- externalRefs ]); + actuals_with_kwp += (isEmpty(actuals_with_kwp) ? "" : ", ") + intercalate(", ", [ varName(var) | var <- externalRefs ]); } } key = isConstructorAType(def_type) ? 0 : (def_type.isConcreteArg ? def_type.concreteFingerprint : def_type.abstractFingerprint); //key = /*def_type.isDefault ? 0 :*/ (def_type.isConcreteArg ? def_type.concreteFingerprint : def_type.abstractFingerprint); call_code = base_call = ""; - cst = resolver_returns_void ? "" : "()"; if(isFunctionAType(def_type)){ + cst = resolver_returns_void ? "" : "()"; if(jg.isContainedIn(def.defined, module_scope)){ pref = ""; if(def.scope != module_scope){ @@ -461,9 +463,9 @@ str generateResolver(MODID moduleId, str functionName, set[Define] fun_defs, map } } } - call_code = "()"; + call_code = "()"; } else if(/*jg.isContainedIn(def.defined, def.scope),*/ def.scope in module_scopes){ - call_code = ".()"; // was uniqueName + call_code = ".()"; // was uniqueName } else { return; //do nothing } @@ -475,9 +477,9 @@ str generateResolver(MODID moduleId, str functionName, set[Define] fun_defs, map } } else { if(hasKeywordParameters(def_type)){ - base_call = "return $RVF.constructor(, new IValue[]{}, $kwpActuals);"; + base_call = "return $RVF.constructor(, new IValue[]{}, $kwpActuals);"; } else { - base_call = "return $RVF.constructor(, new IValue[]{});"; + base_call = "return $RVF.constructor(, new IValue[]{});"; } } 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 cb8a17ba40e..fdaeebb3164 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/util/Names.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/util/Names.rsc @@ -26,6 +26,7 @@ POSSIBILITY OF SUCH DAMAGE. } module lang::rascalcore::compile::util::Names +import IO; import String; import List; import util::Reflective; @@ -267,12 +268,12 @@ str unescapeName(str s){ return s[0] == "\\" ? s[1..] : s; } -bool isEqualModule(str name1, name2){ - if(contains(name1, "::") && contains(name2, "::")) return name1 == name2; - name1a = replaceAll(name1, "::", "_"); - name2a = replaceAll(name2, "::", "_"); - res = endsWith(name1a, name2a) || endsWith(name2a, name1a); - //println("isEqualModule(, ) =\> "); - return res; -} +// bool isEqualModule(str name1, name2){ +// if(contains(name1, "::") && contains(name2, "::")) return name1 == name2; +// name1a = replaceAll(name1, "::", "_"); +// name2a = replaceAll(name2, "::", "_"); +// res = endsWith(name1a, name2a) || endsWith(name2a, name1a); +// // println("isEqualModule(, ) =\> "); +// return res; +// } diff --git a/src/org/rascalmpl/library/lang/html5/DOM.rsc b/src/org/rascalmpl/library/lang/html5/DOM.rsc index 79127968a1d..70801d74029 100644 --- a/src/org/rascalmpl/library/lang/html5/DOM.rsc +++ b/src/org/rascalmpl/library/lang/html5/DOM.rsc @@ -456,6 +456,6 @@ private HTML5Node example @synopsis{pretty print HTML5Node DOM to a string} str toString(HTML5Node x) { attrs = { k | HTML5Attr k <- x.kids }; - kids = [ k | value k <- x.kids, !(HTML5Attr _ := k) ]; + kids = [ k | value k <- x.kids, HTML5Attr _ !:= k ]; return nodeToString(x.name, attrs, kids); } \ No newline at end of file diff --git a/src/org/rascalmpl/library/lang/rascal/tests/basic/Functions.rsc b/src/org/rascalmpl/library/lang/rascal/tests/basic/Functions.rsc index 375832d1051..479527d7dad 100644 --- a/src/org/rascalmpl/library/lang/rascal/tests/basic/Functions.rsc +++ b/src/org/rascalmpl/library/lang/rascal/tests/basic/Functions.rsc @@ -648,6 +648,8 @@ test bool voidInitializerIsRejected() { } data Article = article(str name); + +@ignoreCompiler{The type checker rejects the overloading with the above constructor} void article(value args...) {} // The ADT qualifier excludes the void function, so only the constructor remains diff --git a/src/org/rascalmpl/library/lang/rascal/tests/concrete/recovery/ParseBenchmark.rsc b/src/org/rascalmpl/library/lang/rascal/tests/concrete/recovery/ParseBenchmark.rsc index e7bb923bebe..af2197792f0 100644 --- a/src/org/rascalmpl/library/lang/rascal/tests/concrete/recovery/ParseBenchmark.rsc +++ b/src/org/rascalmpl/library/lang/rascal/tests/concrete/recovery/ParseBenchmark.rsc @@ -91,7 +91,7 @@ private str syntaxLocToModuleName(loc syntaxFile) { } -private void benchmark(ParseBenchmarkConfig config) { +private void parserBenchmark(ParseBenchmarkConfig config) { writeFile(config.statFile, "input,size,duration\n"); Module \module = parse(#start[Module], config.syntaxFile).top; str modName = syntaxLocToModuleName(config.syntaxFile); @@ -128,7 +128,7 @@ int main(list[str] args) { } } - benchmark(config); + parserBenchmark(config); return 0; }