Skip to content

Commit

Permalink
eliminates hacky overloads ! (#129)
Browse files Browse the repository at this point in the history
* eliminates hacky overloads !

JuliaLang/julia#39305 is merged, and now we can
really clean up our `abstractinterpretation.jl`.
The legacy hacky overloads will be kept in 
`src/legacy/abstractinterpretation.jl`
for the compatbility with Julia v1.6.

JET benchmark will also show the impact analysis of constant prop' on
union-split signatures on JET analysis.

* add `at-doc` annotations

* styling tweaks

* codecov tweak
  • Loading branch information
aviatesk authored Mar 11, 2021
1 parent b35d569 commit e49cc95
Show file tree
Hide file tree
Showing 7 changed files with 515 additions and 839 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/legacy/* linguist-language=Julia
src/legacy/*.md linguist-language=Markdown
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ No errors !

- documentation: WIP at <https://github.com/aviatesk/JET.jl/pull/127>
- release: see <https://github.com/aviatesk/JET.jl/issues/121>
- remove `Core.eval(CC, ...)` monkey patches (<https://github.com/JuliaLang/julia/pull/39439>, <https://github.com/JuliaLang/julia/pull/39305>, see also "developer note" section)
- more accurate error reports in general
* enable constant propagation on union-split signatures (<https://github.com/JuliaLang/julia/pull/39305>)
- provide editor/IDE integrations for "watch" mode (<https://github.com/aviatesk/JET.jl/pull/85> will be a starting point)
Expand All @@ -175,14 +174,6 @@ JET.jl overloads functions from Juila's `Core.Compiler` module, which are intend
They're overloaded on `JETInterpreter` so that `typeinf(::JETInterpreter, ::InferenceState)` will do abstract interpretation tuned for JET.jl's type error analysis.
Most overloads are done by using `invoke`, which allows us to call down to and reuse the original `NativeInterpreter`'s abstract interpretation methods while passing `JETInterpreter` for subsequent (maybe overloaded) callees (see `@invoke` macro).

But sometimes we can't just use `@invoke` and have to change/discard some logics that are hard-coded within original native function.
In such cases, currently JET.jl copy-and-pasted the original body of the overloaded function and applies monkey patches.
I'm planning to remove those monkey patches by adding some tweaks to Julia's compiler code itself, but for now, in order to keep the least maintainability, we do:
- use syntactic hacks (`#=== ... ===#`) to indicate the locations and purposes of each patch
- each overload is directly evaluated in the `Core.Compiler` module so that we don't need to maintain miscellaneous imports
- as such, the overloads are done within `__init__` hook; there are wrapper functions whose name starts with `overload_` for each overloading and the wrappers are registered to `push_inithook!`
- the docstrings of the wrappers tell the purposes of each overload


### acknowledgement

Expand Down
951 changes: 123 additions & 828 deletions src/abstractinterpretation.jl

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion src/abstractinterpreterinterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ mutable struct JETInterpreter <: AbstractInterpreter
# configurations for JET analysis
analysis_params::JETAnalysisParams

# tracks there has been any error reported in `abstract_call_method`
# that information will help JET decide it's worth to do constant prop' even if
# `NativeInterpreter` doesn't find it useful (i.e. the return type can't be improved anymore)
# NOTE this field is supposed to be computed at each call of `abstract_call_method`, and
# then immediately reset within the next `abstract_call_method_with_const_args` call
anyerror::Bool

## virtual toplevel execution ##

# for sequential assignment of abstract global variables
Expand Down Expand Up @@ -308,12 +315,13 @@ end
current_frame,
cache,
analysis_params,
false,
id,
concretized,
toplevelmod,
global_slots,
logger,
0,
depth,
)
end
# dummies to interpret non-toplevel frames
Expand Down
6 changes: 6 additions & 0 deletions src/legacy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This directory keeps legacy code, which is supposed to work with "older" Julia versions.
It might not be "older" in the usual sense though – currently the code here is kept for the compatibility with Julia v1.6, whose stable version is not even released yet (as of 2021/03/11).
This is because the `AbstractInterpreter` interface is really unstable at this point and right under the rapid development.

Note that the files are not given `.jl` file extensions.
This is a naive hack to prevent [CoverageTools.jl](https://github.com/JuliaCI/CoverageTools.jl) to take into account them when calculating a coverage.
Loading

0 comments on commit e49cc95

Please sign in to comment.