Skip to content

Commit

Permalink
Merge branch 'main' into syntax-role-modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Feb 7, 2024
2 parents d27cbb6 + 8e0f7b2 commit 34cc097
Show file tree
Hide file tree
Showing 21 changed files with 235 additions and 78 deletions.
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
"projectName": "rascal",
"vmArgs": "-Xss80m -Xmx2g -ea"
},
{
"type": "java",
"name": "Launch RascalShell Tutor",
"request": "launch",
"mainClass": "org.rascalmpl.shell.RascalShell",
"projectName": "rascal",
"cwd" : "${workspaceFolder}/../rascal-tutor",
"vmArgs": "-Xss80m -Xmx2g -ea"
},
{
"type": "java",
"name": "Attach RascalShell",
Expand All @@ -40,6 +49,14 @@
"hostName": "localhost",
"port": 9001
},
{
"type": "java",
"name": "Attach Mvn Rascal",
"request": "attach",
"projectName": "rascal-maven-plugin",
"hostName": "localhost",
"port": 8000
},
{
"type": "java",
"name": "Attach Rascal LSP Terminal",
Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.rascalmpl</groupId>
<artifactId>rascal</artifactId>
<version>0.35.0-RC2-SNAPSHOT</version>
<version>0.35.0-RC8-SNAPSHOT</version>
<packaging>jar</packaging>

<scm>
Expand Down Expand Up @@ -32,7 +32,7 @@
<exec.mainClass>org.rascalmpl.shell.RascalShell</exec.mainClass>
<rascal.test.memory>2</rascal.test.memory>
<maven.compiler.release>11</maven.compiler.release>
<rascal-maven.version>0.22.0-RC2</rascal-maven.version>
<rascal-maven.version>0.25.0-RC2-SNAPSHOT</rascal-maven.version>
</properties>


Expand Down Expand Up @@ -116,7 +116,7 @@
<plugin>
<groupId>org.rascalmpl</groupId>
<artifactId>rascal-maven-plugin</artifactId>
<version>${rascal-maven.version}</version>
<version>0.25.0-RC1</version>
<configuration>
<errorsAsWarnings>true</errorsAsWarnings>
<bin>${project.build.outputDirectory}</bin>
Expand Down Expand Up @@ -156,7 +156,7 @@
<goal>package</goal>
</goals>
</execution>
<!--<execution> somehow this breaks if you add new builtins
<execution>
<id>default-cli</id>
<phase>compile</phase>
<goals>
Expand All @@ -177,7 +177,7 @@
<ignore>${project.basedir}/src/org/rascalmpl/library/lang/rascal</ignore>
</ignores>
</configuration>
</execution> -->
</execution>
</executions>
</plugin>
<plugin>
Expand Down Expand Up @@ -366,7 +366,7 @@
<dependency>
<groupId>io.usethesource</groupId>
<artifactId>vallang</artifactId>
<version>1.0.0-RC3</version>
<version>1.0.0-RC11</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
Expand Down
17 changes: 1 addition & 16 deletions src/org/rascalmpl/interpreter/DefaultTestResultListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@
*******************************************************************************/
package org.rascalmpl.interpreter;

import java.io.IOException;
import java.io.PrintWriter;

import org.rascalmpl.exceptions.Throw;
import org.rascalmpl.repl.ReplTextWriter;

import io.usethesource.vallang.ISourceLocation;
import io.usethesource.vallang.io.StandardTextWriter;

public class DefaultTestResultListener implements ITestResultListener{
private PrintWriter err;
Expand Down Expand Up @@ -119,19 +116,7 @@ else if (t != null) {
err.println();
}
err.println("error: " + test + " @ " + ReplTextWriter.valueToString(loc));
err.println("\t" + t.getMessage());

if (t instanceof Throw) {
try {
((Throw) t).getTrace().prettyPrintedString(err, new StandardTextWriter(true));
}
catch (IOException e) {
// should not happen
}
}
else {
t.printStackTrace(err);
}
err.println(message);
}
else {
failures++;
Expand Down
6 changes: 5 additions & 1 deletion src/org/rascalmpl/interpreter/TestEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.rascalmpl.interpreter.env.ModuleEnvironment;
import org.rascalmpl.interpreter.result.AbstractFunction;
import org.rascalmpl.test.infrastructure.QuickCheck;
import org.rascalmpl.test.infrastructure.QuickCheck.TestResult;
import org.rascalmpl.test.infrastructure.QuickCheck.UnExpectedExceptionThrownResult;

import io.usethesource.vallang.IBool;
import io.usethesource.vallang.IString;
Expand Down Expand Up @@ -117,7 +119,8 @@ private void runTests(ModuleEnvironment env, List<AbstractFunction> tests) {
}
}
catch (Throwable e) {
return new TestResult(false, e);
// TODO: add bound type parameters
return new UnExpectedExceptionThrownResult(test.getEnv().getName() + "::" + test.getName(), actuals, Map.of(), args, e);
}
}, env.getRoot().getStore(), tries, maxDepth, maxWidth);

Expand All @@ -137,6 +140,7 @@ private void runTests(ModuleEnvironment env, List<AbstractFunction> tests) {
catch(Throwable e){
testResultListener.report(false, test.getName(), test.getAst().getLocation(), e.getMessage(), e);
}

eval.getOutPrinter().flush();
eval.getErrorPrinter().flush();
}
Expand Down
1 change: 0 additions & 1 deletion src/org/rascalmpl/library/List.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ module List

import Exception;
import Map;
import IO;


@synopsis{Concatenate a list of lists.}
Expand Down
20 changes: 14 additions & 6 deletions src/org/rascalmpl/library/Location.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ Strict containment between two locations `inner` and `outer` holds when
}

bool isStrictlyContainedIn(loc inner, loc outer){
if(inner == outer){
return false;
}
if(isSameFile(inner, outer)){
if(inner.offset?){
return outer.offset? ==> ( inner.offset == outer.offset && inner.offset + inner.length < outer.offset + outer.length
|| inner.offset > outer.offset && inner.offset + inner.length <= outer.offset + outer.length
);
} else {
return inner.offset > 0 && !outer.offset?;
if(outer.offset?){
return inner.offset == outer.offset && inner.offset + inner.length < outer.offset + outer.length
|| inner.offset > outer.offset && inner.offset + inner.length <= outer.offset + outer.length;
} else {
return inner.offset > 0;
}
}
}
return false;
Expand All @@ -102,7 +106,11 @@ Containment between two locations `inner` and `outer` holds when
bool isContainedIn(loc inner, loc outer){
if(isSameFile(inner, outer)){
if(inner.offset?){
return outer.offset? ==> (inner.offset >= outer.offset && inner.offset + inner.length <= outer.offset + outer.length);
if(outer.offset?){
return (inner.offset >= outer.offset && inner.offset + inner.length <= outer.offset + outer.length);
} else {
return true;
}
} else {
return !outer.offset?;
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/rascalmpl/library/Map.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ int incr(int x) { return x + 1; }
mapper(("apple": 1, "pear": 2, "orange": 3), prefix, incr);
```
}
public map[&K, &V] mapper(map[&K, &V] M, &L (&K) F, &W (&V) G)
public map[&L, &W] mapper(map[&K, &V] M, &L (&K) F, &W (&V) G)
= (F(key) : G(M[key]) | &K key <- M);
Expand Down
4 changes: 2 additions & 2 deletions src/org/rascalmpl/library/Prelude.java
Original file line number Diff line number Diff line change
Expand Up @@ -1341,8 +1341,8 @@ private void writeFileEnc(ISourceLocation sloc, IString charset, IList V, boolea
else if (elem.getType().isSubtypeOf(RascalValueFactory.Tree)) {
TreeAdapter.yield((IConstructor) elem, out);
}
else{
out.append(elem.toString());
else {
new StandardTextWriter().write(elem, out);
}
}
if (postfix != null) {
Expand Down
48 changes: 47 additions & 1 deletion src/org/rascalmpl/library/Set.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,13 @@ public default (&T <:num) sum({(&T <: num) e, *(&T <: num) r})

@synopsis{Pick an arbitrary element from a set.}
@description{
This _randomly_ picks one element from a set, unless the set is empty.

:::warning
Use ((getSingleFrom)) if you want the element from a singleton set. ((getOneFrom)) will silently
continue even if there are more element present, which can be a serious threat to the validity of your
analysis algorithm (arbitrary data is not considered).
:::
}
@examples{
```rascal-shell
Expand All @@ -287,22 +293,62 @@ getOneFrom({"elephant", "zebra", "snake"});
getOneFrom({"elephant", "zebra", "snake"});
```
}
@benefits{
* Random sampling can be an effective test input selection strategy.
}
@pitfalls{
* The name ((getOneFrom)) does not convey randomness.
* ((getOneFrom)) drops all the other elements.
If you are sure there is only one element and you need it, then use ((getSingleFrom)). It will fail fast if your assumption is wrong.
* If you need more then one element, then repeatedly calling ((getOneFrom)) will be expensive. Have a look at ((util::Sampling)) for more effective
sampling utilities.
}
@javaClass{org.rascalmpl.library.Prelude}
public java &T getOneFrom(set[&T] st);


@synopsis{Get "first" element from a set.}
@description{
Get "first" element of a set. Of course, sets are unordered and do not have a first element.
However, we may assume that sets are internally ordered in some way and this ordering is reproducible.
However, we could assume that sets are internally ordered in some way and this ordering is reproducible (it's deterministic up to hashing collisions).
Applying `getFirstFrom` on the same set will always returns the same element.

:::warning
Use ((getSingleFrom)) if you want the element from a singleton set. ((getFirstFrom)) will silently
continue even if there are more element present, which can be a serious threat to the validity of your
analysis algorithm (arbitrary data is not considered).
:::
}
@benefits{
This function helps to make set-based code more deterministic, for instance, for testing purposes.
}
@pitfalls{
* The deterministic order is _undefined_. This means it may be stable between runs, but not between releases of Rascal.
* There are much better ways to iterate over the elements of a set:
* Use the `<-` enumerator operator in a `for` loop or a comprehension.
* Use list matching
* ((getFirstFrom)) drops all the other elements
* If you are sure there is only one element and you need it, then use ((getSingleFrom)). It will fail fast if your assumption is wrong.
}
@javaClass{org.rascalmpl.library.Prelude}
public java &T getFirstFrom(set[&T] st);

@synopsis{Get the only element from a singleton set.}
@description{
Get the only element of a singleton set. This fails with a ((CallFailed)) exception when the set is not a singleton.
}
@benefits{
* ((getSingleFrom)) fails _fast_ if the assumption (parameter `st` is a singleton) is not met.
* If a binary relation `r` is injective (i.e. it models a function where each key only has one value) then all projections `r[key]` should produce singleton values: `{v}`.
Using ((getSingleFrom)) to get the element out makes sure we fail fast in case our assumptions were wrong, or they have changed.
* Never use ((getFirstFrom)) or ((takeOneFrom)) if you can use ((getSingleFrom)).
}
@pitfalls{
* ((CallFailed)) exceptions are sometimes hard to diagnose. Look at the stack trace to see that it was ((getSingleFrom))
that caused it, and then look at the parameter of ((CallFailed)) to see that the set was not a singleton.
}
public &T getSingleFrom(set[&T] st) = getFirstFrom(st) when size(st) == 1;

// TODO temporary? replacement due to unexplained behaviour of compiler
//public &T getFirstFrom({&T f, *&T _}) = f;
//public &T getFirstFrom(set[&T] _:{}) { throw EmptySet(); }
Expand Down
2 changes: 1 addition & 1 deletion src/org/rascalmpl/library/lang/java/m3/Core.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ java M3 createM3FromString(loc fileName, str contents, bool errorRecovery = fals
java M3 createM3FromJarClass(loc jarClass, list[loc] classPath = []);
@javaClass{org.rascalmpl.library.lang.java.m3.internal.EclipseJavaCompiler}
java M3 createM3FromSingleClass(loc jarClass, str className);
java M3 createM3FromSingleClass(loc jarClass, str className, list[loc] classPath = []);
@javaClass{org.rascalmpl.library.lang.java.m3.internal.EclipseJavaCompiler}
java M3 createM3FromJarFile(loc jarLoc, list[loc] classPath = []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public IValue createM3FromJarClass(ISourceLocation jarLoc, IList classPath) {
return createM3FromJarClass(jarLoc, classPath, getM3Store());
}

public IValue createM3FromSingleClass(ISourceLocation classLoc, IString className) {
public IValue createM3FromSingleClass(ISourceLocation classLoc, IString className, IList classpath) {
JarConverter converter = new JarConverter(getM3Store(), new HashMap<>());
converter.convertJarFile(classLoc, ((IString) className).getValue());
converter.convertJarFile(classLoc, ((IString) className).getValue(), classpath);
return converter.getModel(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ public void convertJar(ISourceLocation jar, IList classPath) {
* @param classFile
* @param className
*/
public void convertJarFile(ISourceLocation classFile, String className) {
public void convertJarFile(ISourceLocation classFile, String className, IList classpath) {
loc = classFile;
createSingleClassM3(className);
createSingleClassM3(className, classpath);
}

/**
Expand Down Expand Up @@ -172,7 +172,11 @@ private void createM3() {
* and parent packages is triggered.
* @param className
*/
private void createSingleClassM3(String className) {
private void createSingleClassM3(String className, IList classpath) {
if (resolver == null) {
resolver = new ASMNodeResolver(loc, classpath, typeStore);
}

String compUnit = className;
ClassReader classReader = resolver.buildClassReader(className);

Expand Down
16 changes: 16 additions & 0 deletions src/org/rascalmpl/library/lang/rascal/tests/basic/Sets.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ test bool tst_takeOneFrom(set[int] S) {
return x in S && x notin S2 && size(S2) == size(S) - 1 && S2 < S;
}

test bool tst_getSingleFrom(set[int] S) {
if ({e} := S) {
return getSingleFrom(S) == e;
}
return true;
}

test bool tst_getSingleFromExample(str input) {
return getSingleFrom({input}) == input;
}

@expected{CallFailed}
test bool tst_getSingleFromMore(str input, int i) {
getSingleFrom({input, i});
}

test bool tst_toList(set[int] S) = isEmpty(S) || size(S) == size(toList(S)) && all(x <- S, x in toList(S));

test bool tst_toMap(rel[int, int] S) = isEmpty(S) || domain(S) == domain(toMap(S)) && range(S) == {*toMap(S)[k] | k <- toMap(S)};
Expand Down
23 changes: 23 additions & 0 deletions src/org/rascalmpl/library/lang/rascal/tests/concrete/Issue1913.rsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module lang::rascal::tests::concrete::Issue1913

extend lang::std::Layout;
import IO;

syntax As = "begin" A* as "end";

syntax A = "a" | "b";

test bool issue1913() {
A* bs = (As)`begin b a b end`.as;

As prog = (As)`begin b a a end`;

prog = visit (prog) {
case (As)`begin <A* as1> b <A* as2> end`
=> (As)`begin <A* as1> <A* bs> <A* as2> end`
}

println(prog);
// don't loose a space
return "<prog>" == "begin b a b a a end";
}
Loading

0 comments on commit 34cc097

Please sign in to comment.