Skip to content

Conversation

@aviatesk
Copy link
Member

@aviatesk aviatesk commented Apr 21, 2025

This commit implements the migration to the new JuliaInterpreter interface proposed in JuliaDebug/JuliaInterpreter.jl#683.

It purely performs the migration to the new interface and does not include any refactoring based on it.
selective_eval! could now be rewritten as follows using the new interface, that change is not made in this commit for minimizing the diff Now refactored in e41295a

diff --git a/src/codeedges.jl b/src/codeedges.jl
index 3cf2a17..5eba604 100644
--- a/src/codeedges.jl
+++ b/src/codeedges.jl
@@ -1021,6 +1021,33 @@ function add_inplace!(isrequired, src, edges, norequire)
     return changed
 end

+struct SelectiveInterpreter{S<:Interpreter,T<:AbstractVector{Bool}} <: Interpreter
+    inner::S
+    isrequired::T
+end
+function JuliaInterpreter.step_expr!(interp::SelectiveInterpreter, frame::Frame, istoplevel::Bool)
+    pc = frame.pc
+    if interp.isrequired[pc]
+        step_expr!(interp.inner, frame::Frame, istoplevel::Bool)
+    else
+        next_or_nothing!(interp, frame)
+    end
+end
+function JuliaInterpreter.get_return(interp::SelectiveInterpreter, frame::Frame)
+    pc = frame.pc
+    node = pc_expr(frame, pc)
+    if is_return(node)
+        if interp.isrequired[pc]
+            return lookup_return(frame, node)
+        end
+    else
+        if isassigned(frame.framedata.ssavalues, pc)
+            return frame.framedata.ssavalues[pcexec]
+        end
+    end
+    return nothing
+end
+
 """
     selective_eval!([interp::Interpreter=RecursiveInterpreter()], frame::Frame, isrequired::AbstractVector{Bool}, istoplevel=false)

@@ -1037,27 +1064,10 @@ This will return either a `BreakpointRef`, the value obtained from the last exec
 Typically, assignment to a variable binding does not result in an ssa store by JuliaInterpreter.
 """
 function selective_eval!(interp::Interpreter, frame::Frame, isrequired::AbstractVector{Bool}, istoplevel::Bool=false)
-    pc = pcexec = pclast = frame.pc
-    while isa(pc, Int)
-        frame.pc = pc
-        pclast = pcexec::Int
-        if isrequired[pc]
-            pcexec = pc = step_expr!(interp, frame, istoplevel)
-        else
-            pc = next_or_nothing!(interp, frame)
-        end
-    end
-    isa(pc, BreakpointRef) && return pc
-    pcexec = (pcexec === nothing ? pclast : pcexec)::Int
-    frame.pc = pcexec
-    node = pc_expr(frame)
-    is_return(node) && return isrequired[pcexec] ? lookup_return(frame, node) : nothing
-    isassigned(frame.framedata.ssavalues, pcexec) && return frame.framedata.ssavalues[pcexec]
-    return nothing
+    return JuliaInterpreter.finish_and_return!(SelectiveInterpreter(interp, isrequired), frame, istoplevel)
 end
-function selective_eval!(frame::Frame, isrequired::AbstractVector{Bool}, istoplevel::Bool=false)
+selective_eval!(frame::Frame, isrequired::AbstractVector{Bool}, istoplevel::Bool=false) =
     selective_eval!(RecursiveInterpreter(), frame, isrequired, istoplevel)
-end

 """
     selective_eval_fromstart!([interp::Interpreter=RecursiveInterpreter()], frame, isrequired, istoplevel=false)

@aviatesk aviatesk force-pushed the avi/JuliaInterpreter-0.10 branch from e41295a to ba04708 Compare April 22, 2025 12:35
This commit implements the migration to the new JuliaInterpreter
interface proposed in JuliaDebug/JuliaInterpreter.jl#683.

It purely performs the migration to the new interface and does not
include any refactoring based on it.
`selective_eval!` could now be rewritten as follows using the new
interface, that change is not made in this commit for minimizing the
diff:
```diff
diff --git a/src/codeedges.jl b/src/codeedges.jl
index 3cf2a17..5eba604 100644
--- a/src/codeedges.jl
+++ b/src/codeedges.jl
@@ -1021,6 +1021,33 @@ function add_inplace!(isrequired, src, edges, norequire)
     return changed
 end

+struct SelectiveInterpreter{S<:Interpreter,T<:AbstractVector{Bool}} <: Interpreter
+    inner::S
+    isrequired::T
+end
+function JuliaInterpreter.step_expr!(interp::SelectiveInterpreter, frame::Frame, istoplevel::Bool)
+    pc = frame.pc
+    if interp.isrequired[pc]
+        step_expr!(interp.inner, frame::Frame, istoplevel::Bool)
+    else
+        next_or_nothing!(interp, frame)
+    end
+end
+function JuliaInterpreter.get_return(interp::SelectiveInterpreter, frame::Frame)
+    pc = frame.pc
+    node = pc_expr(frame, pc)
+    if is_return(node)
+        if interp.isrequired[pc]
+            return lookup_return(frame, node)
+        end
+    else
+        if isassigned(frame.framedata.ssavalues, pc)
+            return frame.framedata.ssavalues[pcexec]
+        end
+    end
+    return nothing
+end
+
 """
     selective_eval!([interp::Interpreter=RecursiveInterpreter()], frame::Frame, isrequired::AbstractVector{Bool}, istoplevel=false)

@@ -1037,27 +1064,10 @@ This will return either a `BreakpointRef`, the value obtained from the last exec
 Typically, assignment to a variable binding does not result in an ssa store by JuliaInterpreter.
 """
 function selective_eval!(interp::Interpreter, frame::Frame, isrequired::AbstractVector{Bool}, istoplevel::Bool=false)
-    pc = pcexec = pclast = frame.pc
-    while isa(pc, Int)
-        frame.pc = pc
-        pclast = pcexec::Int
-        if isrequired[pc]
-            pcexec = pc = step_expr!(interp, frame, istoplevel)
-        else
-            pc = next_or_nothing!(interp, frame)
-        end
-    end
-    isa(pc, BreakpointRef) && return pc
-    pcexec = (pcexec === nothing ? pclast : pcexec)::Int
-    frame.pc = pcexec
-    node = pc_expr(frame)
-    is_return(node) && return isrequired[pcexec] ? lookup_return(frame, node) : nothing
-    isassigned(frame.framedata.ssavalues, pcexec) && return frame.framedata.ssavalues[pcexec]
-    return nothing
+    return JuliaInterpreter.finish_and_return!(SelectiveInterpreter(interp, isrequired), frame, istoplevel)
 end
-function selective_eval!(frame::Frame, isrequired::AbstractVector{Bool}, istoplevel::Bool=false)
+selective_eval!(frame::Frame, isrequired::AbstractVector{Bool}, istoplevel::Bool=false) =
     selective_eval!(RecursiveInterpreter(), frame, isrequired, istoplevel)
-end

 """
     selective_eval_fromstart!([interp::Interpreter=RecursiveInterpreter()], frame, isrequired, istoplevel=false)
```
@aviatesk aviatesk force-pushed the avi/JuliaInterpreter-0.10 branch from 4a5564a to 1627733 Compare April 22, 2025 12:38
@aviatesk aviatesk closed this Apr 23, 2025
@aviatesk aviatesk reopened this Apr 23, 2025
@aviatesk aviatesk closed this Apr 23, 2025
@aviatesk aviatesk reopened this Apr 23, 2025
@aviatesk aviatesk force-pushed the avi/JuliaInterpreter-0.10 branch from a2d67b2 to 9088af5 Compare April 23, 2025 11:24
@aviatesk aviatesk merged commit bcb6f63 into master Apr 23, 2025
9 checks passed
@aviatesk aviatesk deleted the avi/JuliaInterpreter-0.10 branch April 23, 2025 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants