-
-
Notifications
You must be signed in to change notification settings - Fork 43
Type-assert opts.delim_flags to reduce invalidations
#601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Fixing #600 should fix this too. |
|
Looks like the invalidations are also triggered by InitialValues.jl (in the dependency tree of OhMyThreads.jl): inserting |(x, ::Union{InitialValues.NonspecificInitialValue, InitialValues.SpecificInitialValue{typeof(|)}}) @ InitialValues ~/.julia/packages/InitialValues/OWP8V/src/InitialValues.jl:161 invalidated:
mt_backedges: 1: signature Tuple{typeof(|), Int64, Any} triggered MethodInstance for Base.JuliaSyntax._register_kinds!(::Dict{Int64, Union{Module, Symbol}}, ::Dict{UInt16, String}, ::Dict{String, UInt16}, ::Module, ::Int64, ::Vector{String}) (0 children)
2: signature Tuple{typeof(|), Int64, Any} triggered MethodInstance for Base.JuliaSyntax._register_kinds!(::Dict{Int64, Union{Module, Symbol}}, ::Dict{UInt16, String}, ::Dict{String, UInt16}, ::Module, ::Int64, ::Vector{String}) (0 children)
3: signature Tuple{typeof(|), Bool, Any} triggered MethodInstance for <=(::Char, ::Any) (0 children)
4: signature Tuple{typeof(|), Bool, Any} triggered MethodInstance for <=(::Any, ::Char) (0 children)
5: signature Tuple{typeof(|), Missing, Any} triggered MethodInstance for <=(::Any, ::Char) (1 children)
6: signature Tuple{typeof(|), Missing, Any} triggered MethodInstance for <=(::Char, ::Any) (10 children)
7: signature Tuple{typeof(|), UInt16, Any} triggered MethodInstance for Base.JuliaSyntax.parse_function_signature(::Base.JuliaSyntax.ParseState, ::Bool) (1161 children) |
|
Would it make sense to type assert the whole |
feeb62f to
28fa41d
Compare
|
I had another look at this and I don't think we can realistically type-assert I realize it's a bit late, but is there any chance of getting this in for 1.12.2? 🫣 If so then I can make any necessary backport PRs. |
Can you just confirm that Cthulhu shows the status quo as bad? I have some memory that I tried to look at this with Cthuklhu and it showed that even the current master was ok (which is not true but it still showed that...) |
This prevents invalidations.
|
Hmm this is weird, with Revise loaded the second invocation to |
28fa41d to
2a77932
Compare
|
Yeah this isn't doing it for some reason. For some reason Cthulhu also doesn't show an option to descend into |
|
I tried this commit on the backports-1.12 branch: JamesWrigley@a148565 Tested with InitialValues and DataStructures, and it fixes all the JuliaSyntax invalidations for them. This is what Cthulhu reports (without Revise loaded): 2160 opts::NamedTuple = parse_brackets(ps::JuliaSyntax.ParseState, K")") do had_commas, had_splat, num_semis, num_subexprs
2161 _parsed_call = was_eventually_call(ps)
2162 _needs_parse_call = peek(ps, 2) ∈ KSet"( ."
2163 _is_anon_func = (!_needs_parse_call && !_parsed_call) || had_commas
2164 return (needs_parameters = _is_anon_func,
2165 is_anon_func = _is_anon_func,
2166 parsed_call = _parsed_call,
2167 needs_parse_call = _needs_parse_call,
2168 maybe_grouping_parens = !had_commas && !had_splat && num_semis == 0 && num_subexprs == 1)
2169 end::NamedTuple::Type{JuliaSyntax.var"#parse_function_signature##0#parse_function_signature##1"{JuliaSyntax.ParseState}}
2170 is_anon_func::Bool = (opts::NamedTuple.is_anon_func::Any::Bool)::Bool
2171 parsed_call::Bool = (opts::NamedTuple.parsed_call::Any::Bool)::Bool
2172 needs_parse_call::Bool = (opts::NamedTuple.needs_parse_call::Any::Bool)::Bool
2173 maybe_grouping_parens::Bool = (opts::NamedTuple.maybe_grouping_parens::Any::Bool)::Bool
2174 delim_flags::UInt16 = (opts::NamedTuple.delim_flags::Any::RawFlags::Type{UInt16})::UInt16
2175 if is_anon_func::Bool
2176 # function (x) body end ==> (function (tuple-p x) (block body))
2177 # function (x::f()) end ==> (function (tuple-p (::-i x (call f))) (block))
2178 # function (x,y) end ==> (function (tuple-p x y) (block))
2179 # function (x=1) end ==> (function (tuple-p (= x 1)) (block))
2180 # function (;x=1) end ==> (function (tuple-p (parameters (= x 1))) (block))
2181 # function (f(x),) end ==> (function (tuple-p (call f x)) (block))
2182 ambiguous_parens::Bool = maybe_grouping_parens::Bool &&
2183 (peek_behind(ps::JuliaSyntax.ParseState)::@NamedTuple{kind::JuliaSyntax.Kind, flags::UInt16, orig_kind::JuliaSyntax.Kind, is_leaf::Bool}.kind::JuliaSyntax.Kind in KSet"macrocall $")::Bool
2184 emit(ps::JuliaSyntax.ParseState, mark::JuliaSyntax.ParseStreamPosition, K"tuple", (PARENS_FLAG::Core.Const(0x0020)|delim_flags::UInt16)::UInt16)I fully admit it's a bit ugly... Not sure if it makes sense to merge this PR into main now that JuliaSyntax has been merged into the Julia repo, but if folks think this is acceptable I can make another PR to the upstream version. Is there still time to get it in for Julia 1.12.2? |
|
Bump, would be great to get this into 1.12.2 if possible. |
|
Heya, we just moved JuliaSyntax into Base in JuliaLang/julia#59870 - if you want to re-propose this PR over there, I've created a branch https://github.com/JuliaLang/JuliaSyntax.jl/tree/pr-for-Base/601 to make this easier. To make use of the branch, you can use the following steps:
For example: # git clone [email protected]:JuliaLang/julia julia_dir
# cd julia_dir
git remote add JuliaSyntax [email protected]:JuliaLang/JuliaSyntax.jl
git fetch JuliaSyntax
git checkout pr-for-Base/601
git rebase origin/masterSorry this wasn't dealt with prior to the big move! |
|
I think if JamesWrigley@a148565 is going to be merged then it should be into this repo and then I can make the other PR to Base. But it looks like we'll need a backports-1.12 branch because main and the commit in 1.12 have diverged quite a bit. |
In particular the last line of invalidations from PythonCall.jl (CC @cjdoris):
The issue is that
ops.delim_flagswas getting inferred toAny:But from reading
parse_brackets()I think it's safe to restrict it to aRawFlags