-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Single argument isa
function
#32018
Comments
Yes, this matches a bunch of our other single-argument versions of binary operators. |
Can I Work on this issue? |
Sure, go for it! You'll want to make a PR that:
|
Awesome. Do you have any documentation that i can go through to understand the codebase? |
There's a section on Developer Docs in the manual: https://docs.julialang.org/en/v1/devdocs/init/. I realized that |
Given the comments in #37240, it's somewhat clear that a generic function isn't acceptable. This leads me to another thought about how to approach this (as well as #36163): do the currying during lowering. Here's the idea, apologies if I'm saying something dumb as I mostly only understand IR from IRTools.jl, not the real deal. The idea here is that I explicitly do not want a dispatch that depends on types, I just want julia> f(T) = isa(T)
f (generic function with 1 method)
julia> @code_lowered f(Int)
CodeInfo(
1 ─ %1 = (isa)(T)
└── return %1
)
julia> @code_typed f(Int)
CodeInfo(
1 ─ (isa)(T)::Union{}
└── $(Expr(:unreachable))::Union{}
) => Union{} I think that if during the name resolution (i.e. once we are sure that
with
then we'd get a curried Is this a valid line of attack? I've discussed this with @tkf, but neither of us know enough about lowering to do this ourselves. |
I think this should do the trick: diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm
index 4e75874e8a..a079874321 100644
--- a/src/julia-syntax.scm
+++ b/src/julia-syntax.scm
@@ -2201,6 +2201,9 @@
((and (eq? (identifier-name f) '^) (length= e 4) (integer? (cadddr e)))
(expand-forms
`(call (top literal_pow) ,f ,(caddr e) (call (call (core apply_type) (top Val) ,(cadddr e))))))
+ ((and (eq? f 'isa) (length= e 3))
+ (expand-forms
+ `(call (top Fix2) ,f ,(caddr e))))
(else
(map expand-forms e))))
(map expand-forms e))) If people agree this is the way to go, I can make a PR. |
Isn’t that a syntax level replacement? I think this might be better done during lowering, not parsing but I’m not sure. |
This is during lowering, but note that lowering doesn't resolve julia> dump(Meta.@lower x isa T)
Expr
head: Symbol thunk
args: Array{Any}((1,))
1: Core.CodeInfo
code: Array{Any}((2,))
1: Expr
head: Symbol call
args: Array{Any}((3,))
1: Symbol isa
2: Symbol x
3: Symbol T
2: Expr
head: Symbol return
args: Array{Any}((1,))
1: Core.SSAValue
id: Int64 1
codelocs: Array{Int32}((2,)) Int32[1, 1]
ssavaluetypes: Int64 2
ssaflags: Array{UInt8}((0,)) UInt8[]
method_for_inference_limit_heuristics: Nothing nothing
linetable: Array{Any}((1,))
1: Core.LineInfoNode
method: Symbol top-level scope
file: Symbol none
line: Int64 0
inlined_at: Int64 0
slotnames: Array{Symbol}((0,))
slotflags: Array{UInt8}((0,)) UInt8[]
slottypes: Nothing nothing
rettype: Any
parent: Nothing nothing
edges: Nothing nothing
min_world: UInt64 0x0000000000000001
max_world: UInt64 0xffffffffffffffff
inferred: Bool false
inlineable: Bool false
propagate_inbounds: Bool false
pure: Bool false |
Ah, right. I think what I should have said is maybe 'name resolution' rather than lowering? I think the problem is that we don't want someone to have a local variable or function named |
This cannot possibly be reliably done this way if you still want to keep You are just going to get inconsistent result if the user write |
Right, that's why I said
|
No that's not enough. You don't have enough information until evaluation time regarding how many arguments there are so you can't do this without having the equivalent of adding a method to |
Ah, of course. I didn't think about the possibility of things like splatting. Thank you for explaining this. |
Not even splatting. The use of the object may not be directly tracable to when it is called. e.g.
|
It would be nice to have a single argument
isa
for cleaner filtering code.This would provide some consistency with other functions, such as
isequal
, but sinceisa
is a builtin function, defining other variants doesn't seem trivial.The text was updated successfully, but these errors were encountered: