Skip to content

Commit

Permalink
feature complete
Browse files Browse the repository at this point in the history
  • Loading branch information
kustosz committed Feb 17, 2022
1 parent 9860b54 commit 24179c1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.enso.interpreter.runtime.callable.UnresolvedSymbol;
import org.enso.interpreter.runtime.callable.argument.CallArgumentInfo;
import org.enso.interpreter.runtime.callable.function.Function;
import org.enso.interpreter.runtime.data.ArrayRope;
import org.enso.interpreter.runtime.data.text.Text;
import org.enso.interpreter.runtime.error.DataflowError;
import org.enso.interpreter.runtime.error.PanicSentinel;
Expand Down Expand Up @@ -173,19 +174,33 @@ Stateful doPolyglot(
HostMethodCallNode.PolyglotCallType polyglotCallType,
@Cached(value = "buildExecutors()") ThunkExecutorNode[] argExecutors,
@Cached(value = "buildProfiles()", dimensions = 1) BranchProfile[] profiles,
@Cached(value = "buildProfiles()", dimensions = 1) BranchProfile[] warningProfiles,
@Cached BranchProfile anyWarningsProfile,
@Cached HostMethodCallNode hostMethodCallNode) {
Object[] args = new Object[argExecutors.length];
boolean anyWarnings = false;
ArrayRope<Object> accumulatedWarnings = new ArrayRope<>();
for (int i = 0; i < argExecutors.length; i++) {
Stateful r = argExecutors[i].executeThunk(arguments[i + 1], state, TailStatus.NOT_TAIL);
state = r.getState();
args[i] = r.getValue();
if (r.getValue() instanceof DataflowError) {
profiles[i].enter();
return r;
} else if (r.getValue() instanceof WithWarnings) {
warningProfiles[i].enter();
anyWarnings = true;
accumulatedWarnings =
accumulatedWarnings.append(((WithWarnings) r.getValue()).getWarnings());
args[i] = ((WithWarnings) r.getValue()).getValue();
}
state = r.getState();
args[i] = r.getValue();
}
return new Stateful(
state, hostMethodCallNode.execute(polyglotCallType, symbol.getName(), _this, args));
Object res = hostMethodCallNode.execute(polyglotCallType, symbol.getName(), _this, args);
if (anyWarnings) {
anyWarningsProfile.enter();
res = WithWarnings.prependTo(res, accumulatedWarnings);
}
return new Stateful(state, res);
}

@Specialization(
Expand Down
22 changes: 22 additions & 0 deletions test/Tests/src/Semantic/Warnings_Spec.enso
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from Standard.Base import all

polyglot java import java.lang.Long

import Standard.Test

get_warnings val = Vector.Vector (Warning.get_all val)
Expand Down Expand Up @@ -30,3 +32,23 @@ spec = Test.group "Dataflow Warnings" <|
r = warned.my_method
r.should_equal 6
here.get_warnings r . should_equal ["omgggg"]

Test.specify "should thread warnings through polyglot calls" <|
x = Warning.attach 1 "warn!"
y = Warning.attach 2 "warn!!"
r = Long.sum x y
r.should_equal 3
here.get_warnings r . should_equal ['warn!', 'warn!!']

Test.specify "should thread warnings through case expressions" <|
x = Warning.attach 1 (My_Warning "warn!")
y = Warning.attach 2 (My_Warning "warn!!")
z = Warning.attach 3 (My_Warning "warn!!!")
mtp = My_Type x y z
r = case mtp of
My_Type a b c -> a + b + c
r.should_equal 6
here.get_warnings r . should_equal [My_Warning "warn!", My_Warning "warn!!", My_Warning "warn!!!"]



0 comments on commit 24179c1

Please sign in to comment.