TuringLang / TuringLang/Libtask.jl
Issues found by claude
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 22
- Forks
- 11
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 2
Description
Verified on Julia 1.10, 1.11, and 1.12 where a runtime claim is made.
Bug
-
produceof a non-Intliteral whose result is used across a laterproducecrashesTapedTaskconstruction.src/refelim.jl:234,250(emitted atsrc/transformation.jl:812).function model() s = produce("hi") # constant literal as produce arg t = produce(s) # result `s` live across a later produce -> ref is kept return (s, t) end TapedTask(nothing, model) # ERROR: Unexpected value argument to set_ref_at!: hieliminate_refsonly handlesset_ref_at!value-args that areID,GlobalRef, or
Argument; a literal that survives constant-propagation into a kept cross-suspension ref
hitserror(...). TheIntcase is masked becauseCore.Constfolds the literal into all
use sites, leaving the produce-result SSA unused (no ref kept). Fix: handle a non-ID
constant value-arg like the existingGlobalRef/Argumentarm (store it as-is for a kept
set / substitute it for a dropped get) instead of erroring, in both branches.
Docs / CI
-
Doc build fails:
BasicBlockCode.remake_enterdocstring not indexed.docs/src/internals.md.
makedocs(; modules=[Libtask])enforcescheckdocs=:all;remake_enterhas a docstring
but no@docsentry →[:missing_docs], deterministically on all versions, so Documentation
CI is red. Fix: addLibtask.BasicBlockCode.remake_enterto the@docsblock.
(Already fixed on thesupport-trycatch-194branch; listed for completeness.) -
replace_capturesdocstring references nonexistentbuild_rrule(a Mooncake
leftover) and has a typo "intepreter".src/utils.jl:10. It's a documented internal, so the
stale text renders in the docs. Fix: reword to Libtask's actual use (reusing a compiled
MistyClosure's captures on copy/fresh_copyto avoid recompilation). -
optimise_ir!docstring signature is wrong.src/utils.jl:35. Shows
optimise_ir!(ir, show_ir=false)(positional) but the real signature is
optimise_ir!(ir; show_ir=false, do_inline=true)(keyword-only;do_inlineundocumented).
Documented internal → the rendered call form throwsMethodError. Fix: correct the
signature and documentdo_inline.
Robustness
-
consumeleavestaped_globalsin the calling task's TLS.src/copyable_task.jl:520.
consumesetstask_local_storage(TASK_VARIABLE_KEY, …)on the caller and never clears it,
so after anyconsume(t),get_taped_globals(::Type{T})called outside a TapedTask stops
throwingNotInTapedTaskErrorand returns the stale value — contradicting both docstrings.
(The existing test passes only because it is ordered first.) Fix: save/clear the key in a
try/finallyaround the inner call, or weaken the docstrings to state the key persists. -
get_function(x::Expr) = eval(x)runs arbitrary IR sub-expressions.src/transformation.jl:67,
fromstmt_might_produce's:callbranch. Result only feeds a conservative
isa(f, Union{IntrinsicFunction,Builtin,DataType})test, soevalis both unnecessary and a
side-effect/world-age hazard. Fix: for an unresolvedExprcallee, conservatively return
true(might-produce) instead of evaluating it. -
No
_find_id_uses!(::Switch)method.src/bbcode.jl:699-724.characterise_used_ids
would under-report IDs used only inSwitch.conds(latent today:Switchis synthesized after
the single call site and removed before lowering, butreplace_idsdoes handleSwitch, so
the asymmetry reads as a bug). Fix: add aSwitchmethod mirroringIDPhiNode, or comment
the invariant. -
necessary_ref_idsdedup relies on a non-local invariant.src/refelim.jl:184.
vcat(length(refs), …)force-includes the resume-block ref; correct only because that ref is
never touched viaget_ref_at/set_ref_at!. Fix: use a set union so dedup is explicit.
Concurrency / contract
-
set_taped_globals!over-restricts the new value's type, contradicting the docs.
src/copyable_task.jl:499,217. The method…(t::TapedTask{T}, ::T)and the parametric field
taped_globals::Ttaped_globalspin the type to construction time, so
set_taped_globals!(TapedTask(nothing, f), 5)throws aMethodError. The docstring says "set …
to anything you like." Fix: either widen the field/signature, or correct the docstring (and
the wrong signature shown in theset_taped_globals!docstring) to state the type is fixed. -
generate_irmutates the shared_id_countoutsidebuild_callable_lock.
src/copyable_task.jl:138. It callsseed_id!()and runs the full IR-deriving pipeline
unlocked — a second derivation path outside the lock the concurrency note (#227) forbids.
Debug-only, but violates the invariant. Fix: wrap the ID-generating body in
build_callable_lock. -
GlobalMCCache's internalReentrantLockis dead and its docstring misattributes
thread-safety.src/copyable_task.jl:228-243. All cache access is already under
build_callable_lock; onlysetindex!takes the inner lock (haskey/getindexdon't), so it
never contends and the comment points at the wrong mechanism. Fix: drop the inner lock (thin
Dict wrapper) or lock all accessors + correct the docstring to creditbuild_callable_lock.
Performance (build-time only)
-
get_block_id_from_intlinear-scans per resume site → ~O(blocks × resume_sites).
src/refelim.jl:57. Fix: build anint → IDdict once before the loop. -
Redundant
copyof an already-fresh slice.src/refelim.jl:321—
vcat(typeof(new_refs), copy(ir.argtypes[2:end])); the slice already copies. Fix: dropcopy.
Tests
-
allocsperf flag is a silent no-op for empty-result cases.src/test_utils.jl:52-64.
The allocation loop iteratesiteration_results, so cases with[]expected results assert
nothing — yet "no produce", "kwarg tester 1/2", and both "default kwarg tester" are marked
allocs. Fix: loop1:(length(results)+1)(also measure the terminatingconsume), or
downgrade those cases tonone. -
Duplicate test name + redundant case.
src/test_utils.jl:217-227. Two cases share the
name "default kwarg tester";kwargs=nothingandkwargs=(;)construct the identical task.
Fix: rename / drop the redundant one.
Trivial
- Dead assignment
new_argtypes = copy(ir.argtypes)overwritten on the next line.src/transformation.jl:979— delete it. -
throw(error(msg))double-wraps (and is inconsistent with sibling bareerror(...)sites).src/transformation.jl:77,692— useerror(msg). -
might_produceopt-in API documented but notexported/public.src/Libtask.jl/docs/src/index.md:31-35. Considerpublic might_produce, might_produce_if_sig_contains, @might_produce(guarded for Julia ≥ 1.11). - 1.12.0-prerelease
@warnhas nomaxlog→ floods logs in tight TapedTask-construction loops.src/copyable_task.jl:437— addmaxlog=1. - Typo "hanled" → "handled".
src/bbcode.jl:646(inherited from Mooncake).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
This issue bundles runtime, documentation, concurrency, performance, and test concerns across src/refelim.jl, src/transformation.jl, src/copyable_task.jl, src/bbcode.jl, src/test_utils.jl, and docs/src/internals.md. Start by splitting the checklist into focused changes, then read the cited code and run the relevant tests plus the documentation build. Done means each selected item has a targeted fix, regression coverage where applicable, and passing CI.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- backend, compilers, documentation, performance, testing
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100