LCOV - code coverage report
Current view: top level - gcc/rust/util - rust-hir-map.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 80.7 % 725 585
Test Date: 2026-08-22 16:33:35 Functions: 83.7 % 141 118
Legend: Lines:     hit not hit

            Line data    Source code
       1              : // Copyright (C) 2020-2026 Free Software Foundation, Inc.
       2              : 
       3              : // This file is part of GCC.
       4              : 
       5              : // GCC is free software; you can redistribute it and/or modify it under
       6              : // the terms of the GNU General Public License as published by the Free
       7              : // Software Foundation; either version 3, or (at your option) any later
       8              : // version.
       9              : 
      10              : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      11              : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12              : // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      13              : // for more details.
      14              : 
      15              : // You should have received a copy of the GNU General Public License
      16              : // along with GCC; see the file COPYING3.  If not see
      17              : // <http://www.gnu.org/licenses/>.
      18              : 
      19              : #include "rust-hir-map.h"
      20              : #include "optional.h"
      21              : #include "rust-ast-full.h"
      22              : #include "rust-ast.h"
      23              : #include "rust-diagnostics.h"
      24              : #include "rust-hir-full.h"
      25              : #include "rust-item.h"
      26              : #include "rust-macro-builtins.h"
      27              : #include "rust-mapping-common.h"
      28              : #include "rust-attribute-values.h"
      29              : 
      30              : namespace Rust {
      31              : namespace Analysis {
      32              : 
      33              : NodeMapping
      34        48182 : NodeMapping::get_error ()
      35              : {
      36        48182 :   return NodeMapping (UNKNOWN_CRATENUM, UNKNOWN_NODEID, UNKNOWN_HIRID,
      37        48182 :                       UNKNOWN_LOCAL_DEFID);
      38              : }
      39              : 
      40              : CrateNum
      41      1917151 : NodeMapping::get_crate_num () const
      42              : {
      43      1917151 :   return crateNum;
      44              : }
      45              : 
      46              : NodeId
      47      4147875 : NodeMapping::get_nodeid () const
      48              : {
      49      4147875 :   return nodeId;
      50              : }
      51              : 
      52              : HirId
      53      5486068 : NodeMapping::get_hirid () const
      54              : {
      55      5486068 :   return hirId;
      56              : }
      57              : 
      58              : LocalDefId
      59      1912734 : NodeMapping::get_local_defid () const
      60              : {
      61      1912734 :   return localDefId;
      62              : }
      63              : 
      64              : DefId
      65      1908085 : NodeMapping::get_defid () const
      66              : {
      67      1908085 :   return get_defid (get_crate_num (), get_local_defid ());
      68              : }
      69              : 
      70              : DefId
      71      1908085 : NodeMapping::get_defid (CrateNum crate_num, LocalDefId local_defid)
      72              : {
      73      1908085 :   return DefId{crate_num, local_defid};
      74              : }
      75              : 
      76              : std::string
      77         1187 : NodeMapping::as_string () const
      78              : {
      79         1187 :   std::ostringstream ss;
      80         1187 :   ss << "["
      81         1187 :      << "C: " << get_crate_num ();
      82         1187 :   if (get_nodeid () != UNKNOWN_NODEID)
      83         1187 :     ss << " Nid: " << get_nodeid ();
      84              : 
      85         1187 :   if (get_hirid () != UNKNOWN_HIRID)
      86         1187 :     ss << " Hid: " << get_hirid ();
      87              : 
      88         1187 :   if (get_local_defid () != UNKNOWN_LOCAL_DEFID)
      89         1187 :     ss << " Lid: " << get_local_defid ();
      90              : 
      91         1187 :   ss << "]";
      92         1187 :   return ss.str ();
      93         1187 : }
      94              : 
      95              : // Mappings Class now
      96              : static const HirId kDefaultNodeIdBegin = 1;
      97              : static const HirId kDefaultHirIdBegin = 1;
      98              : static const HirId kDefaultCrateNumBegin = 0;
      99              : 
     100         4984 : Mappings::Mappings ()
     101         4984 :   : crateNumItr (kDefaultCrateNumBegin), currentCrateNum (UNKNOWN_CRATENUM),
     102         4984 :     hirIdIter (kDefaultHirIdBegin), nodeIdIter (kDefaultNodeIdBegin)
     103              : {
     104         4984 :   Analysis::NodeMapping node (0, 0, 0, 0);
     105         4984 :   builtinMarker
     106         9968 :     = new HIR::ImplBlock (node, {}, {}, nullptr, nullptr, HIR::WhereClause ({}),
     107              :                           BoundPolarity::RegularBound,
     108         9968 :                           HIR::Visibility (HIR::Visibility::VisType::Public),
     109         9968 :                           {}, {}, UNDEF_LOCATION);
     110         4984 : }
     111              : 
     112         9968 : Mappings::~Mappings () { delete builtinMarker; }
     113              : 
     114              : Mappings &
     115    121935434 : Mappings::get ()
     116              : {
     117    121940418 :   static Mappings instance{};
     118    121935434 :   return instance;
     119              : }
     120              : 
     121              : CrateNum
     122         4894 : Mappings::get_next_crate_num (const std::string &name)
     123              : {
     124         4894 :   auto id = crateNumItr;
     125         4894 :   crateNumItr++;
     126         4894 :   set_crate_name (id, name);
     127         4894 :   return id;
     128              : }
     129              : 
     130              : void
     131         4966 : Mappings::set_current_crate (CrateNum crateNum)
     132              : {
     133         4966 :   currentCrateNum = crateNum;
     134         4966 : }
     135              : 
     136              : CrateNum
     137       903228 : Mappings::get_current_crate () const
     138              : {
     139       903228 :   return currentCrateNum;
     140              : }
     141              : 
     142              : tl::optional<const std::string &>
     143        44957 : Mappings::get_crate_name (CrateNum crate_num) const
     144              : {
     145        44957 :   auto it = crate_names.find (crate_num);
     146        44957 :   if (it == crate_names.end ())
     147            0 :     return tl::nullopt;
     148              : 
     149        44957 :   return it->second;
     150              : }
     151              : 
     152              : tl::optional<CrateNum>
     153        94173 : Mappings::lookup_crate_num (NodeId node_id) const
     154              : {
     155        94173 :   auto it = crate_node_to_crate_num.find (node_id);
     156        94173 :   if (it == crate_node_to_crate_num.end ())
     157        48070 :     return tl::nullopt;
     158              : 
     159        46103 :   return it->second;
     160              : }
     161              : 
     162              : void
     163         4894 : Mappings::set_crate_name (CrateNum crate_num, const std::string &name)
     164              : {
     165         4894 :   crate_names[crate_num] = name;
     166         4894 : }
     167              : 
     168              : const std::string &
     169        12945 : Mappings::get_current_crate_name () const
     170              : {
     171        12945 :   return get_crate_name (get_current_crate ()).value ();
     172              : }
     173              : 
     174              : tl::optional<CrateNum>
     175          328 : Mappings::lookup_crate_name (const std::string &crate_name) const
     176              : {
     177          656 :   for (const auto &it : crate_names)
     178              :     {
     179          616 :       if (it.second.compare (crate_name) == 0)
     180          288 :         return it.first;
     181              :     }
     182           40 :   return tl::nullopt;
     183              : }
     184              : 
     185              : tl::optional<NodeId>
     186        19524 : Mappings::crate_num_to_nodeid (const CrateNum &crate_num) const
     187              : {
     188        19524 :   auto it = ast_crate_mappings.find (crate_num);
     189        19524 :   if (it == ast_crate_mappings.end ())
     190            0 :     return tl::nullopt;
     191              : 
     192        19524 :   return it->second->get_node_id ();
     193              : }
     194              : 
     195              : bool
     196        52963 : Mappings::node_is_crate (NodeId node_id) const
     197              : {
     198        52963 :   return lookup_crate_num (node_id).has_value ();
     199              : }
     200              : 
     201              : NodeId
     202      6682901 : Mappings::get_next_node_id ()
     203              : {
     204      6682901 :   auto it = nodeIdIter;
     205      6682901 :   if (UNLIKELY (it > MAX_NODEID))
     206            0 :     rust_fatal_error (UNKNOWN_LOCATION, "out of node ids");
     207      6682901 :   nodeIdIter++;
     208      6682901 :   return it;
     209              : }
     210              : 
     211              : HirId
     212       850748 : Mappings::get_next_hir_id (CrateNum crateNum)
     213              : {
     214       850748 :   auto id = hirIdIter;
     215       850748 :   hirIdIter++;
     216              : 
     217       850748 :   auto it = hirNodesWithinCrate.find (crateNum);
     218       850748 :   if (it == hirNodesWithinCrate.end ())
     219              :     {
     220         4869 :       hirNodesWithinCrate.insert ({crateNum, {}});
     221              :     }
     222              : 
     223       850748 :   hirNodesWithinCrate[crateNum].insert (id);
     224       850748 :   return id;
     225              : }
     226              : 
     227              : LocalDefId
     228       132260 : Mappings::get_next_localdef_id (CrateNum crateNum)
     229              : {
     230       132260 :   auto it = localIdIter.find (crateNum);
     231       132260 :   if (it == localIdIter.end ())
     232              :     {
     233         4623 :       localIdIter.insert ({crateNum, 1});
     234              :     }
     235              : 
     236       132260 :   it = localIdIter.find (crateNum);
     237       132260 :   rust_assert (it != localIdIter.end ());
     238              : 
     239       132260 :   LocalDefId id = it->second;
     240       132260 :   localIdIter[crateNum] = id + 1;
     241       132260 :   return id;
     242              : }
     243              : 
     244              : AST::Crate &
     245         9175 : Mappings::get_ast_crate (CrateNum crateNum)
     246              : {
     247         9175 :   auto it = ast_crate_mappings.find (crateNum);
     248         9175 :   rust_assert (it != ast_crate_mappings.end ());
     249         9175 :   return *it->second;
     250              : }
     251              : 
     252              : AST::Crate &
     253            0 : Mappings::get_ast_crate_by_node_id (NodeId id)
     254              : {
     255            0 :   return *get_ast_crate_by_node_id_raw (id);
     256              : }
     257              : 
     258              : AST::Crate *
     259         4869 : Mappings::get_ast_crate_by_node_id_raw (NodeId id)
     260              : {
     261         4869 :   auto i = crate_node_to_crate_num.find (id);
     262         4869 :   rust_assert (i != crate_node_to_crate_num.end ());
     263              : 
     264         4869 :   CrateNum crateNum = i->second;
     265         4869 :   auto it = ast_crate_mappings.find (crateNum);
     266         4869 :   rust_assert (it != ast_crate_mappings.end ());
     267         4869 :   return it->second;
     268              : }
     269              : 
     270              : AST::Crate &
     271         4894 : Mappings::insert_ast_crate (std::unique_ptr<AST::Crate> &&crate,
     272              :                             CrateNum crate_num)
     273              : {
     274         4894 :   auto it = ast_crate_mappings.find (crate_num);
     275         4894 :   rust_assert (it == ast_crate_mappings.end ());
     276              : 
     277              :   // store it
     278         4894 :   crate_node_to_crate_num.insert ({crate->get_node_id (), crate_num});
     279         4894 :   ast_crate_mappings.insert ({crate_num, crate.release ()});
     280              : 
     281              :   // return the reference to it
     282         4894 :   it = ast_crate_mappings.find (crate_num);
     283         4894 :   rust_assert (it != ast_crate_mappings.end ());
     284         4894 :   return *it->second;
     285              : }
     286              : 
     287              : HIR::Crate &
     288            0 : Mappings::get_hir_crate (CrateNum crateNum)
     289              : {
     290            0 :   auto it = hir_crate_mappings.find (crateNum);
     291            0 :   rust_assert (it != hir_crate_mappings.end ());
     292            0 :   return *it->second;
     293              : }
     294              : 
     295              : bool
     296       106950 : Mappings::is_local_hirid_crate (HirId crateNum)
     297              : {
     298       212873 :   for (const auto &it : hir_crate_mappings)
     299              :     {
     300       107166 :       const auto &crate = it.second;
     301       107166 :       if (crate->get_mappings ().get_hirid () == crateNum)
     302       106950 :         return true;
     303              :     }
     304              :   return false;
     305              : }
     306              : 
     307              : HIR::Crate &
     308         4638 : Mappings::insert_hir_crate (std::unique_ptr<HIR::Crate> &&crate)
     309              : {
     310         4638 :   CrateNum crateNum = crate->get_mappings ().get_crate_num ();
     311         4638 :   auto it = hir_crate_mappings.find (crateNum);
     312         4638 :   rust_assert (it == hir_crate_mappings.end ());
     313              : 
     314         4638 :   insert_node_to_hir (crate->get_mappings ().get_nodeid (),
     315         4638 :                       crate->get_mappings ().get_hirid ());
     316         4638 :   hir_crate_mappings.insert ({crateNum, crate.release ()});
     317              : 
     318         4638 :   it = hir_crate_mappings.find (crateNum);
     319         4638 :   rust_assert (it != hir_crate_mappings.end ());
     320         4638 :   return *it->second;
     321              : }
     322              : 
     323              : void
     324        32570 : Mappings::insert_defid_mapping (DefId id, HIR::Item *item)
     325              : {
     326        32570 :   CrateNum crate_num = id.crateNum;
     327        32570 :   LocalDefId local_def_id = id.localDefId;
     328              : 
     329        32570 :   rust_assert (!lookup_defid (id));
     330        32570 :   rust_assert (!lookup_local_defid (crate_num, local_def_id));
     331        32570 :   rust_assert (!lookup_trait_item_defid (id));
     332              : 
     333        32570 :   defIdMappings[id] = item;
     334        32570 :   insert_local_defid_mapping (crate_num, local_def_id, item);
     335        32570 : }
     336              : 
     337              : tl::optional<HIR::Item *>
     338       132683 : Mappings::lookup_defid (DefId id)
     339              : {
     340       132683 :   auto it = defIdMappings.find (id);
     341       132683 :   if (it == defIdMappings.end ())
     342        36872 :     return tl::nullopt;
     343              : 
     344        95811 :   return it->second;
     345              : }
     346              : 
     347              : void
     348         3375 : Mappings::insert_defid_mapping (DefId id, HIR::TraitItem *item)
     349              : {
     350         3375 :   CrateNum crate_num = id.crateNum;
     351         3375 :   LocalDefId local_def_id = id.localDefId;
     352              : 
     353         3375 :   rust_assert (!lookup_defid (id));
     354         3375 :   rust_assert (!lookup_local_defid (crate_num, local_def_id));
     355         3375 :   rust_assert (!lookup_trait_item_defid (id));
     356              : 
     357         3375 :   defIdTraitItemMappings[id] = item;
     358         3375 : }
     359              : 
     360              : tl::optional<HIR::TraitItem *>
     361        38694 : Mappings::lookup_trait_item_defid (DefId id)
     362              : {
     363        38694 :   auto it = defIdTraitItemMappings.find (id);
     364        38694 :   if (it == defIdTraitItemMappings.end ())
     365        37699 :     return tl::nullopt;
     366              : 
     367          995 :   return it->second;
     368              : }
     369              : 
     370              : void
     371        23093 : Mappings::insert_hir_item (HIR::Item *item)
     372              : {
     373        23093 :   auto id = item->get_mappings ().get_hirid ();
     374        23093 :   rust_assert (!lookup_hir_item (id).has_value ());
     375              : 
     376        23093 :   hirItemMappings[id] = item;
     377        23093 :   insert_node_to_hir (item->get_mappings ().get_nodeid (), id);
     378        23093 : }
     379              : 
     380              : tl::optional<HIR::Item *>
     381      2925835 : Mappings::lookup_hir_item (HirId id)
     382              : {
     383      2925835 :   auto it = hirItemMappings.find (id);
     384      2925835 :   if (it == hirItemMappings.end ())
     385       132823 :     return tl::nullopt;
     386      2793012 :   return it->second;
     387              : }
     388              : 
     389              : void
     390         1264 : Mappings::insert_hir_enumitem (HIR::Enum *parent, HIR::EnumItem *item)
     391              : {
     392         1264 :   auto id = item->get_mappings ().get_hirid ();
     393         1264 :   auto result = lookup_hir_enumitem (id);
     394         1264 :   rust_assert (result.first == nullptr);
     395              : 
     396         1264 :   hirEnumItemMappings[id] = {parent, item};
     397         1264 :   insert_node_to_hir (item->get_mappings ().get_nodeid (), id);
     398         1264 : }
     399              : 
     400              : std::pair<HIR::Enum *, HIR::EnumItem *>
     401        67187 : Mappings::lookup_hir_enumitem (HirId id)
     402              : {
     403        67187 :   auto it = hirEnumItemMappings.find (id);
     404        67187 :   if (it == hirEnumItemMappings.end ())
     405        58578 :     return {nullptr, nullptr};
     406              : 
     407         8609 :   return it->second;
     408              : }
     409              : 
     410              : void
     411         3375 : Mappings::insert_hir_trait_item (HIR::TraitItem *item)
     412              : {
     413         3375 :   auto id = item->get_mappings ().get_hirid ();
     414         3375 :   rust_assert (!lookup_hir_trait_item (id).has_value ());
     415              : 
     416         3375 :   hirTraitItemMappings[id] = item;
     417         3375 :   insert_node_to_hir (item->get_mappings ().get_nodeid (), id);
     418         3375 : }
     419              : 
     420              : tl::optional<HIR::TraitItem *>
     421         3679 : Mappings::lookup_hir_trait_item (HirId id)
     422              : {
     423         3679 :   auto it = hirTraitItemMappings.find (id);
     424         3679 :   if (it == hirTraitItemMappings.end ())
     425         3433 :     return tl::nullopt;
     426              : 
     427          246 :   return it->second;
     428              : }
     429              : 
     430              : void
     431         1674 : Mappings::insert_hir_extern_block (HIR::ExternBlock *block)
     432              : {
     433         1674 :   auto id = block->get_mappings ().get_hirid ();
     434         1674 :   rust_assert (!lookup_hir_extern_block (id).has_value ());
     435              : 
     436         1674 :   hirExternBlockMappings[id] = block;
     437         1674 :   insert_node_to_hir (block->get_mappings ().get_nodeid (), id);
     438         1674 : }
     439              : 
     440              : tl::optional<HIR::ExternBlock *>
     441         2778 : Mappings::lookup_hir_extern_block (HirId id)
     442              : {
     443         2778 :   auto it = hirExternBlockMappings.find (id);
     444         2778 :   if (it == hirExternBlockMappings.end ())
     445         1674 :     return tl::nullopt;
     446              : 
     447         1104 :   return it->second;
     448              : }
     449              : 
     450              : void
     451         2566 : Mappings::insert_hir_extern_item (HIR::ExternalItem *item, HirId parent_block)
     452              : {
     453         2566 :   auto id = item->get_mappings ().get_hirid ();
     454         2566 :   rust_assert (!lookup_hir_extern_item (id));
     455              : 
     456         2566 :   hirExternItemMappings[id] = {item, parent_block};
     457         2566 :   insert_node_to_hir (item->get_mappings ().get_nodeid (), id);
     458         2566 : }
     459              : 
     460              : tl::optional<std::pair<HIR::ExternalItem *, HirId>>
     461        33777 : Mappings::lookup_hir_extern_item (HirId id)
     462              : {
     463        33777 :   auto it = hirExternItemMappings.find (id);
     464        33777 :   if (it == hirExternItemMappings.end ())
     465        32096 :     return tl::nullopt;
     466              : 
     467         1681 :   return it->second;
     468              : }
     469              : 
     470              : void
     471         5719 : Mappings::insert_hir_impl_block (HIR::ImplBlock *item)
     472              : {
     473         5719 :   auto id = item->get_mappings ().get_hirid ();
     474         5719 :   rust_assert (!lookup_hir_impl_block (id));
     475              : 
     476         5719 :   HirId impl_type_id = item->get_type ().get_mappings ().get_hirid ();
     477         5719 :   hirImplBlockMappings[id] = item;
     478         5719 :   hirImplBlockTypeMappings[impl_type_id] = item;
     479         5719 :   insert_node_to_hir (item->get_mappings ().get_nodeid (), id);
     480         5719 : }
     481              : 
     482              : tl::optional<HIR::ImplBlock *>
     483         8710 : Mappings::lookup_hir_impl_block (HirId id)
     484              : {
     485         8710 :   auto it = hirImplBlockMappings.find (id);
     486         8710 :   if (it == hirImplBlockMappings.end ())
     487         5719 :     return tl::nullopt;
     488              : 
     489         2991 :   return it->second;
     490              : }
     491              : 
     492              : tl::optional<HIR::ImplBlock *>
     493         2672 : Mappings::lookup_impl_block_type (HirId id)
     494              : {
     495         2672 :   auto it = hirImplBlockTypeMappings.find (id);
     496         2672 :   if (it == hirImplBlockTypeMappings.end ())
     497           53 :     return tl::nullopt;
     498              : 
     499         2619 :   return it->second;
     500              : }
     501              : 
     502              : void
     503         1188 : Mappings::insert_module (HIR::Module *module)
     504              : {
     505         1188 :   auto id = module->get_mappings ().get_hirid ();
     506         1188 :   rust_assert (!lookup_module (id));
     507              : 
     508         1188 :   hirModuleMappings[id] = module;
     509         1188 :   insert_node_to_hir (module->get_mappings ().get_nodeid (), id);
     510         1188 : }
     511              : 
     512              : tl::optional<HIR::Module *>
     513       108146 : Mappings::lookup_module (HirId id)
     514              : {
     515       108146 :   auto it = hirModuleMappings.find (id);
     516       108146 :   if (it == hirModuleMappings.end ())
     517       105316 :     return tl::nullopt;
     518              : 
     519         2830 :   return it->second;
     520              : }
     521              : 
     522              : void
     523         8213 : Mappings::insert_hir_implitem (HirId parent_impl_id, HIR::ImplItem *item)
     524              : {
     525         8213 :   auto id = item->get_impl_mappings ().get_hirid ();
     526         8213 :   rust_assert (!lookup_hir_implitem (id));
     527              : 
     528         8213 :   hirImplItemMappings[id]
     529         8213 :     = std::pair<HirId, HIR::ImplItem *> (parent_impl_id, item);
     530         8213 :   insert_node_to_hir (item->get_impl_mappings ().get_nodeid (), id);
     531         8213 : }
     532              : 
     533              : tl::optional<std::pair<HIR::ImplItem *, HirId>>
     534       102685 : Mappings::lookup_hir_implitem (HirId id)
     535              : {
     536       102685 :   auto it = hirImplItemMappings.find (id);
     537       102685 :   if (it == hirImplItemMappings.end ())
     538        81400 :     return tl::nullopt;
     539              : 
     540        21285 :   return std::make_pair (it->second.second, it->second.first);
     541              : }
     542              : 
     543              : void
     544       157889 : Mappings::insert_hir_expr (HIR::Expr *expr)
     545              : {
     546       157889 :   auto id = expr->get_mappings ().get_hirid ();
     547       157889 :   hirExprMappings[id] = expr;
     548              : 
     549       157889 :   insert_node_to_hir (expr->get_mappings ().get_nodeid (), id);
     550       157889 :   insert_location (id, expr->get_locus ());
     551       157889 : }
     552              : 
     553              : tl::optional<HIR::Expr *>
     554           26 : Mappings::lookup_hir_expr (HirId id)
     555              : {
     556           26 :   auto it = hirExprMappings.find (id);
     557           26 :   if (it == hirExprMappings.end ())
     558           25 :     return tl::nullopt;
     559              : 
     560            1 :   return it->second;
     561              : }
     562              : 
     563              : void
     564        35222 : Mappings::insert_hir_path_expr_seg (HIR::PathExprSegment *expr)
     565              : {
     566        35222 :   auto id = expr->get_mappings ().get_hirid ();
     567        35222 :   rust_assert (!lookup_hir_path_expr_seg (id));
     568              : 
     569        35222 :   hirPathSegMappings[id] = expr;
     570        35222 :   insert_node_to_hir (expr->get_mappings ().get_nodeid (), id);
     571        35222 :   insert_location (id, expr->get_locus ());
     572        35222 : }
     573              : 
     574              : tl::optional<HIR::PathExprSegment *>
     575        35222 : Mappings::lookup_hir_path_expr_seg (HirId id)
     576              : {
     577        35222 :   auto it = hirPathSegMappings.find (id);
     578        35222 :   if (it == hirPathSegMappings.end ())
     579        35222 :     return tl::nullopt;
     580              : 
     581            0 :   return it->second;
     582              : }
     583              : 
     584              : void
     585         8884 : Mappings::insert_hir_generic_param (HIR::GenericParam *param)
     586              : {
     587         8884 :   auto id = param->get_mappings ().get_hirid ();
     588         8884 :   rust_assert (!lookup_hir_generic_param (id));
     589              : 
     590         8884 :   hirGenericParamMappings[id] = param;
     591         8884 :   insert_node_to_hir (param->get_mappings ().get_nodeid (), id);
     592         8884 :   insert_location (id, param->get_locus ());
     593         8884 : }
     594              : 
     595              : tl::optional<HIR::GenericParam *>
     596         8884 : Mappings::lookup_hir_generic_param (HirId id)
     597              : {
     598         8884 :   auto it = hirGenericParamMappings.find (id);
     599         8884 :   if (it == hirGenericParamMappings.end ())
     600         8884 :     return tl::nullopt;
     601              : 
     602            0 :   return it->second;
     603              : }
     604              : 
     605              : void
     606        62286 : Mappings::insert_hir_type (HIR::Type *type)
     607              : {
     608        62286 :   auto id = type->get_mappings ().get_hirid ();
     609        62286 :   rust_assert (!lookup_hir_type (id));
     610              : 
     611        62286 :   hirTypeMappings[id] = type;
     612        62286 :   insert_node_to_hir (type->get_mappings ().get_nodeid (), id);
     613        62286 : }
     614              : 
     615              : tl::optional<HIR::Type *>
     616        62286 : Mappings::lookup_hir_type (HirId id)
     617              : {
     618        62286 :   auto it = hirTypeMappings.find (id);
     619        62286 :   if (it == hirTypeMappings.end ())
     620        62286 :     return tl::nullopt;
     621              : 
     622            0 :   return it->second;
     623              : }
     624              : 
     625              : void
     626        24538 : Mappings::insert_hir_stmt (HIR::Stmt *stmt)
     627              : {
     628        24538 :   auto id = stmt->get_mappings ().get_hirid ();
     629        24538 :   rust_assert (!lookup_hir_stmt (id));
     630              : 
     631        24538 :   hirStmtMappings[id] = stmt;
     632        24538 :   insert_node_to_hir (stmt->get_mappings ().get_nodeid (), id);
     633        24538 : }
     634              : 
     635              : tl::optional<HIR::Stmt *>
     636        24538 : Mappings::lookup_hir_stmt (HirId id)
     637              : {
     638        24538 :   auto it = hirStmtMappings.find (id);
     639        24538 :   if (it == hirStmtMappings.end ())
     640        24538 :     return tl::nullopt;
     641              : 
     642            0 :   return it->second;
     643              : }
     644              : 
     645              : void
     646         8069 : Mappings::insert_hir_param (HIR::FunctionParam *param)
     647              : {
     648         8069 :   auto id = param->get_mappings ().get_hirid ();
     649         8069 :   rust_assert (!lookup_hir_param (id));
     650              : 
     651         8069 :   hirParamMappings[id] = param;
     652         8069 :   insert_node_to_hir (param->get_mappings ().get_nodeid (), id);
     653         8069 : }
     654              : 
     655              : tl::optional<HIR::FunctionParam *>
     656         8069 : Mappings::lookup_hir_param (HirId id)
     657              : {
     658         8069 :   auto it = hirParamMappings.find (id);
     659         8069 :   if (it == hirParamMappings.end ())
     660         8069 :     return tl::nullopt;
     661              : 
     662            0 :   return it->second;
     663              : }
     664              : 
     665              : void
     666         8106 : Mappings::insert_hir_self_param (HIR::SelfParam *param)
     667              : {
     668         8106 :   auto id = param->get_mappings ().get_hirid ();
     669         8106 :   rust_assert (!lookup_hir_self_param (id));
     670              : 
     671         8106 :   hirSelfParamMappings[id] = param;
     672         8106 :   insert_node_to_hir (param->get_mappings ().get_nodeid (), id);
     673         8106 : }
     674              : 
     675              : tl::optional<HIR::SelfParam *>
     676         8106 : Mappings::lookup_hir_self_param (HirId id)
     677              : {
     678         8106 :   auto it = hirSelfParamMappings.find (id);
     679         8106 :   if (it == hirSelfParamMappings.end ())
     680         8106 :     return tl::nullopt;
     681              : 
     682            0 :   return it->second;
     683              : }
     684              : 
     685              : void
     686         2361 : Mappings::insert_hir_struct_field (HIR::StructExprField *field)
     687              : {
     688         2361 :   auto id = field->get_mappings ().get_hirid ();
     689         2361 :   rust_assert (!lookup_hir_struct_field (id));
     690              : 
     691         2361 :   hirStructFieldMappings[id] = field;
     692         2361 :   insert_node_to_hir (field->get_mappings ().get_nodeid (), id);
     693         2361 : }
     694              : 
     695              : tl::optional<HIR::StructExprField *>
     696         2361 : Mappings::lookup_hir_struct_field (HirId id)
     697              : {
     698         2361 :   auto it = hirStructFieldMappings.find (id);
     699         2361 :   if (it == hirStructFieldMappings.end ())
     700         2361 :     return tl::nullopt;
     701              : 
     702            0 :   return it->second;
     703              : }
     704              : 
     705              : void
     706        26626 : Mappings::insert_hir_pattern (HIR::Pattern *pattern)
     707              : {
     708        26626 :   auto id = pattern->get_mappings ().get_hirid ();
     709        26626 :   rust_assert (!lookup_hir_pattern (id));
     710              : 
     711        26626 :   hirPatternMappings[id] = pattern;
     712        26626 :   insert_node_to_hir (pattern->get_mappings ().get_nodeid (), id);
     713        26626 : }
     714              : 
     715              : tl::optional<HIR::Pattern *>
     716        87576 : Mappings::lookup_hir_pattern (HirId id)
     717              : {
     718        87576 :   auto it = hirPatternMappings.find (id);
     719        87576 :   if (it == hirPatternMappings.end ())
     720        60153 :     return tl::nullopt;
     721              : 
     722        27423 :   return it->second;
     723              : }
     724              : 
     725              : void
     726        32570 : Mappings::insert_local_defid_mapping (CrateNum crateNum, LocalDefId id,
     727              :                                       HIR::Item *item)
     728              : {
     729        32570 :   rust_assert (!lookup_local_defid (crateNum, id));
     730        32570 :   localDefIdMappings[crateNum][id] = item;
     731        32570 : }
     732              : 
     733              : tl::optional<HIR::Item *>
     734        68515 : Mappings::lookup_local_defid (CrateNum crateNum, LocalDefId id)
     735              : {
     736        68515 :   auto it = localDefIdMappings.find (crateNum);
     737        68515 :   if (it == localDefIdMappings.end ())
     738         9288 :     return tl::nullopt;
     739              : 
     740        59227 :   auto iy = it->second.find (id);
     741        59227 :   if (iy == it->second.end ())
     742        59227 :     return tl::nullopt;
     743              : 
     744            0 :   return iy->second;
     745              : }
     746              : 
     747              : void
     748            0 : Mappings::walk_local_defids_for_crate (CrateNum crateNum,
     749              :                                        std::function<bool (HIR::Item *)> cb)
     750              : {
     751            0 :   auto it = localDefIdMappings.find (crateNum);
     752            0 :   if (it == localDefIdMappings.end ())
     753              :     return;
     754              : 
     755            0 :   for (auto iy = it->second.begin (); iy != it->second.end (); iy++)
     756              :     {
     757            0 :       if (!cb (iy->second))
     758            0 :         return;
     759              :     }
     760              : }
     761              : 
     762              : void
     763       483066 : Mappings::insert_node_to_hir (NodeId id, HirId ref)
     764              : {
     765       483066 :   nodeIdToHirMappings[id] = ref;
     766       483066 :   hirIdToNodeMappings[ref] = id;
     767       483066 : }
     768              : 
     769              : tl::optional<HirId>
     770      3075318 : Mappings::lookup_node_to_hir (NodeId id)
     771              : {
     772      3075318 :   auto it = nodeIdToHirMappings.find (id);
     773      3075318 :   if (it == nodeIdToHirMappings.end ())
     774            0 :     return tl::nullopt;
     775              : 
     776      3075318 :   return {it->second};
     777              : }
     778              : 
     779              : tl::optional<NodeId>
     780         7113 : Mappings::lookup_hir_to_node (HirId id)
     781              : {
     782         7113 :   auto it = hirIdToNodeMappings.find (id);
     783         7113 :   if (it == hirIdToNodeMappings.end ())
     784            0 :     return tl::nullopt;
     785              : 
     786         7113 :   return {it->second};
     787              : }
     788              : 
     789              : void
     790       675339 : Mappings::insert_location (HirId id, location_t locus)
     791              : {
     792       675339 :   locations[id] = locus;
     793       675339 : }
     794              : 
     795              : location_t
     796      5397654 : Mappings::lookup_location (HirId id)
     797              : {
     798      5397654 :   auto it = locations.find (id);
     799      5397654 :   if (it == locations.end ())
     800              :     return UNDEF_LOCATION;
     801              : 
     802      5317573 :   return it->second;
     803              : }
     804              : 
     805              : tl::optional<HIR::Stmt *>
     806            0 : Mappings::resolve_nodeid_to_stmt (NodeId id)
     807              : {
     808            0 :   auto it = nodeIdToHirMappings.find (id);
     809            0 :   if (it == nodeIdToHirMappings.end ())
     810            0 :     return tl::nullopt;
     811              : 
     812            0 :   HirId resolved = it->second;
     813            0 :   return lookup_hir_stmt (resolved);
     814              : }
     815              : 
     816              : void
     817        15993 : Mappings::iterate_impl_items (
     818              :   std::function<bool (HirId, HIR::ImplItem *, HIR::ImplBlock *)> cb)
     819              : {
     820       339326 :   for (auto it = hirImplItemMappings.begin (); it != hirImplItemMappings.end ();
     821       323333 :        it++)
     822              :     {
     823       323333 :       auto id = it->first;
     824       323333 :       auto impl_item = it->second.second;
     825       323333 :       auto impl
     826       323333 :         = lookup_associated_impl (impl_item->get_impl_mappings ().get_hirid ());
     827       323333 :       if (!cb (id, impl_item, impl))
     828        15993 :         return;
     829              :     }
     830              : }
     831              : 
     832              : void
     833        89312 : Mappings::iterate_impl_blocks (std::function<bool (HirId, HIR::ImplBlock *)> cb)
     834              : {
     835      2743240 :   for (auto it = hirImplBlockMappings.begin ();
     836      2743240 :        it != hirImplBlockMappings.end (); it++)
     837              :     {
     838      2653928 :       HirId id = it->first;
     839      2653928 :       HIR::ImplBlock *impl_block = it->second;
     840      2653928 :       if (!cb (id, impl_block))
     841        89312 :         return;
     842              :     }
     843              : }
     844              : 
     845              : void
     846            0 : Mappings::iterate_trait_items (
     847              :   std::function<bool (HIR::TraitItem *, HIR::Trait *)> cb)
     848              : {
     849            0 :   for (auto it = hirTraitItemMappings.begin ();
     850            0 :        it != hirTraitItemMappings.end (); it++)
     851              :     {
     852            0 :       HirId trait_item_id = it->first;
     853            0 :       HIR::TraitItem *trait_item = it->second;
     854            0 :       HIR::Trait *trait = lookup_trait_item_mapping (trait_item_id);
     855              : 
     856            0 :       if (!cb (trait_item, trait))
     857            0 :         return;
     858              :     }
     859              : }
     860              : 
     861              : void
     862         1698 : Mappings::insert_macro_def (AST::MacroRulesDefinition *macro)
     863              : {
     864         1698 :   auto outer_attrs = macro->get_outer_attrs ();
     865         1698 :   bool should_be_builtin
     866         1698 :     = std::any_of (outer_attrs.begin (), outer_attrs.end (),
     867         1372 :                    [] (AST::Attribute attr) {
     868         1372 :                      return attr.get_path ()
     869         1372 :                             == Values::Attributes::RUSTC_BUILTIN_MACRO;
     870              :                    });
     871         1698 :   if (should_be_builtin)
     872              :     {
     873          193 :       auto builtin
     874          193 :         = MacroBuiltin::builtins.lookup (macro->get_rule_name ().as_string ());
     875          193 :       if (!builtin.has_value ())
     876              :         {
     877            2 :           rust_error_at (macro->get_locus (),
     878              :                          "cannot find a built-in macro with name %qs",
     879            2 :                          macro->get_rule_name ().as_string ().c_str ());
     880            2 :           return;
     881              :         }
     882              : 
     883          191 :       auto transcriber = MacroBuiltin::builtin_transcribers.find (
     884          191 :         macro->get_rule_name ().as_string ());
     885          191 :       macro->set_builtin_transcriber (transcriber->second);
     886              :     }
     887              : 
     888         1696 :   auto it = macroMappings.find (macro->get_node_id ());
     889         1696 :   rust_assert (it == macroMappings.end ());
     890              : 
     891         1696 :   macroMappings[macro->get_node_id ()] = {macro, currentCrateNum};
     892         1698 : }
     893              : 
     894              : tl::optional<AST::MacroRulesDefinition *>
     895       150501 : Mappings::lookup_macro_def (NodeId id)
     896              : {
     897       150501 :   auto it = macroMappings.find (id);
     898       150501 :   if (it == macroMappings.end ())
     899         1698 :     return tl::nullopt;
     900              : 
     901       148803 :   return it->second.first;
     902              : }
     903              : 
     904              : tl::optional<CrateNum>
     905          522 : Mappings::lookup_macro_def_crate (NodeId id)
     906              : {
     907          522 :   auto it = macroMappings.find (id);
     908          522 :   if (it == macroMappings.end ())
     909            0 :     return tl::nullopt;
     910              : 
     911          522 :   return it->second.second;
     912              : }
     913              : 
     914              : void
     915        58237 : Mappings::insert_macro_invocation (AST::MacroInvocation &invoc,
     916              :                                    AST::MacroRulesDefinition *def)
     917              : {
     918        58237 :   auto it = macroInvocations.find (invoc.get_node_id ());
     919        58237 :   rust_assert (it == macroInvocations.end ());
     920              : 
     921        58237 :   macroInvocations[invoc.get_node_id ()] = def;
     922        58237 : }
     923              : 
     924              : tl::optional<AST::MacroRulesDefinition *>
     925       148541 : Mappings::lookup_macro_invocation (AST::MacroInvocation &invoc)
     926              : {
     927       148541 :   auto it = macroInvocations.find (invoc.get_node_id ());
     928       148541 :   if (it == macroInvocations.end ())
     929        58501 :     return tl::nullopt;
     930              : 
     931        90040 :   return it->second;
     932              : }
     933              : 
     934              : void
     935            3 : Mappings::insert_exported_macro (AST::MacroRulesDefinition &def)
     936              : {
     937            3 :   exportedMacros.emplace_back (def);
     938            3 : }
     939              : 
     940              : std::vector<AST::MacroRulesDefinition>
     941         4305 : Mappings::get_exported_macros ()
     942              : {
     943         4305 :   return exportedMacros;
     944              : }
     945              : 
     946              : void
     947           24 : Mappings::insert_derive_proc_macros (CrateNum num,
     948              :                                      std::vector<CustomDeriveProcMacro> macros)
     949              : {
     950           24 :   auto it = procmacrosDeriveMappings.find (num);
     951           24 :   rust_assert (it == procmacrosDeriveMappings.end ());
     952              : 
     953           24 :   procmacrosDeriveMappings[num] = macros;
     954           24 : }
     955              : 
     956              : void
     957           24 : Mappings::insert_bang_proc_macros (CrateNum num,
     958              :                                    std::vector<BangProcMacro> macros)
     959              : {
     960           24 :   auto it = procmacrosBangMappings.find (num);
     961           24 :   rust_assert (it == procmacrosBangMappings.end ());
     962              : 
     963           24 :   procmacrosBangMappings[num] = macros;
     964           24 : }
     965              : 
     966              : void
     967           24 : Mappings::insert_attribute_proc_macros (CrateNum num,
     968              :                                         std::vector<AttributeProcMacro> macros)
     969              : {
     970           24 :   auto it = procmacrosAttributeMappings.find (num);
     971           24 :   rust_assert (it == procmacrosAttributeMappings.end ());
     972              : 
     973           24 :   procmacrosAttributeMappings[num] = macros;
     974           24 : }
     975              : 
     976              : tl::optional<std::vector<CustomDeriveProcMacro> &>
     977           99 : Mappings::lookup_derive_proc_macros (CrateNum num)
     978              : {
     979           99 :   auto it = procmacrosDeriveMappings.find (num);
     980           99 :   if (it == procmacrosDeriveMappings.end ())
     981            3 :     return tl::nullopt;
     982              : 
     983           96 :   return it->second;
     984              : }
     985              : 
     986              : tl::optional<std::vector<BangProcMacro> &>
     987           99 : Mappings::lookup_bang_proc_macros (CrateNum num)
     988              : {
     989           99 :   auto it = procmacrosBangMappings.find (num);
     990           99 :   if (it == procmacrosBangMappings.end ())
     991            3 :     return tl::nullopt;
     992              : 
     993           96 :   return it->second;
     994              : }
     995              : 
     996              : tl::optional<std::vector<AttributeProcMacro> &>
     997           99 : Mappings::lookup_attribute_proc_macros (CrateNum num)
     998              : {
     999           99 :   auto it = procmacrosAttributeMappings.find (num);
    1000           99 :   if (it == procmacrosAttributeMappings.end ())
    1001            3 :     return tl::nullopt;
    1002              : 
    1003           96 :   return it->second;
    1004              : }
    1005              : 
    1006              : void
    1007            0 : Mappings::insert_derive_proc_macro_def (CustomDeriveProcMacro macro)
    1008              : {
    1009            0 :   auto it = procmacroDeriveMappings.find (macro.get_node_id ());
    1010            0 :   rust_assert (it == procmacroDeriveMappings.end ());
    1011              : 
    1012            0 :   procmacroDeriveMappings[macro.get_node_id ()] = macro;
    1013            0 : }
    1014              : 
    1015              : void
    1016            0 : Mappings::insert_bang_proc_macro_def (BangProcMacro macro)
    1017              : {
    1018            0 :   auto it = procmacroBangMappings.find (macro.get_node_id ());
    1019            0 :   rust_assert (it == procmacroBangMappings.end ());
    1020              : 
    1021            0 :   procmacroBangMappings[macro.get_node_id ()] = macro;
    1022            0 : }
    1023              : 
    1024              : void
    1025            0 : Mappings::insert_attribute_proc_macro_def (AttributeProcMacro macro)
    1026              : {
    1027            0 :   auto it = procmacroAttributeMappings.find (macro.get_node_id ());
    1028            0 :   rust_assert (it == procmacroAttributeMappings.end ());
    1029              : 
    1030            0 :   procmacroAttributeMappings[macro.get_node_id ()] = macro;
    1031            0 : }
    1032              : 
    1033              : tl::optional<CustomDeriveProcMacro &>
    1034          688 : Mappings::lookup_derive_proc_macro_def (NodeId id)
    1035              : {
    1036          688 :   auto it = procmacroDeriveMappings.find (id);
    1037          688 :   if (it == procmacroDeriveMappings.end ())
    1038          688 :     return tl::nullopt;
    1039              : 
    1040            0 :   return it->second;
    1041              : }
    1042              : 
    1043              : tl::optional<BangProcMacro &>
    1044            0 : Mappings::lookup_bang_proc_macro_def (NodeId id)
    1045              : {
    1046            0 :   auto it = procmacroBangMappings.find (id);
    1047            0 :   if (it == procmacroBangMappings.end ())
    1048            0 :     return tl::nullopt;
    1049              : 
    1050            0 :   return it->second;
    1051              : }
    1052              : 
    1053              : tl::optional<AttributeProcMacro &>
    1054            1 : Mappings::lookup_attribute_proc_macro_def (NodeId id)
    1055              : {
    1056            1 :   auto it = procmacroAttributeMappings.find (id);
    1057            1 :   if (it == procmacroAttributeMappings.end ())
    1058            1 :     return tl::nullopt;
    1059              : 
    1060            0 :   return it->second;
    1061              : }
    1062              : 
    1063              : void
    1064            0 : Mappings::insert_derive_proc_macro_invocation (AST::SimplePath &invoc,
    1065              :                                                CustomDeriveProcMacro def)
    1066              : {
    1067            0 :   auto it = procmacroDeriveInvocations.find (invoc.get_node_id ());
    1068            0 :   rust_assert (it == procmacroDeriveInvocations.end ());
    1069              : 
    1070            0 :   procmacroDeriveInvocations[invoc.get_node_id ()] = def;
    1071            0 : }
    1072              : 
    1073              : tl::optional<CustomDeriveProcMacro &>
    1074            5 : Mappings::lookup_derive_proc_macro_invocation (AST::SimplePath &invoc)
    1075              : {
    1076            5 :   auto it = procmacroDeriveInvocations.find (invoc.get_node_id ());
    1077            5 :   if (it == procmacroDeriveInvocations.end ())
    1078            5 :     return tl::nullopt;
    1079              : 
    1080            0 :   return it->second;
    1081              : }
    1082              : 
    1083              : void
    1084            0 : Mappings::insert_bang_proc_macro_invocation (AST::MacroInvocation &invoc,
    1085              :                                              BangProcMacro def)
    1086              : {
    1087            0 :   auto it = procmacroBangInvocations.find (invoc.get_node_id ());
    1088            0 :   rust_assert (it == procmacroBangInvocations.end ());
    1089              : 
    1090            0 :   procmacroBangInvocations[invoc.get_node_id ()] = def;
    1091            0 : }
    1092              : 
    1093              : tl::optional<BangProcMacro &>
    1094            0 : Mappings::lookup_bang_proc_macro_invocation (AST::MacroInvocation &invoc)
    1095              : {
    1096            0 :   auto it = procmacroBangInvocations.find (invoc.get_node_id ());
    1097            0 :   if (it == procmacroBangInvocations.end ())
    1098            0 :     return tl::nullopt;
    1099              : 
    1100            0 :   return it->second;
    1101              : }
    1102              : 
    1103              : void
    1104            0 : Mappings::insert_attribute_proc_macro_invocation (AST::SimplePath &invoc,
    1105              :                                                   AttributeProcMacro def)
    1106              : {
    1107            0 :   auto it = procmacroAttributeInvocations.find (invoc.get_node_id ());
    1108            0 :   rust_assert (it == procmacroAttributeInvocations.end ());
    1109              : 
    1110            0 :   procmacroAttributeInvocations[invoc.get_node_id ()] = def;
    1111            0 : }
    1112              : 
    1113              : tl::optional<AttributeProcMacro &>
    1114            1 : Mappings::lookup_attribute_proc_macro_invocation (AST::SimplePath &invoc)
    1115              : {
    1116            1 :   auto it = procmacroAttributeInvocations.find (invoc.get_node_id ());
    1117            1 :   if (it == procmacroAttributeInvocations.end ())
    1118            1 :     return tl::nullopt;
    1119              : 
    1120            0 :   return it->second;
    1121              : }
    1122              : 
    1123              : void
    1124        30343 : Mappings::insert_visibility (NodeId id, Privacy::ModuleVisibility visibility)
    1125              : {
    1126        30343 :   visibility_map.insert ({id, visibility});
    1127        30343 : }
    1128              : 
    1129              : tl::optional<Privacy::ModuleVisibility &>
    1130        67048 : Mappings::lookup_visibility (NodeId id)
    1131              : {
    1132        67048 :   auto it = visibility_map.find (id);
    1133        67048 :   if (it == visibility_map.end ())
    1134        45742 :     return tl::nullopt;
    1135              : 
    1136        21306 :   return it->second;
    1137              : }
    1138              : 
    1139              : void
    1140            0 : Mappings::insert_module_child (NodeId module, NodeId child)
    1141              : {
    1142            0 :   auto it = module_child_map.find (module);
    1143            0 :   if (it == module_child_map.end ())
    1144            0 :     module_child_map.insert ({module, {child}});
    1145              :   else
    1146            0 :     it->second.emplace_back (child);
    1147            0 : }
    1148              : 
    1149              : tl::optional<std::vector<NodeId> &>
    1150            0 : Mappings::lookup_module_children (NodeId module)
    1151              : {
    1152            0 :   auto it = module_child_map.find (module);
    1153            0 :   if (it == module_child_map.end ())
    1154            0 :     return tl::nullopt;
    1155              : 
    1156            0 :   return it->second;
    1157              : }
    1158              : 
    1159              : void
    1160         7548 : Mappings::insert_glob_container (NodeId id, AST::GlobContainer *container)
    1161              : {
    1162         7548 :   rust_assert (glob_containers.find (id) == glob_containers.end ());
    1163              : 
    1164              :   // Crates have different memory managements that regular items
    1165         7548 :   if (container->get_glob_container_kind () == AST::GlobContainer::Kind::Crate)
    1166         4869 :     glob_containers[id] = get_ast_crate_by_node_id_raw (id);
    1167              :   else
    1168         2679 :     glob_containers[id] = container;
    1169         7548 : }
    1170              : 
    1171              : void
    1172        12929 : Mappings::insert_module_id (NodeId id)
    1173              : {
    1174        12929 :   module_ids.insert (id);
    1175        12929 : }
    1176              : 
    1177              : bool
    1178       155114 : Mappings::is_module (NodeId id)
    1179              : {
    1180       155114 :   return module_ids.find (id) != module_ids.end ();
    1181              : }
    1182              : 
    1183              : tl::optional<AST::GlobContainer *>
    1184        70038 : Mappings::lookup_glob_container (NodeId id)
    1185              : {
    1186        70038 :   auto it = glob_containers.find (id);
    1187        70038 :   if (it == glob_containers.end ())
    1188        22620 :     return tl::nullopt;
    1189              : 
    1190        47418 :   return {it->second};
    1191              : }
    1192              : 
    1193              : void
    1194            0 : Mappings::insert_module_child_item (NodeId module,
    1195              :                                     Resolver::CanonicalPath child)
    1196              : {
    1197            0 :   rust_assert (!child.is_empty ());
    1198            0 :   rust_assert (child.get_node_id () != UNKNOWN_NODEID);
    1199              : 
    1200            0 :   auto it = module_child_items.find (module);
    1201            0 :   if (it == module_child_items.end ())
    1202            0 :     module_child_items.insert ({module, {child}});
    1203              :   else
    1204            0 :     it->second.emplace_back (child);
    1205            0 : }
    1206              : 
    1207              : tl::optional<std::vector<Resolver::CanonicalPath> &>
    1208            0 : Mappings::lookup_module_chidren_items (NodeId module)
    1209              : {
    1210            0 :   auto it = module_child_items.find (module);
    1211            0 :   if (it == module_child_items.end ())
    1212            0 :     return tl::nullopt;
    1213              : 
    1214            0 :   return it->second;
    1215              : }
    1216              : 
    1217              : tl::optional<Resolver::CanonicalPath &>
    1218            0 : Mappings::lookup_module_child (NodeId module, const std::string &item_name)
    1219              : {
    1220            0 :   tl::optional<std::vector<Resolver::CanonicalPath> &> children
    1221            0 :     = lookup_module_chidren_items (module);
    1222            0 :   if (!children.has_value ())
    1223            0 :     return tl::nullopt;
    1224              : 
    1225              :   // lookup the children to match the name if we can
    1226            0 :   for (auto &child : children.value ())
    1227              :     {
    1228            0 :       const std::string &raw_identifier = child.get ();
    1229            0 :       bool found = raw_identifier.compare (item_name) == 0;
    1230            0 :       if (found)
    1231            0 :         return child;
    1232            0 :     }
    1233              : 
    1234            0 :   return tl::nullopt;
    1235              : }
    1236              : 
    1237              : void
    1238            0 : Mappings::insert_child_item_to_parent_module_mapping (NodeId child_item,
    1239              :                                                       NodeId parent_module)
    1240              : {
    1241            0 :   child_to_parent_module_map.insert ({child_item, parent_module});
    1242            0 : }
    1243              : 
    1244              : tl::optional<NodeId>
    1245            0 : Mappings::lookup_parent_module (NodeId child_item)
    1246              : {
    1247            0 :   auto it = child_to_parent_module_map.find (child_item);
    1248            0 :   if (it == child_to_parent_module_map.end ())
    1249            0 :     return tl::nullopt;
    1250              : 
    1251            0 :   return it->second;
    1252              : }
    1253              : 
    1254              : bool
    1255            0 : Mappings::node_is_module (NodeId query)
    1256              : {
    1257            0 :   return module_child_items.find (query) != module_child_items.end ();
    1258              : }
    1259              : 
    1260              : void
    1261        23096 : Mappings::insert_ast_item (AST::Item *item)
    1262              : {
    1263        23096 :   auto it = ast_item_mappings.find (item->get_node_id ());
    1264        23096 :   rust_assert (it == ast_item_mappings.end ());
    1265              : 
    1266        23096 :   ast_item_mappings[item->get_node_id ()] = item;
    1267        23096 : }
    1268              : 
    1269              : tl::optional<AST::Item *>
    1270            0 : Mappings::lookup_ast_item (NodeId id)
    1271              : {
    1272            0 :   auto it = ast_item_mappings.find (id);
    1273            0 :   if (it == ast_item_mappings.end ())
    1274            0 :     return tl::nullopt;
    1275              : 
    1276            0 :   return it->second;
    1277              : }
    1278              : 
    1279              : HIR::ImplBlock *
    1280        80047 : Mappings::lookup_builtin_marker ()
    1281              : {
    1282        80047 :   return builtinMarker;
    1283              : }
    1284              : 
    1285              : // FIXME: Before merging: Should we remove the `locus` parameter here? since
    1286              : // lang items are looked up mostly for code generation, it doesn't make sense to
    1287              : // error out on the locus of the node trying to access an inexistant lang item
    1288              : DefId
    1289         9876 : Mappings::get_lang_item (LangItem::Kind item_type, location_t locus)
    1290              : {
    1291         9876 :   if (auto item = lookup_lang_item (item_type))
    1292         9876 :     return *item;
    1293              : 
    1294            0 :   rust_fatal_error (locus, "failed to find lang item %s",
    1295            0 :                     LangItem::ToString (item_type).c_str ());
    1296              : }
    1297              : 
    1298              : tl::optional<HIR::TraitItem *>
    1299           27 : Mappings::lookup_trait_item_lang_item (LangItem::Kind item, location_t locus)
    1300              : {
    1301           27 :   DefId trait_item_id = get_lang_item (item, locus);
    1302           27 :   return lookup_trait_item_defid (trait_item_id);
    1303              : }
    1304              : 
    1305              : void
    1306         3468 : Mappings::insert_lang_item (LangItem::Kind item_type, DefId id)
    1307              : {
    1308         3468 :   auto it = lang_item_mappings.find (item_type);
    1309         3468 :   rust_assert (it == lang_item_mappings.end ());
    1310              : 
    1311         3468 :   lang_item_mappings[item_type] = id;
    1312         3468 : }
    1313              : 
    1314              : tl::optional<DefId &>
    1315       164043 : Mappings::lookup_lang_item (LangItem::Kind item_type)
    1316              : {
    1317       164043 :   auto it = lang_item_mappings.find (item_type);
    1318       164043 :   if (it == lang_item_mappings.end ())
    1319        69798 :     return tl::nullopt;
    1320              : 
    1321        94245 :   return it->second;
    1322              : }
    1323              : 
    1324              : void
    1325         3589 : Mappings::insert_lang_item_node (LangItem::Kind item_type, NodeId node_id)
    1326              : {
    1327         3589 :   auto it = lang_item_nodes.find (item_type);
    1328         3589 :   rust_assert (it == lang_item_nodes.end ());
    1329              : 
    1330         3589 :   lang_item_nodes.insert ({item_type, node_id});
    1331         3589 : }
    1332              : 
    1333              : tl::optional<NodeId &>
    1334         3222 : Mappings::lookup_lang_item_node (LangItem::Kind item_type)
    1335              : {
    1336         3222 :   auto it = lang_item_nodes.find (item_type);
    1337         3222 :   if (it == lang_item_nodes.end ())
    1338            1 :     return tl::nullopt;
    1339              : 
    1340         3221 :   return it->second;
    1341              : }
    1342              : 
    1343              : NodeId
    1344         3222 : Mappings::get_lang_item_node (LangItem::Kind item_type)
    1345              : {
    1346         3222 :   if (auto lookup = lookup_lang_item_node (item_type))
    1347         3221 :     return *lookup;
    1348              : 
    1349            2 :   rust_fatal_error (UNKNOWN_LOCATION, "undeclared lang item: %qs",
    1350            1 :                     LangItem::PrettyString (item_type).c_str ());
    1351              : }
    1352              : 
    1353              : std::string &
    1354         1208 : Mappings::get_lang_item_identifier (LangItem::Kind item_type)
    1355              : {
    1356              :   // Lang item names are hardcoded because they're only required for metadata
    1357              :   // dump which will get removed at some point
    1358         1208 :   static std::unordered_map<LangItem::Kind, std::string> identifiers
    1359           97 :     = {{LangItem::Kind::COPY, "Copy"},
    1360           97 :        {LangItem::Kind::CLONE, "Clone"},
    1361           97 :        {LangItem::Kind::STRUCTURAL_PEQ, "StructuralPartialEq"},
    1362           97 :        {LangItem::Kind::STRUCTURAL_TEQ, "StructuralEq"},
    1363           97 :        {LangItem::Kind::SIZED, "Sized"},
    1364           97 :        {LangItem::Kind::EQ, "PartialEq"},
    1365         1984 :        {LangItem::Kind::PHANTOM_DATA, "PhantomData"}};
    1366         1208 :   auto result = identifiers.find (item_type);
    1367         1208 :   if (result != identifiers.cend ())
    1368         1208 :     return result->second;
    1369            0 :   rust_unreachable ();
    1370              : }
    1371              : 
    1372              : void
    1373           12 : Mappings::insert_auto_trait (HIR::Trait *trait)
    1374              : {
    1375           12 :   auto_traits.emplace_back (trait);
    1376           12 : }
    1377              : 
    1378              : std::vector<HIR::Trait *> &
    1379        80291 : Mappings::get_auto_traits ()
    1380              : {
    1381        80291 :   return auto_traits;
    1382              : }
    1383              : 
    1384              : void
    1385           79 : Mappings::add_capture (NodeId closure, NodeId definition)
    1386              : {
    1387           79 :   auto cap = captures.find (closure);
    1388           79 :   if (cap == captures.end ())
    1389           51 :     captures[closure] = {definition};
    1390              :   else
    1391           28 :     cap->second.push_back (definition);
    1392           79 : }
    1393              : 
    1394              : tl::optional<std::vector<NodeId>>
    1395           65 : Mappings::lookup_captures (NodeId closure)
    1396              : {
    1397           65 :   auto cap = captures.find (closure);
    1398           65 :   if (cap == captures.end ())
    1399           44 :     return tl::nullopt;
    1400              :   else
    1401           21 :     return cap->second;
    1402              : }
    1403              : 
    1404              : void
    1405         1359 : Mappings::add_derived_node (NodeId node_id)
    1406              : {
    1407         1359 :   derived_nodes.insert (node_id);
    1408         1359 : }
    1409              : 
    1410              : bool
    1411            0 : Mappings::is_derived_node (NodeId node_id)
    1412              : {
    1413            0 :   return derived_nodes.find (node_id) != derived_nodes.end ();
    1414              : }
    1415              : 
    1416              : void
    1417       490167 : Mappings::add_function_node (NodeId node_id)
    1418              : {
    1419       490167 :   function_nodes.insert (node_id);
    1420       490167 : }
    1421              : 
    1422              : bool
    1423          943 : Mappings::is_function_node (NodeId node_id)
    1424              : {
    1425          943 :   return function_nodes.find (node_id) != function_nodes.end ();
    1426              : }
    1427              : 
    1428              : } // namespace Analysis
    1429              : } // namespace Rust
        

Generated by: LCOV version 2.4-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.