Repository navigation
Conversation
…he type
Loading Mods in a session whose sysimage contains ModelingToolkit invalidated
4,032 compiled method instances (measured with SnoopCompileCore on Julia 1.13):
654 of them from `iterate(::Type{GaussMod{m}})`. Base has no `iterate` method
on `Type` arguments, so every call site that inference saw as `iterate(::Type)`
was compiled against an empty method set and carries an edge that the first
`iterate(::Type{...})` method breaks.
`allmods(Mod{m})` / `allmods(GaussMod{m})` return a small iterator object that
owns its `iterate`, `length` and `eltype` methods, so defining them cannot
intersect any existing call site. The element order is unchanged; `eltype` is
now the residue type (a generator would give `Any`). Iterating the type itself
is removed rather than deprecated: keeping the old methods would keep the
invalidations.
Not changed: the unary `-(a::GaussMod{N})` (3,656 of the 4,032) is reached
through a `Tuple{typeof(-), Number}` method-table edge recorded by
`Broadcast.combine_eltypes`, which any new unary minus on a `Number` subtype
hits; there is no signature a `Number` subtype can use that avoids it. The
`promote_rule` methods (75) are the sanctioned extension point and are left
as they are.
Co-Authored-By: Claude Fable 5.1 <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.
Proposal (draft). Loading Mods in a session whose sysimage contains ModelingToolkit invalidates ~4,000 compiled method instances (
SnoopCompileCore.@snoop_invalidations, Julia 1.13); 654 of them come fromiterate(::Type{Mod{m}})/iterate(::Type{GaussMod{m}}). Base defines noiteratemethod on types, so every call site inferred asiterate(::Type)carries an edge that the first such method breaks (#37).This replaces iterating the type with
allmods(Mod{m})/allmods(GaussMod{m}), a small iterator object owning its methods (same order;eltypeis nowMod{m}). README, docs and tests updated. It is API-breaking (for x in Mod{5}no longer works), so it would need a major bump; happy to keep the old methods behind a deprecation instead if you prefer, at the cost of keeping the invalidation.The remaining ~3,650 come from
-(a::GaussMod{N})through aTuple{typeof(-), Number}edge; that is inherent to anyNumbersubtype and is left alone. Not run here: the test suite.🤖 Generated with Claude Code