Skip to content

update to JuliaInterpreter 0.10 #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 23, 2025
Merged

update to JuliaInterpreter 0.10 #127

merged 5 commits into from
Apr 23, 2025

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.

1 participant