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.3 % 712 572
Test Date: 2026-07-11 15:47:05 Functions: 83.6 % 140 117
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        47778 : NodeMapping::get_error ()
      35              : {
      36        47778 :   return NodeMapping (UNKNOWN_CRATENUM, UNKNOWN_NODEID, UNKNOWN_HIRID,
      37        47778 :                       UNKNOWN_LOCAL_DEFID);
      38              : }
      39              : 
      40              : CrateNum
      41      1915532 : NodeMapping::get_crate_num () const
      42              : {
      43      1915532 :   return crateNum;
      44              : }
      45              : 
      46              : NodeId
      47      4134825 : NodeMapping::get_nodeid () const
      48              : {
      49      4134825 :   return nodeId;
      50              : }
      51              : 
      52              : HirId
      53      5447229 : NodeMapping::get_hirid () const
      54              : {
      55      5447229 :   return hirId;
      56              : }
      57              : 
      58              : LocalDefId
      59      1911200 : NodeMapping::get_local_defid () const
      60              : {
      61      1911200 :   return localDefId;
      62              : }
      63              : 
      64              : DefId
      65      1906580 : NodeMapping::get_defid () const
      66              : {
      67      1906580 :   return get_defid (get_crate_num (), get_local_defid ());
      68              : }
      69              : 
      70              : DefId
      71      1906580 : NodeMapping::get_defid (CrateNum crate_num, LocalDefId local_defid)
      72              : {
      73      1906580 :   return DefId{crate_num, local_defid};
      74              : }
      75              : 
      76              : std::string
      77         1184 : NodeMapping::as_string () const
      78              : {
      79         1184 :   std::ostringstream ss;
      80         1184 :   ss << "["
      81         1184 :      << "C: " << get_crate_num ();
      82         1184 :   if (get_nodeid () != UNKNOWN_NODEID)
      83         1184 :     ss << " Nid: " << get_nodeid ();
      84              : 
      85         1184 :   if (get_hirid () != UNKNOWN_HIRID)
      86         1184 :     ss << " Hid: " << get_hirid ();
      87              : 
      88         1184 :   if (get_local_defid () != UNKNOWN_LOCAL_DEFID)
      89         1184 :     ss << " Lid: " << get_local_defid ();
      90              : 
      91         1184 :   ss << "]";
      92         1184 :   return ss.str ();
      93         1184 : }
      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         4910 : Mappings::Mappings ()
     101         4910 :   : crateNumItr (kDefaultCrateNumBegin), currentCrateNum (UNKNOWN_CRATENUM),
     102         4910 :     hirIdIter (kDefaultHirIdBegin), nodeIdIter (kDefaultNodeIdBegin)
     103              : {
     104         4910 :   Analysis::NodeMapping node (0, 0, 0, 0);
     105         4910 :   builtinMarker
     106         9820 :     = new HIR::ImplBlock (node, {}, {}, nullptr, nullptr, HIR::WhereClause ({}),
     107              :                           BoundPolarity::RegularBound,
     108         9820 :                           HIR::Visibility (HIR::Visibility::VisType::Public),
     109         9820 :                           {}, {}, UNDEF_LOCATION);
     110         4910 : }
     111              : 
     112         9820 : Mappings::~Mappings () { delete builtinMarker; }
     113              : 
     114              : Mappings &
     115    113454175 : Mappings::get ()
     116              : {
     117    113459085 :   static Mappings instance{};
     118    113454175 :   return instance;
     119              : }
     120              : 
     121              : CrateNum
     122         4821 : Mappings::get_next_crate_num (const std::string &name)
     123              : {
     124         4821 :   auto id = crateNumItr;
     125         4821 :   crateNumItr++;
     126         4821 :   set_crate_name (id, name);
     127         4821 :   return id;
     128              : }
     129              : 
     130              : void
     131         4893 : Mappings::set_current_crate (CrateNum crateNum)
     132              : {
     133         4893 :   currentCrateNum = crateNum;
     134         4893 : }
     135              : 
     136              : CrateNum
     137       896341 : Mappings::get_current_crate () const
     138              : {
     139       896341 :   return currentCrateNum;
     140              : }
     141              : 
     142              : tl::optional<const std::string &>
     143        44258 : Mappings::get_crate_name (CrateNum crate_num) const
     144              : {
     145        44258 :   auto it = crate_names.find (crate_num);
     146        44258 :   if (it == crate_names.end ())
     147            0 :     return tl::nullopt;
     148              : 
     149        44258 :   return it->second;
     150              : }
     151              : 
     152              : tl::optional<CrateNum>
     153        72061 : Mappings::lookup_crate_num (NodeId node_id) const
     154              : {
     155        72061 :   auto it = crate_node_to_crate_num.find (node_id);
     156        72061 :   if (it == crate_node_to_crate_num.end ())
     157        30975 :     return tl::nullopt;
     158              : 
     159        41086 :   return it->second;
     160              : }
     161              : 
     162              : void
     163         4821 : Mappings::set_crate_name (CrateNum crate_num, const std::string &name)
     164              : {
     165         4821 :   crate_names[crate_num] = name;
     166         4821 : }
     167              : 
     168              : const std::string &
     169        12762 : Mappings::get_current_crate_name () const
     170              : {
     171        12762 :   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        19108 : Mappings::crate_num_to_nodeid (const CrateNum &crate_num) const
     187              : {
     188        19108 :   auto it = ast_crate_mappings.find (crate_num);
     189        19108 :   if (it == ast_crate_mappings.end ())
     190            0 :     return tl::nullopt;
     191              : 
     192        19108 :   return it->second->get_node_id ();
     193              : }
     194              : 
     195              : bool
     196        35770 : Mappings::node_is_crate (NodeId node_id) const
     197              : {
     198        35770 :   return lookup_crate_num (node_id).has_value ();
     199              : }
     200              : 
     201              : NodeId
     202      1399911 : Mappings::get_next_node_id ()
     203              : {
     204      1399911 :   auto it = nodeIdIter;
     205      1399911 :   if (UNLIKELY (it > MAX_NODEID))
     206            0 :     rust_fatal_error (UNKNOWN_LOCATION, "out of node ids");
     207      1399911 :   nodeIdIter++;
     208      1399911 :   return it;
     209              : }
     210              : 
     211              : HirId
     212       845088 : Mappings::get_next_hir_id (CrateNum crateNum)
     213              : {
     214       845088 :   auto id = hirIdIter;
     215       845088 :   hirIdIter++;
     216              : 
     217       845088 :   auto it = hirNodesWithinCrate.find (crateNum);
     218       845088 :   if (it == hirNodesWithinCrate.end ())
     219              :     {
     220         4791 :       hirNodesWithinCrate.insert ({crateNum, {}});
     221              :     }
     222              : 
     223       845088 :   hirNodesWithinCrate[crateNum].insert (id);
     224       845088 :   return id;
     225              : }
     226              : 
     227              : LocalDefId
     228       131264 : Mappings::get_next_localdef_id (CrateNum crateNum)
     229              : {
     230       131264 :   auto it = localIdIter.find (crateNum);
     231       131264 :   if (it == localIdIter.end ())
     232              :     {
     233         4553 :       localIdIter.insert ({crateNum, 1});
     234              :     }
     235              : 
     236       131264 :   it = localIdIter.find (crateNum);
     237       131264 :   rust_assert (it != localIdIter.end ());
     238              : 
     239       131264 :   LocalDefId id = it->second;
     240       131264 :   localIdIter[crateNum] = id + 1;
     241       131264 :   return id;
     242              : }
     243              : 
     244              : AST::Crate &
     245         4728 : Mappings::get_ast_crate (CrateNum crateNum)
     246              : {
     247         4728 :   auto it = ast_crate_mappings.find (crateNum);
     248         4728 :   rust_assert (it != ast_crate_mappings.end ());
     249         4728 :   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         4771 : Mappings::get_ast_crate_by_node_id_raw (NodeId id)
     260              : {
     261         4771 :   auto i = crate_node_to_crate_num.find (id);
     262         4771 :   rust_assert (i != crate_node_to_crate_num.end ());
     263              : 
     264         4771 :   CrateNum crateNum = i->second;
     265         4771 :   auto it = ast_crate_mappings.find (crateNum);
     266         4771 :   rust_assert (it != ast_crate_mappings.end ());
     267         4771 :   return it->second;
     268              : }
     269              : 
     270              : AST::Crate &
     271         4821 : Mappings::insert_ast_crate (std::unique_ptr<AST::Crate> &&crate,
     272              :                             CrateNum crate_num)
     273              : {
     274         4821 :   auto it = ast_crate_mappings.find (crate_num);
     275         4821 :   rust_assert (it == ast_crate_mappings.end ());
     276              : 
     277              :   // store it
     278         4821 :   crate_node_to_crate_num.insert ({crate->get_node_id (), crate_num});
     279         4821 :   ast_crate_mappings.insert ({crate_num, crate.release ()});
     280              : 
     281              :   // return the reference to it
     282         4821 :   it = ast_crate_mappings.find (crate_num);
     283         4821 :   rust_assert (it != ast_crate_mappings.end ());
     284         4821 :   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       106092 : Mappings::is_local_hirid_crate (HirId crateNum)
     297              : {
     298       211720 :   for (const auto &it : hir_crate_mappings)
     299              :     {
     300       106300 :       const auto &crate = it.second;
     301       106300 :       if (crate->get_mappings ().get_hirid () == crateNum)
     302       106092 :         return true;
     303              :     }
     304              :   return false;
     305              : }
     306              : 
     307              : HIR::Crate &
     308         4568 : Mappings::insert_hir_crate (std::unique_ptr<HIR::Crate> &&crate)
     309              : {
     310         4568 :   CrateNum crateNum = crate->get_mappings ().get_crate_num ();
     311         4568 :   auto it = hir_crate_mappings.find (crateNum);
     312         4568 :   rust_assert (it == hir_crate_mappings.end ());
     313              : 
     314         4568 :   insert_node_to_hir (crate->get_mappings ().get_nodeid (),
     315         4568 :                       crate->get_mappings ().get_hirid ());
     316         4568 :   hir_crate_mappings.insert ({crateNum, crate.release ()});
     317              : 
     318         4568 :   it = hir_crate_mappings.find (crateNum);
     319         4568 :   rust_assert (it != hir_crate_mappings.end ());
     320         4568 :   return *it->second;
     321              : }
     322              : 
     323              : void
     324        32283 : Mappings::insert_defid_mapping (DefId id, HIR::Item *item)
     325              : {
     326        32283 :   CrateNum crate_num = id.crateNum;
     327        32283 :   LocalDefId local_def_id = id.localDefId;
     328              : 
     329        32283 :   rust_assert (!lookup_defid (id));
     330        32283 :   rust_assert (!lookup_local_defid (crate_num, local_def_id));
     331        32283 :   rust_assert (!lookup_trait_item_defid (id));
     332              : 
     333        32283 :   defIdMappings[id] = item;
     334        32283 :   insert_local_defid_mapping (crate_num, local_def_id, item);
     335        32283 : }
     336              : 
     337              : tl::optional<HIR::Item *>
     338       132307 : Mappings::lookup_defid (DefId id)
     339              : {
     340       132307 :   auto it = defIdMappings.find (id);
     341       132307 :   if (it == defIdMappings.end ())
     342        36577 :     return tl::nullopt;
     343              : 
     344        95730 :   return it->second;
     345              : }
     346              : 
     347              : void
     348         3367 : Mappings::insert_defid_mapping (DefId id, HIR::TraitItem *item)
     349              : {
     350         3367 :   CrateNum crate_num = id.crateNum;
     351         3367 :   LocalDefId local_def_id = id.localDefId;
     352              : 
     353         3367 :   rust_assert (!lookup_defid (id));
     354         3367 :   rust_assert (!lookup_local_defid (crate_num, local_def_id));
     355         3367 :   rust_assert (!lookup_trait_item_defid (id));
     356              : 
     357         3367 :   defIdTraitItemMappings[id] = item;
     358         3367 : }
     359              : 
     360              : tl::optional<HIR::TraitItem *>
     361        38391 : Mappings::lookup_trait_item_defid (DefId id)
     362              : {
     363        38391 :   auto it = defIdTraitItemMappings.find (id);
     364        38391 :   if (it == defIdTraitItemMappings.end ())
     365        37396 :     return tl::nullopt;
     366              : 
     367          995 :   return it->second;
     368              : }
     369              : 
     370              : void
     371        22846 : Mappings::insert_hir_item (HIR::Item *item)
     372              : {
     373        22846 :   auto id = item->get_mappings ().get_hirid ();
     374        22846 :   rust_assert (!lookup_hir_item (id).has_value ());
     375              : 
     376        22846 :   hirItemMappings[id] = item;
     377        22846 :   insert_node_to_hir (item->get_mappings ().get_nodeid (), id);
     378        22846 : }
     379              : 
     380              : tl::optional<HIR::Item *>
     381      2923225 : Mappings::lookup_hir_item (HirId id)
     382              : {
     383      2923225 :   auto it = hirItemMappings.find (id);
     384      2923225 :   if (it == hirItemMappings.end ())
     385       131163 :     return tl::nullopt;
     386      2792062 :   return it->second;
     387              : }
     388              : 
     389              : void
     390         1246 : Mappings::insert_hir_enumitem (HIR::Enum *parent, HIR::EnumItem *item)
     391              : {
     392         1246 :   auto id = item->get_mappings ().get_hirid ();
     393         1246 :   auto result = lookup_hir_enumitem (id);
     394         1246 :   rust_assert (result.first == nullptr);
     395              : 
     396         1246 :   hirEnumItemMappings[id] = {parent, item};
     397         1246 :   insert_node_to_hir (item->get_mappings ().get_nodeid (), id);
     398         1246 : }
     399              : 
     400              : std::pair<HIR::Enum *, HIR::EnumItem *>
     401        66773 : Mappings::lookup_hir_enumitem (HirId id)
     402              : {
     403        66773 :   auto it = hirEnumItemMappings.find (id);
     404        66773 :   if (it == hirEnumItemMappings.end ())
     405        58226 :     return {nullptr, nullptr};
     406              : 
     407         8547 :   return it->second;
     408              : }
     409              : 
     410              : void
     411         3367 : Mappings::insert_hir_trait_item (HIR::TraitItem *item)
     412              : {
     413         3367 :   auto id = item->get_mappings ().get_hirid ();
     414         3367 :   rust_assert (!lookup_hir_trait_item (id).has_value ());
     415              : 
     416         3367 :   hirTraitItemMappings[id] = item;
     417         3367 :   insert_node_to_hir (item->get_mappings ().get_nodeid (), id);
     418         3367 : }
     419              : 
     420              : tl::optional<HIR::TraitItem *>
     421         3671 : Mappings::lookup_hir_trait_item (HirId id)
     422              : {
     423         3671 :   auto it = hirTraitItemMappings.find (id);
     424         3671 :   if (it == hirTraitItemMappings.end ())
     425         3425 :     return tl::nullopt;
     426              : 
     427          246 :   return it->second;
     428              : }
     429              : 
     430              : void
     431         1653 : Mappings::insert_hir_extern_block (HIR::ExternBlock *block)
     432              : {
     433         1653 :   auto id = block->get_mappings ().get_hirid ();
     434         1653 :   rust_assert (!lookup_hir_extern_block (id).has_value ());
     435              : 
     436         1653 :   hirExternBlockMappings[id] = block;
     437         1653 :   insert_node_to_hir (block->get_mappings ().get_nodeid (), id);
     438         1653 : }
     439              : 
     440              : tl::optional<HIR::ExternBlock *>
     441         2773 : Mappings::lookup_hir_extern_block (HirId id)
     442              : {
     443         2773 :   auto it = hirExternBlockMappings.find (id);
     444         2773 :   if (it == hirExternBlockMappings.end ())
     445         1653 :     return tl::nullopt;
     446              : 
     447         1120 :   return it->second;
     448              : }
     449              : 
     450              : void
     451         2545 : Mappings::insert_hir_extern_item (HIR::ExternalItem *item, HirId parent_block)
     452              : {
     453         2545 :   auto id = item->get_mappings ().get_hirid ();
     454         2545 :   rust_assert (!lookup_hir_extern_item (id));
     455              : 
     456         2545 :   hirExternItemMappings[id] = {item, parent_block};
     457         2545 :   insert_node_to_hir (item->get_mappings ().get_nodeid (), id);
     458         2545 : }
     459              : 
     460              : tl::optional<std::pair<HIR::ExternalItem *, HirId>>
     461        33580 : Mappings::lookup_hir_extern_item (HirId id)
     462              : {
     463        33580 :   auto it = hirExternItemMappings.find (id);
     464        33580 :   if (it == hirExternItemMappings.end ())
     465        31884 :     return tl::nullopt;
     466              : 
     467         1696 :   return it->second;
     468              : }
     469              : 
     470              : void
     471         5697 : Mappings::insert_hir_impl_block (HIR::ImplBlock *item)
     472              : {
     473         5697 :   auto id = item->get_mappings ().get_hirid ();
     474         5697 :   rust_assert (!lookup_hir_impl_block (id));
     475              : 
     476         5697 :   HirId impl_type_id = item->get_type ().get_mappings ().get_hirid ();
     477         5697 :   hirImplBlockMappings[id] = item;
     478         5697 :   hirImplBlockTypeMappings[impl_type_id] = item;
     479         5697 :   insert_node_to_hir (item->get_mappings ().get_nodeid (), id);
     480         5697 : }
     481              : 
     482              : tl::optional<HIR::ImplBlock *>
     483         8688 : Mappings::lookup_hir_impl_block (HirId id)
     484              : {
     485         8688 :   auto it = hirImplBlockMappings.find (id);
     486         8688 :   if (it == hirImplBlockMappings.end ())
     487         5697 :     return tl::nullopt;
     488              : 
     489         2991 :   return it->second;
     490              : }
     491              : 
     492              : tl::optional<HIR::ImplBlock *>
     493         2689 : Mappings::lookup_impl_block_type (HirId id)
     494              : {
     495         2689 :   auto it = hirImplBlockTypeMappings.find (id);
     496         2689 :   if (it == hirImplBlockTypeMappings.end ())
     497           61 :     return tl::nullopt;
     498              : 
     499         2628 :   return it->second;
     500              : }
     501              : 
     502              : void
     503         1212 : Mappings::insert_module (HIR::Module *module)
     504              : {
     505         1212 :   auto id = module->get_mappings ().get_hirid ();
     506         1212 :   rust_assert (!lookup_module (id));
     507              : 
     508         1212 :   hirModuleMappings[id] = module;
     509         1212 :   insert_node_to_hir (module->get_mappings ().get_nodeid (), id);
     510         1212 : }
     511              : 
     512              : tl::optional<HIR::Module *>
     513       107312 : Mappings::lookup_module (HirId id)
     514              : {
     515       107312 :   auto it = hirModuleMappings.find (id);
     516       107312 :   if (it == hirModuleMappings.end ())
     517       104034 :     return tl::nullopt;
     518              : 
     519         3278 :   return it->second;
     520              : }
     521              : 
     522              : void
     523         8191 : Mappings::insert_hir_implitem (HirId parent_impl_id, HIR::ImplItem *item)
     524              : {
     525         8191 :   auto id = item->get_impl_mappings ().get_hirid ();
     526         8191 :   rust_assert (!lookup_hir_implitem (id));
     527              : 
     528         8191 :   hirImplItemMappings[id]
     529         8191 :     = std::pair<HirId, HIR::ImplItem *> (parent_impl_id, item);
     530         8191 :   insert_node_to_hir (item->get_impl_mappings ().get_nodeid (), id);
     531         8191 : }
     532              : 
     533              : tl::optional<std::pair<HIR::ImplItem *, HirId>>
     534       101214 : Mappings::lookup_hir_implitem (HirId id)
     535              : {
     536       101214 :   auto it = hirImplItemMappings.find (id);
     537       101214 :   if (it == hirImplItemMappings.end ())
     538        79978 :     return tl::nullopt;
     539              : 
     540        21236 :   return std::make_pair (it->second.second, it->second.first);
     541              : }
     542              : 
     543              : void
     544       156607 : Mappings::insert_hir_expr (HIR::Expr *expr)
     545              : {
     546       156607 :   auto id = expr->get_mappings ().get_hirid ();
     547       156607 :   hirExprMappings[id] = expr;
     548              : 
     549       156607 :   insert_node_to_hir (expr->get_mappings ().get_nodeid (), id);
     550       156607 :   insert_location (id, expr->get_locus ());
     551       156607 : }
     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        34895 : Mappings::insert_hir_path_expr_seg (HIR::PathExprSegment *expr)
     565              : {
     566        34895 :   auto id = expr->get_mappings ().get_hirid ();
     567        34895 :   rust_assert (!lookup_hir_path_expr_seg (id));
     568              : 
     569        34895 :   hirPathSegMappings[id] = expr;
     570        34895 :   insert_node_to_hir (expr->get_mappings ().get_nodeid (), id);
     571        34895 :   insert_location (id, expr->get_locus ());
     572        34895 : }
     573              : 
     574              : tl::optional<HIR::PathExprSegment *>
     575        34895 : Mappings::lookup_hir_path_expr_seg (HirId id)
     576              : {
     577        34895 :   auto it = hirPathSegMappings.find (id);
     578        34895 :   if (it == hirPathSegMappings.end ())
     579        34895 :     return tl::nullopt;
     580              : 
     581            0 :   return it->second;
     582              : }
     583              : 
     584              : void
     585         8831 : Mappings::insert_hir_generic_param (HIR::GenericParam *param)
     586              : {
     587         8831 :   auto id = param->get_mappings ().get_hirid ();
     588         8831 :   rust_assert (!lookup_hir_generic_param (id));
     589              : 
     590         8831 :   hirGenericParamMappings[id] = param;
     591         8831 :   insert_node_to_hir (param->get_mappings ().get_nodeid (), id);
     592         8831 :   insert_location (id, param->get_locus ());
     593         8831 : }
     594              : 
     595              : tl::optional<HIR::GenericParam *>
     596         8831 : Mappings::lookup_hir_generic_param (HirId id)
     597              : {
     598         8831 :   auto it = hirGenericParamMappings.find (id);
     599         8831 :   if (it == hirGenericParamMappings.end ())
     600         8831 :     return tl::nullopt;
     601              : 
     602            0 :   return it->second;
     603              : }
     604              : 
     605              : void
     606        61763 : Mappings::insert_hir_type (HIR::Type *type)
     607              : {
     608        61763 :   auto id = type->get_mappings ().get_hirid ();
     609        61763 :   rust_assert (!lookup_hir_type (id));
     610              : 
     611        61763 :   hirTypeMappings[id] = type;
     612        61763 :   insert_node_to_hir (type->get_mappings ().get_nodeid (), id);
     613        61763 : }
     614              : 
     615              : tl::optional<HIR::Type *>
     616        61763 : Mappings::lookup_hir_type (HirId id)
     617              : {
     618        61763 :   auto it = hirTypeMappings.find (id);
     619        61763 :   if (it == hirTypeMappings.end ())
     620        61763 :     return tl::nullopt;
     621              : 
     622            0 :   return it->second;
     623              : }
     624              : 
     625              : void
     626        24213 : Mappings::insert_hir_stmt (HIR::Stmt *stmt)
     627              : {
     628        24213 :   auto id = stmt->get_mappings ().get_hirid ();
     629        24213 :   rust_assert (!lookup_hir_stmt (id));
     630              : 
     631        24213 :   hirStmtMappings[id] = stmt;
     632        24213 :   insert_node_to_hir (stmt->get_mappings ().get_nodeid (), id);
     633        24213 : }
     634              : 
     635              : tl::optional<HIR::Stmt *>
     636        24213 : Mappings::lookup_hir_stmt (HirId id)
     637              : {
     638        24213 :   auto it = hirStmtMappings.find (id);
     639        24213 :   if (it == hirStmtMappings.end ())
     640        24213 :     return tl::nullopt;
     641              : 
     642            0 :   return it->second;
     643              : }
     644              : 
     645              : void
     646         7981 : Mappings::insert_hir_param (HIR::FunctionParam *param)
     647              : {
     648         7981 :   auto id = param->get_mappings ().get_hirid ();
     649         7981 :   rust_assert (!lookup_hir_param (id));
     650              : 
     651         7981 :   hirParamMappings[id] = param;
     652         7981 :   insert_node_to_hir (param->get_mappings ().get_nodeid (), id);
     653         7981 : }
     654              : 
     655              : tl::optional<HIR::FunctionParam *>
     656         7981 : Mappings::lookup_hir_param (HirId id)
     657              : {
     658         7981 :   auto it = hirParamMappings.find (id);
     659         7981 :   if (it == hirParamMappings.end ())
     660         7981 :     return tl::nullopt;
     661              : 
     662            0 :   return it->second;
     663              : }
     664              : 
     665              : void
     666         8084 : Mappings::insert_hir_self_param (HIR::SelfParam *param)
     667              : {
     668         8084 :   auto id = param->get_mappings ().get_hirid ();
     669         8084 :   rust_assert (!lookup_hir_self_param (id));
     670              : 
     671         8084 :   hirSelfParamMappings[id] = param;
     672         8084 :   insert_node_to_hir (param->get_mappings ().get_nodeid (), id);
     673         8084 : }
     674              : 
     675              : tl::optional<HIR::SelfParam *>
     676         8084 : Mappings::lookup_hir_self_param (HirId id)
     677              : {
     678         8084 :   auto it = hirSelfParamMappings.find (id);
     679         8084 :   if (it == hirSelfParamMappings.end ())
     680         8084 :     return tl::nullopt;
     681              : 
     682            0 :   return it->second;
     683              : }
     684              : 
     685              : void
     686         2336 : Mappings::insert_hir_struct_field (HIR::StructExprField *field)
     687              : {
     688         2336 :   auto id = field->get_mappings ().get_hirid ();
     689         2336 :   rust_assert (!lookup_hir_struct_field (id));
     690              : 
     691         2336 :   hirStructFieldMappings[id] = field;
     692         2336 :   insert_node_to_hir (field->get_mappings ().get_nodeid (), id);
     693         2336 : }
     694              : 
     695              : tl::optional<HIR::StructExprField *>
     696         2336 : Mappings::lookup_hir_struct_field (HirId id)
     697              : {
     698         2336 :   auto it = hirStructFieldMappings.find (id);
     699         2336 :   if (it == hirStructFieldMappings.end ())
     700         2336 :     return tl::nullopt;
     701              : 
     702            0 :   return it->second;
     703              : }
     704              : 
     705              : void
     706        26266 : Mappings::insert_hir_pattern (HIR::Pattern *pattern)
     707              : {
     708        26266 :   auto id = pattern->get_mappings ().get_hirid ();
     709        26266 :   rust_assert (!lookup_hir_pattern (id));
     710              : 
     711        26266 :   hirPatternMappings[id] = pattern;
     712        26266 :   insert_node_to_hir (pattern->get_mappings ().get_nodeid (), id);
     713        26266 : }
     714              : 
     715              : tl::optional<HIR::Pattern *>
     716        86716 : Mappings::lookup_hir_pattern (HirId id)
     717              : {
     718        86716 :   auto it = hirPatternMappings.find (id);
     719        86716 :   if (it == hirPatternMappings.end ())
     720        59464 :     return tl::nullopt;
     721              : 
     722        27252 :   return it->second;
     723              : }
     724              : 
     725              : void
     726        32283 : Mappings::insert_local_defid_mapping (CrateNum crateNum, LocalDefId id,
     727              :                                       HIR::Item *item)
     728              : {
     729        32283 :   rust_assert (!lookup_local_defid (crateNum, id));
     730        32283 :   localDefIdMappings[crateNum][id] = item;
     731        32283 : }
     732              : 
     733              : tl::optional<HIR::Item *>
     734        67933 : Mappings::lookup_local_defid (CrateNum crateNum, LocalDefId id)
     735              : {
     736        67933 :   auto it = localDefIdMappings.find (crateNum);
     737        67933 :   if (it == localDefIdMappings.end ())
     738         9148 :     return tl::nullopt;
     739              : 
     740        58785 :   auto iy = it->second.find (id);
     741        58785 :   if (iy == it->second.end ())
     742        58785 :     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       477795 : Mappings::insert_node_to_hir (NodeId id, HirId ref)
     764              : {
     765       477795 :   nodeIdToHirMappings[id] = ref;
     766       477795 :   hirIdToNodeMappings[ref] = id;
     767       477795 : }
     768              : 
     769              : tl::optional<HirId>
     770      3071234 : Mappings::lookup_node_to_hir (NodeId id)
     771              : {
     772      3071234 :   auto it = nodeIdToHirMappings.find (id);
     773      3071234 :   if (it == nodeIdToHirMappings.end ())
     774            0 :     return tl::nullopt;
     775              : 
     776      3071234 :   return {it->second};
     777              : }
     778              : 
     779              : tl::optional<NodeId>
     780         7038 : Mappings::lookup_hir_to_node (HirId id)
     781              : {
     782         7038 :   auto it = hirIdToNodeMappings.find (id);
     783         7038 :   if (it == hirIdToNodeMappings.end ())
     784            0 :     return tl::nullopt;
     785              : 
     786         7038 :   return {it->second};
     787              : }
     788              : 
     789              : void
     790       670769 : Mappings::insert_location (HirId id, location_t locus)
     791              : {
     792       670769 :   locations[id] = locus;
     793       670769 : }
     794              : 
     795              : location_t
     796      5394584 : Mappings::lookup_location (HirId id)
     797              : {
     798      5394584 :   auto it = locations.find (id);
     799      5394584 :   if (it == locations.end ())
     800              :     return UNDEF_LOCATION;
     801              : 
     802      5314749 :   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        15912 : Mappings::iterate_impl_items (
     818              :   std::function<bool (HirId, HIR::ImplItem *, HIR::ImplBlock *)> cb)
     819              : {
     820       339177 :   for (auto it = hirImplItemMappings.begin (); it != hirImplItemMappings.end ();
     821       323265 :        it++)
     822              :     {
     823       323265 :       auto id = it->first;
     824       323265 :       auto impl_item = it->second.second;
     825       323265 :       auto impl
     826       323265 :         = lookup_associated_impl (impl_item->get_impl_mappings ().get_hirid ());
     827       323265 :       if (!cb (id, impl_item, impl))
     828        15912 :         return;
     829              :     }
     830              : }
     831              : 
     832              : void
     833        89244 : Mappings::iterate_impl_blocks (std::function<bool (HirId, HIR::ImplBlock *)> cb)
     834              : {
     835      2742940 :   for (auto it = hirImplBlockMappings.begin ();
     836      2742940 :        it != hirImplBlockMappings.end (); it++)
     837              :     {
     838      2653696 :       HirId id = it->first;
     839      2653696 :       HIR::ImplBlock *impl_block = it->second;
     840      2653696 :       if (!cb (id, impl_block))
     841        89244 :         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          981 : Mappings::insert_macro_def (AST::MacroRulesDefinition *macro)
     863              : {
     864          981 :   auto outer_attrs = macro->get_outer_attrs ();
     865          981 :   bool should_be_builtin
     866          981 :     = std::any_of (outer_attrs.begin (), outer_attrs.end (),
     867          170 :                    [] (AST::Attribute attr) {
     868          170 :                      return attr.get_path ()
     869          170 :                             == Values::Attributes::RUSTC_BUILTIN_MACRO;
     870              :                    });
     871          981 :   if (should_be_builtin)
     872              :     {
     873          155 :       auto builtin
     874          155 :         = MacroBuiltin::builtins.lookup (macro->get_rule_name ().as_string ());
     875          155 :       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          153 :       auto transcriber = MacroBuiltin::builtin_transcribers.find (
     884          153 :         macro->get_rule_name ().as_string ());
     885          153 :       macro->set_builtin_transcriber (transcriber->second);
     886              :     }
     887              : 
     888          979 :   auto it = macroMappings.find (macro->get_node_id ());
     889          979 :   rust_assert (it == macroMappings.end ());
     890              : 
     891          979 :   macroMappings[macro->get_node_id ()] = {macro, currentCrateNum};
     892          981 : }
     893              : 
     894              : tl::optional<AST::MacroRulesDefinition *>
     895        11358 : Mappings::lookup_macro_def (NodeId id)
     896              : {
     897        11358 :   auto it = macroMappings.find (id);
     898        11358 :   if (it == macroMappings.end ())
     899          981 :     return tl::nullopt;
     900              : 
     901        10377 :   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         2821 : Mappings::insert_macro_invocation (AST::MacroInvocation &invoc,
     916              :                                    AST::MacroRulesDefinition *def)
     917              : {
     918         2821 :   auto it = macroInvocations.find (invoc.get_node_id ());
     919         2821 :   rust_assert (it == macroInvocations.end ());
     920              : 
     921         2821 :   macroInvocations[invoc.get_node_id ()] = def;
     922         2821 : }
     923              : 
     924              : tl::optional<AST::MacroRulesDefinition *>
     925         5684 : Mappings::lookup_macro_invocation (AST::MacroInvocation &invoc)
     926              : {
     927         5684 :   auto it = macroInvocations.find (invoc.get_node_id ());
     928         5684 :   if (it == macroInvocations.end ())
     929         2866 :     return tl::nullopt;
     930              : 
     931         2818 :   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         4244 : Mappings::get_exported_macros ()
     942              : {
     943         4244 :   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           75 : Mappings::lookup_derive_proc_macros (CrateNum num)
     978              : {
     979           75 :   auto it = procmacrosDeriveMappings.find (num);
     980           75 :   if (it == procmacrosDeriveMappings.end ())
     981            3 :     return tl::nullopt;
     982              : 
     983           72 :   return it->second;
     984              : }
     985              : 
     986              : tl::optional<std::vector<BangProcMacro> &>
     987           75 : Mappings::lookup_bang_proc_macros (CrateNum num)
     988              : {
     989           75 :   auto it = procmacrosBangMappings.find (num);
     990           75 :   if (it == procmacrosBangMappings.end ())
     991            3 :     return tl::nullopt;
     992              : 
     993           72 :   return it->second;
     994              : }
     995              : 
     996              : tl::optional<std::vector<AttributeProcMacro> &>
     997           75 : Mappings::lookup_attribute_proc_macros (CrateNum num)
     998              : {
     999           75 :   auto it = procmacrosAttributeMappings.find (num);
    1000           75 :   if (it == procmacrosAttributeMappings.end ())
    1001            3 :     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            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        30085 : Mappings::insert_visibility (NodeId id, Privacy::ModuleVisibility visibility)
    1125              : {
    1126        30085 :   visibility_map.insert ({id, visibility});
    1127        30085 : }
    1128              : 
    1129              : tl::optional<Privacy::ModuleVisibility &>
    1130        66533 : Mappings::lookup_visibility (NodeId id)
    1131              : {
    1132        66533 :   auto it = visibility_map.find (id);
    1133        66533 :   if (it == visibility_map.end ())
    1134        45494 :     return tl::nullopt;
    1135              : 
    1136        21039 :   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         6962 : Mappings::insert_glob_container (NodeId id, AST::GlobContainer *container)
    1161              : {
    1162         6962 :   rust_assert (glob_containers.find (id) == glob_containers.end ());
    1163              : 
    1164              :   // Crates have different memory managements that regular items
    1165         6962 :   if (container->get_glob_container_kind () == AST::GlobContainer::Kind::Crate)
    1166         4771 :     glob_containers[id] = get_ast_crate_by_node_id_raw (id);
    1167              :   else
    1168         2191 :     glob_containers[id] = container;
    1169         6962 : }
    1170              : 
    1171              : void
    1172         4537 : Mappings::insert_module_id (NodeId id)
    1173              : {
    1174         4537 :   module_ids.insert (id);
    1175         4537 : }
    1176              : 
    1177              : bool
    1178        80240 : Mappings::is_module (NodeId id)
    1179              : {
    1180        80240 :   return module_ids.find (id) != module_ids.end ();
    1181              : }
    1182              : 
    1183              : tl::optional<AST::GlobContainer *>
    1184        27493 : Mappings::lookup_glob_container (NodeId id)
    1185              : {
    1186        27493 :   auto it = glob_containers.find (id);
    1187        27493 :   if (it == glob_containers.end ())
    1188         9452 :     return tl::nullopt;
    1189              : 
    1190        18041 :   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        22849 : Mappings::insert_ast_item (AST::Item *item)
    1262              : {
    1263        22849 :   auto it = ast_item_mappings.find (item->get_node_id ());
    1264        22849 :   rust_assert (it == ast_item_mappings.end ());
    1265              : 
    1266        22849 :   ast_item_mappings[item->get_node_id ()] = item;
    1267        22849 : }
    1268              : 
    1269              : tl::optional<AST::Item *>
    1270         2813 : Mappings::lookup_ast_item (NodeId id)
    1271              : {
    1272         2813 :   auto it = ast_item_mappings.find (id);
    1273         2813 :   if (it == ast_item_mappings.end ())
    1274            0 :     return tl::nullopt;
    1275              : 
    1276         2813 :   return it->second;
    1277              : }
    1278              : 
    1279              : HIR::ImplBlock *
    1280        79982 : Mappings::lookup_builtin_marker ()
    1281              : {
    1282        79982 :   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         9854 : Mappings::get_lang_item (LangItem::Kind item_type, location_t locus)
    1290              : {
    1291         9854 :   if (auto item = lookup_lang_item (item_type))
    1292         9854 :     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         3424 : Mappings::insert_lang_item (LangItem::Kind item_type, DefId id)
    1307              : {
    1308         3424 :   auto it = lang_item_mappings.find (item_type);
    1309         3424 :   rust_assert (it == lang_item_mappings.end ());
    1310              : 
    1311         3424 :   lang_item_mappings[item_type] = id;
    1312         3424 : }
    1313              : 
    1314              : tl::optional<DefId &>
    1315       154253 : Mappings::lookup_lang_item (LangItem::Kind item_type)
    1316              : {
    1317       154253 :   auto it = lang_item_mappings.find (item_type);
    1318       154253 :   if (it == lang_item_mappings.end ())
    1319        60131 :     return tl::nullopt;
    1320              : 
    1321        94122 :   return it->second;
    1322              : }
    1323              : 
    1324              : void
    1325         3454 : Mappings::insert_lang_item_node (LangItem::Kind item_type, NodeId node_id)
    1326              : {
    1327         3454 :   auto it = lang_item_nodes.find (item_type);
    1328         3454 :   rust_assert (it == lang_item_nodes.end ());
    1329              : 
    1330         3454 :   lang_item_nodes.insert ({item_type, node_id});
    1331         3454 : }
    1332              : 
    1333              : tl::optional<NodeId &>
    1334          808 : Mappings::lookup_lang_item_node (LangItem::Kind item_type)
    1335              : {
    1336          808 :   auto it = lang_item_nodes.find (item_type);
    1337          808 :   if (it == lang_item_nodes.end ())
    1338            1 :     return tl::nullopt;
    1339              : 
    1340          807 :   return it->second;
    1341              : }
    1342              : 
    1343              : NodeId
    1344          808 : Mappings::get_lang_item_node (LangItem::Kind item_type)
    1345              : {
    1346          808 :   if (auto lookup = lookup_lang_item_node (item_type))
    1347          807 :     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              : void
    1354           12 : Mappings::insert_auto_trait (HIR::Trait *trait)
    1355              : {
    1356           12 :   auto_traits.emplace_back (trait);
    1357           12 : }
    1358              : 
    1359              : std::vector<HIR::Trait *> &
    1360        80226 : Mappings::get_auto_traits ()
    1361              : {
    1362        80226 :   return auto_traits;
    1363              : }
    1364              : 
    1365              : void
    1366           21 : Mappings::add_capture (NodeId closure, NodeId definition)
    1367              : {
    1368           21 :   auto cap = captures.find (closure);
    1369           21 :   if (cap == captures.end ())
    1370           21 :     captures[closure] = {definition};
    1371              :   else
    1372            0 :     cap->second.push_back (definition);
    1373           21 : }
    1374              : 
    1375              : tl::optional<std::vector<NodeId>>
    1376           65 : Mappings::lookup_captures (NodeId closure)
    1377              : {
    1378           65 :   auto cap = captures.find (closure);
    1379           65 :   if (cap == captures.end ())
    1380           44 :     return tl::nullopt;
    1381              :   else
    1382           21 :     return cap->second;
    1383              : }
    1384              : 
    1385              : void
    1386          433 : Mappings::add_derived_node (NodeId node_id)
    1387              : {
    1388          433 :   derived_nodes.insert (node_id);
    1389          433 : }
    1390              : 
    1391              : bool
    1392            0 : Mappings::is_derived_node (NodeId node_id)
    1393              : {
    1394            0 :   return derived_nodes.find (node_id) != derived_nodes.end ();
    1395              : }
    1396              : 
    1397              : void
    1398        64280 : Mappings::add_function_node (NodeId node_id)
    1399              : {
    1400        64280 :   function_nodes.insert (node_id);
    1401        64280 : }
    1402              : 
    1403              : bool
    1404          140 : Mappings::is_function_node (NodeId node_id)
    1405              : {
    1406          140 :   return function_nodes.find (node_id) != function_nodes.end ();
    1407              : }
    1408              : 
    1409              : } // namespace Analysis
    1410              : } // 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.