class_docstr: Base effect handler class for the :func:`~pyro.contrib.funsor.to_funsor`
  and :func:`~pyro.contrib.funsor.to_data` primitives.
  Any effect handlers that invoke these primitives internally or wrap
  code that does should inherit from :class:`~NamedMessenger`.
  
  This design ensures that the global name-dim mapping is reset upon handler exit
  rather than potentially persisting until the entire program terminates.
code: def __exit__(self, *args, **kwargs):
      if self._ref_count == 1:
          if self.first_available_dim is not None:
              _DIM_STACK.set_first_available_dim(self._prev_first_dim)
          if _DIM_STACK.outermost is self:
              _DIM_STACK.outermost = None
              _DIM_STACK.set_first_available_dim(
                  _DIM_STACK.DEFAULT_FIRST_DIM
              )
              self._saved_dims |= set(
                  _DIM_STACK.global_frame.name_to_dim.items()
              )
          for name, dim in self._saved_dims:
              del _DIM_STACK.global_frame[name]
      return super().__exit__(*args, **kwargs)
  
imports: from collections import OrderedDict
  from contextlib import ExitStack
  from pyro.contrib.funsor.handlers.runtime import _DIM_STACK, DimRequest, DimType, StackFrame
  from pyro.poutine.reentrant_messenger import ReentrantMessenger
label_desc: Use image node_id 3 for calling the NamedMessenger obj's underlying member method code with example usage: obj.__exit__() and returns: super