Conversation
`@define_diffrule` wrote into a global `Dict`, so rules declared outside DiffRules were lost during precompilation and never reached downstream packages (#90). It now defines a method of `diffrule` instead, making the method table the registry: rules declared anywhere are precompiled and visible, and `diffrules`/`hasdiffrule` read them back by scanning it. That in turn allows the SpecialFunctions, NaNMath and LogExpFunctions rules to move into package extensions (#106), which drops those packages from `[deps]`. Depending on DiffRules now installs 2 packages instead of 22, and no longer pulls in OpenSpecFun_jll. `NaNMath.lgamma` is the one rule reaching across packages, so it lives in an extension triggered by both NaNMath and SpecialFunctions. Rules interpolate the functions they call rather than naming them, so a rule can be evaluated without its defining package being in scope, and cannot pick up a shadowed binding. Lookup by function object and by module is supported alongside the existing symbol-keyed API: diffrule(sin, :x) diffrule(Base, :sin, :x) diffrule(:Base, :sin, :x) The module of a rule is derived via `Base.moduleroot`, so functions such as `Base.sec` that live in `Base.Math` keep reporting `:Base` and stay splice-able as `M.f` downstream. `test/baseline.jl` lists every rule key so downstream code generation is guarded against unintended changes, and `test/precompilation.jl` checks in a separate process that rules defined in another package survive precompilation and that the extensions load while a dependent is precompiled. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`_resolve` built the full rule list on every symbol lookup and had no early exit, which downstream packages hit once per rule while precompiling. Scan the method table directly instead. Make `diffrule(M::Module, ...)` throw a `KeyError` like its `Symbol` counterpart rather than an `UndefVarError`, and drop the IrrationalConstants imports that moved out with the SpecialFunctions rules. The `@define_diffrule` docstring named `Base.polygamma`, which lives in SpecialFunctions; harmless when the macro only stored symbols, wrong now that it evaluates `M.f`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
An extension's `PkgId` is derived from the parent package's UUID, so the prefix bought nothing. While here, import the functions the SpecialFunctions and LogExpFunctions rules call instead of naming them through their module, which leaves the rules readable. NaNMath keeps the qualified form because its names shadow `Base`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`Pkg.test` runs the test process with `JULIA_LOAD_PATH="@:<pkgdir>/test"`, which the spawned probe inherited. That dropped `@stdlib` off its load path, so `using Pkg` failed and the testset errored. It also stacked our test environment under the probe's project: a probe with an empty `Project.toml` could still find SpecialFunctions, so anything the probe asserted about an unloaded package was vacuous. Pin the child to its own project plus the stdlibs, and have it print labelled lines rather than destructuring exactly two lines of stdout. With the environments actually isolated, probe the two properties the suite cannot check in-process, since it loads every provider: that no provider rules exist until the provider is loaded, and that `NaNMath.lgamma` appears only once NaNMath and SpecialFunctions are both loaded (#106). Also tighten `unknown rules`, which passed on any exception at all, and assert that `diffrules()` has no duplicate keys. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The rules now evaluate the functions they are defined for, so a provider version that predates one of them makes the whole extension fail to precompile instead of registering a key that never resolved. `version: 'min'` pins Julia, not the packages, so nothing exercised the bounds. They hold today: at SpecialFunctions 1.1.0, NaNMath 0.3.2 and LogExpFunctions 0.3.2 all four extensions precompile and all 153 rules are present. This guards the next rule added for a function newer than the bounds. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Warning
WIP, just playing around a bit. Not ready for review.
Closes #90, closes #106.
@define_diffrulewrote into a globalDict, so rules declared outside DiffRules were lost during precompilation. It now defines a method ofdiffruleinstead, which makes the method table the registry: rules declared anywhere are precompiled and visible, anddiffrules/hasdiffruleread them back by scanning it.That in turn lets the SpecialFunctions, NaNMath and LogExpFunctions rules move into extensions.
NaNMath.lgammais the one rule reaching across packages, so it needs both NaNMath and SpecialFunctions.Lookup by function object and by module works alongside the existing symbol-keyed API:
The module of a rule comes from
Base.moduleroot, soBase.secand friends still report:Baserather than:Mathand stay splice-able asM.fdownstream.Rules now interpolate the functions they call instead of naming them, so a rule can be evaluated without its defining package in scope.
Notes
OpenSpecFun_jllis no longer in the closure.test/precompilation.jlchecks in a separate process that rules defined in another package survive precompilation, and that the extensions are loaded while a dependent is precompiled.isdefinedbefore generating code, so it is worth a look before release.🤖 Generated with Claude Code