Skip to content

Commit

Permalink
Assertions can be enabled via env var
Browse files Browse the repository at this point in the history
  • Loading branch information
Akirathan committed Sep 27, 2023
1 parent cffd2e4 commit b435b75
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
5 changes: 5 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,11 @@ configured correctly and run the tests as following:
LANG=C enso --run test/Tests
```

Note that JVM assertions are not enabled by default, one has to pass `-ea`
via `JAVA_OPTS` environment variable. There are also Enso-specific assertions
(method `Runtime.assert`) that can be enabled when `ENSO_ENABLE_ASSERTIONS`
environemtn variable is non-empty.

#### Test Dependencies

To run all the stdlib test suites, set `CI=true` environment variable:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public static AssertNode build() {
public abstract Object execute(
VirtualFrame frame, State state, @Suspend Object action, Object msg);

protected Assumption getAssertionsDisabledAssumption() {
return EnsoContext.get(this).getAssertsDisabledAssumption();
protected boolean isAssertionsEnabled() {
return EnsoContext.get(this).isAssertionsEnabled();
}

@Specialization(assumptions = "getAssertionsDisabledAssumption()")
@Specialization(guards = "!isAssertionsEnabled()")
Object doAssertionsDisabled(VirtualFrame frame, State state, Object action, Object msg) {
return EnsoContext.get(this).getNothing();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public final class EnsoContext {

private final EnsoLanguage language;
private final Env environment;
private final Assumption assertsDisabledAssumption = Truffle.getRuntime().createAssumption("Enso assertions disabled");
private final boolean assertionsEnabled;
private @CompilationFinal Compiler compiler;
private final PrintStream out;
private final PrintStream err;
Expand Down Expand Up @@ -135,8 +135,10 @@ public EnsoContext(
this.isIrCachingDisabled =
getOption(RuntimeOptions.DISABLE_IR_CACHES_KEY) || isParallelismEnabled;
this.executionEnvironment = getOption(EnsoLanguage.EXECUTION_ENVIRONMENT);
if (getOption(RuntimeOptions.ENABLE_ASSERTIONS_KEY)) {
this.assertsDisabledAssumption.invalidate("Enso assertions are enabled");
if (System.getenv("ENSO_ENABLE_ASSERTIONS") != null) {
this.assertionsEnabled = true;
} else {
this.assertionsEnabled = false;
}
this.shouldWaitForPendingSerializationJobs =
getOption(RuntimeOptions.WAIT_FOR_PENDING_SERIALIZATION_JOBS_KEY);
Expand Down Expand Up @@ -606,8 +608,8 @@ public boolean isUseGlobalCache() {
return getOption(RuntimeOptions.USE_GLOBAL_IR_CACHE_LOCATION_KEY);
}

public Assumption getAssertsDisabledAssumption() {
return assertsDisabledAssumption;
public boolean isAssertionsEnabled() {
return assertionsEnabled;
}

/**
Expand Down

0 comments on commit b435b75

Please sign in to comment.