Skip to content

Commit

Permalink
finetuning of the progress bars around testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Apr 3, 2024
1 parent bda3846 commit 8df9d9e
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 76 deletions.
8 changes: 4 additions & 4 deletions src/org/rascalmpl/interpreter/Evaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -1373,14 +1373,14 @@ private char[] getResourceContent(ISourceLocation location) throws IOException{
* effect of declaring non-terminal types in the given environment.
*/
@Override
public ITree parseModuleAndFragments(IRascalMonitor monitor, ISourceLocation location) throws IOException{
return parseModuleAndFragments(monitor, getResourceContent(location), location);
public ITree parseModuleAndFragments(IRascalMonitor monitor, ISourceLocation location, String jobName) throws IOException{
return parseModuleAndFragments(monitor, jobName, getResourceContent(location), location);
}

public ITree parseModuleAndFragments(IRascalMonitor monitor, char[] data, ISourceLocation location){
public ITree parseModuleAndFragments(IRascalMonitor monitor, String jobName, char[] data, ISourceLocation location){
IRascalMonitor old = setMonitor(monitor);
try {
return org.rascalmpl.semantics.dynamic.Import.parseModuleAndFragments(data, location, this);
return org.rascalmpl.semantics.dynamic.Import.parseModuleAndFragments(data, location, jobName, this);
}
finally{
setMonitor(old);
Expand Down
2 changes: 1 addition & 1 deletion src/org/rascalmpl/interpreter/IEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public interface IEvaluator<T> extends IEvaluatorContext {
public ITree parseCommand(IRascalMonitor monitor, String command,
ISourceLocation location);

public ITree parseModuleAndFragments(IRascalMonitor monitor, ISourceLocation location) throws IOException;
public ITree parseModuleAndFragments(IRascalMonitor monitor, ISourceLocation location, String jobName) throws IOException;

public void registerConstructorDeclaredListener(IConstructorDeclared iml);

Expand Down
7 changes: 6 additions & 1 deletion src/org/rascalmpl/repl/TerminalProgressBarMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ void update() {
write();
writer.write(ANSI.moveDown(bars.size() - bars.indexOf(this)));
writer.write(ANSI.showCursor());
writer.flush();
}
}

Expand Down Expand Up @@ -297,7 +298,7 @@ public synchronized void jobStep(String name, String message, int workShare) {
public synchronized int jobEnd(String name, boolean succeeded) {
var pb = findBarByName(name);

if (pb != null && --pb.nesting == 0) {
if (pb != null && --pb.nesting == -1) {
eraseBars();
// write it one last time into the scrollback buffer (on top)
pb.done();
Expand All @@ -307,6 +308,10 @@ public synchronized int jobEnd(String name, boolean succeeded) {
printBars();
return pb.current;
}
else if (pb != null) {
pb.done();
pb.update();

Check warning on line 313 in src/org/rascalmpl/repl/TerminalProgressBarMonitor.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/repl/TerminalProgressBarMonitor.java#L312-L313

Added lines #L312 - L313 were not covered by tests
}

return -1;

Check warning on line 316 in src/org/rascalmpl/repl/TerminalProgressBarMonitor.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/repl/TerminalProgressBarMonitor.java#L316

Added line #L316 was not covered by tests
}
Expand Down
130 changes: 64 additions & 66 deletions src/org/rascalmpl/semantics/dynamic/Import.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,64 +293,64 @@ else if (eval.getCurrentEnvt() == eval.__getRootScope()) {

public static ModuleEnvironment loadModule(ISourceLocation x, String name, IEvaluator<Result<IValue>> eval) {
GlobalEnvironment heap = eval.getHeap();


ModuleEnvironment env = heap.getModule(name);
if (env == null) {
env = new ModuleEnvironment(name, heap);
heap.addModule(env);
ModuleEnvironment m = heap.getModule(name);
if (m == null) {
m = new ModuleEnvironment(name, heap);
heap.addModule(m);
}
final ModuleEnvironment env = m;

ISourceLocation uri = eval.getRascalResolver().resolveModule(name);

try {
eval.getMonitor().jobStart("loading", 1);
eval.job("loading " + name, 1, (jobName) -> {
try {
if (uri == null) {
throw new ModuleImport(name, "can not find in search path", x);

Check warning on line 309 in src/org/rascalmpl/semantics/dynamic/Import.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/semantics/dynamic/Import.java#L309

Added line #L309 was not covered by tests
}
Module module = buildModule(uri, env, eval, jobName);

if (uri == null) {
throw new ModuleImport(name, "can not find in search path", x);
}
Module module = buildModule(uri, env, eval);
if (isDeprecated(module)) {
eval.getErrorPrinter().println("WARNING: deprecated module " + name + ":" + getDeprecatedMessage(module));

Check warning on line 314 in src/org/rascalmpl/semantics/dynamic/Import.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/semantics/dynamic/Import.java#L314

Added line #L314 was not covered by tests
}

if (isDeprecated(module)) {
eval.getErrorPrinter().println("WARNING: deprecated module " + name + ":" + getDeprecatedMessage(module));
}
if (module != null) {
String internalName = org.rascalmpl.semantics.dynamic.Module.getModuleName(module);
if (!internalName.equals(name)) {
throw new ModuleNameMismatch(internalName, name, x);

Check warning on line 320 in src/org/rascalmpl/semantics/dynamic/Import.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/semantics/dynamic/Import.java#L320

Added line #L320 was not covered by tests
}
heap.setModuleURI(name, module.getLocation().getURI());

if (module != null) {
String internalName = org.rascalmpl.semantics.dynamic.Module.getModuleName(module);
if (!internalName.equals(name)) {
throw new ModuleNameMismatch(internalName, name, x);
}
heap.setModuleURI(name, module.getLocation().getURI());
module.interpret(eval);

module.interpret(eval);
eval.jobStep(jobName, "loaded " + URIUtil.getLocationName(uri), 1);
}

eval.jobStep("loading", "loaded " + URIUtil.getLocationName(uri), 1);
return env;
}
}
catch (SyntaxError e) {
handleLoadError(heap, env, eval, name, e.getMessage(), e.getLocation(), x);
throw e;
}
catch (StaticError e) {
handleLoadError(heap, env, eval, name, e.getMessage(), e.getLocation(), x);
throw e;
}
catch (Throw e) {
handleLoadError(heap, env, eval, name, e.getMessage(), e.getLocation(), x);
throw e;
}
catch (Throwable e) {
handleLoadError(heap, env, eval, name, e.getMessage(), x, x);
e.printStackTrace();
throw new ModuleImport(name, e.getMessage(), x);
}
finally {
eval.jobEnd("loading", true);
}
return true;
}
catch (SyntaxError e) {
handleLoadError(heap, env, eval, name, e.getMessage(), e.getLocation(), x);
throw e;

Check warning on line 333 in src/org/rascalmpl/semantics/dynamic/Import.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/semantics/dynamic/Import.java#L331-L333

Added lines #L331 - L333 were not covered by tests
}
catch (StaticError e) {
handleLoadError(heap, env, eval, name, e.getMessage(), e.getLocation(), x);
throw e;

Check warning on line 337 in src/org/rascalmpl/semantics/dynamic/Import.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/semantics/dynamic/Import.java#L335-L337

Added lines #L335 - L337 were not covered by tests
}
catch (Throw e) {
handleLoadError(heap, env, eval, name, e.getMessage(), e.getLocation(), x);
throw e;

Check warning on line 341 in src/org/rascalmpl/semantics/dynamic/Import.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/semantics/dynamic/Import.java#L339-L341

Added lines #L339 - L341 were not covered by tests
}
catch (Throwable e) {
handleLoadError(heap, env, eval, name, e.getMessage(), x, x);
e.printStackTrace();
throw new ModuleImport(name, e.getMessage(), x);

Check warning on line 346 in src/org/rascalmpl/semantics/dynamic/Import.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/semantics/dynamic/Import.java#L343-L346

Added lines #L343 - L346 were not covered by tests
}
finally {
eval.jobStep(jobName, name);
}
});

heap.removeModule(env);
throw new ImplementationError("Unexpected error while parsing module " + name + " and building an AST for it ", x);
return env;
}

private static void handleLoadError(GlobalEnvironment heap, ModuleEnvironment env, IEvaluator<Result<IValue>> eval,
Expand Down Expand Up @@ -379,8 +379,8 @@ private static String getDeprecatedMessage(Module preModule){
return "";
}

private static Module buildModule(ISourceLocation uri, ModuleEnvironment env, IEvaluator<Result<IValue>> eval) throws IOException {
ITree tree = eval.parseModuleAndFragments(eval, uri);
private static Module buildModule(ISourceLocation uri, ModuleEnvironment env, IEvaluator<Result<IValue>> eval, String jobName) throws IOException {
ITree tree = eval.parseModuleAndFragments(eval, uri, jobName);

return getBuilder().buildModule(tree);
}
Expand All @@ -399,21 +399,22 @@ private static void addImportToCurrentModule(ISourceLocation src, String name, I
current.setSyntaxDefined(current.definesSyntax() || module.definesSyntax());
}

public static ITree parseModuleAndFragments(char[] data, ISourceLocation location, IEvaluator<Result<IValue>> eval) {
public static ITree parseModuleAndFragments(char[] data, ISourceLocation location, String jobName, IEvaluator<Result<IValue>> eval) {
eval.__setInterrupt(false);
IActionExecutor<ITree> actions = new NoActionExecutor();
ITree tree;

eval.jobTodo("loading", 1);
eval.jobTodo(jobName, 1);

try {
tree = new RascalParser().parse(Parser.START_MODULE, location.getURI(), data, actions, new DefaultNodeFlattener<IConstructor, ITree, ISourceLocation>(), new UPTRNodeFactory(true));
}
catch (ParseError e) {
throw new SyntaxError("module", IRascalValueFactory.getInstance().sourceLocation(location, e.getOffset(), e.getLength(), e.getBeginLine(), e.getEndLine(), e.getBeginColumn(), e.getEndColumn()));
}

eval.jobStep("loading", "parsed " + URIUtil.getLocationName(location), 1);
finally {
eval.jobStep(jobName, "parsed " + URIUtil.getLocationName(location), 1);
}

if (TreeAdapter.isAmb(tree)) {
// Ambiguity is dealt with elsewhere
Expand Down Expand Up @@ -446,28 +447,28 @@ public static ITree parseModuleAndFragments(char[] data, ISourceLocation locatio
ISet rules = Modules.getSyntax(top);
for (IValue rule : rules) {
evalImport(eval, (IConstructor) rule);
eval.getMonitor().jobStep("loading", "defining syntax", 1);
eval.getMonitor().jobStep(jobName, "defining syntax", 1);
}

ISet imports = Modules.getImports(top);
eval.getMonitor().jobTodo("loading", imports.size());
eval.getMonitor().jobTodo(jobName, imports.size());
for (IValue mod : imports) {
evalImport(eval, (IConstructor) mod);
eval.getMonitor().jobStep("loading", "importing", 1);
eval.getMonitor().jobStep(jobName, "importing", 1);
}

ISet extend = Modules.getExtends(top);
eval.getMonitor().jobTodo("loading", extend.size());
eval.getMonitor().jobTodo(jobName, extend.size());
for (IValue mod : extend) {
evalImport(eval, (IConstructor) mod);
eval.getMonitor().jobStep("loading", "extending", 1);
eval.getMonitor().jobStep(jobName, "extending", 1);
}

ISet externals = Modules.getExternals(top);
eval.getMonitor().jobTodo("loading", externals.size());
eval.getMonitor().jobTodo(jobName, externals.size());
for (IValue mod : externals) {
evalImport(eval, (IConstructor) mod);
eval.getMonitor().jobStep("loading", "external importing", 1);
eval.getMonitor().jobStep(jobName, "external importing", 1);

Check warning on line 471 in src/org/rascalmpl/semantics/dynamic/Import.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/semantics/dynamic/Import.java#L471

Added line #L471 was not covered by tests
}
}
finally {
Expand All @@ -481,7 +482,7 @@ public static ITree parseModuleAndFragments(char[] data, ISourceLocation locatio
RascalFunctionValueFactory vf = eval.getFunctionValueFactory();
URIResolverRegistry reg = URIResolverRegistry.getInstance();
ISourceLocation parserCacheFile = URIUtil.changeExtension(location, "parsers");
eval.jobStep("loading", "parsing concrete fragment in " + name);
eval.jobStep(jobName, "parsing concrete fragment in " + name);

IFunction parsers = null;

Expand All @@ -502,17 +503,14 @@ else if (reg.exists(parserCacheFile)) {
parsers = vf.parsers(reifiedType, vf.bool(false), vf.bool(false), vf.bool(false), vf.set());
}

eval.getMonitor().jobTodo("loading", 1);
eval.getMonitor().jobTodo(jobName, 1);
result = parseFragments(vf, eval.getMonitor(), parsers, tree, location, env);
eval.getMonitor().jobStep("loading", "parsed concrete fragments", 1);
eval.getMonitor().jobStep(jobName, "parsed concrete fragments", 1);
}
}
catch (URISyntaxException | ClassNotFoundException | IOException e) {
eval.warning("reusing parsers failed during module import: " + e.getMessage(), env.getLocation());
}
finally {
eval.jobEnd("loading", true);
}

return result;
}
Expand Down
5 changes: 1 addition & 4 deletions src/org/rascalmpl/test/infrastructure/TestFramework.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ private void reset() {
catch (IOException e) {
}
}
generatedModules.clear();


generatedModules.clear();
evaluator.getAccumulators().clear();
}

Expand Down Expand Up @@ -138,7 +136,6 @@ public TestFramework prepare(String command) {
try {
reset();
execute(command);

}
catch (StaticError e) {
throw e;
Expand Down

0 comments on commit 8df9d9e

Please sign in to comment.