Skip to content

Commit 32ac664

Browse files
committed
refactor: remove reference stuff from read only nodes
1 parent 067734a commit 32ac664

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

src/ReadOnlyNode.jl

+5-19
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,23 @@ module ReadOnlyNodeModule
22

33
using DispatchDoctor: @unstable
44

5-
using ..NodeModule: AbstractExpressionNode, Node
5+
using ..NodeModule: AbstractExpressionNode, Node, max_degree
66
import ..NodeModule: default_allocator, with_type_parameters, constructorof, get_children
77

8-
abstract type AbstractReadOnlyNode{T,D,N<:AbstractExpressionNode{T,D},IS_REF} <:
8+
abstract type AbstractReadOnlyNode{T,D,N<:AbstractExpressionNode{T,D}} <:
99
AbstractExpressionNode{T,D} end
1010

1111
"""A type of expression node that prevents writing to the inner node"""
12-
struct ReadOnlyNode{T,D,N,IS_REF} <: AbstractReadOnlyNode{T,D,N,IS_REF}
12+
struct ReadOnlyNode{T,D,N} <: AbstractReadOnlyNode{T,D,N}
1313
_inner::N
1414

15-
function ReadOnlyNode(
16-
n::N, ::Val{IS_REF}
17-
) where {T,D,N<:AbstractExpressionNode{T,D},IS_REF}
18-
return new{T,D,N,IS_REF}(n)
19-
end
20-
function ReadOnlyNode(n::N) where {T,D,N<:AbstractExpressionNode{T,D}}
21-
return ReadOnlyNode(n, Val(false))
22-
end
23-
function ReadOnlyNode(n::AbstractReadOnlyNode)
24-
return n
25-
end
26-
function ReadOnlyNode(n::Ref{<:AbstractExpressionNode})
27-
return ReadOnlyNode(n[], Val(true))
28-
end
15+
ReadOnlyNode(n::N) where {T,N<:AbstractExpressionNode{T}} = new{T,max_degree(N),N}(n)
2916
end
3017
@inline inner(n::AbstractReadOnlyNode) = getfield(n, :_inner)
3118
@unstable constructorof(::Type{<:ReadOnlyNode}) = ReadOnlyNode
32-
Base.getindex(n::AbstractReadOnlyNode{T,D,N,true} where {T,D,N}) = n
3319
@inline function Base.getproperty(n::AbstractReadOnlyNode, s::Symbol)
3420
out = getproperty(inner(n), s)
35-
if out isa Union{AbstractExpressionNode,Ref{<:AbstractExpressionNode}}
21+
if out isa AbstractExpressionNode
3622
return ReadOnlyNode(out)
3723
else
3824
return out

0 commit comments

Comments
 (0)