Skip to content

Commit 297c7c7

Browse files
authored
rewrite make_zero! and remake_zero! with ntuple over fields (#2607)
1 parent 8da98df commit 297c7c7

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/typeutils/make_zero.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,13 +572,13 @@ end
572572
return nothing
573573
end
574574
push!(seen, prev)
575-
for i in 1:nf
575+
ntuple(Val(nf)) do i
576+
@inline
576577
if isdefined(prev, i)
577578
xi = getfield(prev, i)
578579
SBT = Core.Typeof(xi)
579580
activitystate = active_reg_nothrow(SBT)
580581
if activitystate == AnyState # guaranteed_const
581-
continue
582582
elseif ismutabletype(T) && !ismutabletype(SBT)
583583
yi = make_zero_immutable!(xi, seen)
584584
if Base.isconst(T, i)
@@ -593,6 +593,7 @@ end
593593
throw(ArgumentError(msg))
594594
end
595595
end
596+
return nothing
596597
end
597598
return nothing
598599
end
@@ -611,13 +612,13 @@ end
611612
return nothing
612613
end
613614
push!(seen, prev)
614-
for i in 1:nf
615+
ntuple(Val(nf)) do i
616+
@inline
615617
if isdefined(prev, i)
616618
xi = getfield(prev, i)
617619
SBT = Core.Typeof(xi)
618620
activitystate = active_reg_nothrow(SBT)
619621
if activitystate == AnyState # guaranteed_const
620-
continue
621622
elseif ismutabletype(T) && !ismutabletype(SBT)
622623
yi = make_zero_immutable!(xi, seen)
623624
if Base.isconst(T, i)
@@ -631,6 +632,7 @@ end
631632
EnzymeCore.remake_zero!(xi, seen)
632633
end
633634
end
635+
return nothing
634636
end
635637
return nothing
636638
end

0 commit comments

Comments
 (0)