# Trying to understand inferred effects

**URL:** <https://discourse.julialang.org/t/trying-to-understand-inferred-effects/110854>\
**Category:** General Usage\
**Tags:** effects\
**Created:** [February 27, 2024, 3:59pm UTC](https://discourse.julialang.org/t/trying-to-understand-inferred-effects/110854 "2024-02-27T15:59:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [February 27, 2024, 3:59pm UTC](https://discourse.julialang.org/t/trying-to-understand-inferred-effects/110854/1 "2024-02-27T15:59:09Z")

</div>

```julia
julia> Base.infer_effects(getindex, (UnitRange{Int}, Int))
(+c,+e,!n,+t,+s,+m,+u)

julia> Base.infer_effects(getindex, (Base.OneTo{Int}, Int))
(!c,+e,!n,+t,+s,+m,+u)

julia> VERSION
v"1.12.0-DEV.88"

```

Firstly, why is the inbounds effect not displayed (there are seven flags, not eight), even though the documentation says that this should be there? Secondly, why is the `consistent` flag different between the two? Indexing a `Base.OneTo` is a simpler operation, so I would have naively expected the flag to hold as well. ~~I noticed that the `getindex` for a `UnitRange{Int}` with an `Int` index uses `val % T` instead of `convert(T, val)`, so is this what is leading to the difference? These should both be no-ops, so I don’t see why this difference should matter.~~ (it doesn’t)

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [February 27, 2024, 5:28pm UTC](https://discourse.julialang.org/t/trying-to-understand-inferred-effects/110854/2 "2024-02-27T17:28:51Z")

</div>

this appears to be a bug.

---

<div class="post-metadata">

**Author:** ![aviatesk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aviatesk/32/7610_2.png) [@aviatesk](https://discourse.julialang.org/u/aviatesk)\
**Post date:** [February 28, 2024, 8:06am UTC](https://discourse.julialang.org/t/trying-to-understand-inferred-effects/110854/3 "2024-02-28T08:06:39Z")

</div>

As for the first point, this is just because the documentation for `Core.Compiler.Effects` isn’t synced with the latest implementation. We should update it.

---

<div class="post-metadata">

**Author:** ![aviatesk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aviatesk/32/7610_2.png) [@aviatesk](https://discourse.julialang.org/u/aviatesk)\
**Post date:** [February 28, 2024, 10:02am UTC](https://discourse.julialang.org/t/trying-to-understand-inferred-effects/110854/4 "2024-02-28T10:02:05Z")

</div>

The second issue definitely is a bug. Actually, `getindex(::Base.OneTo, ...)` and `getindex(::UnitRange, ...)` both include `@boundscheck` and their behavior is changed by the caller’s `@inbounds` context, meaning they shouldn’t be considered `:consistent`.  
See [post-opt analysis bug: wrongly refine `:consistent` of `Base._getindex(::Base.OneTo{Int}, ::Int)` · Issue #53508 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/53508) for more details.
