Skip to content

feat: @entered — ask which marked definitions one call went through - #24

Merged
sotashimozono merged 5 commits into
mainfrom
feat/entered-macro
Sep 6, 2026
Merged

feat: @entered — ask which marked definitions one call went through#24
sotashimozono merged 5 commits into
mainfrom
feat/entered-macro

Conversation

@sotashimozono

Copy link
Copy Markdown
Member

entered() answers this about a whole process. record(() -> f(x)) answers it about one call, and
is what this is built on. The macro earns its place by knowing two things a closure cannot: the
source text of the expression, and the line it was written on.

julia> ExperimentalAPI.@entered sweep(model; βs = 0.05:0.05:2.0)
┌ @entered sweep(model; βs = 0.05:0.05:2.0)   at sweep.jl:42
│   MyPkg.energy       ×10000 — convergence not established below β  0.1
│   MyPkg.correlator   ×  500 — edge cases at zero separation untested
└ 15 of 17 observable marked definitions were not entered
0.42713

It returns the value of the expression, so it drops into existing code the way @time does.

The last line is the point

julia> ExperimentalAPI.@entered publish(result)
┌ @entered publish(result)   at sweep.jl:57
└ entered nothing marked — 17 observable marked definitions were loaded

"Entered nothing" and "nothing is marked anywhere" are different states, and a package that has
not adopted this yet is in the second one. A report that could not tell them apart would read as
reassurance on a package where nothing had ever been declared. The two branches print different
text, and the tests assert both — a report that always printed one of them could not pass both.

What the tests pin that nothing else would

  • The expression is evaluated exactly once. A macro that splices expr into both the run and
    the report doubles every count it prints, and the count is the answer. Verified by mutation:
    splicing a second time makes the test read 2 == 1.
  • The value comes back, not the record. The property that makes it droppable.
  • The location is the caller's, asserted against @__LINE__ taken on the same line, so a
    report naming the macro's own definition site would fail.
  • Recording is not left on afterwards.

Two deliberate omissions, both stated in the docstring

  • Time. Capturing a path and running the sampler cannot happen in the same block (fix: paths and time are two unwinders on one stack, and cannot both run #23), and
    this asks the question that needs neither.
  • The route. It was implemented and then removed: a captured path is a list of frame names,
    and Base's higher-order functions are in it — sum(f, xs) over a generator reports
    driver → sum → mapreduce → mapfoldl → mapfoldl_impl → foldl_impl → _foldl_impl → MappingRF → inner → energy, three names the reader wrote and seven they did not. Printing that is worse
    than printing nothing. Separating them needs paths to carry which module each frame came
    from, which is a change to what Hit.paths means and belongs in its own change.

public, not exported — @experimental remains the only exported name, and a test says so.

🤖 Generated with Claude Code

@github-actions github-actions Bot added the enhancement New feature or request label Sep 6, 2026
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

📚 Docs preview: https://codes.sota-shimozono.com/ExperimentalAPI.jl/previews/PR24/

(updates on each push to this PR)

@codecov

codecov Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@sotashimozono
sotashimozono merged commit e2fea32 into main Sep 6, 2026
14 checks passed
@sotashimozono
sotashimozono deleted the feat/entered-macro branch September 6, 2026 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant