LCOV - code coverage report
Current view: top level - gcc/rust/util - rust-hir-map.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 78.9 % 702 554
Test Date: 2026-02-28 14:20:25 Functions: 82.4 % 136 112
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        45928 : NodeMapping::get_error ()
      35              : {
      36        45928 :   return NodeMapping (UNKNOWN_CRATENUM, UNKNOWN_NODEID, UNKNOWN_HIRID,
      37        45928 :                       UNKNOWN_LOCAL_DEFID);
      38              : }
      39              : 
      40              : CrateNum
      41      1529658 : NodeMapping::get_crate_num () const
      42              : {
      43      1529658 :   return crateNum;
      44              : }
      45              : 
      46              : NodeId
      47      3546180 : NodeMapping::get_nodeid () const
      48              : {
      49      3546180 :   return nodeId;
      50              : }
      51              : 
      52              : HirId
      53      4884975 : NodeMapping::get_hirid () const
      54              : {
      55      4884975 :   return hirId;
      56              : }
      57              : 
      58              : LocalDefId
      59      1527665 : NodeMapping::get_local_defid () const
      60              : {
      61      1527665 :   return localDefId;
      62              : }
      63              : 
      64              : DefId
      65      1518927 : NodeMapping::get_defid () const
      66              : {
      67      1518927 :   return get_defid (get_crate_num (), get_local_defid ());
      68              : }
      69              : 
      70              : DefId
      71      1518927 : NodeMapping::get_defid (CrateNum crate_num, LocalDefId local_defid)
      72              : {
      73      1518927 :   return DefId{crate_num, local_defid};
      74              : }
      75              : 
      76              : std::string
      77         3271 : NodeMapping::as_string () const
      78              : {
      79         3271 :   std::ostringstream ss;
      80         3271 :   ss << "["
      81         3271 :      << "C: " << get_crate_num ();
      82         3271 :   if (get_nodeid () != UNKNOWN_NODEID)
      83         3271 :     ss << " Nid: " << get_nodeid ();
      84              : 
      85         3271 :   if (get_hirid () != UNKNOWN_HIRID)
      86         3271 :     ss << " Hid: " << get_hirid ();
      87              : 
      88         3271 :   if (get_local_defid () != UNKNOWN_LOCAL_DEFID)
      89         3271 :     ss << " Lid: " << get_local_defid ();
      90              : 
      91         3271 :   ss << "]";
      92         3271 :   return ss.str ();
      93         3271 : }
      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         4636 : Mappings::Mappings ()
     101         4636 :   : crateNumItr (kDefaultCrateNumBegin), currentCrateNum (UNKNOWN_CRATENUM),
     102         4636 :     hirIdIter (kDefaultHirIdBegin), nodeIdIter (kDefaultNodeIdBegin)
     103              : {
     104         4636 :   Analysis::NodeMapping node (0, 0, 0, 0);
     105         4636 :   builtinMarker
     106         9272 :     = new HIR::ImplBlock (node, {}, {}, nullptr, nullptr, HIR::WhereClause ({}),
     107              :                           BoundPolarity::RegularBound,
     108         9272 :                           HIR::Visibility (HIR::Visibility::VisType::PUBLIC),
     109         9272 :                           {}, {}, UNDEF_LOCATION);
     110         4636 : }
     111              : 
     112         9272 : Mappings::~Mappings () { delete builtinMarker; }
     113              : 
     114              : Mappings &
     115    101074679 : Mappings::get ()
     116              : {
     117    101079315 :   static Mappings instance{};
     118    101074679 :   return instance;
     119              : }
     120              : 
     121              : CrateNum
     122         4560 : Mappings::get_next_crate_num (const std::string &name)
     123              : {
     124         4560 :   auto id = crateNumItr;
     125         4560 :   crateNumItr++;
     126         4560 :   set_crate_name (id, name);
     127         4560 :   return id;
     128              : }
     129              : 
     130              : void
     131         4632 : Mappings::set_current_crate (CrateNum crateNum)
     132              : {
     133         4632 :   currentCrateNum = crateNum;
     134         4632 : }
     135              : 
     136              : CrateNum
     137       813723 : Mappings::get_current_crate () const
     138              : {
     139       813723 :   return currentCrateNum;
     140              : }
     141              : 
     142              : tl::optional<const std::string &>
     143        41978 : Mappings::get_crate_name (CrateNum crate_num) const
     144              : {
     145        41978 :   auto it = crate_names.find (crate_num);
     146        41978 :   if (it == crate_names.end ())
     147            0 :     return tl::nullopt;
     148              : 
     149        41978 :   return it->second;
     150              : }
     151              : 
     152              : tl::optional<CrateNum>
     153        68746 : Mappings::lookup_crate_num (NodeId node_id) const
     154              : {
     155        68746 :   auto it = crate_node_to_crate_num.find (node_id);
     156        68746 :   if (it == crate_node_to_crate_num.end ())
     157        29808 :     return tl::nullopt;
     158              : 
     159        38938 :   return it->second;
     160              : }
     161              : 
     162              : void
     163         4560 : Mappings::set_crate_name (CrateNum crate_num, const std::string &name)
     164              : {
     165         4560 :   crate_names[crate_num] = name;
     166         4560 : }
     167              : 
     168              : const std::string &
     169        12108 : Mappings::get_current_crate_name () const
     170              : {
     171        12108 :   return get_crate_name (get_current_crate ()).value ();
     172              : }
     173              : 
     174              : tl::optional<CrateNum>
     175          228 : Mappings::lookup_crate_name (const std::string &crate_name) const
     176              : {
     177          456 :   for (const auto &it : crate_names)
     178              :     {
     179          420 :       if (it.second.compare (crate_name) == 0)
     180          192 :         return it.first;
     181              :     }
     182           36 :   return tl::nullopt;
     183              : }
     184              : 
     185              : tl::optional<NodeId>
     186        18064 : Mappings::crate_num_to_nodeid (const CrateNum &crate_num) const
     187              : {
     188        18064 :   auto it = ast_crate_mappings.find (crate_num);
     189        18064 :   if (it == ast_crate_mappings.end ())
     190            0 :     return tl::nullopt;
     191              : 
     192        18064 :   return it->second->get_node_id ();
     193              : }
     194              : 
     195              : bool
     196        34342 : Mappings::node_is_crate (NodeId node_id) const
     197              : {
     198        34342 :   return lookup_crate_num (node_id).has_value ();
     199              : }
     200              : 
     201              : NodeId
     202      1223961 : Mappings::get_next_node_id ()
     203              : {
     204      1223961 :   auto it = nodeIdIter;
     205      1223961 :   if (UNLIKELY (it > MAX_NODEID))
     206            0 :     rust_fatal_error (UNKNOWN_LOCATION, "out of node ids");
     207      1223961 :   nodeIdIter++;
     208      1223961 :   return it;
     209              : }
     210              : 
     211              : HirId
     212       743503 : Mappings::get_next_hir_id (CrateNum crateNum)
     213              : {
     214       743503 :   auto id = hirIdIter;
     215       743503 :   hirIdIter++;
     216              : 
     217       743503 :   auto it = hirNodesWithinCrate.find (crateNum);
     218       743503 :   if (it == hirNodesWithinCrate.end ())
     219              :     {
     220         4530 :       hirNodesWithinCrate.insert ({crateNum, {}});
     221              :     }
     222              : 
     223       743503 :   hirNodesWithinCrate[crateNum].insert (id);
     224       743503 :   return id;
     225              : }
     226              : 
     227              : LocalDefId
     228       127275 : Mappings::get_next_localdef_id (CrateNum crateNum)
     229              : {
     230       127275 :   auto it = localIdIter.find (crateNum);
     231       127275 :   if (it == localIdIter.end ())
     232              :     {
     233         4317 :       localIdIter.insert ({crateNum, 1});
     234              :     }
     235              : 
     236       127275 :   it = localIdIter.find (crateNum);
     237       127275 :   rust_assert (it != localIdIter.end ());
     238              : 
     239       127275 :   LocalDefId id = it->second;
     240       127275 :   localIdIter[crateNum] = id + 1;
     241       127275 :   return id;
     242              : }
     243              : 
     244              : AST::Crate &
     245         4485 : Mappings::get_ast_crate (CrateNum crateNum)
     246              : {
     247         4485 :   auto it = ast_crate_mappings.find (crateNum);
     248         4485 :   rust_assert (it != ast_crate_mappings.end ());
     249         4485 :   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         4510 : Mappings::get_ast_crate_by_node_id_raw (NodeId id)
     260              : {
     261         4510 :   auto i = crate_node_to_crate_num.find (id);
     262         4510 :   rust_assert (i != crate_node_to_crate_num.end ());
     263              : 
     264         4510 :   CrateNum crateNum = i->second;
     265         4510 :   auto it = ast_crate_mappings.find (crateNum);
     266         4510 :   rust_assert (it != ast_crate_mappings.end ());
     267         4510 :   return it->second;
     268              : }
     269              : 
     270              : AST::Crate &
     271         4560 : Mappings::insert_ast_crate (std::unique_ptr<AST::Crate> &&crate,
     272              :                             CrateNum crate_num)
     273              : {
     274         4560 :   auto it = ast_crate_mappings.find (crate_num);
     275         4560 :   rust_assert (it == ast_crate_mappings.end ());
     276              : 
     277              :   // store it
     278         4560 :   crate_node_to_crate_num.insert ({crate->get_node_id (), crate_num});
     279         4560 :   ast_crate_mappings.insert ({crate_num, crate.release ()});
     280              : 
     281              :   // return the reference to it
     282         4560 :   it = ast_crate_mappings.find (crate_num);
     283         4560 :   rust_assert (it != ast_crate_mappings.end ());
     284         4560 :   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       102909 : Mappings::is_local_hirid_crate (HirId crateNum)
     297              : {
     298       205355 :   for (const auto &it : hir_crate_mappings)
     299              :     {
     300       103117 :       const auto &crate = it.second;
     301       103117 :       if (crate->get_mappings ().get_hirid () == crateNum)
     302       102909 :         return true;
     303              :     }
     304              :   return false;
     305              : }
     306              : 
     307              : HIR::Crate &
     308         4331 : Mappings::insert_hir_crate (std::unique_ptr<HIR::Crate> &&crate)
     309              : {
     310         4331 :   CrateNum crateNum = crate->get_mappings ().get_crate_num ();
     311         4331 :   auto it = hir_crate_mappings.find (crateNum);
     312         4331 :   rust_assert (it == hir_crate_mappings.end ());
     313              : 
     314         4331 :   insert_node_to_hir (crate->get_mappings ().get_nodeid (),
     315         4331 :                       crate->get_mappings ().get_hirid ());
     316         4331 :   hir_crate_mappings.insert ({crateNum, crate.release ()});
     317              : 
     318         4331 :   it = hir_crate_mappings.find (crateNum);
     319         4331 :   rust_assert (it != hir_crate_mappings.end ());
     320         4331 :   return *it->second;
     321              : }
     322              : 
     323              : void
     324        31264 : Mappings::insert_defid_mapping (DefId id, HIR::Item *item)
     325              : {
     326        31264 :   CrateNum crate_num = id.crateNum;
     327        31264 :   LocalDefId local_def_id = id.localDefId;
     328              : 
     329        31264 :   rust_assert (!lookup_defid (id));
     330        31264 :   rust_assert (!lookup_local_defid (crate_num, local_def_id));
     331        31264 :   rust_assert (!lookup_trait_item_defid (id));
     332              : 
     333        31264 :   defIdMappings[id] = item;
     334        31264 :   insert_local_defid_mapping (crate_num, local_def_id, item);
     335        31264 : }
     336              : 
     337              : tl::optional<HIR::Item *>
     338       116994 : Mappings::lookup_defid (DefId id)
     339              : {
     340       116994 :   auto it = defIdMappings.find (id);
     341       116994 :   if (it == defIdMappings.end ())
     342        35498 :     return tl::nullopt;
     343              : 
     344        81496 :   return it->second;
     345              : }
     346              : 
     347              : void
     348         3321 : Mappings::insert_defid_mapping (DefId id, HIR::TraitItem *item)
     349              : {
     350         3321 :   CrateNum crate_num = id.crateNum;
     351         3321 :   LocalDefId local_def_id = id.localDefId;
     352              : 
     353         3321 :   rust_assert (!lookup_defid (id));
     354         3321 :   rust_assert (!lookup_local_defid (crate_num, local_def_id));
     355         3321 :   rust_assert (!lookup_trait_item_defid (id));
     356              : 
     357         3321 :   defIdTraitItemMappings[id] = item;
     358         3321 : }
     359              : 
     360              : tl::optional<HIR::TraitItem *>
     361        37387 : Mappings::lookup_trait_item_defid (DefId id)
     362              : {
     363        37387 :   auto it = defIdTraitItemMappings.find (id);
     364        37387 :   if (it == defIdTraitItemMappings.end ())
     365        36307 :     return tl::nullopt;
     366              : 
     367         1080 :   return it->second;
     368              : }
     369              : 
     370              : void
     371        21953 : Mappings::insert_hir_item (HIR::Item *item)
     372              : {
     373        21953 :   auto id = item->get_mappings ().get_hirid ();
     374        21953 :   rust_assert (!lookup_hir_item (id).has_value ());
     375              : 
     376        21953 :   hirItemMappings[id] = item;
     377        21953 :   insert_node_to_hir (item->get_mappings ().get_nodeid (), id);
     378        21953 : }
     379              : 
     380              : tl::optional<HIR::Item *>
     381      2391533 : Mappings::lookup_hir_item (HirId id)
     382              : {
     383      2391533 :   auto it = hirItemMappings.find (id);
     384      2391533 :   if (it == hirItemMappings.end ())
     385       124715 :     return tl::nullopt;
     386      2266818 :   return it->second;
     387              : }
     388              : 
     389              : void
     390         1225 : Mappings::insert_hir_enumitem (HIR::Enum *parent, HIR::EnumItem *item)
     391              : {
     392         1225 :   auto id = item->get_mappings ().get_hirid ();
     393         1225 :   auto result = lookup_hir_enumitem (id);
     394         1225 :   rust_assert (result.first == nullptr);
     395              : 
     396         1225 :   hirEnumItemMappings[id] = {parent, item};
     397         1225 :   insert_node_to_hir (item->get_mappings ().get_nodeid (), id);
     398         1225 : }
     399              : 
     400              : std::pair<HIR::Enum *, HIR::EnumItem *>
     401        64930 : Mappings::lookup_hir_enumitem (HirId id)
     402              : {
     403        64930 :   auto it = hirEnumItemMappings.find (id);
     404        64930 :   if (it == hirEnumItemMappings.end ())
     405        56451 :     return {nullptr, nullptr};
     406              : 
     407         8479 :   return it->second;
     408              : }
     409              : 
     410              : void
     411         3321 : Mappings::insert_hir_trait_item (HIR::TraitItem *item)
     412              : {
     413         3321 :   auto id = item->get_mappings ().get_hirid ();
     414         3321 :   rust_assert (!lookup_hir_trait_item (id).has_value ());
     415              : 
     416         3321 :   hirTraitItemMappings[id] = item;
     417         3321 :   insert_node_to_hir (item->get_mappings ().get_nodeid (), id);
     418         3321 : }
     419              : 
     420              : tl::optional<HIR::TraitItem *>
     421         3625 : Mappings::lookup_hir_trait_item (HirId id)
     422              : {
     423         3625 :   auto it = hirTraitItemMappings.find (id);
     424         3625 :   if (it == hirTraitItemMappings.end ())
     425         3381 :     return tl::nullopt;
     426              : 
     427          244 :   return it->second;
     428              : }
     429              : 
     430              : void
     431         1469 : Mappings::insert_hir_extern_block (HIR::ExternBlock *block)
     432              : {
     433         1469 :   auto id = block->get_mappings ().get_hirid ();
     434         1469 :   rust_assert (!lookup_hir_extern_block (id).has_value ());
     435              : 
     436         1469 :   hirExternBlockMappings[id] = block;
     437         1469 :   insert_node_to_hir (block->get_mappings ().get_nodeid (), id);
     438         1469 : }
     439              : 
     440              : tl::optional<HIR::ExternBlock *>
     441         1738 : Mappings::lookup_hir_extern_block (HirId id)
     442              : {
     443         1738 :   auto it = hirExternBlockMappings.find (id);
     444         1738 :   if (it == hirExternBlockMappings.end ())
     445         1469 :     return tl::nullopt;
     446              : 
     447          269 :   return it->second;
     448              : }
     449              : 
     450              : void
     451         2214 : Mappings::insert_hir_extern_item (HIR::ExternalItem *item, HirId parent_block)
     452              : {
     453         2214 :   auto id = item->get_mappings ().get_hirid ();
     454         2214 :   rust_assert (!lookup_hir_extern_item (id));
     455              : 
     456         2214 :   hirExternItemMappings[id] = {item, parent_block};
     457         2214 :   insert_node_to_hir (item->get_mappings ().get_nodeid (), id);
     458         2214 : }
     459              : 
     460              : tl::optional<std::pair<HIR::ExternalItem *, HirId>>
     461        32208 : Mappings::lookup_hir_extern_item (HirId id)
     462              : {
     463        32208 :   auto it = hirExternItemMappings.find (id);
     464        32208 :   if (it == hirExternItemMappings.end ())
     465        31371 :     return tl::nullopt;
     466              : 
     467          837 :   return it->second;
     468              : }
     469              : 
     470              : void
     471         5599 : Mappings::insert_hir_impl_block (HIR::ImplBlock *item)
     472              : {
     473         5599 :   auto id = item->get_mappings ().get_hirid ();
     474         5599 :   rust_assert (!lookup_hir_impl_block (id));
     475              : 
     476         5599 :   HirId impl_type_id = item->get_type ().get_mappings ().get_hirid ();
     477         5599 :   hirImplBlockMappings[id] = item;
     478         5599 :   hirImplBlockTypeMappings[impl_type_id] = item;
     479         5599 :   insert_node_to_hir (item->get_mappings ().get_nodeid (), id);
     480         5599 : }
     481              : 
     482              : tl::optional<HIR::ImplBlock *>
     483         8878 : Mappings::lookup_hir_impl_block (HirId id)
     484              : {
     485         8878 :   auto it = hirImplBlockMappings.find (id);
     486         8878 :   if (it == hirImplBlockMappings.end ())
     487         5599 :     return tl::nullopt;
     488              : 
     489         3279 :   return it->second;
     490              : }
     491              : 
     492              : tl::optional<HIR::ImplBlock *>
     493         2658 : Mappings::lookup_impl_block_type (HirId id)
     494              : {
     495         2658 :   auto it = hirImplBlockTypeMappings.find (id);
     496         2658 :   if (it == hirImplBlockTypeMappings.end ())
     497           61 :     return tl::nullopt;
     498              : 
     499         2597 :   return it->second;
     500              : }
     501              : 
     502              : void
     503         1202 : Mappings::insert_module (HIR::Module *module)
     504              : {
     505         1202 :   auto id = module->get_mappings ().get_hirid ();
     506         1202 :   rust_assert (!lookup_module (id));
     507              : 
     508         1202 :   hirModuleMappings[id] = module;
     509         1202 :   insert_node_to_hir (module->get_mappings ().get_nodeid (), id);
     510         1202 : }
     511              : 
     512              : tl::optional<HIR::Module *>
     513       104119 : Mappings::lookup_module (HirId id)
     514              : {
     515       104119 :   auto it = hirModuleMappings.find (id);
     516       104119 :   if (it == hirModuleMappings.end ())
     517       100845 :     return tl::nullopt;
     518              : 
     519         3274 :   return it->second;
     520              : }
     521              : 
     522              : void
     523         8086 : Mappings::insert_hir_implitem (HirId parent_impl_id, HIR::ImplItem *item)
     524              : {
     525         8086 :   auto id = item->get_impl_mappings ().get_hirid ();
     526         8086 :   rust_assert (!lookup_hir_implitem (id));
     527              : 
     528         8086 :   hirImplItemMappings[id]
     529         8086 :     = std::pair<HirId, HIR::ImplItem *> (parent_impl_id, item);
     530         8086 :   insert_node_to_hir (item->get_impl_mappings ().get_nodeid (), id);
     531         8086 : }
     532              : 
     533              : tl::optional<std::pair<HIR::ImplItem *, HirId>>
     534        95199 : Mappings::lookup_hir_implitem (HirId id)
     535              : {
     536        95199 :   auto it = hirImplItemMappings.find (id);
     537        95199 :   if (it == hirImplItemMappings.end ())
     538        74989 :     return tl::nullopt;
     539              : 
     540        20210 :   return std::make_pair (it->second.second, it->second.first);
     541              : }
     542              : 
     543              : void
     544       146103 : Mappings::insert_hir_expr (HIR::Expr *expr)
     545              : {
     546       146103 :   auto id = expr->get_mappings ().get_hirid ();
     547       146103 :   hirExprMappings[id] = expr;
     548              : 
     549       146103 :   insert_node_to_hir (expr->get_mappings ().get_nodeid (), id);
     550       146103 :   insert_location (id, expr->get_locus ());
     551       146103 : }
     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        33167 : Mappings::insert_hir_path_expr_seg (HIR::PathExprSegment *expr)
     565              : {
     566        33167 :   auto id = expr->get_mappings ().get_hirid ();
     567        33167 :   rust_assert (!lookup_hir_path_expr_seg (id));
     568              : 
     569        33167 :   hirPathSegMappings[id] = expr;
     570        33167 :   insert_node_to_hir (expr->get_mappings ().get_nodeid (), id);
     571        33167 :   insert_location (id, expr->get_locus ());
     572        33167 : }
     573              : 
     574              : tl::optional<HIR::PathExprSegment *>
     575        33167 : Mappings::lookup_hir_path_expr_seg (HirId id)
     576              : {
     577        33167 :   auto it = hirPathSegMappings.find (id);
     578        33167 :   if (it == hirPathSegMappings.end ())
     579        33167 :     return tl::nullopt;
     580              : 
     581            0 :   return it->second;
     582              : }
     583              : 
     584              : void
     585         8369 : Mappings::insert_hir_generic_param (HIR::GenericParam *param)
     586              : {
     587         8369 :   auto id = param->get_mappings ().get_hirid ();
     588         8369 :   rust_assert (!lookup_hir_generic_param (id));
     589              : 
     590         8369 :   hirGenericParamMappings[id] = param;
     591         8369 :   insert_node_to_hir (param->get_mappings ().get_nodeid (), id);
     592         8369 :   insert_location (id, param->get_locus ());
     593         8369 : }
     594              : 
     595              : tl::optional<HIR::GenericParam *>
     596         8369 : Mappings::lookup_hir_generic_param (HirId id)
     597              : {
     598         8369 :   auto it = hirGenericParamMappings.find (id);
     599         8369 :   if (it == hirGenericParamMappings.end ())
     600         8369 :     return tl::nullopt;
     601              : 
     602            0 :   return it->second;
     603              : }
     604              : 
     605              : void
     606        60165 : Mappings::insert_hir_type (HIR::Type *type)
     607              : {
     608        60165 :   auto id = type->get_mappings ().get_hirid ();
     609        60165 :   rust_assert (!lookup_hir_type (id));
     610              : 
     611        60165 :   hirTypeMappings[id] = type;
     612        60165 :   insert_node_to_hir (type->get_mappings ().get_nodeid (), id);
     613        60165 : }
     614              : 
     615              : tl::optional<HIR::Type *>
     616        60165 : Mappings::lookup_hir_type (HirId id)
     617              : {
     618        60165 :   auto it = hirTypeMappings.find (id);
     619        60165 :   if (it == hirTypeMappings.end ())
     620        60165 :     return tl::nullopt;
     621              : 
     622            0 :   return it->second;
     623              : }
     624              : 
     625              : void
     626        22384 : Mappings::insert_hir_stmt (HIR::Stmt *stmt)
     627              : {
     628        22384 :   auto id = stmt->get_mappings ().get_hirid ();
     629        22384 :   rust_assert (!lookup_hir_stmt (id));
     630              : 
     631        22384 :   hirStmtMappings[id] = stmt;
     632        22384 :   insert_node_to_hir (stmt->get_mappings ().get_nodeid (), id);
     633        22384 : }
     634              : 
     635              : tl::optional<HIR::Stmt *>
     636        22384 : Mappings::lookup_hir_stmt (HirId id)
     637              : {
     638        22384 :   auto it = hirStmtMappings.find (id);
     639        22384 :   if (it == hirStmtMappings.end ())
     640        22384 :     return tl::nullopt;
     641              : 
     642            0 :   return it->second;
     643              : }
     644              : 
     645              : void
     646         7937 : Mappings::insert_hir_param (HIR::FunctionParam *param)
     647              : {
     648         7937 :   auto id = param->get_mappings ().get_hirid ();
     649         7937 :   rust_assert (!lookup_hir_param (id));
     650              : 
     651         7937 :   hirParamMappings[id] = param;
     652         7937 :   insert_node_to_hir (param->get_mappings ().get_nodeid (), id);
     653         7937 : }
     654              : 
     655              : tl::optional<HIR::FunctionParam *>
     656         7937 : Mappings::lookup_hir_param (HirId id)
     657              : {
     658         7937 :   auto it = hirParamMappings.find (id);
     659         7937 :   if (it == hirParamMappings.end ())
     660         7937 :     return tl::nullopt;
     661              : 
     662            0 :   return it->second;
     663              : }
     664              : 
     665              : void
     666         7955 : Mappings::insert_hir_self_param (HIR::SelfParam *param)
     667              : {
     668         7955 :   auto id = param->get_mappings ().get_hirid ();
     669         7955 :   rust_assert (!lookup_hir_self_param (id));
     670              : 
     671         7955 :   hirSelfParamMappings[id] = param;
     672         7955 :   insert_node_to_hir (param->get_mappings ().get_nodeid (), id);
     673         7955 : }
     674              : 
     675              : tl::optional<HIR::SelfParam *>
     676         7955 : Mappings::lookup_hir_self_param (HirId id)
     677              : {
     678         7955 :   auto it = hirSelfParamMappings.find (id);
     679         7955 :   if (it == hirSelfParamMappings.end ())
     680         7955 :     return tl::nullopt;
     681              : 
     682            0 :   return it->second;
     683              : }
     684              : 
     685              : void
     686         2284 : Mappings::insert_hir_struct_field (HIR::StructExprField *field)
     687              : {
     688         2284 :   auto id = field->get_mappings ().get_hirid ();
     689         2284 :   rust_assert (!lookup_hir_struct_field (id));
     690              : 
     691         2284 :   hirStructFieldMappings[id] = field;
     692         2284 :   insert_node_to_hir (field->get_mappings ().get_nodeid (), id);
     693         2284 : }
     694              : 
     695              : tl::optional<HIR::StructExprField *>
     696         2284 : Mappings::lookup_hir_struct_field (HirId id)
     697              : {
     698         2284 :   auto it = hirStructFieldMappings.find (id);
     699         2284 :   if (it == hirStructFieldMappings.end ())
     700         2284 :     return tl::nullopt;
     701              : 
     702            0 :   return it->second;
     703              : }
     704              : 
     705              : void
     706        25944 : Mappings::insert_hir_pattern (HIR::Pattern *pattern)
     707              : {
     708        25944 :   auto id = pattern->get_mappings ().get_hirid ();
     709        25944 :   rust_assert (!lookup_hir_pattern (id));
     710              : 
     711        25944 :   hirPatternMappings[id] = pattern;
     712        25944 :   insert_node_to_hir (pattern->get_mappings ().get_nodeid (), id);
     713        25944 : }
     714              : 
     715              : tl::optional<HIR::Pattern *>
     716        84343 : Mappings::lookup_hir_pattern (HirId id)
     717              : {
     718        84343 :   auto it = hirPatternMappings.find (id);
     719        84343 :   if (it == hirPatternMappings.end ())
     720        57408 :     return tl::nullopt;
     721              : 
     722        26935 :   return it->second;
     723              : }
     724              : 
     725              : void
     726        31264 : Mappings::insert_local_defid_mapping (CrateNum crateNum, LocalDefId id,
     727              :                                       HIR::Item *item)
     728              : {
     729        31264 :   rust_assert (!lookup_local_defid (crateNum, id));
     730        31264 :   localDefIdMappings[crateNum][id] = item;
     731        31264 : }
     732              : 
     733              : tl::optional<HIR::Item *>
     734        65849 : Mappings::lookup_local_defid (CrateNum crateNum, LocalDefId id)
     735              : {
     736        65849 :   auto it = localDefIdMappings.find (crateNum);
     737        65849 :   if (it == localDefIdMappings.end ())
     738         8677 :     return tl::nullopt;
     739              : 
     740        57172 :   auto iy = it->second.find (id);
     741        57172 :   if (iy == it->second.end ())
     742        57172 :     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       454353 : Mappings::insert_node_to_hir (NodeId id, HirId ref)
     764              : {
     765       454353 :   nodeIdToHirMappings[id] = ref;
     766       454353 :   hirIdToNodeMappings[ref] = id;
     767       454353 : }
     768              : 
     769              : tl::optional<HirId>
     770      2532611 : Mappings::lookup_node_to_hir (NodeId id)
     771              : {
     772      2532611 :   auto it = nodeIdToHirMappings.find (id);
     773      2532611 :   if (it == nodeIdToHirMappings.end ())
     774            0 :     return tl::nullopt;
     775              : 
     776      2532611 :   return {it->second};
     777              : }
     778              : 
     779              : tl::optional<NodeId>
     780         6984 : Mappings::lookup_hir_to_node (HirId id)
     781              : {
     782         6984 :   auto it = hirIdToNodeMappings.find (id);
     783         6984 :   if (it == hirIdToNodeMappings.end ())
     784            0 :     return tl::nullopt;
     785              : 
     786         6984 :   return {it->second};
     787              : }
     788              : 
     789              : void
     790       601142 : Mappings::insert_location (HirId id, location_t locus)
     791              : {
     792       601142 :   locations[id] = locus;
     793       601142 : }
     794              : 
     795              : location_t
     796      4436436 : Mappings::lookup_location (HirId id)
     797              : {
     798      4436436 :   auto it = locations.find (id);
     799      4436436 :   if (it == locations.end ())
     800              :     return UNDEF_LOCATION;
     801              : 
     802      4362914 :   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        15572 : Mappings::iterate_impl_items (
     818              :   std::function<bool (HirId, HIR::ImplItem *, HIR::ImplBlock *)> cb)
     819              : {
     820       338421 :   for (auto it = hirImplItemMappings.begin (); it != hirImplItemMappings.end ();
     821       322849 :        it++)
     822              :     {
     823       322849 :       auto id = it->first;
     824       322849 :       auto impl_item = it->second.second;
     825       322849 :       auto impl
     826       322849 :         = lookup_associated_impl (impl_item->get_impl_mappings ().get_hirid ());
     827       322849 :       if (!cb (id, impl_item, impl))
     828        15572 :         return;
     829              :     }
     830              : }
     831              : 
     832              : void
     833        75447 : Mappings::iterate_impl_blocks (std::function<bool (HirId, HIR::ImplBlock *)> cb)
     834              : {
     835      2209449 :   for (auto it = hirImplBlockMappings.begin ();
     836      2209449 :        it != hirImplBlockMappings.end (); it++)
     837              :     {
     838      2134002 :       HirId id = it->first;
     839      2134002 :       HIR::ImplBlock *impl_block = it->second;
     840      2134002 :       if (!cb (id, impl_block))
     841        75447 :         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          968 : Mappings::insert_macro_def (AST::MacroRulesDefinition *macro)
     863              : {
     864          968 :   auto outer_attrs = macro->get_outer_attrs ();
     865          968 :   bool should_be_builtin
     866          968 :     = std::any_of (outer_attrs.begin (), outer_attrs.end (),
     867          160 :                    [] (AST::Attribute attr) {
     868          160 :                      return attr.get_path ()
     869          160 :                             == Values::Attributes::RUSTC_BUILTIN_MACRO;
     870              :                    });
     871          968 :   if (should_be_builtin)
     872              :     {
     873          147 :       auto builtin
     874          147 :         = MacroBuiltin::builtins.lookup (macro->get_rule_name ().as_string ());
     875          147 :       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          145 :       auto transcriber = MacroBuiltin::builtin_transcribers.find (
     884          145 :         macro->get_rule_name ().as_string ());
     885          145 :       macro->set_builtin_transcriber (transcriber->second);
     886              :     }
     887              : 
     888          966 :   auto it = macroMappings.find (macro->get_node_id ());
     889          966 :   rust_assert (it == macroMappings.end ());
     890              : 
     891          966 :   macroMappings[macro->get_node_id ()] = {macro, currentCrateNum};
     892          968 : }
     893              : 
     894              : tl::optional<AST::MacroRulesDefinition *>
     895        14063 : Mappings::lookup_macro_def (NodeId id)
     896              : {
     897        14063 :   auto it = macroMappings.find (id);
     898        14063 :   if (it == macroMappings.end ())
     899          968 :     return tl::nullopt;
     900              : 
     901        13095 :   return it->second.first;
     902              : }
     903              : 
     904              : tl::optional<CrateNum>
     905           10 : Mappings::lookup_macro_def_crate (NodeId id)
     906              : {
     907           10 :   auto it = macroMappings.find (id);
     908           10 :   if (it == macroMappings.end ())
     909            0 :     return tl::nullopt;
     910              : 
     911           10 :   return it->second.second;
     912              : }
     913              : 
     914              : void
     915         2800 : Mappings::insert_macro_invocation (AST::MacroInvocation &invoc,
     916              :                                    AST::MacroRulesDefinition *def)
     917              : {
     918         2800 :   auto it = macroInvocations.find (invoc.get_macro_node_id ());
     919         2800 :   rust_assert (it == macroInvocations.end ());
     920              : 
     921         2800 :   macroInvocations[invoc.get_macro_node_id ()] = def;
     922         2800 : }
     923              : 
     924              : tl::optional<AST::MacroRulesDefinition *>
     925         8439 : Mappings::lookup_macro_invocation (AST::MacroInvocation &invoc)
     926              : {
     927         8439 :   auto it = macroInvocations.find (invoc.get_macro_node_id ());
     928         8439 :   if (it == macroInvocations.end ())
     929         2839 :     return tl::nullopt;
     930              : 
     931         5600 :   return it->second;
     932              : }
     933              : 
     934              : void
     935            2 : Mappings::insert_exported_macro (AST::MacroRulesDefinition &def)
     936              : {
     937            2 :   exportedMacros.emplace_back (def);
     938            2 : }
     939              : 
     940              : std::vector<AST::MacroRulesDefinition>
     941         4028 : Mappings::get_exported_macros ()
     942              : {
     943         4028 :   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           72 : Mappings::lookup_derive_proc_macros (CrateNum num)
     978              : {
     979           72 :   auto it = procmacrosDeriveMappings.find (num);
     980           72 :   if (it == procmacrosDeriveMappings.end ())
     981            0 :     return tl::nullopt;
     982              : 
     983           72 :   return it->second;
     984              : }
     985              : 
     986              : tl::optional<std::vector<BangProcMacro> &>
     987           72 : Mappings::lookup_bang_proc_macros (CrateNum num)
     988              : {
     989           72 :   auto it = procmacrosBangMappings.find (num);
     990           72 :   if (it == procmacrosBangMappings.end ())
     991            0 :     return tl::nullopt;
     992              : 
     993           72 :   return it->second;
     994              : }
     995              : 
     996              : tl::optional<std::vector<AttributeProcMacro> &>
     997           72 : Mappings::lookup_attribute_proc_macros (CrateNum num)
     998              : {
     999           72 :   auto it = procmacrosAttributeMappings.find (num);
    1000           72 :   if (it == procmacrosAttributeMappings.end ())
    1001            0 :     return tl::nullopt;
    1002              : 
    1003           72 :   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            0 : Mappings::lookup_derive_proc_macro_def (NodeId id)
    1035              : {
    1036            0 :   auto it = procmacroDeriveMappings.find (id);
    1037            0 :   if (it == procmacroDeriveMappings.end ())
    1038            0 :     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            0 : Mappings::lookup_derive_proc_macro_invocation (AST::SimplePath &invoc)
    1075              : {
    1076            0 :   auto it = procmacroDeriveInvocations.find (invoc.get_node_id ());
    1077            0 :   if (it == procmacroDeriveInvocations.end ())
    1078            0 :     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_macro_node_id ());
    1088            0 :   rust_assert (it == procmacroBangInvocations.end ());
    1089              : 
    1090            0 :   procmacroBangInvocations[invoc.get_macro_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_macro_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        29162 : Mappings::insert_visibility (NodeId id, Privacy::ModuleVisibility visibility)
    1125              : {
    1126        29162 :   visibility_map.insert ({id, visibility});
    1127        29162 : }
    1128              : 
    1129              : tl::optional<Privacy::ModuleVisibility &>
    1130        67389 : Mappings::lookup_visibility (NodeId id)
    1131              : {
    1132        67389 :   auto it = visibility_map.find (id);
    1133        67389 :   if (it == visibility_map.end ())
    1134        46947 :     return tl::nullopt;
    1135              : 
    1136        20442 :   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         6359 : Mappings::insert_glob_container (NodeId id, AST::GlobContainer *container)
    1161              : {
    1162         6359 :   rust_assert (glob_containers.find (id) == glob_containers.end ());
    1163              : 
    1164              :   // Crates have different memory managements that regular items
    1165         6359 :   if (container->get_glob_container_kind () == AST::GlobContainer::Kind::Crate)
    1166         4510 :     glob_containers[id] = get_ast_crate_by_node_id_raw (id);
    1167              :   else
    1168         1849 :     glob_containers[id] = container;
    1169         6359 : }
    1170              : 
    1171              : tl::optional<AST::GlobContainer *>
    1172        24842 : Mappings::lookup_glob_container (NodeId id)
    1173              : {
    1174        24842 :   auto it = glob_containers.find (id);
    1175        24842 :   if (it == glob_containers.end ())
    1176         7776 :     return tl::nullopt;
    1177              : 
    1178        17066 :   return {it->second};
    1179              : }
    1180              : 
    1181              : void
    1182            0 : Mappings::insert_module_child_item (NodeId module,
    1183              :                                     Resolver::CanonicalPath child)
    1184              : {
    1185            0 :   rust_assert (!child.is_empty ());
    1186            0 :   rust_assert (child.get_node_id () != UNKNOWN_NODEID);
    1187              : 
    1188            0 :   auto it = module_child_items.find (module);
    1189            0 :   if (it == module_child_items.end ())
    1190            0 :     module_child_items.insert ({module, {child}});
    1191              :   else
    1192            0 :     it->second.emplace_back (child);
    1193            0 : }
    1194              : 
    1195              : tl::optional<std::vector<Resolver::CanonicalPath> &>
    1196            0 : Mappings::lookup_module_chidren_items (NodeId module)
    1197              : {
    1198            0 :   auto it = module_child_items.find (module);
    1199            0 :   if (it == module_child_items.end ())
    1200            0 :     return tl::nullopt;
    1201              : 
    1202            0 :   return it->second;
    1203              : }
    1204              : 
    1205              : tl::optional<Resolver::CanonicalPath &>
    1206            0 : Mappings::lookup_module_child (NodeId module, const std::string &item_name)
    1207              : {
    1208            0 :   tl::optional<std::vector<Resolver::CanonicalPath> &> children
    1209            0 :     = lookup_module_chidren_items (module);
    1210            0 :   if (!children.has_value ())
    1211            0 :     return tl::nullopt;
    1212              : 
    1213              :   // lookup the children to match the name if we can
    1214            0 :   for (auto &child : children.value ())
    1215              :     {
    1216            0 :       const std::string &raw_identifier = child.get ();
    1217            0 :       bool found = raw_identifier.compare (item_name) == 0;
    1218            0 :       if (found)
    1219            0 :         return child;
    1220            0 :     }
    1221              : 
    1222            0 :   return tl::nullopt;
    1223              : }
    1224              : 
    1225              : void
    1226            0 : Mappings::insert_child_item_to_parent_module_mapping (NodeId child_item,
    1227              :                                                       NodeId parent_module)
    1228              : {
    1229            0 :   child_to_parent_module_map.insert ({child_item, parent_module});
    1230            0 : }
    1231              : 
    1232              : tl::optional<NodeId>
    1233            0 : Mappings::lookup_parent_module (NodeId child_item)
    1234              : {
    1235            0 :   auto it = child_to_parent_module_map.find (child_item);
    1236            0 :   if (it == child_to_parent_module_map.end ())
    1237            0 :     return tl::nullopt;
    1238              : 
    1239            0 :   return it->second;
    1240              : }
    1241              : 
    1242              : bool
    1243            0 : Mappings::node_is_module (NodeId query)
    1244              : {
    1245            0 :   return module_child_items.find (query) != module_child_items.end ();
    1246              : }
    1247              : 
    1248              : void
    1249        21955 : Mappings::insert_ast_item (AST::Item *item)
    1250              : {
    1251        21955 :   auto it = ast_item_mappings.find (item->get_node_id ());
    1252        21955 :   rust_assert (it == ast_item_mappings.end ());
    1253              : 
    1254        21955 :   ast_item_mappings[item->get_node_id ()] = item;
    1255        21955 : }
    1256              : 
    1257              : tl::optional<AST::Item *>
    1258         2622 : Mappings::lookup_ast_item (NodeId id)
    1259              : {
    1260         2622 :   auto it = ast_item_mappings.find (id);
    1261         2622 :   if (it == ast_item_mappings.end ())
    1262            0 :     return tl::nullopt;
    1263              : 
    1264         2622 :   return it->second;
    1265              : }
    1266              : 
    1267              : HIR::ImplBlock *
    1268        66215 : Mappings::lookup_builtin_marker ()
    1269              : {
    1270        66215 :   return builtinMarker;
    1271              : }
    1272              : 
    1273              : // FIXME: Before merging: Should we remove the `locus` parameter here? since
    1274              : // lang items are looked up mostly for code generation, it doesn't make sense to
    1275              : // error out on the locus of the node trying to access an inexistant lang item
    1276              : DefId
    1277         9325 : Mappings::get_lang_item (LangItem::Kind item_type, location_t locus)
    1278              : {
    1279         9325 :   if (auto item = lookup_lang_item (item_type))
    1280         9324 :     return *item;
    1281              : 
    1282            2 :   rust_fatal_error (locus, "failed to find lang item %s",
    1283            1 :                     LangItem::ToString (item_type).c_str ());
    1284              : }
    1285              : 
    1286              : tl::optional<HIR::TraitItem *>
    1287           27 : Mappings::lookup_trait_item_lang_item (LangItem::Kind item, location_t locus)
    1288              : {
    1289           27 :   DefId trait_item_id = get_lang_item (item, locus);
    1290           27 :   return lookup_trait_item_defid (trait_item_id);
    1291              : }
    1292              : 
    1293              : void
    1294         3191 : Mappings::insert_lang_item (LangItem::Kind item_type, DefId id)
    1295              : {
    1296         3191 :   auto it = lang_item_mappings.find (item_type);
    1297         3191 :   rust_assert (it == lang_item_mappings.end ());
    1298              : 
    1299         3191 :   lang_item_mappings[item_type] = id;
    1300         3191 : }
    1301              : 
    1302              : tl::optional<DefId &>
    1303        97435 : Mappings::lookup_lang_item (LangItem::Kind item_type)
    1304              : {
    1305        97435 :   auto it = lang_item_mappings.find (item_type);
    1306        97435 :   if (it == lang_item_mappings.end ())
    1307        17921 :     return tl::nullopt;
    1308              : 
    1309        79514 :   return it->second;
    1310              : }
    1311              : 
    1312              : void
    1313         3227 : Mappings::insert_lang_item_node (LangItem::Kind item_type, NodeId node_id)
    1314              : {
    1315         3227 :   auto it = lang_item_nodes.find (item_type);
    1316         3227 :   rust_assert (it == lang_item_nodes.end ());
    1317              : 
    1318         3227 :   lang_item_nodes.insert ({item_type, node_id});
    1319         3227 : }
    1320              : 
    1321              : tl::optional<NodeId &>
    1322          805 : Mappings::lookup_lang_item_node (LangItem::Kind item_type)
    1323              : {
    1324          805 :   auto it = lang_item_nodes.find (item_type);
    1325          805 :   if (it == lang_item_nodes.end ())
    1326            0 :     return tl::nullopt;
    1327              : 
    1328          805 :   return it->second;
    1329              : }
    1330              : 
    1331              : NodeId
    1332          805 : Mappings::get_lang_item_node (LangItem::Kind item_type)
    1333              : {
    1334          805 :   if (auto lookup = lookup_lang_item_node (item_type))
    1335          805 :     return *lookup;
    1336              : 
    1337            0 :   rust_fatal_error (UNKNOWN_LOCATION, "undeclared lang item: %qs",
    1338            0 :                     LangItem::PrettyString (item_type).c_str ());
    1339              : }
    1340              : 
    1341              : void
    1342           12 : Mappings::insert_auto_trait (HIR::Trait *trait)
    1343              : {
    1344           12 :   auto_traits.emplace_back (trait);
    1345           12 : }
    1346              : 
    1347              : std::vector<HIR::Trait *> &
    1348        66508 : Mappings::get_auto_traits ()
    1349              : {
    1350        66508 :   return auto_traits;
    1351              : }
    1352              : 
    1353              : void
    1354           21 : Mappings::add_capture (NodeId closure, NodeId definition)
    1355              : {
    1356           21 :   auto cap = captures.find (closure);
    1357           21 :   if (cap == captures.end ())
    1358           21 :     captures[closure] = {definition};
    1359              :   else
    1360            0 :     cap->second.push_back (definition);
    1361           21 : }
    1362              : 
    1363              : tl::optional<std::vector<NodeId>>
    1364           65 : Mappings::lookup_captures (NodeId closure)
    1365              : {
    1366           65 :   auto cap = captures.find (closure);
    1367           65 :   if (cap == captures.end ())
    1368           44 :     return tl::nullopt;
    1369              :   else
    1370           21 :     return cap->second;
    1371              : }
    1372              : 
    1373              : void
    1374          431 : Mappings::add_derived_node (NodeId node_id)
    1375              : {
    1376          431 :   derived_nodes.insert (node_id);
    1377          431 : }
    1378              : 
    1379              : bool
    1380            0 : Mappings::is_derived_node (NodeId node_id)
    1381              : {
    1382            0 :   return derived_nodes.find (node_id) != derived_nodes.end ();
    1383              : }
    1384              : 
    1385              : } // namespace Analysis
    1386              : } // 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.