Skip to content

Commit

Permalink
make REPL ast transforms instance-specific (#34626)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj authored Feb 10, 2020
1 parent c6748a9 commit a211abc
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,28 @@ mutable struct REPLBackend
response_channel::Channel
"flag indicating the state of this backend"
in_eval::Bool
"transformation functions to apply before evaluating expressions"
ast_transforms::Vector{Any}
"current backend task"
backend_task::Task

REPLBackend(repl_channel, response_channel, in_eval) =
new(repl_channel, response_channel, in_eval)
REPLBackend(repl_channel, response_channel, in_eval, ast_transforms=copy(repl_ast_transforms)) =
new(repl_channel, response_channel, in_eval, ast_transforms)
end

function softscope!(ex)
"""
softscope(ex)
Return a modified version of the parsed expression `ex` that uses
the REPL's "soft" scoping rules for global syntax blocks.
"""
function softscope(@nospecialize ex)
if ex isa Expr
h = ex.head
if h === :toplevel
for i = 1:length(ex.args)
ex.args[i] = softscope!(ex.args[i])
end
ex′ = Expr(h)
map!(softscope, resize!(ex′.args, length(ex.args)), ex.args)
return ex′
elseif h in (:meta, :import, :using, :export, :module, :error, :incomplete, :thunk)
return ex
else
Expand All @@ -89,7 +97,10 @@ function softscope!(ex)
return ex
end

const repl_ast_transforms = Any[softscope!]
# Temporary alias until Documenter updates
const softscope! = softscope

const repl_ast_transforms = Any[softscope] # defaults for new REPL backends

function eval_user_input(@nospecialize(ast), backend::REPLBackend)
lasterr = nothing
Expand All @@ -101,7 +112,7 @@ function eval_user_input(@nospecialize(ast), backend::REPLBackend)
put!(backend.response_channel, (lasterr,true))
else
backend.in_eval = true
for xf in repl_ast_transforms
for xf in backend.ast_transforms
ast = xf(ast)
end
value = Core.eval(Main, ast)
Expand Down

6 comments on commit a211abc

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your package evaluation job has completed - possible new issues were detected. A full report can be found here. cc @maleadt

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

Please sign in to comment.