Skip to content

Commit

Permalink
SnoopPrecompile + pipe handling
Browse files Browse the repository at this point in the history
This switches to SnoopPrecompile and uses more careful handling of
pipes to ensure tasks run to completion (see comment in #343).
  • Loading branch information
timholy committed Jan 22, 2023
1 parent 362a3ae commit 43f7689
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ FoldingTrees = "1eca21be-9b9b-4ed8-839a-6d8ae26b1781"
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
SnoopPrecompile = "66db9d55-30c0-4569-8b51-7e840670fc0c"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[compat]
CodeTracking = "0.5, 1"
FoldingTrees = "1"
Preferences = "1"
SnoopPrecompile = "1"
julia = "1.7"

[extras]
Expand Down
19 changes: 13 additions & 6 deletions src/Cthulhu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -807,13 +807,20 @@ with the option to `descend` into intermediate calls. `kwargs` are passed to [`d
"""
ascend

if ccall(:jl_generating_output, Cint, ()) == 1
input = Pipe()
Base.link_pipe!(input, reader_supports_async=true, writer_supports_async=true)
term = REPL.Terminals.TTYTerminal("dumb", input.out, IOBuffer(), IOBuffer())
using SnoopPrecompile
@precompile_setup begin
linked_pipe() = Base.link_pipe!(Pipe(), reader_supports_async=true, writer_supports_async=true)

input, output, err = linked_pipe(), linked_pipe(), linked_pipe()
term = REPL.Terminals.TTYTerminal("dumb", input.out, output.in, err.in)
write(input.in, 'q')
descend(gcd, (Int, Int); terminal=term)
close(input)
@precompile_all_calls begin
descend(gcd, (Int, Int); terminal=term)
readuntil(output.out, "")
end
close(input.in)
close(output.in)
close(err.in)
nothing
end

Expand Down

0 comments on commit 43f7689

Please sign in to comment.