code: def _maybe_finalise_jaxpr(val: Any):
      is_open_jaxpr = False
      if isinstance(val, jax.core.Jaxpr):
          if len(val.constvars) == 0:
              is_open_jaxpr = True
              val = jax.core.ClosedJaxpr(val, [])
          else:
              return val
      if isinstance(val, jax.core.ClosedJaxpr):
          val = finalise_jaxpr(val)
      if is_open_jaxpr:
          val = val.jaxpr
      return val
  
imports: import functools
  from collections.abc import Callable
  from typing import Any, cast, Literal, overload, Union
  import jax
  import jax.core
  import jax.custom_derivatives
  import jax.tree_util
  from jaxtyping import PyTree
  from .._unvmap import unvmap_all_p, unvmap_any_p, unvmap_max_p
  from ..debug._announce_transform import announce_jaxpr_p
  from ._loop import maybe_set_p, select_if_vmap_p
  from ._noinline import noinline_p
  from ._nontraceable import nonbatchable_p, nondifferentiable_backward_p, nontraceable_p
label_desc: Use image node_id 2 for calling a global function with example usage: _maybe_finalise_jaxpr(val) and returns: val, val