• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JuliaLang / julia / #37632

26 Sep 2023 06:44AM UTC coverage: 86.999% (-0.9%) from 87.914%
#37632

push

local

web-flow
inference: make `throw` block deoptimization concrete-eval friendly (#49235)

The deoptimization can sometimes destroy the effects analysis and
disable [semi-]concrete evaluation that is otherwise possible. This is
because the deoptimization was designed with the type domain
profitability in mind (#35982), and hasn't been adequately considering
the effects domain.

This commit makes the deoptimization aware of the effects domain more
and enables the `throw` block deoptimization only when the effects
already known to be ineligible for concrete-evaluation.

In our current effect system, `ALWAYS_FALSE`/`false` means that the
effect can not be refined to `ALWAYS_TRUE`/`true` anymore (unless given
user annotation later). Therefore we can enable the `throw` block
deoptimization without hindering the chance of concrete-evaluation when
any of the following conditions are met:
- `effects.consistent === ALWAYS_FALSE`
- `effects.effect_free === ALWAYS_FALSE`
- `effects.terminates === false`
- `effects.nonoverlayed === false`

Here are some numbers:

| Metric | master | this commit | #35982 reverted (set
`unoptimize_throw_blocks=false`) |

|-------------------------|-----------|-------------|--------------------------------------------|
| Base (seconds) | 15.579300 | 15.206645 | 15.296319 |
| Stdlibs (seconds) | 17.919013 | 17.667094 | 17.738128 |
| Total (seconds) | 33.499279 | 32.874737 | 33.035448 |
| Precompilation (seconds) | 49.967516 | 49.421121 | 49.999998 |
| First time `plot(rand(10,3))` [^1] | `2.476678 seconds (11.74 M
allocations)` | `2.430355 seconds (11.77 M allocations)` | `2.514874
seconds (11.64 M allocations)` |
| First time `solve(prob, QNDF())(5.0)` [^2] | `4.469492 seconds (15.32
M allocations)` | `4.499217 seconds (15.41 M allocations)` | `4.470772
seconds (15.38 M allocations)` |

[^1]: With disabling precompilation of Plots.jl.
[^2]: With disabling precompilation of OrdinaryDiffEq.

These numbers ma... (continued)

7 of 7 new or added lines in 1 file covered. (100.0%)

73407 of 84377 relevant lines covered (87.0%)

11275130.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.0
/base/docs/bindings.jl
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2

3
export @var
4

5
struct Binding
6
    mod::Module
7
    var::Symbol
8

9
    function Binding(m::Module, v::Symbol)
513✔
10
        # Normalise the binding module for module symbols so that:
11
        #   Binding(Base, :Base) === Binding(Main, :Base)
12
        m = nameof(m) === v ? parentmodule(m) : m
513✔
13
        new(Base.binding_module(m, v), v)
749✔
14
    end
15
end
16

17
bindingexpr(x) = Expr(:call, Binding, splitexpr(x)...)
280✔
18

19
defined(b::Binding) = isdefined(b.mod, b.var)
704✔
20
resolve(b::Binding) = getfield(b.mod, b.var)
596✔
21

22
function splitexpr(x::Expr)
21✔
23
    isexpr(x, :macrocall) ? splitexpr(x.args[1]) :
21✔
24
    isexpr(x, :.)         ? (x.args[1], x.args[2]) :
25
    error("Invalid @var syntax `$x`.")
26
end
27
splitexpr(s::Symbol) = Expr(:macrocall, getfield(Base, Symbol("@__MODULE__")), nothing), quot(s)
259✔
28
splitexpr(r::GlobalRef) = r.mod, quot(r.name)
×
29
splitexpr(other)     = error("Invalid @var syntax `$other`.")
×
30

31
macro var(x)
32
    esc(bindingexpr(x))
33
end
34

35
function Base.show(io::IO, b::Binding)
3,045✔
36
    if b.mod === Base.active_module()
3,045✔
37
        print(io, b.var)
11✔
38
    else
39
        print(io, b.mod, '.', Base.isoperator(b.var) ? ":" : "", b.var)
3,034✔
40
    end
41
end
42

43
aliasof(b::Binding)     = defined(b) ? (a = aliasof(resolve(b), b); defined(a) ? a : b) : b
183✔
44
aliasof(d::DataType, b) = Binding(d.name.module, d.name.name)
6✔
45
aliasof(λ::Function, b) = (m = typeof(λ).name.mt; Binding(m.module, m.name))
4✔
46
aliasof(m::Module,   b) = Binding(m, nameof(m))
228✔
47
aliasof(other,       b) = b
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc