LCOV - code coverage report
Current view: top level - gcc/rust/typecheck - rust-tyty-util.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 100.0 % 45 45
Test Date: 2024-04-13 14:00:49 Functions: 100.0 % 8 8
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : // Copyright (C) 2020-2024 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-tyty.h"
      21                 :             : 
      22                 :             : namespace Rust {
      23                 :             : namespace TyTy {
      24                 :             : 
      25                 :      859024 : TyVar::TyVar (HirId ref) : ref (ref)
      26                 :             : {
      27                 :             :   // ensure this reference is defined within the context
      28                 :      859024 :   auto context = Resolver::TypeCheckContext::get ();
      29                 :      859024 :   BaseType *lookup = nullptr;
      30                 :      859024 :   bool ok = context->lookup_type (ref, &lookup);
      31                 :      859024 :   rust_assert (ok);
      32                 :      859024 : }
      33                 :             : 
      34                 :             : BaseType *
      35                 :     1295595 : TyVar::get_tyty () const
      36                 :             : {
      37                 :     1295595 :   auto context = Resolver::TypeCheckContext::get ();
      38                 :     1295595 :   BaseType *lookup = nullptr;
      39                 :     1295595 :   bool ok = context->lookup_type (ref, &lookup);
      40                 :     1295595 :   rust_assert (ok);
      41                 :     1295595 :   return lookup;
      42                 :             : }
      43                 :             : 
      44                 :             : TyVar
      45                 :        5360 : TyVar::get_implicit_infer_var (location_t locus)
      46                 :             : {
      47                 :        5360 :   auto mappings = Analysis::Mappings::get ();
      48                 :        5360 :   auto context = Resolver::TypeCheckContext::get ();
      49                 :             : 
      50                 :        5360 :   InferType *infer = new InferType (mappings->get_next_hir_id (),
      51                 :             :                                     InferType::InferTypeKind::GENERAL,
      52                 :        5360 :                                     InferType::TypeHint::Default (), locus);
      53                 :        5360 :   context->insert_type (Analysis::NodeMapping (mappings->get_current_crate (),
      54                 :             :                                                UNKNOWN_NODEID,
      55                 :             :                                                infer->get_ref (),
      56                 :             :                                                UNKNOWN_LOCAL_DEFID),
      57                 :             :                         infer);
      58                 :        5360 :   mappings->insert_location (infer->get_ref (), locus);
      59                 :             : 
      60                 :        5360 :   return TyVar (infer->get_ref ());
      61                 :             : }
      62                 :             : 
      63                 :             : TyVar
      64                 :        6529 : TyVar::subst_covariant_var (TyTy::BaseType *orig, TyTy::BaseType *subst)
      65                 :             : {
      66                 :        6529 :   if (orig->get_kind () != TyTy::TypeKind::PARAM)
      67                 :        1323 :     return TyVar (subst->get_ty_ref ());
      68                 :        5206 :   else if (subst->get_kind () == TyTy::TypeKind::PARAM)
      69                 :             :     {
      70                 :        5206 :       TyTy::ParamType *p = static_cast<TyTy::ParamType *> (subst);
      71                 :        5206 :       if (p->resolve ()->get_kind () == TyTy::TypeKind::PARAM)
      72                 :             :         {
      73                 :         257 :           return TyVar (subst->get_ty_ref ());
      74                 :             :         }
      75                 :             :     }
      76                 :             : 
      77                 :        4949 :   return TyVar (subst->get_ref ());
      78                 :             : }
      79                 :             : 
      80                 :             : TyVar
      81                 :       42895 : TyVar::clone () const
      82                 :             : {
      83                 :       42895 :   TyTy::BaseType *c = get_tyty ()->clone ();
      84                 :       42895 :   return TyVar (c->get_ref ());
      85                 :             : }
      86                 :             : 
      87                 :             : TyVar
      88                 :         773 : TyVar::monomorphized_clone () const
      89                 :             : {
      90                 :         773 :   auto mappings = Analysis::Mappings::get ();
      91                 :         773 :   auto context = Resolver::TypeCheckContext::get ();
      92                 :             : 
      93                 :             :   // this needs a new hirid
      94                 :         773 :   TyTy::BaseType *c = get_tyty ()->monomorphized_clone ();
      95                 :         773 :   c->set_ref (mappings->get_next_hir_id ());
      96                 :             : 
      97                 :             :   // insert it
      98                 :         773 :   context->insert_type (Analysis::NodeMapping (mappings->get_current_crate (),
      99                 :             :                                                UNKNOWN_NODEID, c->get_ref (),
     100                 :             :                                                UNKNOWN_LOCAL_DEFID),
     101                 :             :                         c);
     102                 :             : 
     103                 :         773 :   return TyVar (c->get_ref ());
     104                 :             : }
     105                 :             : 
     106                 :       78162 : TyWithLocation::TyWithLocation (BaseType *ty, location_t locus)
     107                 :       78162 :   : ty (ty), locus (locus)
     108                 :       78162 : {}
     109                 :             : 
     110                 :      231319 : TyWithLocation::TyWithLocation (BaseType *ty) : ty (ty)
     111                 :             : {
     112                 :      231319 :   auto mappings = Analysis::Mappings::get ();
     113                 :      231319 :   locus = mappings->lookup_location (ty->get_ref ());
     114                 :      231319 : }
     115                 :             : 
     116                 :             : } // namespace TyTy
     117                 :             : } // namespace Rust
        

Generated by: LCOV version 2.1-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.