LCOV - code coverage report
Current view: top level - gcc/rust/typecheck - rust-tyty-subst.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 87.2 % 547 477
Test Date: 2026-11-14 16:39:50 Functions: 87.2 % 78 68
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-tyty-subst.h"
      20              : 
      21              : #include "rust-hir-generic-param.h"
      22              : #include "rust-system.h"
      23              : #include "rust-tyty.h"
      24              : #include "rust-hir-type-check.h"
      25              : #include "rust-substitution-mapper.h"
      26              : #include "rust-hir-type-check-type.h"
      27              : #include "rust-hir-type-check-expr.h"
      28              : #include "rust-compile-base.h"
      29              : #include "rust-type-util.h"
      30              : #include "tree.h"
      31              : 
      32              : namespace Rust {
      33              : namespace TyTy {
      34              : 
      35      9759873 : SubstitutionParamMapping::SubstitutionParamMapping (HIR::GenericParam &generic,
      36              :                                                     BaseGeneric *param)
      37      9759873 :   : generic (generic), param (param)
      38      9759873 : {}
      39              : 
      40     11904551 : SubstitutionParamMapping::SubstitutionParamMapping (
      41              :   const SubstitutionParamMapping &other)
      42     11904551 :   : generic (other.generic), param (other.param)
      43     11904551 : {}
      44              : 
      45              : std::string
      46        33319 : SubstitutionParamMapping::as_string () const
      47              : {
      48        33319 :   if (param == nullptr)
      49            0 :     return "nullptr";
      50              : 
      51        33319 :   return param->get_name ();
      52              : }
      53              : 
      54              : SubstitutionParamMapping
      55      9702182 : SubstitutionParamMapping::clone () const
      56              : {
      57      9702182 :   return SubstitutionParamMapping (generic, static_cast<BaseGeneric *> (
      58      9702182 :                                               param->clone ()));
      59              : }
      60              : 
      61              : BaseGeneric *
      62      1408910 : SubstitutionParamMapping::get_param_ty ()
      63              : {
      64      1408910 :   return param;
      65              : }
      66              : 
      67              : const BaseGeneric *
      68      9445983 : SubstitutionParamMapping::get_param_ty () const
      69              : {
      70      9445983 :   return param;
      71              : }
      72              : 
      73              : HIR::GenericParam &
      74        63028 : SubstitutionParamMapping::get_generic_param ()
      75              : {
      76        63028 :   return generic;
      77              : }
      78              : 
      79              : const HIR::GenericParam &
      80       157160 : SubstitutionParamMapping::get_generic_param () const
      81              : {
      82       157160 :   return generic;
      83              : }
      84              : 
      85              : bool
      86       591258 : SubstitutionParamMapping::needs_substitution () const
      87              : {
      88       591258 :   return !(get_param_ty ()->is_concrete ());
      89              : }
      90              : 
      91              : Identifier
      92         3638 : SubstitutionParamMapping::get_type_representation () const
      93              : {
      94         7276 :   return param->get_symbol ();
      95              : }
      96              : 
      97              : location_t
      98        38815 : SubstitutionParamMapping::get_param_locus () const
      99              : {
     100        38815 :   return generic.get_locus ();
     101              : }
     102              : 
     103              : bool
     104       340524 : SubstitutionParamMapping::param_has_default_ty () const
     105              : {
     106       340524 :   if (generic.get_kind () == HIR::GenericParam::GenericKind::TYPE)
     107              :     {
     108       339837 :       const auto &type_param = static_cast<const HIR::TypeParam &> (generic);
     109       339837 :       return type_param.has_type ();
     110              :     }
     111              : 
     112          687 :   rust_assert (generic.get_kind () == HIR::GenericParam::GenericKind::CONST);
     113          687 :   const auto &const_param
     114              :     = static_cast<const HIR::ConstGenericParam &> (generic);
     115          687 :   return const_param.has_default_expression ();
     116              : }
     117              : 
     118              : BaseType *
     119         8235 : SubstitutionParamMapping::get_default_ty () const
     120              : {
     121         8235 :   if (generic.get_kind () == HIR::GenericParam::GenericKind::TYPE)
     122              :     {
     123         8230 :       const auto &type_param = static_cast<const HIR::TypeParam &> (generic);
     124         8230 :       TyVar var (type_param.get_type_mappings ().get_hirid ());
     125         8230 :       return var.get_tyty ();
     126              :     }
     127              : 
     128            5 :   rust_assert (generic.get_kind () == HIR::GenericParam::GenericKind::CONST);
     129            5 :   const auto &const_param
     130              :     = static_cast<const HIR::ConstGenericParam &> (generic);
     131            5 :   rust_assert (const_param.has_default_expression ());
     132              : 
     133            5 :   const auto &expr = const_param.get_default_expression ();
     134            5 :   TyVar var (expr.get_mappings ().get_hirid ());
     135            5 :   return var.get_tyty ();
     136              : }
     137              : 
     138              : bool
     139            0 : SubstitutionParamMapping::need_substitution () const
     140              : {
     141            0 :   if (!param->can_resolve ())
     142              :     return true;
     143              : 
     144            0 :   auto resolved = param->resolve ();
     145            0 :   return !resolved->is_concrete ();
     146              : }
     147              : 
     148              : bool
     149       295154 : SubstitutionParamMapping::fill_param_ty (
     150              :   SubstitutionArgumentMappings &subst_mappings, location_t locus,
     151              :   bool needs_bounds_check)
     152              : {
     153       295154 :   SubstitutionArg arg = SubstitutionArg::error ();
     154       295154 :   bool ok = subst_mappings.get_argument_for_symbol (get_param_ty (), &arg);
     155       295154 :   if (!ok)
     156              :     return true;
     157              : 
     158       295154 :   TyTy::BaseType &type = *arg.get_tyty ();
     159       295154 :   std::pair<HirId, HirId> subst_key (param->get_ref (), type.get_ref ());
     160       297188 :   static std::vector<std::pair<HirId, HirId>> active_substs;
     161       295154 :   bool is_recursive_subst
     162       295154 :     = Resolver::ScopedPush<std::pair<HirId, HirId>>::contains (active_substs,
     163              :                                                                subst_key);
     164       295154 :   bool skip_recursive_bounds
     165       295154 :     = is_recursive_subst && type.get_kind () == TyTy::TypeKind::INFER;
     166           28 :   if (skip_recursive_bounds)
     167              :     {
     168           28 :       type.append_reference (param->get_ref ());
     169           28 :       type.append_reference (param->get_ty_ref ());
     170           28 :       for (auto ref : param->get_combined_refs ())
     171            0 :         type.append_reference (ref);
     172           28 :       if (param->can_resolve ())
     173              :         {
     174           28 :           TyTy::BaseType *resolved = param->resolve ();
     175           28 :           type.append_reference (resolved->get_ref ());
     176           28 :           type.append_reference (resolved->get_ty_ref ());
     177           28 :           for (auto ref : resolved->get_combined_refs ())
     178            0 :             type.append_reference (ref);
     179           28 :           if (resolved->get_kind () != TyTy::TypeKind::PARAM
     180           28 :               && resolved->get_kind () != TyTy::TypeKind::INFER)
     181              :             return true;
     182              :         }
     183              :     }
     184              : 
     185       295126 :   Resolver::ScopedPush<std::pair<HirId, HirId>> guard (active_substs, subst_key,
     186       295126 :                                                        !is_recursive_subst);
     187              : 
     188       295126 :   if (type.get_kind () == TyTy::TypeKind::INFER)
     189              :     {
     190        13899 :       type.inherit_bounds (*param);
     191              :     }
     192              : 
     193       295126 :   if (type.get_kind () == TypeKind::PARAM)
     194              :     {
     195        61402 :       param = static_cast<BaseGeneric *> (type.clone ());
     196              :     }
     197       233724 :   else if (type.get_kind () == TyTy::TypeKind::CONST)
     198              :     {
     199          413 :       rust_assert (param->get_kind () == TyTy::TypeKind::CONST);
     200          413 :       auto *const_type = type.as_const_type ();
     201          413 :       if (const_type->const_kind () == TyTy::BaseConstType::ConstKind::Decl)
     202          232 :         param = static_cast<BaseGeneric *> (type.clone ());
     203              :       else
     204          181 :         param->set_ty_ref (type.get_ref ());
     205              :     }
     206       233311 :   else if (param->get_kind () == TypeKind::PARAM)
     207              :     {
     208       233311 :       auto &p = *static_cast<TyTy::ParamType *> (param);
     209              : 
     210              :       // check the substitution is compatible with bounds
     211       233311 :       rust_debug_loc (locus,
     212              :                       "fill_param_ty bounds_compatible: param %s type %s",
     213              :                       param->get_name ().c_str (), type.get_name ().c_str ());
     214       233311 :       if (!skip_recursive_bounds && needs_bounds_check
     215       233311 :           && !p.is_implicit_self_trait ())
     216              :         {
     217        89652 :           if (!param->bounds_compatible (type, locus, true))
     218              :             return false;
     219              :         }
     220              : 
     221              :       // recursively pass this down to all HRTB's
     222       233301 :       if (!skip_recursive_bounds)
     223       491357 :         for (auto &bound : param->get_specified_bounds ())
     224       258056 :           bound.handle_substitions (subst_mappings);
     225              : 
     226       233301 :       param->set_ty_ref (type.get_ref ());
     227              :     }
     228              : 
     229              :   return true;
     230       295154 : }
     231              : 
     232              : void
     233         6433 : SubstitutionParamMapping::override_context ()
     234              : {
     235         6433 :   if (!param->can_resolve ())
     236              :     return;
     237              : 
     238         6418 :   auto &mappings = Analysis::Mappings::get ();
     239         6418 :   auto context = Resolver::TypeCheckContext::get ();
     240              : 
     241         6418 :   context->insert_type (
     242         6418 :     Analysis::NodeMapping (mappings.crate.get_current_crate (), UNKNOWN_NODEID,
     243         6418 :                            param->get_ref (), UNKNOWN_LOCAL_DEFID),
     244         6418 :     param->resolve ());
     245              : }
     246              : 
     247      9838518 : SubstitutionArg::SubstitutionArg (const SubstitutionParamMapping *param,
     248              :                                   BaseType *argument)
     249      9838518 :   : param (param), argument (argument)
     250              : {
     251      9838518 :   if (param != nullptr)
     252      8724208 :     original_param = param->get_param_ty ();
     253      9838518 : }
     254              : 
     255     18528292 : SubstitutionArg::SubstitutionArg (const SubstitutionArg &other)
     256     18528292 :   : param (other.param), original_param (other.original_param),
     257     18528292 :     argument (other.argument)
     258     18528292 : {}
     259              : 
     260              : SubstitutionArg &
     261      1142622 : SubstitutionArg::operator= (const SubstitutionArg &other)
     262              : {
     263      1142622 :   param = other.param;
     264      1142622 :   argument = other.argument;
     265      1142622 :   original_param = other.original_param;
     266              : 
     267      1142622 :   return *this;
     268              : }
     269              : 
     270              : BaseType *
     271     52058031 : SubstitutionArg::get_tyty () const
     272              : {
     273     52058031 :   return argument;
     274              : }
     275              : 
     276              : const SubstitutionParamMapping *
     277            0 : SubstitutionArg::get_param_mapping () const
     278              : {
     279            0 :   return param;
     280              : }
     281              : 
     282              : const BaseGeneric *
     283      1359451 : SubstitutionArg::get_param_ty () const
     284              : {
     285      1359451 :   return original_param;
     286              : }
     287              : 
     288              : SubstitutionArg
     289      1114310 : SubstitutionArg::error ()
     290              : {
     291      1114310 :   return SubstitutionArg (nullptr, nullptr);
     292              : }
     293              : 
     294              : bool
     295       431910 : SubstitutionArg::is_error () const
     296              : {
     297       431910 :   return param == nullptr || argument == nullptr;
     298              : }
     299              : 
     300              : bool
     301            0 : SubstitutionArg::is_conrete () const
     302              : {
     303            0 :   if (argument == nullptr)
     304              :     return false;
     305              : 
     306            0 :   if (argument->get_kind () == TyTy::TypeKind::PARAM)
     307              :     return false;
     308              : 
     309            0 :   return argument->is_concrete ();
     310              : }
     311              : 
     312              : std::string
     313            0 : SubstitutionArg::as_string () const
     314              : {
     315            0 :   return original_param->as_string ()
     316            0 :          + (argument != nullptr ? ":" + argument->as_string () : "");
     317              : }
     318              : 
     319              : const RegionParamList &
     320      7692603 : SubstitutionArgumentMappings::get_regions () const
     321              : {
     322      7692603 :   return regions;
     323              : }
     324              : 
     325              : RegionParamList &
     326         2709 : SubstitutionArgumentMappings::get_mut_regions ()
     327              : {
     328         2709 :   return regions;
     329              : }
     330              : 
     331              : // SubstitutionArgumentMappings
     332              : 
     333     15878164 : SubstitutionArgumentMappings::SubstitutionArgumentMappings (
     334              :   std::vector<SubstitutionArg> mappings,
     335              :   std::map<std::string, BaseType *> binding_args, RegionParamList regions,
     336              :   location_t locus, bool trait_item_flag, bool error_flag,
     337              :   std::map<std::string, BaseType *> constraint_args)
     338     15878164 :   : mappings (std::move (mappings)), binding_args (binding_args),
     339     15878164 :     constraint_args (constraint_args), regions (regions), locus (locus),
     340     15878164 :     trait_item_flag (trait_item_flag), error_flag (error_flag)
     341     15878164 : {}
     342              : 
     343      9398337 : SubstitutionArgumentMappings::SubstitutionArgumentMappings (
     344              :   const SubstitutionArgumentMappings &other)
     345      9398337 :   : mappings (other.mappings), binding_args (other.binding_args),
     346      9398337 :     constraint_args (other.constraint_args), regions (other.regions),
     347      9398337 :     locus (other.locus), trait_item_flag (other.trait_item_flag),
     348      9398337 :     error_flag (other.error_flag)
     349      9398337 : {}
     350              : 
     351              : SubstitutionArgumentMappings &
     352       223008 : SubstitutionArgumentMappings::operator= (
     353              :   const SubstitutionArgumentMappings &other)
     354              : {
     355       223008 :   mappings = other.mappings;
     356       223008 :   binding_args = other.binding_args;
     357       223008 :   constraint_args = other.constraint_args;
     358       223008 :   regions = other.regions;
     359       223008 :   locus = other.locus;
     360       223008 :   trait_item_flag = other.trait_item_flag;
     361       223008 :   error_flag = other.error_flag;
     362              : 
     363       223008 :   return *this;
     364              : }
     365              : 
     366              : SubstitutionArgumentMappings
     367       109704 : SubstitutionArgumentMappings::error ()
     368              : {
     369       109704 :   return SubstitutionArgumentMappings ({}, {}, 0, UNDEF_LOCATION, false, true);
     370              : }
     371              : 
     372              : SubstitutionArgumentMappings
     373      8074349 : SubstitutionArgumentMappings::empty (size_t num_regions)
     374              : {
     375      8074349 :   return SubstitutionArgumentMappings ({}, {}, num_regions, UNDEF_LOCATION,
     376      8074349 :                                        false, false);
     377              : }
     378              : 
     379              : bool
     380       190961 : SubstitutionArgumentMappings::is_error () const
     381              : {
     382       190961 :   return error_flag;
     383              : }
     384              : 
     385              : bool
     386      1062267 : SubstitutionArgumentMappings::get_argument_for_symbol (
     387              :   const BaseGeneric *param_to_find, SubstitutionArg *argument) const
     388              : {
     389      1385620 :   for (const auto &mapping : mappings)
     390              :     {
     391      1358697 :       const auto *p = mapping.get_param_ty ();
     392      1358697 :       if (p->get_symbol () == param_to_find->get_symbol ())
     393              :         {
     394      1035344 :           *argument = mapping;
     395      1035344 :           return true;
     396              :         }
     397              :     }
     398              :   return false;
     399              : }
     400              : tl::optional<size_t>
     401            0 : SubstitutionArgumentMappings::find_symbol (const ParamType &param_to_find) const
     402              : {
     403            0 :   auto it = std::find_if (mappings.begin (), mappings.end (),
     404            0 :                           [param_to_find] (const SubstitutionArg &arg) {
     405            0 :                             return arg.get_param_ty ()->get_symbol ()
     406            0 :                                    == param_to_find.get_symbol ();
     407              :                           });
     408            0 :   if (it == mappings.end ())
     409            0 :     return tl::nullopt;
     410            0 :   return std::distance (mappings.begin (), it);
     411              : }
     412              : 
     413              : bool
     414        52043 : SubstitutionArgumentMappings::get_argument_at (size_t index,
     415              :                                                SubstitutionArg *argument)
     416              : {
     417        52043 :   if (index > mappings.size ())
     418              :     return false;
     419              : 
     420        52043 :   *argument = mappings.at (index);
     421        52043 :   return true;
     422              : }
     423              : 
     424              : bool
     425            0 : SubstitutionArgumentMappings::is_concrete () const
     426              : {
     427            0 :   for (auto &mapping : mappings)
     428              :     {
     429            0 :       if (!mapping.is_conrete ())
     430            0 :         return false;
     431              :     }
     432              :   return true;
     433              : }
     434              : 
     435              : location_t
     436      7836072 : SubstitutionArgumentMappings::get_locus () const
     437              : {
     438      7836072 :   return locus;
     439              : }
     440              : 
     441              : size_t
     442       212049 : SubstitutionArgumentMappings::size () const
     443              : {
     444       212049 :   return mappings.size ();
     445              : }
     446              : 
     447              : bool
     448        86463 : SubstitutionArgumentMappings::is_empty () const
     449              : {
     450        86463 :   return size () == 0;
     451              : }
     452              : 
     453              : std::vector<SubstitutionArg> &
     454       600267 : SubstitutionArgumentMappings::get_mappings ()
     455              : {
     456       600267 :   return mappings;
     457              : }
     458              : 
     459              : const std::vector<SubstitutionArg> &
     460     88173800 : SubstitutionArgumentMappings::get_mappings () const
     461              : {
     462     88173800 :   return mappings;
     463              : }
     464              : 
     465              : std::map<std::string, BaseType *> &
     466        53261 : SubstitutionArgumentMappings::get_binding_args ()
     467              : {
     468        53261 :   return binding_args;
     469              : }
     470              : 
     471              : const std::map<std::string, BaseType *> &
     472      7668273 : SubstitutionArgumentMappings::get_binding_args () const
     473              : {
     474      7668273 :   return binding_args;
     475              : }
     476              : 
     477              : const std::map<std::string, BaseType *> &
     478      7715812 : SubstitutionArgumentMappings::get_constraint_args () const
     479              : {
     480      7715812 :   return constraint_args;
     481              : }
     482              : 
     483              : std::string
     484            0 : SubstitutionArgumentMappings::as_string () const
     485              : {
     486            0 :   std::string buffer;
     487            0 :   for (auto &mapping : mappings)
     488              :     {
     489            0 :       buffer += mapping.as_string () + ", ";
     490              :     }
     491            0 :   return "<" + buffer + ">";
     492            0 : }
     493              : 
     494              : bool
     495        53202 : SubstitutionArgumentMappings::trait_item_mode () const
     496              : {
     497        53202 :   return trait_item_flag;
     498              : }
     499              : 
     500              : // SubstitutionRef
     501              : 
     502      8510282 : SubstitutionRef::SubstitutionRef (
     503              :   std::vector<SubstitutionParamMapping> substitutions,
     504              :   SubstitutionArgumentMappings arguments, RegionConstraints region_constraints)
     505      8510282 :   : substitutions (substitutions), used_arguments (arguments),
     506     17020564 :     region_constraints (region_constraints)
     507      8510282 : {}
     508              : 
     509              : bool
     510      3714653 : SubstitutionRef::has_substitutions () const
     511              : {
     512      3714653 :   return substitutions.size () > 0;
     513              : }
     514              : 
     515              : std::string
     516       153990 : SubstitutionRef::subst_as_string () const
     517              : {
     518       153990 :   std::string buffer;
     519       187309 :   for (size_t i = 0; i < substitutions.size (); i++)
     520              :     {
     521        33319 :       const SubstitutionParamMapping &sub = substitutions.at (i);
     522        66638 :       buffer += sub.as_string ();
     523              : 
     524        33319 :       if ((i + 1) < substitutions.size ())
     525         2733 :         buffer += ", ";
     526              :     }
     527              : 
     528       184576 :   return buffer.empty () ? "" : "<" + buffer + ">";
     529       153990 : }
     530              : 
     531              : bool
     532         2014 : SubstitutionRef::supports_associated_bindings () const
     533              : {
     534         2014 :   return get_num_associated_bindings () > 0;
     535              : }
     536              : 
     537              : size_t
     538            1 : SubstitutionRef::get_num_associated_bindings () const
     539              : {
     540            1 :   return 0;
     541              : }
     542              : 
     543              : TypeBoundPredicateItem
     544            0 : SubstitutionRef::lookup_associated_type (const std::string &search)
     545              : {
     546            0 :   return TypeBoundPredicateItem::error ();
     547              : }
     548              : 
     549              : size_t
     550       167556 : SubstitutionRef::get_num_substitutions () const
     551              : {
     552       167556 :   return substitutions.size ();
     553              : }
     554              : size_t
     555          241 : SubstitutionRef::get_num_lifetime_params () const
     556              : {
     557          241 :   return used_arguments.get_regions ().size ();
     558              : }
     559              : size_t
     560          397 : SubstitutionRef::get_num_type_params () const
     561              : {
     562          397 :   return get_num_substitutions ();
     563              : }
     564              : 
     565              : std::vector<SubstitutionParamMapping> &
     566       787216 : SubstitutionRef::get_substs ()
     567              : {
     568       787216 :   return substitutions;
     569              : }
     570              : 
     571              : const std::vector<SubstitutionParamMapping> &
     572      7490750 : SubstitutionRef::get_substs () const
     573              : {
     574      7490750 :   return substitutions;
     575              : }
     576              : 
     577              : std::vector<SubstitutionParamMapping>
     578       632926 : SubstitutionRef::clone_substs () const
     579              : {
     580       632926 :   std::vector<SubstitutionParamMapping> clone;
     581       632926 :   clone.reserve (substitutions.size ());
     582              : 
     583      1061056 :   for (auto &sub : substitutions)
     584       428130 :     clone.push_back (sub.clone ());
     585              : 
     586       632926 :   return clone;
     587              : }
     588              : 
     589              : void
     590         5865 : SubstitutionRef::override_context ()
     591              : {
     592        12298 :   for (auto &sub : substitutions)
     593              :     {
     594         6433 :       sub.override_context ();
     595              :     }
     596         5865 : }
     597              : 
     598              : bool
     599        99545 : SubstitutionRef::needs_substitution () const
     600              : {
     601        99545 :   return std::any_of (substitutions.begin (), substitutions.end (),
     602              :                       std::mem_fn (
     603        99545 :                         &SubstitutionParamMapping::needs_substitution));
     604              : }
     605              : 
     606              : bool
     607           63 : SubstitutionRef::was_substituted () const
     608              : {
     609           63 :   return !needs_substitution ();
     610              : }
     611              : 
     612              : SubstitutionArgumentMappings &
     613        79139 : SubstitutionRef::get_substitution_arguments ()
     614              : {
     615        79139 :   return used_arguments;
     616              : }
     617              : 
     618              : const SubstitutionArgumentMappings &
     619     40655539 : SubstitutionRef::get_substitution_arguments () const
     620              : {
     621     40655539 :   return used_arguments;
     622              : }
     623              : 
     624              : size_t
     625       113814 : SubstitutionRef::num_required_substitutions () const
     626              : {
     627       113814 :   size_t n = 0;
     628       280347 :   for (auto &p : substitutions)
     629              :     {
     630       166533 :       if (p.needs_substitution ())
     631       166122 :         n++;
     632              :     }
     633       113814 :   return n;
     634              : }
     635              : 
     636              : size_t
     637       227665 : SubstitutionRef::min_required_substitutions () const
     638              : {
     639       227665 :   size_t n = 0;
     640       560776 :   for (auto &p : substitutions)
     641              :     {
     642       333111 :       if (p.needs_substitution () && !p.param_has_default_ty ())
     643       242130 :         n++;
     644              :     }
     645       227665 :   return n;
     646              : }
     647              : 
     648              : const SubstitutionArgumentMappings &
     649        20127 : SubstitutionRef::get_used_arguments () const
     650              : {
     651        20127 :   return used_arguments;
     652              : }
     653              : 
     654              : tl::optional<SubstitutionArg>
     655         1109 : SubstitutionRef::get_arg_at (size_t i) const
     656              : {
     657         1109 :   auto param_ty = get_substs ().at (i).get_param_ty ();
     658         1109 :   SubstitutionArg arg = SubstitutionArg::error ();
     659         1109 :   get_used_arguments ().get_argument_for_symbol (param_ty, &arg);
     660         1109 :   if (arg.is_error ())
     661          135 :     return tl::nullopt;
     662          974 :   return arg;
     663              : }
     664              : 
     665              : const RegionConstraints &
     666       522748 : SubstitutionRef::get_region_constraints () const
     667              : {
     668       522748 :   return region_constraints;
     669              : }
     670              : 
     671              : SubstitutionArgumentMappings
     672       113851 : SubstitutionRef::get_mappings_from_generic_args (
     673              :   HIR::GenericArgs &args, const std::vector<Region> &regions)
     674              : {
     675       113851 :   std::map<std::string, BaseType *> binding_arguments;
     676       113851 :   std::map<std::string, BaseType *> constraint_arguments;
     677       113851 :   if (args.get_binding_args ().size () > 0)
     678              :     {
     679         2014 :       if (supports_associated_bindings ())
     680              :         {
     681         2013 :           if (args.get_binding_args ().size () > get_num_associated_bindings ())
     682              :             {
     683            0 :               rich_location r (line_table, args.get_locus ());
     684            0 :               rust_error_at (r,
     685              :                              "generic item takes at most %lu type binding "
     686              :                              "arguments but %lu were supplied",
     687            0 :                              (unsigned long) get_num_associated_bindings (),
     688            0 :                              (unsigned long) args.get_binding_args ().size ());
     689            0 :               return SubstitutionArgumentMappings::error ();
     690            0 :             }
     691              : 
     692         4077 :           for (auto &binding : args.get_binding_args ())
     693              :             {
     694         2064 :               BaseType *resolved
     695         2064 :                 = Resolver::TypeCheckType::Resolve (binding.get_type ());
     696         2064 :               if (resolved == nullptr
     697         2064 :                   || resolved->get_kind () == TyTy::TypeKind::ERROR)
     698              :                 {
     699            0 :                   return SubstitutionArgumentMappings::error ();
     700              :                 }
     701              : 
     702              :               // resolve to relevant binding
     703         2064 :               auto binding_item = lookup_associated_type (
     704         2064 :                 binding.get_identifier ().as_string ());
     705         2064 :               if (binding_item.is_error ())
     706              :                 {
     707            0 :                   rust_error_at (
     708              :                     binding.get_locus (), "unknown associated type binding: %s",
     709            0 :                     binding.get_identifier ().as_string ().c_str ());
     710            0 :                   return SubstitutionArgumentMappings::error ();
     711              :                 }
     712              : 
     713         2064 :               if (binding.get_kind ()
     714              :                   == HIR::GenericArgsBinding::Kind::Constraint)
     715          458 :                 constraint_arguments[binding.get_identifier ().as_string ()]
     716          458 :                   = resolved;
     717              :               else
     718         1606 :                 binding_arguments[binding.get_identifier ().as_string ()]
     719         1606 :                   = resolved;
     720              :             }
     721              :         }
     722              :       else
     723              :         {
     724            1 :           rich_location r (line_table, args.get_locus ());
     725            3 :           for (auto &binding : args.get_binding_args ())
     726            2 :             r.add_range (binding.get_locus ());
     727              : 
     728            1 :           rust_error_at (r, ErrorCode::E0229,
     729              :                          "associated type bindings are not allowed here");
     730            1 :           return SubstitutionArgumentMappings::error ();
     731            1 :         }
     732              :     }
     733              : 
     734              :   // check if we need to use inherited arguments or nothing
     735       113850 :   size_t offs = 0;
     736       113850 :   size_t total_arguments
     737       113850 :     = args.get_type_args ().size () + args.get_const_args ().size ();
     738       113850 :   if (total_arguments < substitutions.size ())
     739              :     {
     740         9264 :       offs = used_arguments.get_mappings ().empty () ? get_outer_param_count ()
     741         1103 :                                                      : used_arguments.size ();
     742         9264 :       total_arguments += offs;
     743              :     }
     744              : 
     745       113850 :   if (total_arguments > substitutions.size ())
     746              :     {
     747            4 :       rich_location r (line_table, args.get_locus ());
     748            4 :       if (!substitutions.empty ())
     749              :         {
     750            3 :           const auto &subst = substitutions.front ();
     751            3 :           const auto &generic = subst.get_generic_param ();
     752            3 :           r.add_range (generic.get_locus ());
     753              :         }
     754              : 
     755            8 :       rust_error_at (
     756              :         r,
     757              :         "generic item takes at most %lu type arguments but %lu were supplied",
     758            4 :         (unsigned long) substitutions.size (),
     759            4 :         (unsigned long) args.get_type_args ().size ());
     760            4 :       return SubstitutionArgumentMappings::error ();
     761            4 :     }
     762              : 
     763       113846 :   if (total_arguments < min_required_substitutions ())
     764              :     {
     765            5 :       rich_location r (line_table, args.get_locus ());
     766            5 :       if (!substitutions.empty ())
     767              :         {
     768            5 :           const auto &subst = substitutions.front ();
     769            5 :           const auto &generic = subst.get_generic_param ();
     770            5 :           r.add_range (generic.get_locus ());
     771              :         }
     772              : 
     773           10 :       rust_error_at (
     774              :         r, ErrorCode::E0107,
     775              :         "generic item takes at least %lu type arguments but %lu were supplied",
     776            5 :         (unsigned long) (min_required_substitutions () - offs),
     777            5 :         (unsigned long) args.get_type_args ().size ());
     778            5 :       return SubstitutionArgumentMappings::error ();
     779            5 :     }
     780              : 
     781       113841 :   std::vector<SubstitutionArg> mappings = used_arguments.get_mappings ();
     782       270654 :   for (auto &arg : args.get_type_args ())
     783              :     {
     784       156839 :       BaseType *resolved = Resolver::TypeCheckType::Resolve (*arg);
     785       156817 :       if (resolved == nullptr || resolved->get_kind () == TyTy::TypeKind::ERROR)
     786              :         {
     787            4 :           return SubstitutionArgumentMappings::error ();
     788              :         }
     789              : 
     790       156817 :       const auto &param_mapping = substitutions.at (offs);
     791       156817 :       const auto &generic = param_mapping.get_generic_param ();
     792       156817 :       if (generic.get_kind () == HIR::GenericParam::GenericKind::TYPE)
     793              :         {
     794       156814 :           const auto &type_param
     795              :             = static_cast<const HIR::TypeParam &> (generic);
     796       156814 :           if (type_param.from_impl_trait ())
     797              :             {
     798            1 :               rich_location r (line_table, arg->get_locus ());
     799            1 :               r.add_fixit_remove (arg->get_locus ());
     800            1 :               rust_error_at (r, ErrorCode::E0632,
     801              :                              "cannot provide explicit generic arguments when "
     802              :                              "%<impl Trait%> is used in argument position");
     803            1 :               return SubstitutionArgumentMappings::error ();
     804            1 :             }
     805              :         }
     806            3 :       else if (generic.get_kind () == HIR::GenericParam::GenericKind::CONST)
     807              :         {
     808            3 :           if (resolved->get_kind () != TyTy::TypeKind::CONST)
     809              :             {
     810            3 :               rich_location r (line_table, arg->get_locus ());
     811            3 :               r.add_fixit_remove (arg->get_locus ());
     812            3 :               rust_error_at (r, ErrorCode::E0747,
     813              :                              "type provided when a constant was expected");
     814            3 :               return SubstitutionArgumentMappings::error ();
     815            3 :             }
     816              :         }
     817              : 
     818       156813 :       mappings.emplace_back (&param_mapping, resolved);
     819       156813 :       offs++;
     820              :     }
     821              : 
     822       114149 :   for (auto &arg : args.get_const_args ())
     823              :     {
     824          335 :       auto &expr = *arg.get_expression ().get ();
     825          335 :       const auto &param_mapping = substitutions.at (offs);
     826          335 :       const auto &generic = param_mapping.get_generic_param ();
     827          335 :       if (generic.get_kind () != HIR::GenericParam::GenericKind::CONST)
     828              :         {
     829            0 :           rich_location r (line_table, arg.get_locus ());
     830            0 :           r.add_fixit_remove (expr.get_locus ());
     831            0 :           rust_error_at (r, "invalid position for a const generic argument");
     832            0 :           return SubstitutionArgumentMappings::error ();
     833            0 :         }
     834              : 
     835          335 :       auto specified_type = param_mapping.get_param_ty ()
     836          335 :                               ->as_const_type ()
     837          335 :                               ->get_specified_type ();
     838          335 :       auto const_value_ty = resolve_const_argument (expr, specified_type);
     839          335 :       if (const_value_ty->is<ErrorType> ())
     840            1 :         return SubstitutionArgumentMappings::error ();
     841              : 
     842          334 :       mappings.emplace_back (&param_mapping, const_value_ty);
     843          334 :       offs++;
     844              :     }
     845              : 
     846              :   // we must need to fill out defaults
     847       113814 :   size_t left_over
     848       113814 :     = num_required_substitutions () - min_required_substitutions ();
     849       113814 :   if (left_over > 0)
     850              :     {
     851        53314 :       for (size_t offs = mappings.size (); offs < substitutions.size (); offs++)
     852              :         {
     853         8235 :           SubstitutionParamMapping &param = substitutions.at (offs);
     854         8235 :           rust_assert (param.param_has_default_ty ());
     855              : 
     856         8235 :           BaseType *resolved = param.get_default_ty ();
     857         8235 :           if (resolved->get_kind () == TypeKind::ERROR)
     858            0 :             return SubstitutionArgumentMappings::error ();
     859              : 
     860              :           // this resolved default might already contain default parameters
     861         8235 :           if (!resolved->is_concrete ())
     862              :             {
     863         8213 :               SubstitutionArgumentMappings intermediate (
     864              :                 mappings, binding_arguments,
     865         8213 :                 {used_arguments.get_regions ().size ()}, args.get_locus ());
     866         8213 :               resolved = Resolver::SubstMapperInternal::Resolve (resolved,
     867              :                                                                  intermediate);
     868              : 
     869         8213 :               if (resolved->get_kind () == TypeKind::ERROR)
     870            0 :                 return SubstitutionArgumentMappings::error ();
     871         8213 :             }
     872              : 
     873         8235 :           mappings.emplace_back (&param, resolved);
     874              :         }
     875              :     }
     876              : 
     877       113814 :   return {mappings,
     878              :           binding_arguments,
     879       227628 :           RegionParamList::from_subst (used_arguments.get_regions ().size (),
     880              :                                        regions),
     881              :           args.get_locus (),
     882              :           false,
     883              :           false,
     884       341442 :           constraint_arguments};
     885       227648 : }
     886              : 
     887              : BaseType *
     888          336 : SubstitutionRef::resolve_const_argument (HIR::Expr &expr,
     889              :                                          BaseType *specified_type)
     890              : {
     891          336 :   BaseType *expr_type = Resolver::TypeCheckExpr::Resolve (expr);
     892          672 :   if (expr_type == nullptr || expr_type->is<ErrorType> ())
     893            0 :     return new ErrorType (expr.get_mappings ().get_hirid ());
     894              : 
     895          336 :   TyTy::BaseType *coerced_type = nullptr;
     896          336 :   if (expr_type->get_kind () == TyTy::TypeKind::CONST)
     897              :     {
     898          232 :       auto const_expr_type = expr_type->as_const_type ();
     899          232 :       auto const_value_type = const_expr_type->get_specified_type ();
     900          232 :       coerced_type
     901          232 :         = Resolver::coercion_site (expr.get_mappings ().get_hirid (),
     902          232 :                                    TyTy::TyWithLocation (specified_type),
     903              :                                    TyTy::TyWithLocation (const_value_type,
     904          232 :                                                          expr.get_locus ()),
     905          232 :                                    expr.get_locus ());
     906              :     }
     907              :   else
     908              :     {
     909          104 :       coerced_type
     910          104 :         = Resolver::coercion_site (expr.get_mappings ().get_hirid (),
     911          104 :                                    TyTy::TyWithLocation (specified_type),
     912              :                                    TyTy::TyWithLocation (expr_type,
     913          104 :                                                          expr.get_locus ()),
     914          104 :                                    expr.get_locus ());
     915              :     }
     916              : 
     917          672 :   if (coerced_type == nullptr || coerced_type->is<ErrorType> ())
     918            0 :     return new ErrorType (expr.get_mappings ().get_hirid ());
     919              : 
     920          336 :   TyTy::BaseType *const_value_ty = nullptr;
     921          336 :   if (expr_type->get_kind () == TyTy::TypeKind::CONST)
     922              :     const_value_ty = expr_type;
     923              :   else
     924              :     {
     925          104 :       auto ctx = Compile::Context::get ();
     926          104 :       tree folded
     927          104 :         = Compile::HIRCompileBase::query_compile_const_expr (ctx, coerced_type,
     928              :                                                              expr);
     929              : 
     930          104 :       if (folded == error_mark_node)
     931              :         {
     932            1 :           rich_location r (line_table, expr.get_locus ());
     933            1 :           r.add_range (expr.get_locus ());
     934            1 :           rust_error_at (r, "failed to resolve const expression");
     935            1 :           return new ErrorType (expr.get_mappings ().get_hirid ());
     936            1 :         }
     937              : 
     938              :       // Use a fresh HirId to avoid conflicts with the expr's type
     939          103 :       auto &global_mappings = Analysis::Mappings::get ();
     940          103 :       HirId const_value_id = global_mappings.get_next_hir_id ();
     941          103 :       const_value_ty
     942          103 :         = new TyTy::ConstValueType (folded, coerced_type, const_value_id,
     943          103 :                                     const_value_id, {});
     944              : 
     945              :       // Insert the ConstValueType into the context so it can be looked up
     946          103 :       auto context = Resolver::TypeCheckContext::get ();
     947          103 :       context->insert_type (Analysis::NodeMapping (0, 0,
     948              :                                                    const_value_ty->get_ref (),
     949          103 :                                                    0),
     950              :                             const_value_ty);
     951              :     }
     952              : 
     953              :   return const_value_ty;
     954              : }
     955              : 
     956              : BaseType *
     957         9617 : SubstitutionRef::infer_substitions (location_t locus)
     958              : {
     959         9617 :   std::vector<SubstitutionArg> args;
     960         9617 :   std::map<std::string, BaseType *> argument_mappings;
     961        20841 :   for (auto &p : get_substs ())
     962              :     {
     963        11224 :       if (p.needs_substitution ())
     964              :         {
     965        11180 :           const HIR::GenericParam &generic = p.get_generic_param ();
     966        11180 :           const std::string &symbol = p.get_param_ty ()->get_symbol ();
     967        11180 :           auto it = argument_mappings.find (symbol);
     968        11180 :           bool have_mapping = it != argument_mappings.end ();
     969              : 
     970        11180 :           if (have_mapping)
     971              :             {
     972          121 :               args.emplace_back (&p, it->second);
     973              :             }
     974        11059 :           else if (generic.get_kind () == HIR::GenericParam::GenericKind::TYPE)
     975              :             {
     976        11039 :               TyVar infer_var = TyVar::get_implicit_infer_var (locus);
     977        11039 :               args.emplace_back (&p, infer_var.get_tyty ());
     978        11039 :               argument_mappings[symbol] = infer_var.get_tyty ();
     979              :             }
     980           20 :           else if (generic.get_kind () == HIR::GenericParam::GenericKind::CONST)
     981              :             {
     982           20 :               TyVar infer_var = TyVar::get_implicit_const_infer_var (locus);
     983           20 :               args.emplace_back (&p, infer_var.get_tyty ());
     984           20 :               argument_mappings[symbol] = infer_var.get_tyty ();
     985              :             }
     986        11180 :         }
     987              :       else
     988              :         {
     989           44 :           args.emplace_back (&p, p.get_param_ty ()->resolve ());
     990              :         }
     991              :     }
     992              : 
     993              :   // FIXME do we need to add inference variables to all the possible bindings?
     994              :   // it might just lead to inference variable hell not 100% sure if rustc does
     995              :   // this i think the language might needs this to be explicitly set
     996              : 
     997         9617 :   SubstitutionArgumentMappings infer_arguments (std::move (args),
     998              :                                                 {} /* binding_arguments */,
     999              :                                                 used_arguments.get_regions (),
    1000         9617 :                                                 locus);
    1001         9617 :   return handle_substitions (infer_arguments);
    1002         9617 : }
    1003              : 
    1004              : SubstitutionArgumentMappings
    1005        53200 : SubstitutionRef::adjust_mappings_for_this (
    1006              :   SubstitutionArgumentMappings &mappings, bool trait_mode)
    1007              : {
    1008        53200 :   std::vector<SubstitutionArg> resolved_mappings;
    1009       122156 :   for (size_t i = 0; i < substitutions.size (); i++)
    1010              :     {
    1011        68956 :       auto &subst = substitutions.at (i);
    1012              : 
    1013        68956 :       SubstitutionArg arg = SubstitutionArg::error ();
    1014        68956 :       if (mappings.size () == substitutions.size ())
    1015              :         {
    1016        52043 :           mappings.get_argument_at (i, &arg);
    1017              :         }
    1018              :       else
    1019              :         {
    1020        16913 :           if (subst.needs_substitution ())
    1021              :             {
    1022              :               // get from passed in mappings
    1023        16606 :               bool found
    1024        16606 :                 = mappings.get_argument_for_symbol (subst.get_param_ty (),
    1025              :                                                     &arg);
    1026        16606 :               if (!found)
    1027              :                 {
    1028              :                   // This type can already be partially instantiated from an
    1029              :                   // outer scope
    1030          862 :                   SubstitutionArg bound_arg = SubstitutionArg::error ();
    1031          862 :                   bool have_binding = used_arguments.get_argument_for_symbol (
    1032          862 :                     subst.get_param_ty (), &bound_arg);
    1033              : 
    1034          862 :                   if (have_binding && !bound_arg.is_error ())
    1035              :                     {
    1036          382 :                       BaseType *resolved
    1037          382 :                         = Resolver::SubstMapperInternal::Resolve (
    1038              :                           bound_arg.get_tyty (), mappings);
    1039          382 :                       if (resolved->get_kind () != TypeKind::ERROR)
    1040          382 :                         arg = SubstitutionArg (&subst, resolved);
    1041              :                     }
    1042              :                 }
    1043              :             }
    1044              :           else
    1045              :             {
    1046              :               // we should already have this somewhere
    1047          307 :               used_arguments.get_argument_for_symbol (subst.get_param_ty (),
    1048              :                                                       &arg);
    1049              :             }
    1050              :         }
    1051              : 
    1052        68956 :       bool ok = !arg.is_error ();
    1053        68956 :       if (ok || (trait_mode && i == 0))
    1054        68476 :         resolved_mappings.emplace_back (&subst, arg.get_tyty ());
    1055              :     }
    1056              : 
    1057        53200 :   if (resolved_mappings.empty ())
    1058            2 :     return SubstitutionArgumentMappings::error ();
    1059              : 
    1060        53198 :   return SubstitutionArgumentMappings (resolved_mappings,
    1061        53198 :                                        mappings.get_binding_args (),
    1062              :                                        mappings.get_regions (),
    1063              :                                        mappings.get_locus (),
    1064              :                                        mappings.trait_item_mode (), false,
    1065       106396 :                                        mappings.get_constraint_args ());
    1066        53200 : }
    1067              : 
    1068              : bool
    1069            0 : SubstitutionRef::are_mappings_bound (SubstitutionArgumentMappings &mappings)
    1070              : {
    1071            0 :   std::vector<SubstitutionArg> resolved_mappings;
    1072            0 :   for (size_t i = 0; i < substitutions.size (); i++)
    1073              :     {
    1074            0 :       auto &subst = substitutions.at (i);
    1075              : 
    1076            0 :       SubstitutionArg arg = SubstitutionArg::error ();
    1077            0 :       if (mappings.size () == substitutions.size ())
    1078              :         {
    1079            0 :           mappings.get_argument_at (i, &arg);
    1080              :         }
    1081              :       else
    1082              :         {
    1083            0 :           if (subst.needs_substitution ())
    1084              :             {
    1085              :               // get from passed in mappings
    1086            0 :               mappings.get_argument_for_symbol (subst.get_param_ty (), &arg);
    1087              :             }
    1088              :           else
    1089              :             {
    1090              :               // we should already have this somewhere
    1091            0 :               used_arguments.get_argument_for_symbol (subst.get_param_ty (),
    1092              :                                                       &arg);
    1093              :             }
    1094              :         }
    1095              : 
    1096            0 :       bool ok = !arg.is_error ();
    1097            0 :       if (ok)
    1098            0 :         resolved_mappings.emplace_back (&subst, arg.get_tyty ());
    1099              :     }
    1100              : 
    1101            0 :   return !resolved_mappings.empty ();
    1102            0 : }
    1103              : 
    1104              : // this function assumes that the mappings being passed are for the same type as
    1105              : // this new substitution reference so ordering matters here
    1106              : SubstitutionArgumentMappings
    1107           63 : SubstitutionRef::solve_mappings_from_receiver_for_self (
    1108              :   SubstitutionArgumentMappings &mappings) const
    1109              : {
    1110           63 :   std::vector<SubstitutionArg> resolved_mappings;
    1111              : 
    1112           63 :   rust_assert (mappings.size () == get_num_substitutions ());
    1113          126 :   for (size_t i = 0; i < get_num_substitutions (); i++)
    1114              :     {
    1115           63 :       const SubstitutionParamMapping &param_mapping = substitutions.at (i);
    1116           63 :       SubstitutionArg &arg = mappings.get_mappings ().at (i);
    1117              : 
    1118           63 :       if (param_mapping.needs_substitution ())
    1119           63 :         resolved_mappings.emplace_back (&param_mapping, arg.get_tyty ());
    1120              :     }
    1121              : 
    1122           63 :   return SubstitutionArgumentMappings (resolved_mappings,
    1123           63 :                                        mappings.get_binding_args (),
    1124              :                                        mappings.get_regions (),
    1125              :                                        mappings.get_locus (), false, false,
    1126          126 :                                        mappings.get_constraint_args ());
    1127           63 : }
    1128              : 
    1129              : bool
    1130        20341 : SubstitutionRef::monomorphize ()
    1131              : {
    1132        32617 :   for (const auto &subst : get_substs ())
    1133              :     {
    1134        12276 :       const auto pty = subst.get_param_ty ();
    1135        12276 :       if (!pty->can_resolve ())
    1136          110 :         continue;
    1137              : 
    1138        12166 :       TyTy::BaseType *binding = pty->resolve ();
    1139        12166 :       if (binding->get_kind () == TyTy::TypeKind::PARAM)
    1140         2485 :         continue;
    1141              : 
    1142              :       // For each where-clause bound on this fn-substitution param, find the
    1143              :       // impl block that satisfies the bound for binding and unify
    1144              :       // its signature against binding + bound. This pins inference
    1145              :       // variables that should be constrained
    1146              :       //
    1147              :       //   fn into_iter<I: Iterator> with binding = Range<{integer}>
    1148              :       //
    1149              :       // the only matching
    1150              :       //
    1151              :       //   <A: Step> Iterator for Range<A>
    1152              :       //
    1153              :       // Step for usize impl together force {integer} = usize instead of
    1154              :       // letting it default.
    1155        21197 :       for (const auto &bound : pty->get_specified_bounds ())
    1156              :         {
    1157        11516 :           bool ambigious = false;
    1158        11516 :           auto associated
    1159        11516 :             = Resolver::lookup_associated_impl_block (bound, binding,
    1160              :                                                       &ambigious);
    1161        11516 :           if (associated != nullptr)
    1162         2820 :             associated->bind_impl_for_bound (binding, bound, UNKNOWN_LOCATION);
    1163              :         }
    1164              :     }
    1165              : 
    1166        20341 :   return true;
    1167              : }
    1168              : 
    1169              : } // namespace TyTy
    1170              : } // namespace Rust
        

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