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: make Core.Compiler.return_type respect max_methods setting #46810

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

aviatesk
Copy link
Member

@aviatesk aviatesk commented Sep 17, 2022

Previously we didn't limit the number of matching methods for
Core.Compiler.return_type, which could lead to a potential latency
problem.
This commit makes Core.Compiler.return_type and the corresponding
tfunc return_type_tfunc respect max_methods setting as like the
ordinary inference.
One caveat here is that the current Core.Compiler.return_type interface
unfortunately doesn't allow it to see the caller module context, so it
can't respect module-wide max_methods setting (I guess the change to
the interface should be made as of version 2.0), that I think can lead
to a potential confusion.

@aviatesk aviatesk added the compiler:inference Type inference label Sep 17, 2022
@aviatesk aviatesk force-pushed the avi/return_type-max_methods branch from 9232929 to 059345f Compare September 17, 2022 03:47
sv.restrict_abstract_call_sites = old_restrict
else
call = abstract_call(interp, ArgInfo(nothing, argtypes_vec), sv, -1)
call = abstract_call(interp, ArgInfo(nothing, argtypes_vec), sv)
Copy link
Member

Choose a reason for hiding this comment

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

This needs to match the implementation of return_type

for match in _methods_by_ftype(t, -1, get_world_counter(interp))::Vector

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, I synced the implementations of Core.Compiler.return_type and return_type_tfunc.
One thing I'm not satisfied with is that the current Core.Compiler.return_type interface doesn't allow it to see caller module context, so it can't respect module-wise max_methods setting.

@aviatesk aviatesk force-pushed the avi/return_type-max_methods branch from 059345f to ddcd2f0 Compare September 20, 2022 09:45
@aviatesk aviatesk changed the title inference: use default max_methods setting for return_type_tfunc inference: make Core.Compiler.return_type respect max_methods setting Sep 20, 2022
@aviatesk aviatesk changed the title inference: make Core.Compiler.return_type respect max_methods setting inference: make Core.Compiler.return_type respect max_methods setting Sep 20, 2022
@aviatesk aviatesk force-pushed the avi/return_type-max_methods branch 3 times, most recently from 190026c to a48650d Compare November 29, 2022 04:21
@aviatesk aviatesk force-pushed the avi/return_type-max_methods branch from a48650d to 496192d Compare May 11, 2023 08:19
aviatesk added a commit that referenced this pull request May 12, 2023
Since this part of refactoring is generally useful and I would like to
utilize it for other PRs that may be merged before #46810.
aviatesk added a commit that referenced this pull request May 12, 2023
Since this part of refactoring is generally useful and I would like to
utilize it for other PRs that may be merged before #46810.
@aviatesk aviatesk force-pushed the avi/return_type-max_methods branch 2 times, most recently from b349f09 to 9419d6c Compare May 12, 2023 13:35
aviatesk added a commit that referenced this pull request May 13, 2023
This would help inference on `Core.Compiler.return_type(isequal, tt)`
when `tt` is not well inferred (e.g. `tt` is inferred to `Tuple{Any,Any}`).
(although #46810 may disable this `Core.Compiler.return_type`
improvement for good reasons).

Anyway, it is explicitly stated in the documentation that the `isequal`
method should always return a value of `Bool`. So, not only does this
annotation assist inference, it also serves to ensure the correctness of
our code base, and therefore should be beneficial. We may need to take
similar measures for `isless` and `isgreater` (in separate PRs).
aviatesk added a commit that referenced this pull request May 13, 2023
This would help inference on `Core.Compiler.return_type(isequal, tt)`
when `tt` is not well inferred (e.g. `tt` is inferred to `Tuple{Any,Any}`).
(although #46810 may disable this `Core.Compiler.return_type`
improvement for good reasons).

Anyway, it is explicitly stated in the documentation that the `isequal`
method should always return a value of `Bool`. So, not only does this
annotation assist inference, it also serves to ensure the correctness of
our code base, and therefore should be beneficial. We may need to take
similar measures for `isless` and `isgreater` (in separate PRs).
aviatesk added a commit that referenced this pull request May 13, 2023
This would help inference on `Core.Compiler.return_type(isequal, tt)`
when `tt` is not well inferred (e.g. `tt` is inferred to `Tuple{Any,Any}`).
(although #46810 may disable this `Core.Compiler.return_type`
improvement for good reasons).

Anyway, it is explicitly stated in the documentation that the `isequal`
method should always return a value of `Bool`. So, not only does this
annotation assist inference, it also serves to ensure the correctness of
our code base, and therefore should be beneficial. We may need to take
similar measures for `isless` and `isgreater` (in separate PRs).
aviatesk added a commit that referenced this pull request May 16, 2023
This would help inference on `Core.Compiler.return_type(isequal, tt)`
when `tt` is not well inferred (e.g. `tt` is inferred to `Tuple{Any,Any}`).
(although #46810 may disable this `Core.Compiler.return_type`
improvement for good reasons).

Anyway, it is explicitly stated in the documentation that the `isequal`
method should always return a value of `Bool`. So, not only does this
annotation assist inference, it also serves to ensure the correctness of
our code base, and therefore should be beneficial. We may need to take
similar measures for `isless` and `isgreater` (in separate PRs).
@aviatesk aviatesk force-pushed the avi/return_type-max_methods branch from 9419d6c to 0b975c0 Compare May 18, 2023 03:50
aviatesk added 2 commits May 19, 2023 21:28
…ting

Previously we didn't limit the number of matching methods for
`Core.Compiler.return_type`, which could lead to a potential latency
problem.
This commit makes `Core.Compiler.return_type` and the corresponding
tfunc `return_type_tfunc` respect `max_methods` setting as like the
ordinary inference.
One caveat here is that the current `Core.Compiler.return_type` interface
unfortunately doesn't allow it to see the caller module context, so it
can't respect module-wide `max_methods` setting (I guess the change to
the interface should be made as of version 2.0), that I think can lead
to a potential confusion.
@vtjnash vtjnash force-pushed the avi/return_type-max_methods branch from 0b975c0 to 48955b4 Compare May 20, 2023 01:28
@vtjnash
Copy link
Member

vtjnash commented May 20, 2023

I am not sure why SparseArrays tests failed so badly (looks like undef arrays being returned?), so I restarted it

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

Successfully merging this pull request may close these issues.

3 participants