code: def populate_hash_if_needed(msg: ForwardMsg) -> str:
      """Computes and assigns the unique hash for a ForwardMsg.
  
      If the ForwardMsg already has a hash, this is a no-op.
  
      Parameters
      ----------
      msg : ForwardMsg
  
      Returns
      -------
      string
          The message's hash, returned here for convenience. (The hash
          will also be assigned to the ForwardMsg; callers do not need
          to do this.)
  
      """
      if msg.hash == "":
          # Move the message's metadata aside. It's not part of the
          # hash calculation.
          metadata = msg.metadata
          msg.ClearField("metadata")
  
          # MD5 is good enough for what we need, which is uniqueness.
          hasher = hashlib.md5(**HASHLIB_KWARGS)
          hasher.update(msg.SerializeToString())
          msg.hash = hasher.hexdigest()
  
          # Restore metadata.
          msg.metadata.CopyFrom(metadata)
  
      return msg.hash
  
imports: import hashlib
  from typing import TYPE_CHECKING, Dict, List, MutableMapping, Optional
  from weakref import WeakKeyDictionary
  from streamlit import config, util
  from streamlit.logger import get_logger
  from streamlit.proto.ForwardMsg_pb2 import ForwardMsg
  from streamlit.runtime.stats import CacheStat, CacheStatsProvider, group_stats
  from streamlit.util import HASHLIB_KWARGS
label_desc: Use image node_id 1 for calling a global function with example usage: populate_hash_if_needed(msg) and returns: msg