@@ -13,10 +13,12 @@ using ..NodeModule:
1313 default_allocator,
1414 with_type_parameters,
1515 leaf_copy,
16+ leaf_copy!,
1617 leaf_convert,
1718 leaf_hash,
1819 leaf_equal,
1920 branch_copy,
21+ branch_copy!,
2022 branch_convert,
2123 branch_hash,
2224 branch_equal,
@@ -262,6 +264,12 @@ function _check_leaf_copy(tree::AbstractExpressionNode)
262264 tree. degree != 0 && return true
263265 return leaf_copy (tree) isa typeof (tree)
264266end
267+ function _check_leaf_copy! (tree:: AbstractExpressionNode{T} ) where {T}
268+ tree. degree != 0 && return true
269+ new_leaf = constructorof (typeof (tree))(; val= zero (T))
270+ ret = leaf_copy! (new_leaf, tree)
271+ return new_leaf == tree && ret === new_leaf
272+ end
265273function _check_leaf_convert (tree:: AbstractExpressionNode )
266274 tree. degree != 0 && return true
267275 return leaf_convert (typeof (tree), tree) isa typeof (tree) &&
@@ -284,6 +292,19 @@ function _check_branch_copy(tree::AbstractExpressionNode)
284292 return branch_copy (tree, tree. l, tree. r) isa typeof (tree)
285293 end
286294end
295+ function _check_branch_copy! (tree:: AbstractExpressionNode{T} ) where {T}
296+ if tree. degree == 0
297+ return true
298+ end
299+ new_branch = constructorof (typeof (tree))(; val= zero (T))
300+ if tree. degree == 1
301+ ret = branch_copy! (new_branch, tree, copy (tree. l))
302+ return new_branch == tree && ret === new_branch
303+ else
304+ ret = branch_copy! (new_branch, tree, copy (tree. l), copy (tree. r))
305+ return new_branch == tree && ret === new_branch
306+ end
307+ end
287308function _check_branch_convert (tree:: AbstractExpressionNode )
288309 if tree. degree == 0
289310 return true
@@ -352,10 +373,12 @@ ni_components = (
352373 ),
353374 optional = (
354375 leaf_copy = " copies a leaf node" => _check_leaf_copy,
376+ leaf_copy! = " copies a leaf node in-place" => _check_leaf_copy!,
355377 leaf_convert = " converts a leaf node" => _check_leaf_convert,
356378 leaf_hash = " computes the hash of a leaf node" => _check_leaf_hash,
357379 leaf_equal = " checks equality of two leaf nodes" => _check_leaf_equal,
358380 branch_copy = " copies a branch node" => _check_branch_copy,
381+ branch_copy! = " copies a branch node in-place" => _check_branch_copy!,
359382 branch_convert = " converts a branch node" => _check_branch_convert,
360383 branch_hash = " computes the hash of a branch node" => _check_branch_hash,
361384 branch_equal = " checks equality of two branch nodes" => _check_branch_equal,
@@ -396,7 +419,7 @@ ni_description = (
396419 [Arguments ()]
397420)
398421@implements (
399- NodeInterface{all_ni_methods_except (())},
422+ NodeInterface{all_ni_methods_except ((:leaf_copy! , :branch_copy! ))},
400423 GraphNode,
401424 [Arguments ()]
402425)
0 commit comments