Conversation
`Base.get_extension` returns `nothing` for an unknown extension name, so querying `:InverseFunctionsTest` instead of `:InverseFunctionsTestExt` left the guard permanently true: "Did you forget to load Test?" was appended to every `test_inverse` `MethodError`, including those raised when `Test` is loaded and the extension method exists. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`test_inverse` is now a regular method of the package that forwards to `_test_inverse`, which `InverseFunctionsTestExt` implements. This removes `__init__` and with it the error hint: registering the hint cost 17-20 ms of load time on Julia 1.10 (~80% of it compilation), and an empty `__init__` costs the same, so the cost is having one at all. Precompilation gets cheaper too, since `__init__` also runs there. Arity errors now go through ordinary dispatch, so no internal method leaks into "Closest candidates", and the "load Test" message cannot be emitted while the extension is loaded. Unlike a `Base.get_extension` lookup, the stub needs no extension name literal -- the source of the bug fixed in the previous commit -- and stays statically resolvable, so it does not trip the `--trim` verifier. Behaviour change: a correct-arity call without `Test` now throws an `ArgumentError` instead of a `MethodError` carrying a hint, and a wrong-arity call without `Test` gets a plain `MethodError` with no hint at all. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #67 +/- ##
==========================================
+ Coverage 98.48% 98.49% +0.01%
==========================================
Files 6 6
Lines 132 133 +1
==========================================
+ Hits 130 131 +1
Misses 2 2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Two commits, kept separate so the pre-existing bug stays in the history even though the second commit deletes the line it lives on.
1. Fix the extension name in the error hint. The guard queried
:InverseFunctionsTest, but the extension is registered asInverseFunctionsTestExt.Base.get_extensionreturnsnothingfor an unknown name rather than erroring, so the guard was permanently true and "Did you forget to load Test?" was appended to everytest_inverseMethodError— including ones raised whileTestis loaded.2. Let the extension implement an internal stub.
test_inversebecomes a regular method that forwards to_test_inverse, implemented byInverseFunctionsTestExt. That removes__init__, which is the expensive part: on Julia 1.10 (LTS) it costs 17–20 ms of load time, ~80% of it compilation, and an empty__init__costs the same, so the cost is having one at all. Load time drops to 1.3–1.9 ms; precompilation gets cheaper too.Compared with a
Base.get_extensionlookup, the stub needs no extension-name literal — the construct behind the bug in commit 1 — and stays statically resolvable, so it does not trip the--trimverifier. Arity errors go through ordinary dispatch, so no internal method leaks into "Closest candidates".Behaviour change: a correct-arity call without
Testnow throwsArgumentErrorinstead of aMethodErrorcarrying a hint, and a wrong-arity call withoutTestgets a plainMethodErrorwith no hint. The latter is inherent to removing__init__on Julia ≤ 1.10.Tests cover both directions, plus
@test !isdefined(InverseFunctions, :__init__)so the load-time fix cannot be silently reverted. Full suite passes on 1.11; error shapes and happy path checked on 1.6, 1.10 and 1.11.Closes #62 (same goal, different route — credit to @Beforerr for identifying the load-time cost) and closes #66 (version bumped to 0.1.18 here).
🤖 Generated with Claude Code