Skip to content

Commit

Permalink
Revert "support repl_ast_transforms in Julia 1.5 (#947)"
Browse files Browse the repository at this point in the history
This reverts commit 4fd955a.
  • Loading branch information
stevengj committed Nov 14, 2020
1 parent 6b65e21 commit 29a2e5d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 40 deletions.
11 changes: 1 addition & 10 deletions docs/src/library/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ IJulia.init

## Cell execution hooks

These functions can be used to modify the behavior of IJulia
by executing custom code before or after cells are executed
(or errors are handled).

In Julia 1.5 or later, you can *also* add a transformation
function to `REPL.repl_ast_transforms` which takes every parsed
expression and transforms it to another expression. These
transformations are [used in the Julia REPL](https://github.com/JuliaLang/julia/issues/37047) (technically, they are the deaults for `Base.active_repl_backend.ast_transforms` in new REPL instances),
and are also executed by IJulia on each parsed code-cell expression.

```@docs
IJulia.pop_posterror_hook
IJulia.pop_postexecute_hook
Expand All @@ -29,6 +19,7 @@ IJulia.push_postexecute_hook
IJulia.push_preexecute_hook
```


## Messaging

```@docs
Expand Down
11 changes: 1 addition & 10 deletions docs/src/manual/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,6 @@ It defaults to `Main`.

By default, IJulia evaluates user code using "soft" global scope, via the [SoftGlobalScope.jl package](https://github.com/stevengj/SoftGlobalScope.jl): this means that you don't need explicit `global` declarations to modify global variables in `for` loops and similar, which is convenient for interactive use.

To opt out of this behavior, making notebooks behave similarly to global code in Julia `.jl` files or the REPL in Julia 1.0…1.4,
To opt out of this behavior, making notebooks behave similarly to global code in Julia `.jl` files,
you can set `IJulia.SOFTSCOPE[] = false` at runtime, or include the environment variable `IJULIA_SOFTSCOPE=no`
environment of the IJulia kernel when it is launched.

In Julia 1.5 or later, [soft-scope became the default
in the Julia REPL](https://julialang.org/blog/2020/08/julia-1.5-highlights/#the_return_of_quotsoft_scopequot_in_the_repl), and
IJulia once again matches the REPL behavior. The `IJULIA_SOFTSCOPE`
and `IJulia.SOFTSCOPE[]` can still be used to disable soft scope
in IJulia, however. More generally, the soft scoping can
be disabled in both the REPL and in IJulia by removing the
`REPL.softscope` function from the variable `REPL.repl_ast_transforms`
in your [`~/.julia/config/startup.jl`](https://docs.julialang.org/en/v1/manual/getting-started/) file.
22 changes: 2 additions & 20 deletions src/execute_request.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,11 @@ execute_msg = Msg(["julia"], Dict("username"=>"jlkernel", "session"=>uuid4()), D
# request
const stdio_bytes = Ref(0)

import REPL
import REPL: helpmode

# use a global array to accumulate "payloads" for the execute_reply message
const execute_payloads = Dict[]

function execute_code(code::AbstractString, filename::AbstractString)
@static if !isdefined(REPL, :repl_ast_transforms)
return SOFTSCOPE[] ? softscope_include_string(current_module[], code, "In[$n]") :
include_string(current_module[], code, "In[$n]")
else
# use the default REPL ast transformations in Julia 1.5,
# which include the soft-scope transformation.
include_string(current_module[], code, "In[$n]") do ast
for xf in REPL.repl_ast_transforms
if xf !== REPL.softscope || SOFTSCOPE[]
ast = Base.invokelatest(xf, ast)
end
end
ast
end
end
end

function execute_request(socket, msg)
code = msg.content["code"]
@vprintln("EXECUTING ", code)
Expand Down Expand Up @@ -84,7 +65,8 @@ function execute_request(socket, msg)
else
#run the code!
occursin(magics_regex, code) && match(magics_regex, code).offset == 1 ? magics_help(code) :
execute_code(code, "In[$n]")
SOFTSCOPE[] ? softscope_include_string(current_module[], code, "In[$n]") :
include_string(current_module[], code, "In[$n]")
end

if silent
Expand Down

0 comments on commit 29a2e5d

Please sign in to comment.