2525import com .oracle .truffle .api .Assumption ;
2626import com .oracle .truffle .api .CompilerDirectives ;
2727import com .oracle .truffle .api .frame .VirtualFrame ;
28- import com .oracle .truffle .api .nodes .InvalidAssumptionException ;
2928import com .oracle .truffle .api .profiles .BranchProfile ;
3029import com .oracle .truffle .r .nodes .function .ArgumentStatePush ;
3130import com .oracle .truffle .r .nodes .function .PromiseHelperNode ;
@@ -137,12 +136,9 @@ public OptForcedEagerPromiseNode(RPromiseFactory factory, int wrapIndex, Assumpt
137136 @ Override
138137 public Object execute (final VirtualFrame frame ) {
139138 Object value = null ;
140- try {
141- allArgPromisesCanOptimize .check ();
142- } catch (InvalidAssumptionException e ) {
143- return getFallback ().execute (frame );
139+ if (!allArgPromisesCanOptimize .isValid ()) {
140+ return rewriteToFallback ().execute (frame );
144141 }
145-
146142 RCaller currentCaller = RArguments .getCall (frame );
147143 boolean previousEvalEagerOnly = currentCaller .evaluateOnlyEagerPromises ();
148144 try {
@@ -167,8 +163,10 @@ public Object execute(final VirtualFrame frame) {
167163 }
168164 } catch (CannotOptimizePromise ex ) {
169165 allArgPromisesCanOptimize .invalidate ();
170-
171166 if (previousEvalEagerOnly ) {
167+ // no point in continuing executing this node, which checks this assumption as the
168+ // first thing in this method
169+ rewriteToFallback ();
172170 throw ex ;
173171 }
174172 value = null ;
@@ -195,6 +193,10 @@ public RSyntaxNode getPromiseExpr() {
195193 return expr .asRSyntaxNode ();
196194 }
197195
196+ private PromiseNode rewriteToFallback () {
197+ return replace (getFallback ());
198+ }
199+
198200 private PromiseNode getFallback () {
199201 if (fallback == null ) {
200202 CompilerDirectives .transferToInterpreterAndInvalidate ();
0 commit comments