Skip to content

Commit

Permalink
fix #169, implement experimental pluggable analysis interface (#209)
Browse files Browse the repository at this point in the history
* fix #169, implement experimental pluggable analysis interface

* example: find_unstable_api.jl

* wip: include plugins documentation
  • Loading branch information
aviatesk committed Jun 3, 2021
1 parent 2dba2b6 commit 417c5f8
Show file tree
Hide file tree
Showing 27 changed files with 1,788 additions and 1,260 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
Manifest.toml
!/benchmark/Manifest.toml
!/docs/Manifest.toml
!/examples/Manifest.toml
4 changes: 2 additions & 2 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ SUITE["invalidation"] = @jetbenchmarkable (@analyze_call println(QuoteNode(nothi
end
SUITE["self analysis"] = @jetbenchmarkable(
begin
interp = JET.JETInterpreter()
analyzer = JET.JETAnalyzer()
m = methods(JET.virtual_process).ms[1]
JET.analyze_method!(interp, m)
JET.analyze_method!(analyzer, m)
end,
setup = begin
using JET
Expand Down
58 changes: 54 additions & 4 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,62 @@
using Documenter, JET

joinlines(lines) = join(lines, '\n')

function make_example_doc(filename)
doc, code = get_doc_and_code(filename)
return joinlines((
doc,
"```julia",
code,
"```",
))
end

function get_doc_and_code(filename)
doclines, codelines = String[], String[]
indoc = false
for line in readlines(filename)
if line == "\"\"\""
indoc = !indoc
continue
end
push!(indoc ? doclines : codelines, line)
end
return joinlines(doclines), joinlines(codelines)
end

function attach_doc!(dir)
docs = String[]

function gen_doc!(dir)
for (root, dirs, files) in walkdir(dir)
for file in files
endswith(file, ".jl") || continue
push!(docs, make_example_doc(normpath(root, file)))
end
for dir in dirs
gen_doc!(normpath(root, dir))
end
end
end
gen_doc!(dir)

doc = join(docs, "\n---\n")

@eval JET module PluginExamples end
@eval JET @doc $doc PluginExamples
end

attach_doc!(normpath(@__DIR__, "..", "examples"))

makedocs(; modules = [JET],
sitename="JET.jl",
pages = [
"README" => "index.md",
"Usages" => "usages.md",
"Configurations" => "config.md",
"Internals" => "internals.md",
"README" => "index.md",
"Usages" => "usages.md",
"Configurations" => "config.md",
"Internals" => "internals.md",
"Pluggable Analysis Framework" => "plugins.md",
],
format = Documenter.HTML(prettyurls = get(ENV, "CI", nothing) == "true"),
)
Expand Down
4 changes: 2 additions & 2 deletions docs/src/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
## Abstract Interpretation Based Analysis

JET.jl overloads functions with the [`Core.Compiler.AbstractInterpreter` interface](https://github.com/JuliaLang/julia/blob/master/base/compiler/types.jl), and customizes its abstract interpretation routine.
The overloads are done on `JETInterpreter <: AbstractInterpreter` so that `typeinf(::JETInterpreter, ::InferenceState)` will do the customized abstract interpretation and collect type errors.
The overloads are done on `AbstractAnalyzer <: AbstractInterpreter` so that `typeinf(::AbstractAnalyzer, ::InferenceState)` will do the customized abstract interpretation and collect type errors.

Most overloads use the [`invoke`](https://docs.julialang.org/en/v1/base/base/#Core.invoke) reflection, which allows
`JETInterpreter` to dispatch to the original `AbstractInterpreter`'s abstract interpretation methods and still keep passing
`AbstractAnalyzer` to dispatch to the original `AbstractInterpreter`'s abstract interpretation methods and still keep passing
it to the subsequent (maybe overloaded) callees (see [`JET.@invoke`](@ref) macro).

```@docs
Expand Down
16 changes: 16 additions & 0 deletions docs/src/plugins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# JET.jl Pluggable Analysis Framework

The documentation for the framework is very WIP.

## Interfaces

```@docs
JET.AbstractAnalyzer
JET.ReportPass
```

## Examples

```@docs
JET.PluginExamples
```
175 changes: 175 additions & 0 deletions examples/Manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# This file is machine-generated - editing it directly is not advised

[[ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"

[[Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"

[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[CodeTracking]]
deps = ["InteractiveUtils", "UUIDs"]
path = "../../CodeTracking"
uuid = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
version = "1.0.5"

[[Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[Downloads]]
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"

[[FileWatching]]
uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"

[[IRTools]]
deps = ["InteractiveUtils", "MacroTools", "Test"]
git-tree-sha1 = "c67e7515a11f726f44083e74f218d134396d6510"
pinned = true
uuid = "7869d1d1-7146-5819-86e3-90919afe41df"
version = "0.4.2"

[[InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[JET]]
deps = ["InteractiveUtils", "JuliaInterpreter", "LoweredCodeUtils", "MacroTools", "Pkg", "Revise"]
path = ".."
uuid = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
version = "0.3.2"

[[JuliaInterpreter]]
deps = ["CodeTracking", "InteractiveUtils", "Random", "UUIDs"]
path = "../../JuliaInterpreter"
uuid = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
version = "0.8.16"

[[LibCURL]]
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"

[[LibCURL_jll]]
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"

[[LibGit2]]
deps = ["Base64", "NetworkOptions", "Printf", "SHA"]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"

[[LibSSH2_jll]]
deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8"

[[Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[LoweredCodeUtils]]
deps = ["JuliaInterpreter"]
path = "../../LoweredCodeUtils"
uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b"
version = "2.1.0"

[[MacroTools]]
deps = ["Markdown", "Random"]
git-tree-sha1 = "6a8a2a625ab0dea913aba95c11370589e0239ff0"
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
version = "0.5.6"

[[Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[MbedTLS_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"

[[MozillaCACerts_jll]]
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"

[[NetworkOptions]]
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"

[[OrderedCollections]]
git-tree-sha1 = "85f8e6578bf1f9ee0d11e7bb1b1456435479d47c"
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
version = "1.4.1"

[[Pkg]]
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[[Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[[Random]]
deps = ["Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[Requires]]
deps = ["UUIDs"]
git-tree-sha1 = "4036a3bd08ac7e968e27c203d45f5fff15020621"
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
version = "1.1.3"

[[Revise]]
deps = ["CodeTracking", "Distributed", "FileWatching", "JuliaInterpreter", "LibGit2", "LoweredCodeUtils", "OrderedCollections", "Pkg", "REPL", "Requires", "UUIDs", "Unicode"]
path = "../../Revise"
uuid = "295af30f-e4ad-537b-8983-00126c2a3abe"
version = "3.1.16"

[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"

[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[TOML]]
deps = ["Dates"]
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

[[Tar]]
deps = ["ArgTools", "SHA"]
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"

[[Test]]
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[UUIDs]]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"

[[Zlib_jll]]
deps = ["Libdl"]
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"

[[nghttp2_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"

[[p7zip_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
3 changes: 3 additions & 0 deletions examples/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[deps]
IRTools = "7869d1d1-7146-5819-86e3-90919afe41df"
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
6 changes: 6 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# JET.jl plug-in analysis examples

This directory keeps examples that demonstrates JET's extensibility;
we can do various kinds of analysis as a plug-in analysis under the JET's framework.

The examples will be automatically included into JET's documentation.
Loading

0 comments on commit 417c5f8

Please sign in to comment.