Permalink
Browse files

[runtime][stmt] Add the single space variable declaration, and modify…

… the functions modifying RW counters.
  • Loading branch information...
ptal committed Nov 12, 2018
1 parent 728e135 commit 7095585413b92adaf2747e100d48a213cabfda53
Showing with 297 additions and 58 deletions.
  1. +1 −1 Cargo.toml
  2. +1 −1 manual-installation.md
  3. +1 −0 runtime/src/main/java/bonsai/runtime/synchronous/CanResult.java
  4. +18 −4 runtime/src/main/java/bonsai/runtime/synchronous/NAryCall.java
  5. +1 −1 runtime/src/main/java/bonsai/runtime/synchronous/SpaceMachine.java
  6. +8 −0 runtime/src/main/java/bonsai/runtime/synchronous/env/Layer.java
  7. +1 −1 runtime/src/main/java/bonsai/runtime/synchronous/expressions/Access.java
  8. +9 −3 runtime/src/main/java/bonsai/runtime/synchronous/expressions/Entailment.java
  9. +7 −1 runtime/src/main/java/bonsai/runtime/synchronous/expressions/FreeAccess.java
  10. +2 −2 runtime/src/main/java/bonsai/runtime/synchronous/expressions/FunctionCall.java
  11. +10 −5 runtime/src/main/java/bonsai/runtime/synchronous/expressions/ReadAccess.java
  12. +10 −5 runtime/src/main/java/bonsai/runtime/synchronous/expressions/ReadWriteAccess.java
  13. +10 −5 runtime/src/main/java/bonsai/runtime/synchronous/expressions/WriteAccess.java
  14. +31 −0 runtime/src/main/java/bonsai/runtime/synchronous/interfaces/CanAnalysis.java
  15. +1 −1 runtime/src/main/java/bonsai/runtime/synchronous/interfaces/Expression.java
  16. +3 −1 runtime/src/main/java/bonsai/runtime/synchronous/interfaces/Prepare.java
  17. +2 −2 runtime/src/main/java/bonsai/runtime/synchronous/interfaces/Program.java
  18. +3 −5 runtime/src/main/java/bonsai/runtime/synchronous/interfaces/Schedulable.java
  19. +11 −5 runtime/src/main/java/bonsai/runtime/synchronous/statements/Nothing.java
  20. +4 −4 runtime/src/main/java/bonsai/runtime/synchronous/statements/ProcedureCall.java
  21. +14 −5 runtime/src/main/java/bonsai/runtime/synchronous/statements/QFUniverse.java
  22. +136 −0 runtime/src/main/java/bonsai/runtime/synchronous/statements/SingleSpaceVarDecl.java
  23. +12 −5 runtime/src/main/java/bonsai/runtime/synchronous/statements/SpaceStmt.java
  24. +1 −1 setup.py
@@ -17,7 +17,7 @@ name = "bonsai"
doc = false
[dependencies]
oak = "^0.5.9"
oak = "^0.6.0"
oak_runtime = "^0.5.5"
partial = "^0.4.0"
clap = "^2"
@@ -9,7 +9,7 @@ See [README.md](README.md)
## Installing the bonsai compiler
```sh
rustup override set nightly-2018-08-18
rustup override set nightly-2018-11-09
cargo install
```
@@ -15,6 +15,7 @@
package bonsai.runtime.synchronous;
public class CanResult {
public static CanResult IDENTITY = new CanResult(true, false);
public boolean canTerminate;
public boolean canWrite;
public CanResult(boolean canTerminate, boolean canWrite) {
@@ -32,13 +32,13 @@ public NAryCall(List<Access> args) {
this.argsEval = new ArrayList(args.size());
}
protected void prepareInstant(Layer layer) {
protected void prepare(Layer layer) {
argsEval.clear();
for(int i=0; i < args.size(); i++) {
argsEval.add(null);
}
for (Access access : args) {
access.prepareInstant(layer);
access.prepare(layer);
}
}
@@ -62,9 +62,23 @@ public CanResult canWriteOn(String uid, boolean inSurface) {
.reduce(new CanResult(true,false), CanResult::and_term);
}
public void meetRWCounter(Layer layer) {
public boolean canAnalysis(Layer layer) {
for (Access access : args) {
access.meetRWCounter(layer);
checkTerminated(access.canAnalysis(layer));
}
return true;
}
public boolean terminate(Layer layer) {
for (Access access : args) {
checkTerminated(access.terminate(layer));
}
return true;
}
private void checkTerminated(boolean terminated) {
if(!terminated) {
throw new RuntimeException("[BUG] Arguments of NAryCall must always terminate.");
}
}
}
@@ -42,7 +42,7 @@ CompletionCode executeLayer() {
env.incTargetLayer();
CompletionCode status = CompletionCode.PAUSE;
while (status == CompletionCode.PAUSE) {
body.prepareSubInstant(env, Environment.OUTERMOST_LAYER);
body.prepareSub(env, Environment.OUTERMOST_LAYER);
// We execute as much as we can of the current instant.
status = executeInstant();
// If we are blocked but a sub-layer can be activated, we proceed.
@@ -52,4 +52,12 @@ public boolean processWasScheduled() {
public boolean unblock(Program body) {
return false;
}
public void enterScope(String uid, Object defaultValue, Consumer<Object> refUpdater) {
space.enterScope(uid, defaultValue, refUpdater);
}
public void exitScope(String uid) {
space.exitScope(uid);
}
}
@@ -29,7 +29,7 @@ public Access(String uid) {
hasSubscribed = false;
}
public void prepareInstant(Layer layer) {
public void prepare(Layer layer) {
hasSubscribed = false;
}
@@ -43,11 +43,11 @@ public Entailment(List<FreeAccess> leftVars, List<FreeAccess> rightVars,
private void prepareArgs(Layer layer, List<FreeAccess> accesses) {
for (FreeAccess access: accesses) {
access.prepareInstant(layer);
access.prepare(layer);
}
}
public void prepareInstant(Layer layer) {
public void prepare(Layer layer) {
this.result = new ExprResult();
prepareArgs(layer, leftVars);
prepareArgs(layer, rightVars);
@@ -99,5 +99,11 @@ public CanResult canWriteOn(String uid, boolean inSurface) {
return new CanResult(true,false);
}
public void meetRWCounter(Layer layer) {}
public boolean canAnalysis(Layer layer) {
return true;
}
public boolean terminate(Layer layer) {
return true;
}
}
@@ -40,5 +40,11 @@ public CanResult canWriteOn(String uid, boolean inSurface) {
return new CanResult(true,false);
}
public void meetRWCounter(Layer layer) {}
public boolean canAnalysis(Layer layer) {
return true;
}
public boolean terminate(Layer layer) {
return true;
}
}
@@ -32,9 +32,9 @@ public FunctionCall(List<Access> args, Function<ArrayList<Object>, Object> funct
this.function = function;
}
public void prepareInstant(Layer layer) {
public void prepare(Layer layer) {
result = new ExprResult();
super.prepareInstant(layer);
super.prepare(layer);
}
public ExprResult execute(Layer layer) {
@@ -30,10 +30,8 @@ public ReadAccess(String uid) {
this.hasSubscribed = false;
}
public void prepareInstant(Layer layer) {
super.prepareInstant(layer);
Variable var = layer.lookUpVar(uid);
var.joinRead(layer);
public void prepare(Layer layer) {
super.prepare(layer);
}
public ExprResult execute(Layer layer) {
@@ -51,8 +49,15 @@ public CanResult canWriteOn(String uid, boolean inSurface) {
return new CanResult(true,false);
}
public void meetRWCounter(Layer layer) {
public boolean canAnalysis(Layer layer) {
Variable var = layer.lookUpVar(uid);
var.joinRead(layer);
return true;
}
public boolean terminate(Layer layer) {
Variable var = layer.lookUpVar(uid);
var.meetRead(layer);
return true;
}
}
@@ -27,10 +27,8 @@ public ReadWriteAccess(String uid) {
super(uid);
}
public void prepareInstant(Layer layer) {
super.prepareInstant(layer);
Variable var = layer.lookUpVar(uid);
var.joinReadWrite(layer);
public void prepare(Layer layer) {
super.prepare(layer);
}
public ExprResult execute(Layer layer) {
@@ -48,8 +46,15 @@ public CanResult canWriteOn(String uid, boolean inSurface) {
return new CanResult(true, uid == this.uid);
}
public void meetRWCounter(Layer layer) {
public boolean canAnalysis(Layer layer) {
Variable var = layer.lookUpVar(uid);
var.joinReadWrite(layer);
return true;
}
public boolean terminate(Layer layer) {
Variable var = layer.lookUpVar(uid);
var.meetReadWrite(layer);
return true;
}
}
@@ -27,10 +27,8 @@ public WriteAccess(String uid) {
super(uid);
}
public void prepareInstant(Layer layer) {
super.prepareInstant(layer);
Variable var = layer.lookUpVar(uid);
var.joinWrite(layer);
public void prepare(Layer layer) {
super.prepare(layer);
}
// A write access is always possible.
@@ -43,8 +41,15 @@ public CanResult canWriteOn(String uid, boolean inSurface) {
return new CanResult(true, uid == this.uid);
}
public void meetRWCounter(Layer layer) {
public boolean canAnalysis(Layer layer) {
Variable var = layer.lookUpVar(uid);
var.joinWrite(layer);
return true;
}
public boolean terminate(Layer layer) {
Variable var = layer.lookUpVar(uid);
var.meetWrite(layer);
return true;
}
}
@@ -0,0 +1,31 @@
// Copyright 2018 Pierre Talbot
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package bonsai.runtime.synchronous.interfaces;
import bonsai.runtime.synchronous.*;
import bonsai.runtime.synchronous.env.*;
public interface CanAnalysis
{
// We analyse the current program to prove that a write on `uid` still can happen.
// We suppose the conditions currently suspended on `uid` to be `false` (if `inSurface` is `true`).
// `inSurface` is `true` if the statement analysed is currently suspended.
// This method can only be called on non-terminated statements or suspended expressions.
CanResult canWriteOn(String uid, boolean inSurface);
// `true` if it can terminate, count all the possible read/write operations (an upper bound) and add them in `layer`.
boolean canAnalysis(Layer layer);
// Reduce the read/write counter of the terminated (or aborted) operations.
boolean terminate(Layer layer);
}
@@ -18,7 +18,7 @@
import bonsai.runtime.synchronous.*;
import bonsai.runtime.synchronous.env.*;
public interface Expression extends Schedulable, Prepare
public interface Expression extends Schedulable, Prepare, CanAnalysis
{
/// Idempotent: if called two times in a row, it must return the same result.
ExprResult execute(Layer env);
@@ -19,5 +19,7 @@
public interface Prepare
{
void prepareInstant(Layer env);
// This method is called before the statement is executed.
// `prepare` is not called again until termination (terminated completion code for statements (or aborted), and returning a non-suspended value for expressions).
void prepare(Layer env);
}
@@ -17,9 +17,9 @@
import bonsai.runtime.synchronous.*;
import bonsai.runtime.synchronous.env.*;
public interface Program extends Prepare, Schedulable
public interface Program extends Prepare, Schedulable, CanAnalysis
{
void prepareSubInstant(Environment env, int layerIndex);
void prepareSub(Environment env, int layerIndex);
CompletionCode executeSub(Environment env, int layerIndex);
CompletionCode execute(Layer env);
}
@@ -19,13 +19,11 @@
public interface Schedulable
{
// We analyse the current program to prove that a write on `uid` still can happen.
// We suppose the conditions currently suspended on `uid` to be `false` (if `inSurface` is `true`).
// `inSurface` is `true` if the statement analysed is currently suspended.
CanResult canWriteOn(String uid, boolean inSurface);
void meetRWCounter(Layer env);
void setParent(Schedulable parent);
// `schedule` can be called even if the current process is terminated.
// see Scheduler.schedule.
// It notifies the current process that an event arrived on a variable of one of its sub-expressions.
// Therefore it can be reschuled for execution.
// Note: this method should only be of interest in the parallel statements (to avoid rescheduling processes if nothing changed).
void schedule(Schedulable from);
}
@@ -26,22 +26,28 @@ public Nothing() {
super();
}
public void prepareSubInstant(Environment env, int layerIndex) {
throw new NoSubLayerException("Nothing.prepareSubInstant");
public void prepareSub(Environment env, int layerIndex) {
throw new NoSubLayerException("Nothing.prepareSub");
}
public CompletionCode executeSub(Environment env, int layerIndex) {
throw new NoSubLayerException("Nothing.executeSub");
}
public void prepareInstant(Layer layer) {}
public void prepare(Layer layer) {}
public CompletionCode execute(Layer layer) {
return CompletionCode.TERMINATE;
}
public void meetRWCounter(Layer layer) {}
public CanResult canWriteOn(String uid, boolean inSurface) {
return new CanResult(true, false);
}
public boolean canAnalysis(Layer layer) {
return true;
}
public boolean terminate(Layer layer) {
return true;
}
}
@@ -33,16 +33,16 @@ public ProcedureCall(List<Access> args, Consumer<ArrayList<Object>> procedure) {
this.procedure = procedure;
}
public void prepareSubInstant(Environment env, int layerIndex) {
throw new NoSubLayerException("ProcedureCall.prepareSubInstant");
public void prepareSub(Environment env, int layerIndex) {
throw new NoSubLayerException("ProcedureCall.prepareSub");
}
public CompletionCode executeSub(Environment env, int layerIndex) {
throw new NoSubLayerException("ProcedureCall.executeSub");
}
public void prepareInstant(Layer layer) {
public void prepare(Layer layer) {
result = CompletionCode.WAIT;
super.prepareInstant(layer);
super.prepare(layer);
}
public CompletionCode execute(Layer layer) {
Oops, something went wrong.

0 comments on commit 7095585

Please sign in to comment.