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

Print out warnings associated with local variables #10842

Merged
merged 30 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d70cd37
Duplicating the test to get ready for new use-cases
JaroslavTulach Aug 16, 2024
01c6ce5
Only enable the ReplDebuggerInstrument when ENABLE_OPTION is specified
JaroslavTulach Aug 16, 2024
b8bee0d
Remove test cases that don't invoke Debug.breakpoint at the end of th…
JaroslavTulach Aug 16, 2024
eb3b76e
Let FN_OPTION also enable ReplDebuggerInstrument
JaroslavTulach Aug 16, 2024
454804f
Allow activation of REPL at end of given function name
JaroslavTulach Aug 16, 2024
63d1560
Keep the binding on during the whole DebugServerTest
JaroslavTulach Aug 17, 2024
7f06236
Sharing the client initialization code among both options
JaroslavTulach Aug 17, 2024
dbe3c45
Extract value from a warning and print associated warnings on other l…
JaroslavTulach Aug 17, 2024
4fda04b
Print warnings on local variables to stderr
JaroslavTulach Aug 18, 2024
aa7c9a7
More normalized JUnit test
JaroslavTulach Aug 18, 2024
1312546
Print out Error values as well as warnings
JaroslavTulach Aug 18, 2024
42da3aa
Note in changelog
JaroslavTulach Aug 18, 2024
2cc7ef5
When an Error is found, return it instead of real value
JaroslavTulach Aug 18, 2024
7df58ef
Enable check for warnings when runMain
JaroslavTulach Aug 18, 2024
e6fbf73
Fail the execution if the result looks like an error
JaroslavTulach Aug 18, 2024
f61b6fd
Using DebugServerInfo constant in ContextFactory
JaroslavTulach Aug 18, 2024
40ed823
Only one block node with RootTag per function
JaroslavTulach Aug 18, 2024
1ef93a3
Special case for invocation of main
JaroslavTulach Aug 18, 2024
4501988
Arguments are no longer RootTagged
JaroslavTulach Aug 18, 2024
83d0af9
Introducing enableDebugServer builder option
JaroslavTulach Aug 18, 2024
c7a6228
Fixing four of five Insight tests
JaroslavTulach Aug 18, 2024
41b3473
Initialize argument variables first, then RootBodyTag node
JaroslavTulach Aug 18, 2024
8f6ebdb
Check behavior of an unused errorneus variable
JaroslavTulach Aug 20, 2024
47c4e68
Don't change main method return value, just wrap it with exit exception
JaroslavTulach Aug 20, 2024
49d535b
Print out warnings for REPL return value too
JaroslavTulach Aug 20, 2024
6987125
Call it METHOD_BREAKPOINT_OPTION
JaroslavTulach Aug 20, 2024
8dcc6ae
Removing pointless s variable
JaroslavTulach Aug 20, 2024
c4b1815
No need to cast
JaroslavTulach Aug 20, 2024
6b69f09
Adjust tests to the METHOD_BREAKPOINT_OPTION rename
JaroslavTulach Aug 20, 2024
5f393c5
Avoid dealing with new lines
JaroslavTulach Aug 21, 2024
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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@
[10725]: https:/enso-org/enso/pull/10725
[10820]: https:/enso-org/enso/pull/10820

# Enso 2023.3
#### Enso Language & Runtime

- [Print out warnings associated with local variables][10842]

[10842]: https:/enso-org/enso/pull/10842

# Enso 2024.3

#### Enso Language & Runtime

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
* @param options additional options for the Context
* @param executionEnvironment optional name of the execution environment to use during execution
* @param warningsLimit maximal number of warnings reported to the user
* @param checkForWarnings name of method to check for warnings
* @param enableDebugServer enable debug (e.g. REPL) server
*/
public final class ContextFactory {
private String projectRoot;
Expand All @@ -47,8 +49,10 @@ public final class ContextFactory {
private boolean useGlobalIrCacheLocation = true;
private boolean enableAutoParallelism;
private String executionEnvironment;
private String checkForWarnings;
private int warningsLimit = 100;
private java.util.Map<String, String> options = java.util.Collections.emptyMap();
private boolean enableDebugServer;

private ContextFactory() {}

Expand Down Expand Up @@ -141,6 +145,16 @@ public ContextFactory options(Map<String, String> options) {
return this;
}

public ContextFactory checkForWarnings(String fqnOfMethod) {
this.checkForWarnings = fqnOfMethod;
return this;
}

public ContextFactory enableDebugServer(boolean b) {
this.enableDebugServer = b;
return this;
}

public Context build() {
if (executionEnvironment != null) {
options.put("enso.ExecutionEnvironment", executionEnvironment);
Expand Down Expand Up @@ -169,6 +183,12 @@ public Context build() {
.out(out)
.err(err)
.in(in);
if (checkForWarnings != null) {
builder.option(DebugServerInfo.METHOD_BREAKPOINT_OPTION, checkForWarnings);
}
if (enableDebugServer) {
builder.option(DebugServerInfo.ENABLE_OPTION, "true");
}
if (messageTransport != null) {
builder.serverTransport(messageTransport);
}
Expand Down Expand Up @@ -239,5 +259,4 @@ private static HostAccess allWithTypeMapping() {
.allowAccessInheritance(true)
.build();
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package org.enso.polyglot.debugger;
package org.enso.common;

/** Container for Runtime Server related constants. */
/** Container for debug server related constants. */
public class DebugServerInfo {
private DebugServerInfo() {

}
public static final String URI = "enso://debug-server";
public static final String INSTRUMENT_NAME = "enso-debug-server";
public static final String ENABLE_OPTION = INSTRUMENT_NAME + ".enable";
public static final String METHOD_BREAKPOINT_OPTION = INSTRUMENT_NAME + ".method-break-point";
}
44 changes: 33 additions & 11 deletions engine/runner/src/main/java/org/enso/runner/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.commons.cli.OptionGroup;
import org.apache.commons.cli.Options;
import org.enso.common.ContextFactory;
import org.enso.common.DebugServerInfo;
import org.enso.common.HostEnsoUtils;
import org.enso.common.LanguageInfo;
import org.enso.distribution.DistributionManager;
Expand All @@ -37,7 +38,6 @@
import org.enso.pkg.Template;
import org.enso.polyglot.Module;
import org.enso.polyglot.PolyglotContext;
import org.enso.polyglot.debugger.DebugServerInfo;
import org.enso.polyglot.debugger.DebuggerSessionManagerEndpoint;
import org.enso.profiling.sampler.NoopSampler;
import org.enso.profiling.sampler.OutputStreamSampler;
Expand Down Expand Up @@ -688,6 +688,24 @@ private void handleRun(
}
var projectMode = fileAndProject._1();
var file = fileAndProject._2();
var mainFile = file;
if (projectMode) {
var result = PackageManager$.MODULE$.Default().loadPackage(file);
if (result.isSuccess()) {
@SuppressWarnings("unchecked")
var pkg = (org.enso.pkg.Package<java.io.File>) result.get();

mainFile = pkg.mainFile();
if (!mainFile.exists()) {
println("Main file does not exist.");
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this print to stderr?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question. However the code has been there before this PR - so the answer doesn't need to be provided by this PR.

throw exitFail();
}
} else {
println(result.failed().get().getMessage());
throw exitFail();
}
}

var projectRoot = fileAndProject._3();
var options = new HashMap<String, String>();

Expand All @@ -714,7 +732,9 @@ private void handleRun(
}
if (enableDebugServer) {
factory.messageTransport(replTransport());
options.put(DebugServerInfo.ENABLE_OPTION, "true");
factory.enableDebugServer(true);
} else {
factory.checkForWarnings(mainFile.getName().replace(".enso", "") + ".main");
}
var context = new PolyglotContext(factory.build());

Expand All @@ -724,12 +744,6 @@ private void handleRun(
var s = (scala.util.Success) result;
@SuppressWarnings("unchecked")
var pkg = (org.enso.pkg.Package<java.io.File>) s.get();
var main = pkg.mainFile();
if (!main.exists()) {
println("Main file does not exist.");
context.context().close();
throw exitFail();
}
var mainModuleName = pkg.moduleNameForFile(pkg.mainFile()).toString();
runPackage(context, mainModuleName, file, additionalArgs);
} else {
Expand Down Expand Up @@ -879,11 +893,20 @@ private void runMain(
if (!res.isNull()) {
var textRes = res.isString() ? res.asString() : res.toString();
println(textRes);
if (res.isException()) {
try {
throw res.throwException();
} catch (PolyglotException e) {
if (e.isExit()) {
throw doExit(e.getExitStatus());
}
}
}
}
}
} catch (PolyglotException e) {
if (e.isExit()) {
doExit(e.getExitStatus());
throw doExit(e.getExitStatus());
} else {
printPolyglotException(e, rootPkgPath);
throw exitFail();
Expand Down Expand Up @@ -917,14 +940,13 @@ private void runRepl(
.replace("$mainMethodName", mainMethodName);
var replModuleName = "Internal_Repl_Module___";
var projectRoot = projectPath != null ? projectPath : "";
var options = Collections.singletonMap(DebugServerInfo.ENABLE_OPTION, "true");

var context =
new PolyglotContext(
ContextFactory.create()
.projectRoot(projectRoot)
.messageTransport(replTransport())
.options(options)
.enableDebugServer(true)
.logLevel(logLevel)
.logMasking(logMasking)
.enableIrCaches(enableIrCaches)
Expand Down
Loading
Loading