LCOV - code coverage report
Current view: top level - gcc/rust/backend - rust-compile-implitem.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 43.5 % 46 20
Test Date: 2026-07-11 15:47:05 Functions: 50.0 % 2 1
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-compile-implitem.h"
      20              : #include "rust-rib.h"
      21              : 
      22              : namespace Rust {
      23              : namespace Compile {
      24              : 
      25              : void
      26            0 : CompileTraitItem::visit (HIR::TraitItemConst &constant)
      27              : {
      28            0 :   rust_assert (concrete != nullptr);
      29            0 :   TyTy::BaseType *resolved_type = concrete;
      30              : 
      31            0 :   auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get ();
      32              : 
      33            0 :   Resolver::CanonicalPath canonical_path
      34            0 :     = nr_ctx.to_canonical_path (constant.get_mappings ().get_nodeid (),
      35            0 :                                 Resolver2_0::Namespace::Values);
      36              : 
      37            0 :   HIR::Expr &const_value_expr = constant.get_expr ();
      38            0 :   TyTy::BaseType *expr_type = nullptr;
      39            0 :   bool ok = ctx->get_tyctx ()->lookup_type (
      40            0 :     const_value_expr.get_mappings ().get_hirid (), &expr_type);
      41            0 :   rust_assert (ok);
      42              : 
      43            0 :   tree const_expr
      44            0 :     = compile_constant_item (constant.get_mappings ().get_hirid (), expr_type,
      45              :                              resolved_type, canonical_path, const_value_expr,
      46              :                              constant.get_locus (),
      47            0 :                              const_value_expr.get_locus ());
      48            0 :   if (const_expr != error_mark_node)
      49              :     {
      50            0 :       ctx->push_const (const_expr);
      51            0 :       ctx->insert_const_decl (constant.get_mappings ().get_hirid (),
      52              :                               const_expr);
      53              :     }
      54              : 
      55            0 :   reference = const_expr;
      56            0 : }
      57              : 
      58              : void
      59          259 : CompileTraitItem::visit (HIR::TraitItemFunc &func)
      60              : {
      61          259 :   rust_assert (func.has_definition ());
      62              : 
      63          259 :   rust_assert (concrete->get_kind () == TyTy::TypeKind::FNDEF);
      64          259 :   TyTy::FnType *fntype = static_cast<TyTy::FnType *> (concrete);
      65          259 :   fntype->monomorphize ();
      66              : 
      67              :   // items can be forward compiled which means we may not need to invoke this
      68              :   // code. We might also have already compiled this generic function as well.
      69          259 :   tree lookup = NULL_TREE;
      70          259 :   if (ctx->lookup_function_decl (fntype->get_ty_ref (), &lookup,
      71              :                                  fntype->get_id (), fntype))
      72              :     {
      73              :       // has this been added to the list then it must be finished
      74            0 :       if (ctx->function_completed (lookup))
      75              :         {
      76            0 :           tree dummy = NULL_TREE;
      77            0 :           if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &dummy))
      78              :             {
      79            0 :               ctx->insert_function_decl (fntype, lookup);
      80              :             }
      81              : 
      82            0 :           reference = address_expression (lookup, ref_locus);
      83            0 :           return;
      84              :         }
      85              :     }
      86              : 
      87          259 :   if (fntype->has_substitutions_defined ())
      88              :     {
      89              :       // override the Hir Lookups for the substituions in this context
      90          259 :       fntype->override_context ();
      91              :     }
      92              : 
      93          259 :   auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get ();
      94              : 
      95          259 :   Resolver::CanonicalPath canonical_path
      96          259 :     = nr_ctx.to_canonical_path (func.get_mappings ().get_nodeid (),
      97          259 :                                 Resolver2_0::Namespace::Values);
      98              : 
      99              :   // FIXME: How do we get the proper visibility here?
     100          259 :   auto vis = HIR::Visibility (HIR::Visibility::VisType::Public);
     101          259 :   HIR::TraitFunctionDecl &function = func.get_decl ();
     102          259 :   tree fndecl
     103          259 :     = compile_function (false, function.get_function_name ().as_string (),
     104              :                         function.get_self (), function.get_function_params (),
     105              :                         function.get_qualifiers (), vis,
     106              :                         func.get_outer_attrs (), func.get_locus (),
     107          259 :                         &func.get_block_expr (), canonical_path, fntype);
     108          259 :   reference = address_expression (fndecl, ref_locus);
     109          259 : }
     110              : 
     111              : } // namespace Compile
     112              : } // 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.