From bb90f3c36c6746a618523df0de20441dd3517561 Mon Sep 17 00:00:00 2001 From: jumerckx <31353884+jumerckx@users.noreply.github.com> Date: Wed, 21 May 2025 22:21:35 +0200 Subject: [PATCH] allow path==nothing This seemed nice to have when using make_tracer as utility to clone objects. I don't think I actually use it already in the function call insertion, but I think there's places where I could. --- src/Tracing.jl | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/Tracing.jl b/src/Tracing.jl index e110407c05..fefc4dfb2f 100644 --- a/src/Tracing.jl +++ b/src/Tracing.jl @@ -961,6 +961,7 @@ function make_tracer( return prev end append_path(@nospecialize(path), i) = (path..., i) +append_path(::Nothing, i) = nothing Base.@nospecializeinfer function make_tracer_via_immutable_constructor( seen, @@ -1283,21 +1284,24 @@ Base.@nospecializeinfer function make_tracer( return nothing end if mode == TracedTrack - TracedUtils.set_paths!(prev, (TracedUtils.get_paths(prev)..., path)) + !isnothing(path) && + TracedUtils.set_paths!(prev, (TracedUtils.get_paths(prev)..., path)) if !haskey(seen, prev) return seen[prev] = prev end return prev end if mode == NoStopTracedTrack - TracedUtils.set_paths!(prev, (TracedUtils.get_paths(prev)..., path)) + !isnothing(path) && + TracedUtils.set_paths!(prev, (TracedUtils.get_paths(prev)..., path)) if !haskey(seen, prev) seen[prev] = prev # don't return! end return prev end if mode == TracedSetPath - TracedUtils.set_paths!(prev, (TracedUtils.get_paths(prev)..., path)) + !isnothing(path) && + TracedUtils.set_paths!(prev, (TracedUtils.get_paths(prev)..., path)) if haskey(seen, prev) return seen[prev] end @@ -1361,21 +1365,24 @@ Base.@nospecializeinfer function make_tracer( return nothing end if mode == TracedTrack - TracedUtils.set_paths!(prev, (TracedUtils.get_paths(prev)..., path)) + !isnothing(path) && + TracedUtils.set_paths!(prev, (TracedUtils.get_paths(prev)..., path)) if !haskey(seen, prev) return seen[prev] = prev end return prev end if mode == NoStopTracedTrack - TracedUtils.set_paths!(prev, (TracedUtils.get_paths(prev)..., path)) + !isnothing(path) && + TracedUtils.set_paths!(prev, (TracedUtils.get_paths(prev)..., path)) if !haskey(seen, prev) seen[prev] = prev # don't return! end return prev end if mode == TracedSetPath - TracedUtils.set_paths!(prev, (TracedUtils.get_paths(prev)..., path)) + !isnothing(path) && + TracedUtils.set_paths!(prev, (TracedUtils.get_paths(prev)..., path)) if haskey(seen, prev) return seen[prev] end @@ -1430,21 +1437,24 @@ Base.@nospecializeinfer function make_tracer( throw("Cannot have MissingTracedValue as function call argument.") end if mode == TracedTrack - TracedUtils.set_paths!(prev, (TracedUtils.get_paths(prev)..., path)) + !isnothing(path) && + TracedUtils.set_paths!(prev, (TracedUtils.get_paths(prev)..., path)) if !haskey(seen, prev) return seen[prev] = prev end return prev end if mode == NoStopTracedTrack - TracedUtils.set_paths!(prev, (TracedUtils.get_paths(prev)..., path)) + !isnothing(path) && + TracedUtils.set_paths!(prev, (TracedUtils.get_paths(prev)..., path)) if !haskey(seen, prev) seen[prev] = prev # don't return! end return prev end if mode == TracedSetPath - TracedUtils.set_paths!(prev, (TracedUtils.get_paths(prev)..., path)) + !isnothing(path) && + TracedUtils.set_paths!(prev, (TracedUtils.get_paths(prev)..., path)) haskey(seen, prev) && return seen[prev] res = MissingTracedValue((path,)) seen[res] = res