getCgIdInfo :: Id -> CodeGen CgIdInfo
getCgIdInfo id = do
  localBindings <- getBindings
  case lookupVarEnv localBindings id of
    Just info -> return info
    Nothing -> do
      curMod <- getModule
      let name = idName id
      -- TODO: Change this back.
      let mod = fromMaybe (pprPanic "getCgIdInfo: no module" (ppr id)) $ nameModule_maybe name
      --let mod = fromMaybe curMod $ nameModule_maybe name
      dflags <- getDynFlags
      if mod /= curMod then return . mkCgIdInfo dflags id $ mkLFImported id
      else return . mkCgIdInfo dflags id $ mkLFImported id
      -- TODO: Change this back.
      -- crashDoc $ str "getCgIdInfo[not external name]:" <+> ppr id
getCgIdInfo :: Id -> CodeGen CgIdInfo
getCgIdInfo id = do
  localBindings <- getBindings
  case lookupVarEnv localBindings id of
    Just info -> return info
    Nothing -> do
      curMod <- getModule
      let name = idName id
      -- TODO: Change this back.
      let mod = fromMaybe (pprPanic "getCgIdInfo: no module" (ppr id)) $ nameModule_maybe name
      --let mod = fromMaybe curMod $ nameModule_maybe name
      dflags <- getDynFlags
      if mod /= curMod then return . mkCgIdInfo dflags id $ mkLFImported id
      else return . mkCgIdInfo dflags id $ mkLFImported id
      -- TODO: Change this back.
      -- crashDoc $ str "getCgIdInfo[not external name]:" <+> ppr id
getCgIdInfo id = do
  localBindings <- getBindings
  case lookupVarEnv localBindings id of
    Just info -> return info
    Nothing -> do
      curMod <- getModule
      let name = idName id
      -- TODO: Change this back.
      let mod = fromMaybe (pprPanic "getCgIdInfo: no module" (ppr id)) $ nameModule_maybe name
      --let mod = fromMaybe curMod $ nameModule_maybe name
      dflags <- getDynFlags
      if mod /= curMod then return . mkCgIdInfo dflags id $ mkLFImported id
      else return . mkCgIdInfo dflags id $ mkLFImported id
      -- TODO: Change this back.
      -- crashDoc $ str "getCgIdInfo[not external name]:" <+> ppr id