Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace gen with fn, gen.{trace,splice} => gen.dynamic.{trace!,splice!} #41

Merged
merged 2 commits into from
Oct 2, 2023

Conversation

sritchie
Copy link
Collaborator

@sritchie sritchie commented Sep 11, 2023

This PR:

  • Moves gen.{trace,splice} to gen.dynamic.{trace!, splice!} to prevent clashes between these functions and the gen.trace namespace
  • gen.dynamic.trace/without-tracing becomes gen.dynamic/untraced
  • Changes the signature of trace to (trace! <addr> <gf> & <args>), simplifying the macro implementation and bringing it more inline with GenJAX and Gen.jl (similar change to splice)
  • trace! and splice! called outside of a gen macro will now error.
  • Fixes missing untraced call around the biggest arity of invoke for DynamicDSLFunction

There is a lurking bug that this PR exposed. trace! and splice! will currently only work if called as trace!, dynamic/trace! or gen.dynamic/trace!. If you bind the symbol some other way, like d/trace!, tracing will error.

We can fix this with some clever macro work for the cljs and SCI environments, but I want to hold off in this PR.

@sritchie sritchie requested a review from zane September 11, 2023 15:44
@codecov
Copy link

codecov bot commented Sep 11, 2023

Codecov Report

Merging #41 (db72f04) into main (7636f80) will decrease coverage by 0.06%.
The diff coverage is 40.74%.

@@            Coverage Diff             @@
##             main      #41      +/-   ##
==========================================
- Coverage   66.36%   66.30%   -0.06%     
==========================================
  Files          16       16              
  Lines         666      653      -13     
  Branches       22       16       -6     
==========================================
- Hits          442      433       -9     
- Misses        202      204       +2     
+ Partials       22       16       -6     
Files Coverage Δ
src/gen/dynamic/trace.cljc 71.42% <100.00%> (-1.30%) ⬇️
src/gen/clerk/viewer.cljc 37.50% <0.00%> (ø)
src/gen/dynamic.cljc 45.74% <40.38%> (-1.88%) ⬇️

... and 1 file with indirect coverage changes

`(binding [dynamic.trace/*trace* dynamic.trace/no-op]
~@body))

(defmacro gen
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(this is just an alias now)


(defrecord DynamicDSLFunction [clojure-fn]
(defmacro trace! [addr [f & xs]]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if you really want to go all functions (which I DO!) then we'd change this to a function and change the calls to

(trace! gf x1 x2 ...)

and don't try to make it look like a function call. Then trace! is conceptually like apply.

@sritchie sritchie force-pushed the sritchie/nosplice branch 2 times, most recently from 0d3bc33 to cc5017c Compare September 29, 2023 17:17
@sritchie sritchie changed the title Replace gen with fn, gen.{trace,splice} => gen.dynamic.{trace!, untraced} Replace gen with fn, gen.{trace,splice} => gen.dynamic.{trace!,splice!} Sep 29, 2023
(untraced
(apply clojure-fn x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 x16 x17 x18 x19 x20 xs)))
(applyTo [_ xlist]
(untraced (.applyTo ^clojure.lang.IFn clojure-fn xlist)))]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this untraced wrapper was missing on main for clj and cljs.


(defn trace-form?
"Returns true if `form` is a trace form."
[form]
(and (seq? form)
(= `gen/trace (first form))))
(#{'trace! 'dynamic/trace! 'gen.dynamic/trace!} (first form))))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is a hack for now, but I want to get things working in SCI before we take on a cleaner solution.

(or (symbol? gfn)
(and (seq gfn)
(= `gen (first gfn)))))))))
(#{'splice! 'dynamic/splice! 'gen.dynamic/splice!} (first form))))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

same here.

Copy link
Collaborator

@zane zane left a comment

Choose a reason for hiding this comment

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

Suggestions:

  • Add a comment above the hack linking it to the issue you made.
  • Extract out the code that changes (trace! …) such that the call isn't wrapped.
    • Have McCoy or someone from the Gen team review that.
  • Change the commit scope from feat to refactor! if, as it seems, this isn't actually introducing new functionality.

@sritchie sritchie merged commit ddda4d2 into main Oct 2, 2023
4 of 6 checks passed
@sritchie sritchie deleted the sritchie/nosplice branch October 2, 2023 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants