Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimenting with some low hanging fruit in the code that parses and imports modules for the sake of DSL loading time in VScode #1863

Merged
merged 11 commits into from
Sep 20, 2023
21 changes: 18 additions & 3 deletions src/org/rascalmpl/semantics/dynamic/Import.java
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,12 @@ public ITree visitTreeAppl(ITree tree) {
IListWriter w = vf.listWriter();
IList args = TreeAdapter.getArgs(tree);
for (IValue arg : args) {
w.append(arg.accept(this));
if (TreeAdapter.isContextFree(tree)) {
w.append(arg.accept(this));
}
else {
w.append(arg);
}
}
args = w.done();

Expand Down Expand Up @@ -686,7 +691,12 @@ public ITree visitTreeAppl(ITree tree) {
IListWriter w = vf.listWriter();
IList args = TreeAdapter.getArgs(tree);
for (IValue arg : args) {
w.append(arg.accept(this));
if (!TreeAdapter.isLayout((ITree) arg)) {
w.append(arg.accept(this));
}
else {
w.append(arg);
}
}
args = w.done();

Expand Down Expand Up @@ -772,7 +782,12 @@ public ITree visitTreeAppl(ITree tree) {
IListWriter w = vf.listWriter();
IList args = TreeAdapter.getArgs(tree);
for (IValue elem : args) {
w.append(elem.accept(this));
if (!TreeAdapter.isLayout((ITree) elem)) {
w.append(elem.accept(this));
}
else {
w.append(elem);
}
}
args = w.done();

Expand Down
3 changes: 2 additions & 1 deletion src/org/rascalmpl/values/parsetrees/ProductionAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public static IList getASTSymbols(IConstructor tree) {
}

public static boolean isContextFree(IConstructor tree) {
return SymbolAdapter.isSort(getType(tree));
IConstructor t = getType(tree);
return SymbolAdapter.isSort(t) || SymbolAdapter.isParameterizedSort(t);
}

public static boolean isLayout(IConstructor tree) {
Expand Down
1 change: 1 addition & 0 deletions src/org/rascalmpl/values/parsetrees/SymbolAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public static String getLabel(IConstructor tree) {
}

public static boolean isParameterizedSort(IConstructor tree) {
tree = delabel(tree);
return tree.getConstructorType() == Symbol_ParameterizedSort;
}

Expand Down
37 changes: 37 additions & 0 deletions src/org/rascalmpl/values/parsetrees/TreeAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
import java.io.Writer;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import org.fusesource.jansi.Ansi;
import org.fusesource.jansi.Ansi.Attribute;
Expand Down Expand Up @@ -369,6 +372,21 @@ public static IList getListASTArgs(ITree tree) {
}
return writer.done();
}

public static Stream<ITree> streamListASTArgs(ITree tree) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see calls to these functions?

if (!isList(tree)) {
throw new ImplementationError("This is not a context-free list production: " + tree);
}

IList children = getArgs(tree);
int jump = isSeparatedList(tree) ? getSeparatorCount(tree) - 1 : 2;

return IntStream.range(0, children.size())
.filter(i -> i % jump == 0)
.mapToObj(children::get)
.map(t -> (ITree) t)
;
}

public static int getSeparatorCount(ITree tree) {
IConstructor nt = ProductionAdapter.getType(getProduction(tree));
Expand Down Expand Up @@ -412,6 +430,25 @@ public static IList getASTArgs(ITree tree) {
return writer.done();
}

public static Stream<ITree> streamASTArgs(ITree tree) {
if (SymbolAdapter.isStartSort(TreeAdapter.getType(tree))) {
return Stream.of((ITree) getArgs(tree).get(1));
}

if (isLexical(tree)) {
throw new ImplementationError("This is not a context-free production: " + tree);
}

IList children = getArgs(tree);

return IntStream.range(0, children.size())
.filter(i -> i % 2 == 0)
.mapToObj(children::get)
.map(t -> (ITree) t)
.filter(t -> !isLiteral(t) && !isCILiteral(t))
;
}

public static boolean isCILiteral(ITree tree) {
return isAppl(tree) && ProductionAdapter.isCILiteral(getProduction(tree));
}
Expand Down