Skip to content

Commit b5285f7

Browse files
committed
fix: segfault in NodeIndex
See JuliaLang/julia#55076 for details
1 parent 3ed6b41 commit b5285f7

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/DynamicExpressions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,5 @@ end
117117
@ignore include("../test/runtests.jl")
118118

119119
include("precompile.jl")
120-
# do_precompilation(; mode=:precompile)
120+
do_precompilation(; mode=:precompile)
121121
end

src/Node.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module NodeModule
33
using DispatchDoctor: @unstable
44

55
import ..OperatorEnumModule: AbstractOperatorEnum
6-
import ..UtilsModule: @memoize_on, @with_memoize, deprecate_varmap, Undefined
6+
import ..UtilsModule: deprecate_varmap, Undefined
77

88
const DEFAULT_NODE_TYPE = Float32
99

src/NodeUtils.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,23 +143,28 @@ end
143143
## Assign index to nodes of a tree
144144
# This will mirror a Node struct, rather
145145
# than adding a new attribute to Node.
146-
struct NodeIndex{T,D} <: AbstractNode{D}
146+
mutable struct NodeIndex{T,D} <: AbstractNode{D}
147147
degree::UInt8 # 0 for constant/variable, 1 for cos/sin, 2 for +/* etc.
148148
val::T # If is a constant, this stores the actual value
149149
# ------------------- (possibly undefined below)
150150
children::NTuple{D,Base.RefValue{NodeIndex{T,D}}}
151151

152-
NodeIndex(::Type{_T}, ::Val{_D}) where {_T,_D} = new{_T,_D}(0, zero(_T))
153-
NodeIndex(::Type{_T}, ::Val{_D}, val) where {_T,_D} = new{_T,_D}(0, convert(_T, val))
152+
function NodeIndex(::Type{_T}, ::Val{_D}, val) where {_T,_D}
153+
return new{_T,_D}(
154+
0, convert(_T, val), ntuple(_ -> Ref{NodeIndex{_T,_D}}(), Val(_D))
155+
)
156+
end
154157
function NodeIndex(
155158
::Type{_T}, ::Val{_D}, children::Vararg{NodeIndex{_T,_D},_D2}
156159
) where {_T,_D,_D2}
157160
_children = ntuple(
158161
i -> i <= _D2 ? Ref(children[i]) : Ref{NodeIndex{_T,_D}}(), Val(_D)
159162
)
160-
return new{_T,_D}(1, zero(_T), _children)
163+
return new{_T,_D}(convert(UInt8, _D2), zero(_T), _children)
161164
end
162165
end
166+
NodeIndex(::Type{T}, ::Val{D}) where {T,D} = NodeIndex(T, Val(D), zero(T))
167+
163168
# Sharing is never needed for NodeIndex,
164169
# as we trace over the node we are indexing on.
165170
preserve_sharing(::Union{Type{<:NodeIndex},NodeIndex}) = false

0 commit comments

Comments
 (0)