File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -116,6 +116,15 @@ nestedsum(ls::Int) = ls
116
116
nestedsum (ls:: Val ) = ls
117
117
nestedsum (ls:: Tuple ) = sum (_val ∘ nestedsum, ls)
118
118
119
+ # to_nested_shape() definition uses both @eval and @generated
120
+ #
121
+ # @eval is needed because the code for different recursion depths should be different for inference,
122
+ # not the same method with different parameters.
123
+ #
124
+ # @generated is used to unpack target lengths from the second argument at compile time to make to_nested_shape() as cheap as possible.
125
+ #
126
+ # Note: to_nested_shape() only operates on plain Julia types and won't be affected by user lens definition, unlike setall for example.
127
+ # That's why it's safe to make it @generated.
119
128
to_nested_shape (vs, :: Val{LS} , :: Val{1} ) where {LS} = (@assert length (vs) == _val (LS); vs)
120
129
for i in 2 : 10
121
130
@eval @generated function to_nested_shape (vs, ls:: Val{LS} , :: Val{$i} ) where {LS}
You can’t perform that action at this time.
0 commit comments