Skip to content
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

Actually compute sparams in jl_fptr_sparam #57236

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Keno
Copy link
Member

@Keno Keno commented Feb 2, 2025

I was running a debug build of julia through the cmdlineargs tests and saw it repeatedly hit the sparams != jl_emptysvec assertion. That assertion doesn't make sense to me, since jl_fptr_sparam is specifically used in the case where the sparams need to be recomputed:

julia/src/codegen.cpp

Lines 3038 to 3043 in 12698af

if ((size_t)jl_subtype_env_size(lam->def.method->sig) != jl_svec_len(lam->sparam_vals))
needsparams = true;
for (size_t i = 0; i < jl_svec_len(lam->sparam_vals); ++i) {
if (jl_is_typevar(jl_svecref(lam->sparam_vals, i)))
needsparams = true;
}

It's possible I'm missing some larger point, but this fixes the assertion.

@Keno Keno requested a review from vtjnash February 2, 2025 21:08
I was running a debug build of julia through the cmdlineargs tests
and saw it repeatedly hit the `sparams != jl_emptysvec` assertion.
That assertion doesn't make sense to me, since jl_fptr_sparam is
specifically used in the case where the sparams need to be recomputed:

https://github.com/JuliaLang/julia/blob/12698af99f2502227aba611f0107b1dc3a6872d2/src/codegen.cpp#L3038-L3043

It's possible I'm missing some larger point, but this fixes the
assertion.
@vtjnash
Copy link
Member

vtjnash commented Feb 2, 2025

It should never directly execute this function, as it should have copied the function pointer into a MethodInstance that is populated correctly

@Keno
Copy link
Member Author

Keno commented Feb 2, 2025

Can you elaborate how that is supposed to work, since it appears to not be happening under some circumstances?

@vtjnash
Copy link
Member

vtjnash commented Feb 3, 2025

I think jl_compilation_sig is supposed to form the version without sparam_vals, but when the call to methods such as cache_method processes that, it is expected to set cache_with_orig so that the cache gets a direct fast lookup of the vals, but later jl_normalize_to_compilable_mi (in jl_compile_method_internal) will ensure that we compile the jl_compilation_sig instead to compute the invoke, and then copy that pointer to the call.

I have the sense that some callers of jl_normalize_to_compilable_sig aren't correctly anticipating the need to verify the sparams they got back (generally they should check if they are egal to the original set going into it to verify whether it is valid to use that result directly)

Alternatively/additionally, we can go with this approach where we no longer cache that result, and instead rely on detecting on the fly whether sparam_vals has been computed already or not and re-computing them every time you call the method.

@JeffBezanson
Copy link
Member

The intent was definitely to have the values already computed by this point since the type intersection is very expensive.

@KristofferC
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants