Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c95ff9f
added causes to ambiguous type reference for debugging purposes
jurgenvinju May 15, 2026
aa7fb07
minor maintenance in List.rsc for speed and added zip2 and zip3 for u…
jurgenvinju May 15, 2026
51f8bd8
fixed bug
jurgenvinju May 15, 2026
b784904
optimizations
jurgenvinju May 15, 2026
db8cf87
Merge branch 'main' into fix/double-src-resolutions
jurgenvinju May 17, 2026
100b2eb
forgot to add case for sets instead of lists of zipi
jurgenvinju May 17, 2026
ca29c49
fixes
jurgenvinju May 17, 2026
011b85a
let annotation usage fail the documentation builder by printing a war…
jurgenvinju May 17, 2026
de90b1c
remove dead code wrt mapping loc to src because loc is not there anymore
jurgenvinju May 17, 2026
ba73e4b
removed hardwired implementation of src field, since it is now presen…
jurgenvinju May 17, 2026
444e86f
removed legacy static name and test for the loc name
jurgenvinju May 17, 2026
88478e6
report all (also loc) usages and declarations as of annotations as de…
jurgenvinju May 17, 2026
78fd280
made statements with @ annotations deprecated
jurgenvinju May 17, 2026
102f653
annotation get is also deprecated
jurgenvinju May 17, 2026
1430ccf
removed commented code about loc anno
jurgenvinju May 17, 2026
fbaa0f8
fixes
jurgenvinju May 18, 2026
e9e203e
fixed typos
jurgenvinju May 18, 2026
226577c
added more tests, which surprisingly do not fail
jurgenvinju May 18, 2026
d7f63b7
Undone code removal
PaulKlint May 19, 2026
dca8c6b
Test case
PaulKlint May 19, 2026
4c95f68
added failing test by @paulklint
jurgenvinju May 19, 2026
ae15312
fixed TODO
jurgenvinju May 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,8 @@ void collect(Tag tg, Collector c){
// Deprecated
void collect(current: (Declaration) `<Tags tags> <Visibility visibility> anno <Type annoType> <Type onType> @ <Name name> ;`, Collector c){
pname = prettyPrintName(name);
if(pname != "loc"){
c.report(warning(current, "Annotations are deprecated, use keyword parameters instead"));
}

c.report(warning(current, "Annotations are deprecated, use keyword fields instead"));

tagsMap = getTags(tags);
if(hasIgnoreCompilerTag(tagsMap)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ void collect(current: (Expression) `<Expression e> [ <OptionalExpression ofirst>
// ---- fieldAccess

void collect(current: (Expression) `<Expression expression> . <Name field>`, Collector c){
c.useViaType(expression, field, {fieldId(), keywordFieldId(), annoId()}); // DURING TRANSITION: allow annoIds
c.useViaType(expression, field, {fieldId(), keywordFieldId()});
c.require("non void or overloaded", expression, [], makeNonVoidNonOverloadedRequirement(expression, "Base expression of field selection"));
c.fact(current, field);
collect(expression, c);
Expand Down Expand Up @@ -1238,12 +1238,15 @@ private AType do_computeSetAnnotationType(Tree current, AType t1, AType tn, ATyp
return avalue();
}

// TODO: Deprecated
void collect(current:(Expression) `<Expression expression> [ @ <Name name> = <Expression repl> ]`, Collector c) {
pname = prettyPrintName(name);
if(pname != "loc"){
if (pname == "loc") {
c.report(error(current, "The Tree@\\loc annotation has been replaced by the Tree.src keyword field."));
}
else {
c.report(warning(current, "Annotations are deprecated, use keyword parameters instead"));
}

c.use(name, {annoId()});
c.calculate("set annotation", current, [expression, name, repl],
AType(Solver s){
Expand Down Expand Up @@ -1275,9 +1278,14 @@ private AType do_computeGetAnnotationType(Tree current, AType t1, AType tn, Solv
// TODO: Deprecated
void collect(current:(Expression) `<Expression expression>@<Name name>`, Collector c) {
pname = prettyPrintName(name);
if(pname != "loc"){

if (pname == "loc") {
c.report(error(current, "The Tree@\\loc annotation has been replaced by the Tree.src keyword field."));
}
else {
c.report(warning(current, "Annotations are deprecated, use keyword parameters instead"));
}

c.use(name, {annoId()});
c.calculate("get annotation", current, [expression, name],
AType(Solver s){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,14 @@ void collect(current:(Assignable) `\< <{Assignable ","}+ elements> \>`, Collecto
}

void collect(current:(Assignable) `<Assignable receiver> @ <Name annotation>`, Collector c){
pname = prettyPrintName(annotation);
if (pname == "loc") {
c.report(error(current, "The Tree@\\loc annotation has been replaced by the Tree.src keyword field."));
}
else {
c.report(warning(current, "Annotations are deprecated, use keyword parameters instead"));
}

collect(receiver, annotation, c);
}

Expand Down Expand Up @@ -1112,8 +1120,15 @@ private void checkAssignment(Statement current, receiver: (Assignable) `\< <{Ass
//collect(elements, c);
}

// TODO: Deprecated
private void checkAssignment(Statement current, asg: (Assignable) `<Assignable receiver> @ <Name n>`, str operator, Statement rhs, Collector c){
pname = prettyPrintName(n);
if (pname == "loc") {
c.report(error(current, "The Tree@\\loc annotation has been replaced by the Tree.src keyword field."));
}
else {
c.report(warning(current, "Annotations are deprecated, use keyword parameters instead"));
}

c.use(n, {annoId()});
names = getReceiver(receiver, c);
c.useLub(names[0], variableRoles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,10 @@ void collect(current:(Sym) `<Sym symbol> <NonterminalLabel n>`, Collector c){
throw "Cannot compute md5 for <current>";
}

// TODO require symbol is nonterminal
// NB: by induction a non-terminal role is already required for symbol:
// * either it is a Nonterminal name and the rule for Nonterminal covers this requirement
// * or it is a more complex Sym which are non-terminals by definition

c.define("<n>", fieldId(), n, defType([symbol],
AType(Solver s){
res = s.getType(symbol)[alabel=un];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,15 @@ void(Solver) makeNonVoidRequirement(Tree t, str msg)
void(Solver) makeNonVoidNonOverloadedRequirement(Tree t, str msg)
= void(Solver s) {
checkNonVoid(t, s, msg );
if(isOverloadedAType(s.getType(t))) s.report(error(t, msg + " is ambiguous and should be resolved"));
AType resolution = s.getType(t);

if (isOverloadedAType(resolution)) {
causes =
[ info("Candidate <i+1>: <prettyAType(alt)>.", pos)
| <i, <loc pos, _, AType alt>> <- zipi(resolution.overloads)
];
s.report(error(t, msg + " can not be resolved to a single type.", causes=causes));
}
};

AType unaryOp(str op, AType(Tree, AType, Solver) computeType, Tree current, AType t1, Solver s, bool maybeVoid=false){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ list[str] unexpectedTypeMsgs = [
"Expected a binary relation, found _",
"Constructor _ is overloaded",
"Expression _ is overloaded",
"Base expression of field selection is ambiguous and should be resolved"
"Base expression of field selection can not be resolved to a single type."
];

bool unexpectedTypeInModule(str moduleText, PathConfig pathConfig = getDefaultTestingPathConfig())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,4 +629,70 @@ test bool Issue1353() {
import MC;
value main() = hello();
");
}

test bool DoubleField() {
return checkModuleOK("module Exp
'import ParseTree;
'
'layout L = [\\ \\t\\n]*;
'
'lexical Id = [a-z];
'
'syntax Exp
' = Id
' | left Exp lhs \"*\" Exp rhs
' \> left Exp lhs \"+\" Exp rhs
' ;
'
'test bool expSrc() {
' Exp tmp = (Exp) `a + b`;
' Exp tmp2 = tmp.lhs;
' return (Exp) `a` := tmp2;
'}
'
'test bool expLhsLhs() {
' Exp tmp = (Exp) `a + b + c`;
' Exp tmp2 = tmp.lhs;
' Exp tmp3 = tmp.lhs.lhs;
' return (Exp) `a` := tmp3;
'}");
}

test bool SyntaxFieldSrc() {
return checkModuleOK(
"module Exp
'import ParseTree;
'
'layout L = [\\ \\t\\n]*;
'
'lexical Id = [a-z];
'
'syntax Exp
' = Id
' | left Exp lhs \"*\" Exp rhs
' \> left Exp lhs \"+\" Exp rhs
' ;
'
'test bool expSrc() {
' Exp tmp = (Exp) `a + b`;
' return loc _ := tmp.src;
'}
'
'test bool expLhsSrc() {
' Exp tmp = (Exp) `a + b + c`;
' return loc _ := tmp.lhs.src;
'}");
}

test bool SyntaxFieldInRascalSyntax() {
return checkModuleOK(
"module RascalWithFunction
'
'import lang::rascal::\\syntax::Rascal;
'import ParseTree;
'
'loc translateAddFunction(Expression e) {
' return e.lhs.src;
'}");
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,7 @@ private void generateGettersForAdt(AType adtType, loc module_scope, set[AType] c
str kwFieldName = unescape(kwType.alabel);
if(kwFieldName in generated_common_getters) continue;
generated_common_getters += kwFieldName;
if(asubtype(adtType, treeType)){
if(kwFieldName == "loc") kwFieldName = "src"; // TODO: remove when .src is gone
}

//str fuid = getGetterNameForKwpField(adtType, kwFieldName);
str getterName = unescapeAndStandardize("$getkw_<adtName>_<kwFieldName>");
if(getterName == "$getkw_Tree_message"){ // TODO: remove when annotations are gone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1381,9 +1381,6 @@ MuExp translate (e:(Expression) `<Expression expression> [ @ <Name name> = <Expr
} else if(isMapAType(tp)){
tp = getMapFieldsAsTuple(tp);
} else if(isADTAType(tp)){
if(asubtype(tp, treeType) && uname == "loc"){ //TODO: remove when loc anno has been removed
uname = "src";
}
return muSetField(tp, getType(expression), translate(expression), uname, translate(val));
} else if(isLocAType(tp)){
return muSetField(tp, getType(expression), translate(expression), uname, translate(val));
Expand All @@ -1403,10 +1400,7 @@ MuExp translate (e:(Expression) `<Expression expression> [ @ <Name name> = <Expr
MuExp translate (e:(Expression) `<Expression expression>@<Name name>`) {
tp = getType(expression);
uname = unescape("<name>");
//if(asubtype(tp, treeType) && uname == "loc"){ //TODO: remove when loc anno has been removed
// uname = "src"; // rename loc to src
//}
//return muGetField(getType(e), tp, translate(expression), uname);

return muGetAnno(translate(expression), getType(e), uname);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module lang::rascalcore::compile::Rascal2muRascal::SrcTestCase

import lang::rascal::\syntax::Rascal;
loc translateAddFunction(Expression e){
return e.lhs.src;
}
Original file line number Diff line number Diff line change
Expand Up @@ -607,9 +607,6 @@ tuple[str moduleName, AType atype, bool isKwp] getConstructorInfo(AType adtType,

// Common kw field of concrete type?
if(asubtype(adtType1, treeType)){
//if(fieldName == "src"){ // TODO: remove when @\loc is gone
// return <"ParseTree", adtType1, true>;
//}
for(Keyword kw <- adt_common_keyword_fields[treeType] ? []){
if("<kw.fieldType.alabel>" == fieldName){
return <kw has definingModule ? kw.definingModule : findDefiningModule(getLoc(kw.defaultExp)), is_start ? \start(adtType1) : adtType1, true>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -900,15 +900,13 @@ JCode trans(muAssign(v:muTmpNative(str name, str fuid, NativeKind nkind), MuExp

// muGetAnno
JCode trans(muGetAnno(MuExp exp, AType resultType, str annoName), JGenie jg){
if(annoName == "loc") annoName = "src";// TODO: remove when @\loc is gone
return "$annotation_get(((INode)<trans(exp, jg)>),\"<annoName>\")";
}
//TODO: the "_resultType" (instead of "resultType") is essential to
// avoid a hash collision, size of hash keys should increased!

// muGuardedGetAnno
JCode trans(muGuardedGetAnno(MuExp exp, AType _resultType, str annoName), JGenie jg){
if(annoName == "loc") annoName = "src";// TODO: remove when @\loc is gone
return "$guarded_annotation_get(((INode)<trans(exp, jg)>),\"<annoName>\")";
}

Expand Down Expand Up @@ -1054,7 +1052,6 @@ str prefix(str moduleName, JGenie jg){
JCode trans(muGetKwField(AType resultType, adtType:aadt(_,_,_), MuExp cons, str fieldName, str moduleName), JGenie jg){
adtName = isEmpty(adtType.parameters) ? adtType.adtName : "<adtType.adtName>_<size(adtType.parameters)>";
if(asubtype(adtType, treeType)){
if(fieldName == "loc") fieldName = "src"; // TODO: remove when @\loc is gone
adtName = "Tree";
}
return "<prefix(moduleName,jg)>$getkw_<adtName>_<asJavaName(fieldName,completeId=false)>(<transWithCast(adtType, cons, jg)>)";
Expand All @@ -1063,7 +1060,6 @@ JCode trans(muGetKwField(AType resultType, adtType:aadt(_,_,_), MuExp cons, str
JCode trans(muGetKwField(AType resultType, consType:acons(AType adt, list[AType] fields, list[Keyword] kwFields), MuExp cons, str fieldName, str moduleName), JGenie jg){
adtName = getUniqueADTName(adt);
if(asubtype(adt, treeType)){
if(fieldName == "loc") fieldName = "src"; // TODO: remove when @\loc is gone
adtName = "Tree";
}
isConsKwField = fieldName in {kwf.fieldType.alabel | kwf <- kwFields};
Expand Down
4 changes: 0 additions & 4 deletions src/org/rascalmpl/interpreter/env/ModuleEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,6 @@ public Type aliasType(String name, Type aliased, Type... parameters) {

@Override
public void declareAnnotation(Type onType, String label, Type valueType) {
// TODO: simulating annotations still here
if (RascalValueFactory.isLegacySourceLocationAnnotation(onType, label)) {
label = RascalValueFactory.Location;
}
typeStore.declareKeywordParameter(onType, label, valueType);
}

Expand Down
12 changes: 2 additions & 10 deletions src/org/rascalmpl/interpreter/result/ElementResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.rascalmpl.interpreter.IEvaluatorContext;
import org.rascalmpl.interpreter.env.Environment;
import org.rascalmpl.interpreter.staticErrors.UnexpectedType;
import org.rascalmpl.values.RascalValueFactory;

import io.usethesource.vallang.IBool;
import io.usethesource.vallang.IInteger;
import io.usethesource.vallang.INode;
Expand Down Expand Up @@ -153,14 +151,8 @@ public <U extends IValue, V extends IValue> Result<U> setAnnotation(String annoN
// TODO: simulating annotations still here
Type annoType;

if (RascalValueFactory.isLegacySourceLocationAnnotation(getStaticType(), annoName)) {
annoName = RascalValueFactory.Location;
annoType = getTypeFactory().sourceLocationType();
}
else {
annoType = env.getKeywordParameterTypes(getStaticType()).get(annoName);
}

annoType = env.getKeywordParameterTypes(getStaticType()).get(annoName);

if (getStaticType() != getTypeFactory().nodeType()) {
if (!anno.getStaticType().isSubtypeOf(annoType)) {
throw new UnexpectedType(annoType, anno.getStaticType(), ctx.getCurrentAST());
Expand Down
Loading
Loading