You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
inference: Model type propagation through exceptions (#51754)
Currently the type of a caught exception is always modeled as `Any`.
This isn't a huge problem, because control flow in Julia is generally
assumed to be somewhat slow, so the extra type imprecision of not
knowing the return type does not matter all that much. However, there
are a few situations where it matters. For example:
```
maybe_getindex(A, i) =
try; A[i]; catch e; isa(e, BoundsError) && return nothing; rethrow(); end
```
At present, we cannot infer :nothrow for this method, even if that is
the only error type that `A[i]` can throw. This is particularly
noticable, since we can now optimize away `:nothrow` exception frames
entirely (#51674). Note that this PR still does not make the above
example particularly efficient (at least interprocedurally), though
specialized codegen could be added on top of this to make that happen.
It does however improve the inference result.
A second major motivation of this change is that reasoning about
exception types is likely to be a major aspect of any future work on
interface checking (since interfaces imply the absence of MethodErrors),
so this PR lays the groundwork for appropriate modeling of these error
paths.
Note that this PR adds all the required plumbing, but does not yet have
a particularly precise model of error types for our builtins, bailing to
`Any` for any builtin not known to be `:nothrow`. This can be improved
in follow up PRs as required.
0 commit comments