Skip to content

Commit 758c9b3

Browse files
committed
Replace check_varargs with which(sig).isva
1 parent 053e784 commit 758c9b3

File tree

2 files changed

+2
-27
lines changed

2 files changed

+2
-27
lines changed

docs/src/internals.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Libtask.get_type
99
Libtask._typeof
1010
Libtask.replace_captures
1111
Libtask.BasicBlockCode
12-
Libtask.check_varargs
1312
Libtask.opaque_closure
1413
Libtask.misty_closure
1514
Libtask.optimise_ir!

src/copyable_task.jl

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,31 +63,6 @@ function callable_ret_type(sig, produce_types)
6363
return Union{Base.code_ircode_by_type(sig)[1][2],produce_type}
6464
end
6565

66-
"""
67-
check_varargs(sig, ir)
68-
69-
For a call signature `sig` and the IR code for it, check whether this is a Varargs call.
70-
71-
The need for this arises because the output of `Base.code_ircode_by_type` does not
72-
distinguish between varargs and tuples, see https://github.com/JuliaLang/julia/issues/58753. Thus we have to go back to the signature that created the IR to check. There are two cases
73-
that signal that this is indeed a varargs call:
74-
1. The last argument in `sig` is a `Vararg` object.
75-
2. The last argument of `ir` is a `Tuple` of the types of the last arguments of `sig`. For
76-
instance `sig` may end in `Symbol, Tuple{Int, Int}` and the last argument of `ir` would be
77-
`Tuple{Symbol, Tuple{Int, Int}}`.
78-
79-
That there are these two cases, and only these two cases, is not based on a good
80-
understanding of anything, but rather on observing which cases arise in our test suite. This solution is thus a hack and should be rewritten by someone who actually understands how IR
81-
handles `Varargs`.
82-
"""
83-
function check_varargs(sig, ir)
84-
sig.parameters[end] isa Core.TypeofVararg && return true
85-
(ir.argtypes[end] isa Type && ir.argtypes[end] <: Tuple) || return false
86-
ir_last_arg_types = ir.argtypes[end].parameters
87-
sig_last_arg_types = sig.parameters[(end - length(ir_last_arg_types) + 1):end]
88-
return sig_last_arg_types == ir_last_arg_types
89-
end
90-
9166
"""
9267
build_callable(sig::Type{<:Tuple})
9368
@@ -109,7 +84,8 @@ function build_callable(sig::Type{<:Tuple})
10984
return fresh_copy(mc_cache[key])
11085
else
11186
ir = Base.code_ircode_by_type(sig)[1][1]
112-
isva = check_varargs(sig, ir)
87+
# Check whether this is a varargs call.
88+
isva = which(sig).isva
11389
bb, refs, types = derive_copyable_task_ir(BBCode(ir))
11490
unoptimised_ir = IRCode(bb)
11591
optimised_ir = optimise_ir!(unoptimised_ir)

0 commit comments

Comments
 (0)