invalid usage of @assume_effects
in base/irrationals.jl
#55874
Description
There are four methods with @assume_effects :total
applied to the entire method in base/irrationals.jl
:
Line 55 in 6e5e87b
Lines 70 to 71 in 6e5e87b
Lines 113 to 120 in 6e5e87b
Issues:
- The
:total
effect is too powerful and not future-proof. I guess what's actually desired is just:foldable
. - It's not valid to apply
@assume_effects
to the::AbstractIrrational
methods, because users may define custom subtypes ofAbstractIrrational
, and thus calls likeBigFloat(::AbstractIrrational)
orbig(::AbstractIrrational)
may execute arbitrary code. That said ... - It's not valid to apply
@assume_effects
even just for::Irrational
, because users may define custom subtypes ofIrrational
! Example:
# in a user package
struct IrrationalSymbol end
function big(::Irrational{IrrationalSymbol})
execute_arbitrary_code()
end
This seems perfectly legal, or at least it's not type piracy.
The solution seems simple: define a Union
of all known irrational constants, something like the following, then dispatch on it for methods that have @assume_effects
, instead of on AbstractIrrational
or on Irrational
:
const _KnownIrrational = (ℯ, π, MathConstants.γ, MathConstants.catalan, MathConstants.φ)
This will ensure calls involving the known constants are foldable, and allow the unsafe @assume_effects
annotations to be deleted. Will make a PR later.