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

inference: followups for #51754 #52241

Merged
merged 5 commits into from
Nov 21, 2023
Merged

inference: followups for #51754 #52241

merged 5 commits into from
Nov 21, 2023

Conversation

aviatesk
Copy link
Sponsor Member

@aviatesk aviatesk commented Nov 20, 2023

Composed of:

  • typeinf_local: factor into update_cycle_worklists! utility (78f7b4e)
  • inference: fix exception type of typename call (fac36d8)
  • add missing type annotations (7ce140e)
  • inference: refine exct information if :nothrow is proven (76143d3)
  • improve exception type inference for core math functions (525bd6c) Separated into TODO

@aviatesk aviatesk requested a review from Keno November 20, 2023 18:22
@aviatesk aviatesk added compiler:inference Type inference don't squash Don't squash merge labels Nov 20, 2023
base/array.jl Outdated
@@ -130,9 +130,9 @@ to tell the compiler that indexing operations within the applied expression are
inbounds and do not need to taint `:consistent` and `:nothrow`.
"""
macro _safeindex(ex)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know where this macro came from, but the __safe_getindex function is very dangerous. Effect annotations need to be valid for all possible argument values. I'd like to limits its further propagation if possible. If we really need this, we could potentially think about call-site @assume_effects, but ugh.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it comes from a desire to let f(a, i) = (@boundscheck boundscheck(a, i); @inbounds a[i]) have the same IPO effects as the combined operation f(a, i) = a[i], while still poisoning the independent expressions themselves (not consistent and ub, respectively) after inlining

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The macro @_safeindex was created to mimic the effect of @inbounds [getindex|setindex!] without affecting :noub. But, echoing Keno's point, a more effective approach might be to isolate the specific indexing code into its own function, and add effects annotations to that function:

I'd rather pull out this table lookup into a separate function along with the jp computation and a long comment about why it's inbounds.

@Keno
Copy link
Member

Keno commented Nov 20, 2023

I'm not too happy with the last commit, but everything else if fine, so if you want to split the PR, those can go ahead and we can keep talking about the last one.

@aviatesk aviatesk force-pushed the avi/exception_types branch 3 times, most recently from 9367cc2 to 6723c80 Compare November 21, 2023 08:50
This commit defines functions that mirror our tools for analyzing return
types and computational effects.

The key point to discuss is that this commit introduces two functions:
`Base.exception_types` and `Base.exception_type`. `Base.exception_types`
acts like `Base.return_types`, giving a list of exception types for each
method that matches with the given call signature. On the other hand,
`Base.exception_type` is akin to `Base.infer_effects`, returning a
single exception type that covers all potential outcomes entailed by the
given call signature. I personally lean towards the latter for its
utility, particularly in testing scenarios, but I included
`exception_types` too for consistency with `return_types`.
I'd welcome any feedback on this approach.
@aviatesk
Copy link
Sponsor Member Author

@nanosoldier runbenchmarks("inference", vs=":master")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - no performance regressions were detected. A full report can be found here.

Base automatically changed from avi/exception_types to master November 21, 2023 11:55
@aviatesk aviatesk merged commit 0402c78 into master Nov 21, 2023
8 of 9 checks passed
@aviatesk aviatesk deleted the avi/follow-51754 branch November 21, 2023 11:58
aviatesk added a commit that referenced this pull request Dec 8, 2023
Continued from #52241. 

This PR focuses on improving exception type inference for core math
functions by using new callsite `Base.@assume_effects` annnotation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference don't squash Don't squash merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants