Skip to content

Commit

Permalink
πŸ’ Fix #734
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Nov 29, 2020
1 parent c5040f2 commit 9e0c8bd
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "Pluto"
uuid = "c3e4b0f8-55cb-11ea-2926-15256bba5781"
license = "MIT"
authors = ["Fons van der Plas <[email protected]>"]
version = "0.12.14"
version = "0.12.15"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/LiveDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export let LiveDocs = ({ desired_doc_query, client, on_update_doc_query, noteboo
? "Live docs"
: html`
<input
title=${no_docs_found ? `"${state.searched_query}" not found!` : ""}
title=${no_docs_found ? `"${state.searched_query}" not found` : ""}
id="live-docs-search"
placeholder="Search docs..."
ref=${live_doc_search_ref}
Expand Down
2 changes: 1 addition & 1 deletion frontend/editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ pluto-helpbox > header > input {
border: none;
}
pluto-helpbox.notfound > header > input {
color: red;
color: rgb(139, 139, 139);
}
pluto-helpbox > header > input:focus {
outline: none;
Expand Down
14 changes: 9 additions & 5 deletions src/runner/PlutoRunner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,15 @@ struct Computer
output_globals::Vector{Symbol}
end

expr_hash(e::Expr) = objectid(e.head) + mapreduce(expr_hash, +, e.args; init=zero(ObjectID))
expr_hash(x) = objectid(x)
# TODO: clear key when a cell is deleted furever
const computers = Dict{Expr,Computer}()
const computers = Dict{ObjectID,Computer}()

const computer_workspace = Main

function register_computer(expr::Expr, input_globals::Vector{Symbol}, output_globals::Vector{Symbol})

function register_computer(expr::Expr, key, input_globals::Vector{Symbol}, output_globals::Vector{Symbol})
proof = ReturnProof()

@gensym result
Expand All @@ -103,7 +106,7 @@ function register_computer(expr::Expr, input_globals::Vector{Symbol}, output_glo

f = Core.eval(computer_workspace, e)

computers[expr] = Computer(f, proof, input_globals, output_globals)
computers[key] = Computer(f, proof, input_globals, output_globals)
end

function compute(computer::Computer)
Expand Down Expand Up @@ -190,10 +193,11 @@ function run_expression(expr::Any, cell_id::UUID, function_wrapped_info::Union{N
wrapped = timed_expr(expr, proof)
run_inside_trycatch(wrapped, cell_id, proof)
else
local computer = get(computers, expr, nothing)
key = expr_hash(expr)
local computer = get(computers, key, nothing)
if computer === nothing
try
computer = register_computer(expr, collect.(function_wrapped_info)...)
computer = register_computer(expr, key, collect.(function_wrapped_info)...)
catch e
# @error "Failed to generate computer function" expr exception=(e,stacktrace(catch_backtrace()))
return run_expression(expr, cell_id, nothing)
Expand Down
12 changes: 12 additions & 0 deletions test/React.jl
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,8 @@ import Distributed
false
end |> length
"""),
Cell("4"),
Cell("[5]"),
])

update_run!(🍭, notebook, notebook.cells)
Expand All @@ -885,6 +887,16 @@ import Distributed
update_run!(🍭, notebook, notebook.cells)
@test 0.2 * good < notebook.cells[3].runtime / 1.0e9 < 1.5 * bad

old = notebook.cells[4].output_repr
setcode(notebook.cells[4], "4.0")
update_run!(🍭, notebook, notebook.cells[4])
@test old != notebook.cells[4].output_repr

old = notebook.cells[5].output_repr
setcode(notebook.cells[5], "[5.0]")
update_run!(🍭, notebook, notebook.cells[5])
@test old != notebook.cells[5].output_repr

WorkspaceManager.unmake_workspace((🍭, notebook))
end

Expand Down
10 changes: 5 additions & 5 deletions test/RichOutput.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ import Pluto: update_run!, WorkspaceManager, ClientSession, ServerSession, Noteb
Cell("DataFrame()"),
Cell("DataFrame(:a => [])"),
Cell("DataFrame(:a => [1,2,3], :b => [999, 5, 6])"),
Cell("DataFrame(rand(20,20))"),
Cell("DataFrame(rand(2000,20))"),
Cell("DataFrame(rand(20,2000))"),
Cell("@view DataFrame(rand(100,3))[:, 2:2]"),
Cell("@view DataFrame(rand(3,100))[2:2, :]"),
Cell("DataFrame(rand(20,20), :auto)"),
Cell("DataFrame(rand(2000,20), :auto)"),
Cell("DataFrame(rand(20,2000), :auto)"),
Cell("@view DataFrame(rand(100,3), :auto)[:, 2:2]"),
Cell("@view DataFrame(rand(3,100), :auto)[2:2, :]"),
Cell("DataFrame"),
Cell("Tables.table(rand(11,11))"),
Cell("Tables.table(rand(120,120))"),
Expand Down

1 comment on commit 9e0c8bd

@fonsp
Copy link
Owner Author

@fonsp fonsp commented on 9e0c8bd Nov 29, 2020

Choose a reason for hiding this comment

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

@JuliaRegistrator register()

Please sign in to comment.