Skip to content

Commit

Permalink
eval static parameter when binding vars
Browse files Browse the repository at this point in the history
  • Loading branch information
KDr2 committed Oct 22, 2024
1 parent 7cab324 commit 08ebc48
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/Testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
matrix:
version:
- '1.7'
- '1.10'
- '1'
- 'nightly'
os:
Expand Down
15 changes: 6 additions & 9 deletions src/tapedfunction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,10 @@ end

const IRVar = Union{Core.SSAValue, Core.SlotNumber}

function bind_var!(var_literal, bindings::Bindings, ir::Core.CodeInfo)
# for literal constants
push!(bindings, var_literal)
function bind_var!(var, bindings::Bindings, ir::Core.CodeInfo)
# for literal constants, and statuc parameter
var = Meta.isexpr(var, :static_parameter) ? ir.parent.sparam_vals[var.args[1]] : var
push!(bindings, var)
idx = length(bindings)
return idx
end
Expand Down Expand Up @@ -412,12 +413,8 @@ function translate!!(var::IRVar, line::Expr,
bindings::Bindings, isconst::Bool, ir::Core.CodeInfo)
head = line.head
_bind_fn = (x) -> bind_var!(x, bindings, ir)
# expand static parameter
_expand_sp = (x) -> begin
Meta.isexpr(x, :static_parameter) ? ir.parent.sparam_vals[x.args[1]] : x
end
if head === :new
args = map(_bind_fn _expand_sp, line.args)
args = map(_bind_fn, line.args)
return Instruction(__new__, args |> Tuple, _bind_fn(var))
elseif head === :call
# Only some of the function calls can be optimized even though many of their results are
Expand All @@ -427,7 +424,7 @@ function translate!!(var::IRVar, line::Expr,
v = ir.ssavaluetypes[var.id].val
_canbeoptimized(v) && return _const_instruction(var, v, bindings, ir)
end
args = map(_bind_fn _expand_sp, line.args)
args = map(_bind_fn, line.args)
# args[1] is the function
func = line.args[1]
if Meta.isexpr(func, :static_parameter) # func is a type parameter
Expand Down

0 comments on commit 08ebc48

Please sign in to comment.