Skip to content

Commit d264e16

Browse files
committed
scopes: Unique subscopes in UnionScope
1 parent 49eea98 commit d264e16

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/scopes.jl

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,37 @@ DefaultScope() = TaintScope(AnyScope(),
2626
"Union of two or more scopes."
2727
struct UnionScope <: AbstractScope
2828
scopes::Tuple
29+
function UnionScope(scopes::Tuple)
30+
scope_set = Set{AbstractScope}()
31+
for scope in scopes
32+
if scope isa UnionScope
33+
for subscope in scope.scopes
34+
push!(scope_set, subscope)
35+
end
36+
else
37+
push!(scope_set, scope)
38+
end
39+
end
40+
return new((collect(scope_set)...,))
41+
end
2942
end
3043
UnionScope(scopes...) = UnionScope((scopes...,))
3144
UnionScope(scopes::Vector{<:AbstractScope}) = UnionScope((scopes...,))
3245
UnionScope(s::AbstractScope) = UnionScope((s,))
33-
UnionScope() = throw(ArgumentError("Cannot construct empty UnionScope"))
46+
UnionScope() = UnionScope(())
47+
48+
function Base.:(==)(us1::UnionScope, us2::UnionScope)
49+
if length(us1.scopes) != length(us2.scopes)
50+
return false
51+
end
52+
scopes = Set{AbstractScope}()
53+
for scope in us2.scopes
54+
if !(scope in us2.scopes)
55+
return false
56+
end
57+
end
58+
return true
59+
end
3460

3561
"Scoped to the same physical node."
3662
struct NodeScope <: AbstractScope

0 commit comments

Comments
 (0)