-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inference: (slightly) improve type stability of capturing closures
As an idea to improve type stability for capturing closures, such as in #31909, I tried this idea of propagating the closure object as a `PartialStruct` whose `fields` include captured variables of which types are (partially) known. By performing const-prop on this `closure::PartialStruct`, we can achieve a certain level of type stability. Specifically, I made some modifications to `abstract_eval_new` to allow creating `PartialStruct` even for `:new` objects that are `!isconcretedispatch` (since `PartialStruct` can now represent abstract elements). I also adjusted `const_prop_argument_heuristic` to perform aggressive constant propagation using such `closure::PartialStruct`. As a result, the following code now achieves type stability: ```julia julia> Base.infer_return_type((Bool,Int,)) do b, y x = b ? 1 : missing inner = y -> x + y return inner(y) end Any # master Union{Missing, Int64} # this commit ``` However, this alone was not enough to fully resolve #31909. The call graph of `map` is extremely complex, and simply applying constant propagation everywhere does not achieve the type safety requested in the issue. Nevertheless this commit alone would still improve type stability for some cases, so I will go ahead and submit it as a PR.
- Loading branch information
Showing
2 changed files
with
65 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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