-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
reflection: add Base.infer_return_type
utility
#52247
Conversation
c936a78
to
4c3a3bb
Compare
base/reflection.jl
Outdated
world::UInt=get_world_counter(), | ||
interp::Core.Compiler.AbstractInterpreter=Core.Compiler.NativeInterpreter(world)) -> rt::Type | ||
|
||
Returns the return type of the function call specified by `f` and `types`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should say "a supertype of the return type"
And seems like Base.infer_return_type
would be consistent with the names of other similar queries?
Also might want to add a See also ref to Base.promote_op
& friends so that people get directed to ways to infer these for generated functions, rather than just being warned that using from a generated function is an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should say "a supertype of the return type"
Maybe "an inferred return type" would be better? "supertype" sounds like returning something that is strictly wider in the type lattice. "inferred" might be a bit ambiguous, but it can still effectively communicate the idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And seems like
Base.infer_return_type
would be consistent with the names of other similar queries?
Yeah. Base.infer_return_type
isn't consistent with Base.return_types
, but we might want to rename Base.return_types
to Base.infer_return_types
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also might want to add a See also ref to
Base.promote_op
& friends so that people get directed to ways to infer these for generated functions, rather than just being warned that using from a generated function is an error
Are you suggesting that when it's absolutely necessary to infer the return type from a generated context, we should lean towards using Core.Compiler.return_type
? Or is the point more about using the docstring of promote_op
as a means to highlight the nuances of using these reflection tools?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is never allowed directly, but you can pass it as an argument to the generated function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean the implicit world::UInt
argument that is passed to the generator function? I'm not sure how promote_op
relates to generated functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, just as a real argument
Base.return_type
utilityBase.infer_return_type
utility
This commit introduces `Base.infer_return_type`, a new reflection utility which shares a similar interface with `Base.return_types` but differs in its output; `Base.infer_return_type` provides a singular return type taking into account all potential outcomes specified with the given call signature. This function parallels `Base.infer_effects` and the newly added `Base.exception_type`, offering some utility, especially in testing scenarios.
4c3a3bb
to
3b9eebb
Compare
This commit introduces `Base.infer_return_type`, a new reflection utility which shares a similar interface with `Base.return_types` but differs in its output; `Base.infer_return_type` provides a singular return type taking into account all potential outcomes specified with the given call signature. This function parallels `Base.infer_effects` and the newly added `Base.infer_exception_type`, offering some utility, especially in testing scenarios.
This commit introduces
Base.infer_return_type
, a new reflectionutility which shares a similar interface with
Base.return_types
butdiffers in its output;
Base.infer_return_type
provides a singularreturn type taking into account all potential outcomes specified with
the given call signature. This function parallels
Base.infer_effects
and the newly added
Base.infer_exception_type
, offering some utility,especially in testing scenarios.