LCOV - code coverage report
Current view: top level - gcc/rust/typecheck - rust-tyty-util.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 96.8 % 62 60
Test Date: 2026-08-22 16:33:35 Functions: 100.0 % 9 9
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-type-check.h"
      20              : #include "rust-mapping-common.h"
      21              : #include "rust-system.h"
      22              : #include "rust-tyty.h"
      23              : 
      24              : namespace Rust {
      25              : namespace TyTy {
      26              : 
      27      5886849 : TyVar::TyVar (HirId ref) : ref (ref)
      28              : {
      29              :   // ensure this reference is defined within the context
      30      5886849 :   auto context = Resolver::TypeCheckContext::get ();
      31      5886849 :   BaseType *lookup = nullptr;
      32      5886849 :   bool ok = context->lookup_type (ref, &lookup);
      33      5886849 :   if (!ok || lookup == nullptr || lookup->get_kind () == TypeKind::ERROR)
      34            1 :     return;
      35              : }
      36              : 
      37              : BaseType *
      38      8007553 : TyVar::get_tyty () const
      39              : {
      40      8007553 :   auto context = Resolver::TypeCheckContext::get ();
      41      8007553 :   BaseType *lookup = nullptr;
      42      8007553 :   bool ok = context->lookup_type (ref, &lookup);
      43      8007553 :   if (!ok || lookup == nullptr)
      44              :     return nullptr;
      45              :   return lookup;
      46              : }
      47              : 
      48              : TyVar
      49       140146 : TyVar::get_implicit_infer_var (location_t locus)
      50              : {
      51       140146 :   auto &mappings = Analysis::Mappings::get ();
      52       140146 :   auto context = Resolver::TypeCheckContext::get ();
      53              : 
      54       140146 :   HirId next = mappings.get_next_hir_id ();
      55       140146 :   auto infer = new InferType (next, InferType::InferTypeKind::GENERAL,
      56       140146 :                               InferType::TypeHint::Default (), locus);
      57              : 
      58       140146 :   context->insert_implicit_type (infer->get_ref (), infer);
      59       140146 :   mappings.insert_location (infer->get_ref (), locus);
      60              : 
      61       140146 :   return TyVar (infer->get_ref ());
      62              : }
      63              : 
      64              : TyVar
      65          108 : TyVar::get_implicit_const_infer_var (location_t locus, TyVar *implicit_type)
      66              : {
      67          108 :   auto &mappings = Analysis::Mappings::get ();
      68          108 :   auto context = Resolver::TypeCheckContext::get ();
      69              : 
      70          108 :   TyVar it = (implicit_type != nullptr) ? *implicit_type
      71          108 :                                         : get_implicit_infer_var (locus);
      72          108 :   HirId next = mappings.get_next_hir_id ();
      73          108 :   auto infer = new ConstInferType (it.get_tyty (), next, next, {});
      74              : 
      75          108 :   context->insert_implicit_type (infer->get_ref (), infer);
      76          108 :   mappings.insert_location (infer->get_ref (), locus);
      77              : 
      78          108 :   return TyVar (infer->get_ref ());
      79              : }
      80              : 
      81              : TyVar
      82        15596 : TyVar::subst_covariant_var (TyTy::BaseType *orig, TyTy::BaseType *subst)
      83              : {
      84        15596 :   if (orig->get_kind () != TyTy::TypeKind::PARAM)
      85         1987 :     return TyVar (subst->get_ty_ref ());
      86        13609 :   else if (subst->get_kind () == TyTy::TypeKind::PARAM)
      87              :     {
      88        13609 :       TyTy::ParamType *p = static_cast<TyTy::ParamType *> (subst);
      89        13609 :       if (p->resolve ()->get_kind () == TyTy::TypeKind::PARAM)
      90              :         {
      91         1478 :           return TyVar (subst->get_ty_ref ());
      92              :         }
      93              :     }
      94              : 
      95        12131 :   return TyVar (subst->get_ref ());
      96              : }
      97              : 
      98              : TyVar
      99        67113 : TyVar::clone () const
     100              : {
     101        67113 :   TyTy::BaseType *base = get_tyty ();
     102        67113 :   if (base == nullptr || base->get_kind () == TypeKind::ERROR)
     103            0 :     return TyVar::get_implicit_infer_var (UNKNOWN_LOCATION);
     104        67113 :   TyTy::BaseType *c = base->clone ();
     105        67113 :   return TyVar (c->get_ref ());
     106              : }
     107              : 
     108              : TyVar
     109         1082 : TyVar::monomorphized_clone () const
     110              : {
     111         1082 :   auto &mappings = Analysis::Mappings::get ();
     112         1082 :   auto context = Resolver::TypeCheckContext::get ();
     113              : 
     114         1082 :   TyTy::BaseType *base = get_tyty ();
     115         1082 :   if (base == nullptr || base->get_kind () == TypeKind::ERROR)
     116            0 :     return TyVar::get_implicit_infer_var (UNKNOWN_LOCATION);
     117              : 
     118              :   // this needs a new hirid
     119         1082 :   TyTy::BaseType *c = get_tyty ()->monomorphized_clone ();
     120         1082 :   c->set_ref (mappings.get_next_hir_id ());
     121              : 
     122              :   // insert it
     123         1082 :   context->insert_type (Analysis::NodeMapping (mappings.get_current_crate (),
     124              :                                                UNKNOWN_NODEID, c->get_ref (),
     125         1082 :                                                UNKNOWN_LOCAL_DEFID),
     126              :                         c);
     127              : 
     128         1082 :   return TyVar (c->get_ref ());
     129              : }
     130              : 
     131       148321 : TyWithLocation::TyWithLocation (BaseType *ty, location_t locus)
     132       148321 :   : ty (ty), locus (locus)
     133       148321 : {}
     134              : 
     135      5279276 : TyWithLocation::TyWithLocation (BaseType *ty) : ty (ty)
     136              : {
     137      5279276 :   auto &mappings = Analysis::Mappings::get ();
     138      5279276 :   locus = mappings.lookup_location (ty->get_ref ());
     139      5279276 : }
     140              : 
     141              : } // namespace TyTy
     142              : } // 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.