LCOV - code coverage report
Current view: top level - gcc/rust/typecheck - rust-tyty-cmp.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 45.4 % 801 364
Test Date: 2024-04-20 14:03:02 Functions: 56.6 % 145 82
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                 :             : #ifndef RUST_TYTY_CMP_H
      20                 :             : #define RUST_TYTY_CMP_H
      21                 :             : 
      22                 :             : #include "rust-diagnostics.h"
      23                 :             : #include "rust-tyty.h"
      24                 :             : #include "rust-tyty-visitor.h"
      25                 :             : #include "rust-hir-map.h"
      26                 :             : #include "rust-hir-type-check.h"
      27                 :             : 
      28                 :             : namespace Rust {
      29                 :             : namespace TyTy {
      30                 :             : 
      31                 :             : class BaseCmp : public TyConstVisitor
      32                 :             : {
      33                 :             : public:
      34                 :      355079 :   virtual bool can_eq (const BaseType *other)
      35                 :             :   {
      36                 :      355079 :     if (other->get_kind () == TypeKind::PARAM)
      37                 :             :       {
      38                 :       15324 :         const ParamType *p = static_cast<const ParamType *> (other);
      39                 :       15324 :         other = p->resolve ();
      40                 :             :       }
      41                 :      355079 :     if (other->get_kind () == TypeKind::PLACEHOLDER)
      42                 :             :       {
      43                 :          30 :         const PlaceholderType *p = static_cast<const PlaceholderType *> (other);
      44                 :          30 :         if (p->can_resolve ())
      45                 :             :           {
      46                 :          23 :             other = p->resolve ();
      47                 :             :           }
      48                 :             :       }
      49                 :      355079 :     if (other->get_kind () == TypeKind::PROJECTION)
      50                 :             :       {
      51                 :         697 :         const ProjectionType *p = static_cast<const ProjectionType *> (other);
      52                 :         697 :         other = p->get ();
      53                 :             :       }
      54                 :             : 
      55                 :      355079 :     other->accept_vis (*this);
      56                 :      355079 :     return ok;
      57                 :             :   }
      58                 :             : 
      59                 :          16 :   virtual void visit (const TupleType &type) override
      60                 :             :   {
      61                 :          16 :     ok = false;
      62                 :             : 
      63                 :          16 :     if (emit_error_flag)
      64                 :             :       {
      65                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
      66                 :           0 :         location_t base_locus
      67                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
      68                 :           0 :         rich_location r (line_table, ref_locus);
      69                 :           0 :         r.add_range (base_locus);
      70                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
      71                 :           0 :                        get_base ()->as_string ().c_str (),
      72                 :           0 :                        type.as_string ().c_str ());
      73                 :           0 :       }
      74                 :          16 :   }
      75                 :             : 
      76                 :       17536 :   virtual void visit (const ADTType &type) override
      77                 :             :   {
      78                 :       17536 :     ok = false;
      79                 :       17536 :     if (emit_error_flag)
      80                 :             :       {
      81                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
      82                 :           0 :         location_t base_locus
      83                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
      84                 :           0 :         rich_location r (line_table, ref_locus);
      85                 :           0 :         r.add_range (base_locus);
      86                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
      87                 :           0 :                        get_base ()->as_string ().c_str (),
      88                 :           0 :                        type.as_string ().c_str ());
      89                 :           0 :       }
      90                 :       17536 :   }
      91                 :             : 
      92                 :         184 :   virtual void visit (const InferType &type) override
      93                 :             :   {
      94                 :         184 :     ok = false;
      95                 :         184 :     if (emit_error_flag)
      96                 :             :       {
      97                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
      98                 :           0 :         location_t base_locus
      99                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
     100                 :           0 :         rich_location r (line_table, ref_locus);
     101                 :           0 :         r.add_range (base_locus);
     102                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
     103                 :           0 :                        get_base ()->as_string ().c_str (),
     104                 :           0 :                        type.as_string ().c_str ());
     105                 :           0 :       }
     106                 :         184 :   }
     107                 :             : 
     108                 :           0 :   virtual void visit (const FnType &type) override
     109                 :             :   {
     110                 :           0 :     ok = false;
     111                 :           0 :     if (emit_error_flag)
     112                 :             :       {
     113                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
     114                 :           0 :         location_t base_locus
     115                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
     116                 :           0 :         rich_location r (line_table, ref_locus);
     117                 :           0 :         r.add_range (base_locus);
     118                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
     119                 :           0 :                        get_base ()->as_string ().c_str (),
     120                 :           0 :                        type.as_string ().c_str ());
     121                 :           0 :       }
     122                 :           0 :   }
     123                 :             : 
     124                 :           0 :   virtual void visit (const FnPtr &type) override
     125                 :             :   {
     126                 :           0 :     ok = false;
     127                 :           0 :     if (emit_error_flag)
     128                 :             :       {
     129                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
     130                 :           0 :         location_t base_locus
     131                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
     132                 :           0 :         rich_location r (line_table, ref_locus);
     133                 :           0 :         r.add_range (base_locus);
     134                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
     135                 :           0 :                        get_base ()->as_string ().c_str (),
     136                 :           0 :                        type.as_string ().c_str ());
     137                 :           0 :       }
     138                 :           0 :   }
     139                 :             : 
     140                 :        4027 :   virtual void visit (const ArrayType &type) override
     141                 :             :   {
     142                 :        4027 :     ok = false;
     143                 :        4027 :     if (emit_error_flag)
     144                 :             :       {
     145                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
     146                 :           0 :         location_t base_locus
     147                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
     148                 :           0 :         rich_location r (line_table, ref_locus);
     149                 :           0 :         r.add_range (base_locus);
     150                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
     151                 :           0 :                        get_base ()->as_string ().c_str (),
     152                 :           0 :                        type.as_string ().c_str ());
     153                 :           0 :       }
     154                 :        4027 :   }
     155                 :             : 
     156                 :        2313 :   virtual void visit (const SliceType &type) override
     157                 :             :   {
     158                 :        2313 :     ok = false;
     159                 :        2313 :     if (emit_error_flag)
     160                 :             :       {
     161                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
     162                 :           0 :         location_t base_locus
     163                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
     164                 :           0 :         rich_location r (line_table, ref_locus);
     165                 :           0 :         r.add_range (base_locus);
     166                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
     167                 :           0 :                        get_base ()->as_string ().c_str (),
     168                 :           0 :                        type.as_string ().c_str ());
     169                 :           0 :       }
     170                 :        2313 :   }
     171                 :             : 
     172                 :        6254 :   virtual void visit (const BoolType &type) override
     173                 :             :   {
     174                 :        6254 :     ok = false;
     175                 :        6254 :     if (emit_error_flag)
     176                 :             :       {
     177                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
     178                 :           0 :         location_t base_locus
     179                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
     180                 :           0 :         rich_location r (line_table, ref_locus);
     181                 :           0 :         r.add_range (base_locus);
     182                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
     183                 :           0 :                        get_base ()->as_string ().c_str (),
     184                 :           0 :                        type.as_string ().c_str ());
     185                 :           0 :       }
     186                 :        6254 :   }
     187                 :             : 
     188                 :       34411 :   virtual void visit (const IntType &type) override
     189                 :             :   {
     190                 :       34411 :     ok = false;
     191                 :       34411 :     if (emit_error_flag)
     192                 :             :       {
     193                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
     194                 :           0 :         location_t base_locus
     195                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
     196                 :           0 :         rich_location r (line_table, ref_locus);
     197                 :           0 :         r.add_range (base_locus);
     198                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
     199                 :           0 :                        get_base ()->as_string ().c_str (),
     200                 :           0 :                        type.as_string ().c_str ());
     201                 :           0 :       }
     202                 :       34411 :   }
     203                 :             : 
     204                 :       73504 :   virtual void visit (const UintType &type) override
     205                 :             :   {
     206                 :       73504 :     ok = false;
     207                 :       73504 :     if (emit_error_flag)
     208                 :             :       {
     209                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
     210                 :           0 :         location_t base_locus
     211                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
     212                 :           0 :         rich_location r (line_table, ref_locus);
     213                 :           0 :         r.add_range (base_locus);
     214                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
     215                 :           0 :                        get_base ()->as_string ().c_str (),
     216                 :           0 :                        type.as_string ().c_str ());
     217                 :           0 :       }
     218                 :       73504 :   }
     219                 :             : 
     220                 :       40989 :   virtual void visit (const USizeType &type) override
     221                 :             :   {
     222                 :       40989 :     ok = false;
     223                 :       40989 :     if (emit_error_flag)
     224                 :             :       {
     225                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
     226                 :           0 :         location_t base_locus
     227                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
     228                 :           0 :         rich_location r (line_table, ref_locus);
     229                 :           0 :         r.add_range (base_locus);
     230                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
     231                 :           0 :                        get_base ()->as_string ().c_str (),
     232                 :           0 :                        type.as_string ().c_str ());
     233                 :           0 :       }
     234                 :       40989 :   }
     235                 :             : 
     236                 :        8474 :   virtual void visit (const ISizeType &type) override
     237                 :             :   {
     238                 :        8474 :     ok = false;
     239                 :        8474 :     if (emit_error_flag)
     240                 :             :       {
     241                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
     242                 :           0 :         location_t base_locus
     243                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
     244                 :           0 :         rich_location r (line_table, ref_locus);
     245                 :           0 :         r.add_range (base_locus);
     246                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
     247                 :           0 :                        get_base ()->as_string ().c_str (),
     248                 :           0 :                        type.as_string ().c_str ());
     249                 :           0 :       }
     250                 :        8474 :   }
     251                 :             : 
     252                 :       33275 :   virtual void visit (const FloatType &type) override
     253                 :             :   {
     254                 :       33275 :     ok = false;
     255                 :       33275 :     if (emit_error_flag)
     256                 :             :       {
     257                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
     258                 :           0 :         location_t base_locus
     259                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
     260                 :           0 :         rich_location r (line_table, ref_locus);
     261                 :           0 :         r.add_range (base_locus);
     262                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
     263                 :           0 :                        get_base ()->as_string ().c_str (),
     264                 :           0 :                        type.as_string ().c_str ());
     265                 :           0 :       }
     266                 :       33275 :   }
     267                 :             : 
     268                 :           1 :   virtual void visit (const ErrorType &type) override
     269                 :             :   {
     270                 :           1 :     ok = false;
     271                 :           1 :     if (emit_error_flag)
     272                 :             :       {
     273                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
     274                 :           0 :         location_t base_locus
     275                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
     276                 :           0 :         rich_location r (line_table, ref_locus);
     277                 :           0 :         r.add_range (base_locus);
     278                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
     279                 :           0 :                        get_base ()->as_string ().c_str (),
     280                 :           0 :                        type.as_string ().c_str ());
     281                 :           0 :       }
     282                 :           1 :   }
     283                 :             : 
     284                 :        5533 :   virtual void visit (const CharType &type) override
     285                 :             :   {
     286                 :        5533 :     ok = false;
     287                 :        5533 :     if (emit_error_flag)
     288                 :             :       {
     289                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
     290                 :           0 :         location_t base_locus
     291                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
     292                 :           0 :         rich_location r (line_table, ref_locus);
     293                 :           0 :         r.add_range (base_locus);
     294                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
     295                 :           0 :                        get_base ()->as_string ().c_str (),
     296                 :           0 :                        type.as_string ().c_str ());
     297                 :           0 :       }
     298                 :        5533 :   }
     299                 :             : 
     300                 :       20163 :   virtual void visit (const ReferenceType &type) override
     301                 :             :   {
     302                 :       20163 :     ok = false;
     303                 :       20163 :     if (emit_error_flag)
     304                 :             :       {
     305                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
     306                 :           0 :         location_t base_locus
     307                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
     308                 :           0 :         rich_location r (line_table, ref_locus);
     309                 :           0 :         r.add_range (base_locus);
     310                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
     311                 :           0 :                        get_base ()->as_string ().c_str (),
     312                 :           0 :                        type.as_string ().c_str ());
     313                 :           0 :       }
     314                 :       20163 :   }
     315                 :             : 
     316                 :         365 :   virtual void visit (const PointerType &type) override
     317                 :             :   {
     318                 :         365 :     ok = false;
     319                 :         365 :     if (emit_error_flag)
     320                 :             :       {
     321                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
     322                 :           0 :         location_t base_locus
     323                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
     324                 :           0 :         rich_location r (line_table, ref_locus);
     325                 :           0 :         r.add_range (base_locus);
     326                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
     327                 :           0 :                        get_base ()->as_string ().c_str (),
     328                 :           0 :                        type.as_string ().c_str ());
     329                 :           0 :       }
     330                 :         365 :   }
     331                 :             : 
     332                 :           7 :   virtual void visit (const StrType &type) override
     333                 :             :   {
     334                 :           7 :     ok = false;
     335                 :           7 :     if (emit_error_flag)
     336                 :             :       {
     337                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
     338                 :           0 :         location_t base_locus
     339                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
     340                 :           0 :         rich_location r (line_table, ref_locus);
     341                 :           0 :         r.add_range (base_locus);
     342                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
     343                 :           0 :                        get_base ()->as_string ().c_str (),
     344                 :           0 :                        type.as_string ().c_str ());
     345                 :           0 :       }
     346                 :           7 :   }
     347                 :             : 
     348                 :         704 :   virtual void visit (const NeverType &type) override
     349                 :             :   {
     350                 :         704 :     ok = false;
     351                 :         704 :     if (emit_error_flag)
     352                 :             :       {
     353                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
     354                 :           0 :         location_t base_locus
     355                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
     356                 :           0 :         rich_location r (line_table, ref_locus);
     357                 :           0 :         r.add_range (base_locus);
     358                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
     359                 :           0 :                        get_base ()->as_string ().c_str (),
     360                 :           0 :                        type.as_string ().c_str ());
     361                 :           0 :       }
     362                 :         704 :   }
     363                 :             : 
     364                 :           0 :   virtual void visit (const ProjectionType &type) override
     365                 :             :   {
     366                 :           0 :     ok = false;
     367                 :           0 :     if (emit_error_flag)
     368                 :             :       {
     369                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
     370                 :           0 :         location_t base_locus
     371                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
     372                 :           0 :         rich_location r (line_table, ref_locus);
     373                 :           0 :         r.add_range (base_locus);
     374                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
     375                 :           0 :                        get_base ()->as_string ().c_str (),
     376                 :           0 :                        type.as_string ().c_str ());
     377                 :           0 :       }
     378                 :           0 :   }
     379                 :             : 
     380                 :          56 :   virtual void visit (const PlaceholderType &type) override
     381                 :             :   {
     382                 :             :     // it is ok for types to can eq to a placeholder
     383                 :          56 :     ok = true;
     384                 :          56 :   }
     385                 :             : 
     386                 :        8526 :   virtual void visit (const ParamType &type) override
     387                 :             :   {
     388                 :        8526 :     ok = false;
     389                 :        8526 :     if (emit_error_flag)
     390                 :             :       {
     391                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
     392                 :           0 :         location_t base_locus
     393                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
     394                 :           0 :         rich_location r (line_table, ref_locus);
     395                 :           0 :         r.add_range (base_locus);
     396                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
     397                 :           0 :                        get_base ()->as_string ().c_str (),
     398                 :           0 :                        type.as_string ().c_str ());
     399                 :           0 :       }
     400                 :        8526 :   }
     401                 :             : 
     402                 :        5284 :   virtual void visit (const DynamicObjectType &type) override
     403                 :             :   {
     404                 :        5284 :     ok = false;
     405                 :        5284 :     if (emit_error_flag)
     406                 :             :       {
     407                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
     408                 :           0 :         location_t base_locus
     409                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
     410                 :           0 :         rich_location r (line_table, ref_locus);
     411                 :           0 :         r.add_range (base_locus);
     412                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
     413                 :           0 :                        get_base ()->as_string ().c_str (),
     414                 :           0 :                        type.as_string ().c_str ());
     415                 :           0 :       }
     416                 :        5284 :   }
     417                 :             : 
     418                 :           7 :   virtual void visit (const ClosureType &type) override
     419                 :             :   {
     420                 :           7 :     ok = false;
     421                 :           7 :     if (emit_error_flag)
     422                 :             :       {
     423                 :           0 :         location_t ref_locus = mappings->lookup_location (type.get_ref ());
     424                 :           0 :         location_t base_locus
     425                 :           0 :           = mappings->lookup_location (get_base ()->get_ref ());
     426                 :           0 :         rich_location r (line_table, ref_locus);
     427                 :           0 :         r.add_range (base_locus);
     428                 :           0 :         rust_error_at (r, "expected [%s] got [%s]",
     429                 :           0 :                        get_base ()->as_string ().c_str (),
     430                 :           0 :                        type.as_string ().c_str ());
     431                 :           0 :       }
     432                 :           7 :   }
     433                 :             : 
     434                 :             : protected:
     435                 :      366122 :   BaseCmp (const BaseType *base, bool emit_errors)
     436                 :      732244 :     : mappings (Analysis::Mappings::get ()),
     437                 :      366122 :       context (Resolver::TypeCheckContext::get ()), ok (false),
     438                 :      366122 :       emit_error_flag (emit_errors)
     439                 :      366122 :   {}
     440                 :             : 
     441                 :             :   Analysis::Mappings *mappings;
     442                 :             :   Resolver::TypeCheckContext *context;
     443                 :             : 
     444                 :             :   bool ok;
     445                 :             :   bool emit_error_flag;
     446                 :             : 
     447                 :             : private:
     448                 :             :   /* Returns a pointer to the ty that created this rule. */
     449                 :             :   virtual const BaseType *get_base () const = 0;
     450                 :             : };
     451                 :             : 
     452                 :             : class InferCmp : public BaseCmp
     453                 :             : {
     454                 :             :   using Rust::TyTy::BaseCmp::visit;
     455                 :             : 
     456                 :             : public:
     457                 :        7247 :   InferCmp (const InferType *base, bool emit_errors)
     458                 :        7247 :     : BaseCmp (base, emit_errors), base (base)
     459                 :             :   {}
     460                 :             : 
     461                 :         184 :   void visit (const BoolType &type) override
     462                 :             :   {
     463                 :         184 :     bool is_valid
     464                 :         184 :       = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL);
     465                 :         184 :     if (is_valid)
     466                 :             :       {
     467                 :         152 :         ok = true;
     468                 :         152 :         return;
     469                 :             :       }
     470                 :             : 
     471                 :          32 :     BaseCmp::visit (type);
     472                 :             :   }
     473                 :             : 
     474                 :         922 :   void visit (const IntType &type) override
     475                 :             :   {
     476                 :         922 :     bool is_valid
     477                 :         922 :       = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL)
     478                 :         922 :         || (base->get_infer_kind ()
     479                 :         922 :             == TyTy::InferType::InferTypeKind::INTEGRAL);
     480                 :         922 :     if (is_valid)
     481                 :             :       {
     482                 :         922 :         ok = true;
     483                 :         922 :         return;
     484                 :             :       }
     485                 :             : 
     486                 :           0 :     BaseCmp::visit (type);
     487                 :             :   }
     488                 :             : 
     489                 :        1452 :   void visit (const UintType &type) override
     490                 :             :   {
     491                 :        1452 :     bool is_valid
     492                 :        1452 :       = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL)
     493                 :        1452 :         || (base->get_infer_kind ()
     494                 :        1452 :             == TyTy::InferType::InferTypeKind::INTEGRAL);
     495                 :        1452 :     if (is_valid)
     496                 :             :       {
     497                 :        1452 :         ok = true;
     498                 :        1452 :         return;
     499                 :             :       }
     500                 :             : 
     501                 :           0 :     BaseCmp::visit (type);
     502                 :             :   }
     503                 :             : 
     504                 :        1476 :   void visit (const USizeType &type) override
     505                 :             :   {
     506                 :        1476 :     bool is_valid
     507                 :        1476 :       = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL)
     508                 :        1476 :         || (base->get_infer_kind ()
     509                 :        1476 :             == TyTy::InferType::InferTypeKind::INTEGRAL);
     510                 :        1476 :     if (is_valid)
     511                 :             :       {
     512                 :        1476 :         ok = true;
     513                 :        1476 :         return;
     514                 :             :       }
     515                 :             : 
     516                 :           0 :     BaseCmp::visit (type);
     517                 :             :   }
     518                 :             : 
     519                 :         214 :   void visit (const ISizeType &type) override
     520                 :             :   {
     521                 :         214 :     bool is_valid
     522                 :         214 :       = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL)
     523                 :         214 :         || (base->get_infer_kind ()
     524                 :         214 :             == TyTy::InferType::InferTypeKind::INTEGRAL);
     525                 :         214 :     if (is_valid)
     526                 :             :       {
     527                 :         214 :         ok = true;
     528                 :         214 :         return;
     529                 :             :       }
     530                 :             : 
     531                 :           0 :     BaseCmp::visit (type);
     532                 :             :   }
     533                 :             : 
     534                 :         750 :   void visit (const FloatType &type) override
     535                 :             :   {
     536                 :         750 :     bool is_valid
     537                 :         750 :       = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL)
     538                 :         750 :         || (base->get_infer_kind () == TyTy::InferType::InferTypeKind::FLOAT);
     539                 :         750 :     if (is_valid)
     540                 :             :       {
     541                 :         622 :         ok = true;
     542                 :         622 :         return;
     543                 :             :       }
     544                 :             : 
     545                 :         128 :     BaseCmp::visit (type);
     546                 :             :   }
     547                 :             : 
     548                 :           0 :   void visit (const ArrayType &type) override
     549                 :             :   {
     550                 :           0 :     bool is_valid
     551                 :           0 :       = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL);
     552                 :           0 :     if (is_valid)
     553                 :             :       {
     554                 :           0 :         ok = true;
     555                 :           0 :         return;
     556                 :             :       }
     557                 :             : 
     558                 :           0 :     BaseCmp::visit (type);
     559                 :             :   }
     560                 :             : 
     561                 :          77 :   void visit (const SliceType &type) override
     562                 :             :   {
     563                 :          77 :     bool is_valid
     564                 :          77 :       = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL);
     565                 :          77 :     if (is_valid)
     566                 :             :       {
     567                 :           0 :         ok = true;
     568                 :           0 :         return;
     569                 :             :       }
     570                 :             : 
     571                 :          77 :     BaseCmp::visit (type);
     572                 :             :   }
     573                 :             : 
     574                 :         166 :   void visit (const ADTType &type) override
     575                 :             :   {
     576                 :         166 :     bool is_valid
     577                 :         166 :       = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL);
     578                 :         166 :     if (is_valid)
     579                 :             :       {
     580                 :          73 :         ok = true;
     581                 :          73 :         return;
     582                 :             :       }
     583                 :             : 
     584                 :          93 :     BaseCmp::visit (type);
     585                 :             :   }
     586                 :             : 
     587                 :           0 :   void visit (const TupleType &type) override
     588                 :             :   {
     589                 :           0 :     bool is_valid
     590                 :           0 :       = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL);
     591                 :           0 :     if (is_valid)
     592                 :             :       {
     593                 :           0 :         ok = true;
     594                 :           0 :         return;
     595                 :             :       }
     596                 :             : 
     597                 :           0 :     BaseCmp::visit (type);
     598                 :             :   }
     599                 :             : 
     600                 :          49 :   void visit (const InferType &type) override
     601                 :             :   {
     602                 :          49 :     switch (base->get_infer_kind ())
     603                 :             :       {
     604                 :          49 :       case InferType::InferTypeKind::GENERAL:
     605                 :          49 :         ok = true;
     606                 :          49 :         return;
     607                 :             : 
     608                 :           0 :         case InferType::InferTypeKind::INTEGRAL: {
     609                 :           0 :           if (type.get_infer_kind () == InferType::InferTypeKind::INTEGRAL)
     610                 :             :             {
     611                 :           0 :               ok = true;
     612                 :           0 :               return;
     613                 :             :             }
     614                 :           0 :           else if (type.get_infer_kind () == InferType::InferTypeKind::GENERAL)
     615                 :             :             {
     616                 :           0 :               ok = true;
     617                 :           0 :               return;
     618                 :             :             }
     619                 :             :         }
     620                 :             :         break;
     621                 :             : 
     622                 :           0 :         case InferType::InferTypeKind::FLOAT: {
     623                 :           0 :           if (type.get_infer_kind () == InferType::InferTypeKind::FLOAT)
     624                 :             :             {
     625                 :           0 :               ok = true;
     626                 :           0 :               return;
     627                 :             :             }
     628                 :           0 :           else if (type.get_infer_kind () == InferType::InferTypeKind::GENERAL)
     629                 :             :             {
     630                 :           0 :               ok = true;
     631                 :           0 :               return;
     632                 :             :             }
     633                 :             :         }
     634                 :             :         break;
     635                 :             :       }
     636                 :             : 
     637                 :           0 :     BaseCmp::visit (type);
     638                 :             :   }
     639                 :             : 
     640                 :         184 :   void visit (const CharType &type) override
     641                 :             :   {
     642                 :         184 :     {
     643                 :         184 :       bool is_valid
     644                 :         184 :         = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL);
     645                 :         184 :       if (is_valid)
     646                 :             :         {
     647                 :         152 :           ok = true;
     648                 :         152 :           return;
     649                 :             :         }
     650                 :             : 
     651                 :          32 :       BaseCmp::visit (type);
     652                 :             :     }
     653                 :             :   }
     654                 :             : 
     655                 :          14 :   void visit (const ReferenceType &type) override
     656                 :             :   {
     657                 :          14 :     bool is_valid
     658                 :          14 :       = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL);
     659                 :          14 :     if (is_valid)
     660                 :             :       {
     661                 :           0 :         ok = true;
     662                 :           0 :         return;
     663                 :             :       }
     664                 :             : 
     665                 :          14 :     BaseCmp::visit (type);
     666                 :             :   }
     667                 :             : 
     668                 :           1 :   void visit (const PointerType &type) override
     669                 :             :   {
     670                 :           1 :     bool is_valid
     671                 :           1 :       = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL);
     672                 :           1 :     if (is_valid)
     673                 :             :       {
     674                 :           0 :         ok = true;
     675                 :           0 :         return;
     676                 :             :       }
     677                 :             : 
     678                 :           1 :     BaseCmp::visit (type);
     679                 :             :   }
     680                 :             : 
     681                 :        1758 :   void visit (const ParamType &) override { ok = true; }
     682                 :             : 
     683                 :           0 :   void visit (const DynamicObjectType &type) override
     684                 :             :   {
     685                 :           0 :     bool is_valid
     686                 :           0 :       = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL);
     687                 :           0 :     if (is_valid)
     688                 :             :       {
     689                 :           0 :         ok = true;
     690                 :           0 :         return;
     691                 :             :       }
     692                 :             : 
     693                 :           0 :     BaseCmp::visit (type);
     694                 :             :   }
     695                 :             : 
     696                 :           0 :   void visit (const ClosureType &type) override
     697                 :             :   {
     698                 :           0 :     bool is_valid
     699                 :           0 :       = (base->get_infer_kind () == TyTy::InferType::InferTypeKind::GENERAL);
     700                 :           0 :     if (is_valid)
     701                 :             :       {
     702                 :           0 :         ok = true;
     703                 :           0 :         return;
     704                 :             :       }
     705                 :             : 
     706                 :           0 :     BaseCmp::visit (type);
     707                 :             :   }
     708                 :             : 
     709                 :             : private:
     710                 :           0 :   const BaseType *get_base () const override { return base; }
     711                 :             :   const InferType *base;
     712                 :             : };
     713                 :             : 
     714                 :             : class FnCmp : public BaseCmp
     715                 :             : {
     716                 :             :   using Rust::TyTy::BaseCmp::visit;
     717                 :             : 
     718                 :             : public:
     719                 :           0 :   FnCmp (const FnType *base, bool emit_errors)
     720                 :           0 :     : BaseCmp (base, emit_errors), base (base)
     721                 :             :   {}
     722                 :             : 
     723                 :           0 :   void visit (const InferType &type) override
     724                 :             :   {
     725                 :           0 :     ok = type.get_infer_kind () == InferType::InferTypeKind::GENERAL;
     726                 :           0 :   }
     727                 :             : 
     728                 :           0 :   void visit (const FnType &type) override
     729                 :             :   {
     730                 :           0 :     if (base->num_params () != type.num_params ())
     731                 :             :       {
     732                 :           0 :         BaseCmp::visit (type);
     733                 :           0 :         return;
     734                 :             :       }
     735                 :             : 
     736                 :           0 :     for (size_t i = 0; i < base->num_params (); i++)
     737                 :             :       {
     738                 :           0 :         auto a = base->param_at (i).second;
     739                 :           0 :         auto b = type.param_at (i).second;
     740                 :             : 
     741                 :           0 :         if (!a->can_eq (b, emit_error_flag))
     742                 :             :           {
     743                 :           0 :             emit_error_flag = false;
     744                 :           0 :             BaseCmp::visit (type);
     745                 :           0 :             return;
     746                 :             :           }
     747                 :             :       }
     748                 :             : 
     749                 :           0 :     if (!base->get_return_type ()->can_eq (type.get_return_type (),
     750                 :           0 :                                            emit_error_flag))
     751                 :             :       {
     752                 :           0 :         emit_error_flag = false;
     753                 :           0 :         BaseCmp::visit (type);
     754                 :           0 :         return;
     755                 :             :       }
     756                 :             : 
     757                 :           0 :     ok = true;
     758                 :             :   }
     759                 :             : 
     760                 :             : private:
     761                 :           0 :   const BaseType *get_base () const override { return base; }
     762                 :             :   const FnType *base;
     763                 :             : };
     764                 :             : 
     765                 :             : class FnptrCmp : public BaseCmp
     766                 :             : {
     767                 :             :   using Rust::TyTy::BaseCmp::visit;
     768                 :             : 
     769                 :             : public:
     770                 :           0 :   FnptrCmp (const FnPtr *base, bool emit_errors)
     771                 :           0 :     : BaseCmp (base, emit_errors), base (base)
     772                 :             :   {}
     773                 :             : 
     774                 :           0 :   void visit (const InferType &type) override
     775                 :             :   {
     776                 :           0 :     if (type.get_infer_kind () != InferType::InferTypeKind::GENERAL)
     777                 :             :       {
     778                 :           0 :         BaseCmp::visit (type);
     779                 :           0 :         return;
     780                 :             :       }
     781                 :             : 
     782                 :           0 :     ok = true;
     783                 :             :   }
     784                 :             : 
     785                 :           0 :   void visit (const FnPtr &type) override
     786                 :             :   {
     787                 :           0 :     if (base->num_params () != type.num_params ())
     788                 :             :       {
     789                 :           0 :         BaseCmp::visit (type);
     790                 :           0 :         return;
     791                 :             :       }
     792                 :             : 
     793                 :           0 :     auto this_ret_type = base->get_return_type ();
     794                 :           0 :     auto other_ret_type = type.get_return_type ();
     795                 :           0 :     if (!this_ret_type->can_eq (other_ret_type, emit_error_flag))
     796                 :             :       {
     797                 :           0 :         BaseCmp::visit (type);
     798                 :           0 :         return;
     799                 :             :       }
     800                 :             : 
     801                 :           0 :     for (size_t i = 0; i < base->num_params (); i++)
     802                 :             :       {
     803                 :           0 :         auto this_param = base->get_param_type_at (i);
     804                 :           0 :         auto other_param = type.get_param_type_at (i);
     805                 :           0 :         if (!this_param->can_eq (other_param, emit_error_flag))
     806                 :             :           {
     807                 :           0 :             BaseCmp::visit (type);
     808                 :           0 :             return;
     809                 :             :           }
     810                 :             :       }
     811                 :             : 
     812                 :           0 :     ok = true;
     813                 :             :   }
     814                 :             : 
     815                 :           0 :   void visit (const FnType &type) override
     816                 :             :   {
     817                 :           0 :     if (base->num_params () != type.num_params ())
     818                 :             :       {
     819                 :           0 :         BaseCmp::visit (type);
     820                 :           0 :         return;
     821                 :             :       }
     822                 :             : 
     823                 :           0 :     auto this_ret_type = base->get_return_type ();
     824                 :           0 :     auto other_ret_type = type.get_return_type ();
     825                 :           0 :     if (!this_ret_type->can_eq (other_ret_type, emit_error_flag))
     826                 :             :       {
     827                 :           0 :         BaseCmp::visit (type);
     828                 :           0 :         return;
     829                 :             :       }
     830                 :             : 
     831                 :           0 :     for (size_t i = 0; i < base->num_params (); i++)
     832                 :             :       {
     833                 :           0 :         auto this_param = base->get_param_type_at (i);
     834                 :           0 :         auto other_param = type.param_at (i).second;
     835                 :           0 :         if (!this_param->can_eq (other_param, emit_error_flag))
     836                 :             :           {
     837                 :           0 :             BaseCmp::visit (type);
     838                 :           0 :             return;
     839                 :             :           }
     840                 :             :       }
     841                 :             : 
     842                 :           0 :     ok = true;
     843                 :             :   }
     844                 :             : 
     845                 :             : private:
     846                 :           0 :   const BaseType *get_base () const override { return base; }
     847                 :             :   const FnPtr *base;
     848                 :             : };
     849                 :             : 
     850                 :             : class ClosureCmp : public BaseCmp
     851                 :             : {
     852                 :             :   using Rust::TyTy::BaseCmp::visit;
     853                 :             : 
     854                 :             : public:
     855                 :          60 :   ClosureCmp (const ClosureType *base, bool emit_errors)
     856                 :          60 :     : BaseCmp (base, emit_errors), base (base)
     857                 :             :   {}
     858                 :             : 
     859                 :           0 :   void visit (const InferType &type) override
     860                 :             :   {
     861                 :           0 :     if (type.get_infer_kind () != InferType::InferTypeKind::GENERAL)
     862                 :             :       {
     863                 :           0 :         BaseCmp::visit (type);
     864                 :           0 :         return;
     865                 :             :       }
     866                 :             : 
     867                 :           0 :     ok = true;
     868                 :             :   }
     869                 :             : 
     870                 :          60 :   void visit (const ClosureType &type) override
     871                 :             :   {
     872                 :          60 :     if (base->get_def_id () != type.get_def_id ())
     873                 :             :       {
     874                 :           7 :         BaseCmp::visit (type);
     875                 :           7 :         return;
     876                 :             :       }
     877                 :             : 
     878                 :          53 :     if (!base->get_parameters ().can_eq (&type.get_parameters (), false))
     879                 :             :       {
     880                 :           0 :         BaseCmp::visit (type);
     881                 :           0 :         return;
     882                 :             :       }
     883                 :             : 
     884                 :          53 :     if (!base->get_result_type ().can_eq (&type.get_result_type (), false))
     885                 :             :       {
     886                 :           0 :         BaseCmp::visit (type);
     887                 :           0 :         return;
     888                 :             :       }
     889                 :             : 
     890                 :          53 :     ok = true;
     891                 :             :   }
     892                 :             : 
     893                 :             : private:
     894                 :           0 :   const BaseType *get_base () const override { return base; }
     895                 :             :   const ClosureType *base;
     896                 :             : };
     897                 :             : 
     898                 :             : class ArrayCmp : public BaseCmp
     899                 :             : {
     900                 :             :   using Rust::TyTy::BaseCmp::visit;
     901                 :             : 
     902                 :             : public:
     903                 :        4351 :   ArrayCmp (const ArrayType *base, bool emit_errors)
     904                 :        4351 :     : BaseCmp (base, emit_errors), base (base)
     905                 :             :   {}
     906                 :             : 
     907                 :          84 :   void visit (const ArrayType &type) override
     908                 :             :   {
     909                 :             :     // check base type
     910                 :          84 :     const BaseType *base_element = base->get_element_type ();
     911                 :          84 :     const BaseType *other_element = type.get_element_type ();
     912                 :          84 :     if (!base_element->can_eq (other_element, emit_error_flag))
     913                 :             :       {
     914                 :           0 :         BaseCmp::visit (type);
     915                 :           0 :         return;
     916                 :             :       }
     917                 :             : 
     918                 :          84 :     ok = true;
     919                 :             :   }
     920                 :             : 
     921                 :           0 :   void visit (const InferType &type) override
     922                 :             :   {
     923                 :           0 :     if (type.get_infer_kind () != InferType::InferTypeKind::GENERAL)
     924                 :             :       {
     925                 :           0 :         BaseCmp::visit (type);
     926                 :           0 :         return;
     927                 :             :       }
     928                 :             : 
     929                 :           0 :     ok = true;
     930                 :             :   }
     931                 :             : 
     932                 :             : private:
     933                 :           0 :   const BaseType *get_base () const override { return base; }
     934                 :             :   const ArrayType *base;
     935                 :             : };
     936                 :             : 
     937                 :             : class SliceCmp : public BaseCmp
     938                 :             : {
     939                 :             :   using Rust::TyTy::BaseCmp::visit;
     940                 :             : 
     941                 :             : public:
     942                 :        3069 :   SliceCmp (const SliceType *base, bool emit_errors)
     943                 :        3069 :     : BaseCmp (base, emit_errors), base (base)
     944                 :             :   {}
     945                 :             : 
     946                 :         756 :   void visit (const SliceType &type) override
     947                 :             :   {
     948                 :             :     // check base type
     949                 :         756 :     const BaseType *base_element = base->get_element_type ();
     950                 :         756 :     const BaseType *other_element = type.get_element_type ();
     951                 :         756 :     if (!base_element->can_eq (other_element, emit_error_flag))
     952                 :             :       {
     953                 :          49 :         BaseCmp::visit (type);
     954                 :          49 :         return;
     955                 :             :       }
     956                 :             : 
     957                 :         707 :     ok = true;
     958                 :             :   }
     959                 :             : 
     960                 :          77 :   void visit (const InferType &type) override
     961                 :             :   {
     962                 :          77 :     if (type.get_infer_kind () != InferType::InferTypeKind::GENERAL)
     963                 :             :       {
     964                 :          77 :         BaseCmp::visit (type);
     965                 :          77 :         return;
     966                 :             :       }
     967                 :             : 
     968                 :           0 :     ok = true;
     969                 :             :   }
     970                 :             : 
     971                 :             : private:
     972                 :           0 :   const BaseType *get_base () const override { return base; }
     973                 :             :   const SliceType *base;
     974                 :             : };
     975                 :             : 
     976                 :             : class BoolCmp : public BaseCmp
     977                 :             : {
     978                 :             :   using Rust::TyTy::BaseCmp::visit;
     979                 :             : 
     980                 :             : public:
     981                 :        6609 :   BoolCmp (const BoolType *base, bool emit_errors)
     982                 :        6609 :     : BaseCmp (base, emit_errors), base (base)
     983                 :             :   {}
     984                 :             : 
     985                 :         341 :   void visit (const BoolType &type) override { ok = true; }
     986                 :             : 
     987                 :          32 :   void visit (const InferType &type) override
     988                 :             :   {
     989                 :          32 :     ok = type.get_infer_kind () == InferType::InferTypeKind::GENERAL;
     990                 :          32 :   }
     991                 :             : 
     992                 :             : private:
     993                 :           0 :   const BaseType *get_base () const override { return base; }
     994                 :             :   const BoolType *base;
     995                 :             : };
     996                 :             : 
     997                 :             : class IntCmp : public BaseCmp
     998                 :             : {
     999                 :             :   using Rust::TyTy::BaseCmp::visit;
    1000                 :             : 
    1001                 :             : public:
    1002                 :       40141 :   IntCmp (const IntType *base, bool emit_errors)
    1003                 :       40141 :     : BaseCmp (base, emit_errors), base (base)
    1004                 :             :   {}
    1005                 :             : 
    1006                 :           0 :   void visit (const InferType &type) override
    1007                 :             :   {
    1008                 :           0 :     ok = type.get_infer_kind () != InferType::InferTypeKind::FLOAT;
    1009                 :           0 :   }
    1010                 :             : 
    1011                 :        5115 :   void visit (const IntType &type) override
    1012                 :             :   {
    1013                 :        5115 :     ok = type.get_int_kind () == base->get_int_kind ();
    1014                 :        5115 :   }
    1015                 :             : 
    1016                 :             : private:
    1017                 :           0 :   const BaseType *get_base () const override { return base; }
    1018                 :             :   const IntType *base;
    1019                 :             : };
    1020                 :             : 
    1021                 :             : class UintCmp : public BaseCmp
    1022                 :             : {
    1023                 :             :   using Rust::TyTy::BaseCmp::visit;
    1024                 :             : 
    1025                 :             : public:
    1026                 :      127422 :   UintCmp (const UintType *base, bool emit_errors)
    1027                 :      127422 :     : BaseCmp (base, emit_errors), base (base)
    1028                 :             :   {}
    1029                 :             : 
    1030                 :           0 :   void visit (const InferType &type) override
    1031                 :             :   {
    1032                 :           0 :     ok = type.get_infer_kind () != InferType::InferTypeKind::FLOAT;
    1033                 :           0 :   }
    1034                 :             : 
    1035                 :       50125 :   void visit (const UintType &type) override
    1036                 :             :   {
    1037                 :       50125 :     ok = type.get_uint_kind () == base->get_uint_kind ();
    1038                 :       50125 :   }
    1039                 :             : 
    1040                 :             : private:
    1041                 :           0 :   const BaseType *get_base () const override { return base; }
    1042                 :             :   const UintType *base;
    1043                 :             : };
    1044                 :             : 
    1045                 :             : class FloatCmp : public BaseCmp
    1046                 :             : {
    1047                 :             :   using Rust::TyTy::BaseCmp::visit;
    1048                 :             : 
    1049                 :             : public:
    1050                 :       38197 :   FloatCmp (const FloatType *base, bool emit_errors)
    1051                 :       38197 :     : BaseCmp (base, emit_errors), base (base)
    1052                 :             :   {}
    1053                 :             : 
    1054                 :         128 :   void visit (const InferType &type) override
    1055                 :             :   {
    1056                 :         128 :     ok = type.get_infer_kind () != InferType::InferTypeKind::INTEGRAL;
    1057                 :         128 :   }
    1058                 :             : 
    1059                 :        4166 :   void visit (const FloatType &type) override
    1060                 :             :   {
    1061                 :        4166 :     ok = type.get_float_kind () == base->get_float_kind ();
    1062                 :        4166 :   }
    1063                 :             : 
    1064                 :             : private:
    1065                 :           0 :   const BaseType *get_base () const override { return base; }
    1066                 :             :   const FloatType *base;
    1067                 :             : };
    1068                 :             : 
    1069                 :             : class ADTCmp : public BaseCmp
    1070                 :             : {
    1071                 :             :   using Rust::TyTy::BaseCmp::visit;
    1072                 :             : 
    1073                 :             : public:
    1074                 :       23164 :   ADTCmp (const ADTType *base, bool emit_errors)
    1075                 :       23164 :     : BaseCmp (base, emit_errors), base (base)
    1076                 :             :   {}
    1077                 :             : 
    1078                 :        7490 :   void visit (const ADTType &type) override
    1079                 :             :   {
    1080                 :        7490 :     if (base->get_adt_kind () != type.get_adt_kind ())
    1081                 :             :       {
    1082                 :          96 :         BaseCmp::visit (type);
    1083                 :          96 :         return;
    1084                 :             :       }
    1085                 :             : 
    1086                 :        7394 :     if (base->get_identifier ().compare (type.get_identifier ()) != 0)
    1087                 :             :       {
    1088                 :        1871 :         BaseCmp::visit (type);
    1089                 :        1871 :         return;
    1090                 :             :       }
    1091                 :             : 
    1092                 :        5523 :     if (base->number_of_variants () != type.number_of_variants ())
    1093                 :             :       {
    1094                 :           0 :         BaseCmp::visit (type);
    1095                 :           0 :         return;
    1096                 :             :       }
    1097                 :             : 
    1098                 :       10365 :     for (size_t i = 0; i < type.number_of_variants (); ++i)
    1099                 :             :       {
    1100                 :        5527 :         TyTy::VariantDef *a = base->get_variants ().at (i);
    1101                 :        5527 :         TyTy::VariantDef *b = type.get_variants ().at (i);
    1102                 :             : 
    1103                 :        5527 :         if (a->num_fields () != b->num_fields ())
    1104                 :             :           {
    1105                 :           0 :             BaseCmp::visit (type);
    1106                 :           0 :             return;
    1107                 :             :           }
    1108                 :             : 
    1109                 :       11314 :         for (size_t j = 0; j < a->num_fields (); j++)
    1110                 :             :           {
    1111                 :        6472 :             TyTy::StructFieldType *base_field = a->get_field_at_index (j);
    1112                 :        6472 :             TyTy::StructFieldType *other_field = b->get_field_at_index (j);
    1113                 :             : 
    1114                 :        6472 :             TyTy::BaseType *this_field_ty = base_field->get_field_type ();
    1115                 :        6472 :             TyTy::BaseType *other_field_ty = other_field->get_field_type ();
    1116                 :             : 
    1117                 :        6472 :             if (!this_field_ty->can_eq (other_field_ty, emit_error_flag))
    1118                 :             :               {
    1119                 :         685 :                 BaseCmp::visit (type);
    1120                 :         685 :                 return;
    1121                 :             :               }
    1122                 :             :           }
    1123                 :             :       }
    1124                 :             : 
    1125                 :        4838 :     ok = true;
    1126                 :             :   }
    1127                 :             : 
    1128                 :          93 :   void visit (const InferType &type) override
    1129                 :             :   {
    1130                 :          93 :     if (type.get_infer_kind () != InferType::InferTypeKind::GENERAL)
    1131                 :             :       {
    1132                 :          93 :         BaseCmp::visit (type);
    1133                 :          93 :         return;
    1134                 :             :       }
    1135                 :             : 
    1136                 :           0 :     ok = true;
    1137                 :             :   }
    1138                 :             : 
    1139                 :             : private:
    1140                 :           0 :   const BaseType *get_base () const override { return base; }
    1141                 :             :   const ADTType *base;
    1142                 :             : };
    1143                 :             : 
    1144                 :             : class TupleCmp : public BaseCmp
    1145                 :             : {
    1146                 :             :   using Rust::TyTy::BaseCmp::visit;
    1147                 :             : 
    1148                 :             : public:
    1149                 :         150 :   TupleCmp (const TupleType *base, bool emit_errors)
    1150                 :         150 :     : BaseCmp (base, emit_errors), base (base)
    1151                 :             :   {}
    1152                 :             : 
    1153                 :         106 :   void visit (const TupleType &type) override
    1154                 :             :   {
    1155                 :         106 :     if (base->num_fields () != type.num_fields ())
    1156                 :             :       {
    1157                 :           0 :         BaseCmp::visit (type);
    1158                 :           0 :         return;
    1159                 :             :       }
    1160                 :             : 
    1161                 :         212 :     for (size_t i = 0; i < base->num_fields (); i++)
    1162                 :             :       {
    1163                 :         106 :         BaseType *bo = base->get_field (i);
    1164                 :         106 :         BaseType *fo = type.get_field (i);
    1165                 :             : 
    1166                 :         106 :         if (!bo->can_eq (fo, emit_error_flag))
    1167                 :             :           {
    1168                 :           0 :             BaseCmp::visit (type);
    1169                 :           0 :             return;
    1170                 :             :           }
    1171                 :             :       }
    1172                 :             : 
    1173                 :         106 :     ok = true;
    1174                 :             :   }
    1175                 :             : 
    1176                 :           0 :   void visit (const InferType &type) override
    1177                 :             :   {
    1178                 :           0 :     if (type.get_infer_kind () != InferType::InferTypeKind::GENERAL)
    1179                 :             :       {
    1180                 :           0 :         BaseCmp::visit (type);
    1181                 :           0 :         return;
    1182                 :             :       }
    1183                 :             : 
    1184                 :           0 :     ok = true;
    1185                 :             :   }
    1186                 :             : 
    1187                 :             : private:
    1188                 :           0 :   const BaseType *get_base () const override { return base; }
    1189                 :             :   const TupleType *base;
    1190                 :             : };
    1191                 :             : 
    1192                 :             : class USizeCmp : public BaseCmp
    1193                 :             : {
    1194                 :             :   using Rust::TyTy::BaseCmp::visit;
    1195                 :             : 
    1196                 :             : public:
    1197                 :       47424 :   USizeCmp (const USizeType *base, bool emit_errors)
    1198                 :       47424 :     : BaseCmp (base, emit_errors), base (base)
    1199                 :             :   {}
    1200                 :             : 
    1201                 :           0 :   void visit (const InferType &type) override
    1202                 :             :   {
    1203                 :           0 :     ok = type.get_infer_kind () != InferType::InferTypeKind::FLOAT;
    1204                 :           0 :   }
    1205                 :             : 
    1206                 :        4615 :   void visit (const USizeType &type) override { ok = true; }
    1207                 :             : 
    1208                 :             : private:
    1209                 :           0 :   const BaseType *get_base () const override { return base; }
    1210                 :             :   const USizeType *base;
    1211                 :             : };
    1212                 :             : 
    1213                 :             : class ISizeCmp : public BaseCmp
    1214                 :             : {
    1215                 :             :   using Rust::TyTy::BaseCmp::visit;
    1216                 :             : 
    1217                 :             : public:
    1218                 :        8716 :   ISizeCmp (const ISizeType *base, bool emit_errors)
    1219                 :        8716 :     : BaseCmp (base, emit_errors), base (base)
    1220                 :             :   {}
    1221                 :             : 
    1222                 :           0 :   void visit (const InferType &type) override
    1223                 :             :   {
    1224                 :           0 :     ok = type.get_infer_kind () != InferType::InferTypeKind::FLOAT;
    1225                 :           0 :   }
    1226                 :             : 
    1227                 :         172 :   void visit (const ISizeType &type) override { ok = true; }
    1228                 :             : 
    1229                 :             : private:
    1230                 :           0 :   const BaseType *get_base () const override { return base; }
    1231                 :             :   const ISizeType *base;
    1232                 :             : };
    1233                 :             : 
    1234                 :             : class CharCmp : public BaseCmp
    1235                 :             : {
    1236                 :             :   using Rust::TyTy::BaseCmp::visit;
    1237                 :             : 
    1238                 :             : public:
    1239                 :        5533 :   CharCmp (const CharType *base, bool emit_errors)
    1240                 :        5533 :     : BaseCmp (base, emit_errors), base (base)
    1241                 :             :   {}
    1242                 :             : 
    1243                 :          32 :   void visit (const InferType &type) override
    1244                 :             :   {
    1245                 :          32 :     ok = type.get_infer_kind () == InferType::InferTypeKind::GENERAL;
    1246                 :          32 :   }
    1247                 :             : 
    1248                 :           0 :   void visit (const CharType &type) override { ok = true; }
    1249                 :             : 
    1250                 :             : private:
    1251                 :           0 :   const BaseType *get_base () const override { return base; }
    1252                 :             :   const CharType *base;
    1253                 :             : };
    1254                 :             : 
    1255                 :             : class ReferenceCmp : public BaseCmp
    1256                 :             : {
    1257                 :             :   using Rust::TyTy::BaseCmp::visit;
    1258                 :             : 
    1259                 :             : public:
    1260                 :       20948 :   ReferenceCmp (const ReferenceType *base, bool emit_errors)
    1261                 :       20948 :     : BaseCmp (base, emit_errors), base (base)
    1262                 :             :   {}
    1263                 :             : 
    1264                 :        2919 :   void visit (const ReferenceType &type) override
    1265                 :             :   {
    1266                 :        2919 :     auto base_type = base->get_base ();
    1267                 :        2919 :     auto other_base_type = type.get_base ();
    1268                 :             : 
    1269                 :        2919 :     bool mutability_ok = base->is_mutable () ? type.is_mutable () : true;
    1270                 :         357 :     if (!mutability_ok)
    1271                 :             :       {
    1272                 :         210 :         BaseCmp::visit (type);
    1273                 :         210 :         return;
    1274                 :             :       }
    1275                 :             : 
    1276                 :        2709 :     if (!base_type->can_eq (other_base_type, emit_error_flag))
    1277                 :             :       {
    1278                 :        2132 :         BaseCmp::visit (type);
    1279                 :        2132 :         return;
    1280                 :             :       }
    1281                 :             : 
    1282                 :         577 :     ok = true;
    1283                 :             :   }
    1284                 :             : 
    1285                 :          14 :   void visit (const InferType &type) override
    1286                 :             :   {
    1287                 :          14 :     if (type.get_infer_kind () != InferType::InferTypeKind::GENERAL)
    1288                 :             :       {
    1289                 :          14 :         BaseCmp::visit (type);
    1290                 :          14 :         return;
    1291                 :             :       }
    1292                 :             : 
    1293                 :           0 :     ok = true;
    1294                 :             :   }
    1295                 :             : 
    1296                 :             : private:
    1297                 :           0 :   const BaseType *get_base () const override { return base; }
    1298                 :             :   const ReferenceType *base;
    1299                 :             : };
    1300                 :             : 
    1301                 :             : class PointerCmp : public BaseCmp
    1302                 :             : {
    1303                 :             :   using Rust::TyTy::BaseCmp::visit;
    1304                 :             : 
    1305                 :             : public:
    1306                 :         425 :   PointerCmp (const PointerType *base, bool emit_errors)
    1307                 :         425 :     : BaseCmp (base, emit_errors), base (base)
    1308                 :             :   {}
    1309                 :             : 
    1310                 :         122 :   void visit (const PointerType &type) override
    1311                 :             :   {
    1312                 :         122 :     auto base_type = base->get_base ();
    1313                 :         122 :     auto other_base_type = type.get_base ();
    1314                 :             : 
    1315                 :         122 :     bool mutability_ok = base->is_mutable () ? type.is_mutable () : true;
    1316                 :          12 :     if (!mutability_ok)
    1317                 :             :       {
    1318                 :          12 :         BaseCmp::visit (type);
    1319                 :          12 :         return;
    1320                 :             :       }
    1321                 :             : 
    1322                 :         110 :     if (!base_type->can_eq (other_base_type, emit_error_flag))
    1323                 :             :       {
    1324                 :          49 :         BaseCmp::visit (type);
    1325                 :          49 :         return;
    1326                 :             :       }
    1327                 :             : 
    1328                 :          61 :     ok = true;
    1329                 :             :   }
    1330                 :             : 
    1331                 :           0 :   void visit (const InferType &type) override
    1332                 :             :   {
    1333                 :           0 :     if (type.get_infer_kind () != InferType::InferTypeKind::GENERAL)
    1334                 :             :       {
    1335                 :           0 :         BaseCmp::visit (type);
    1336                 :           0 :         return;
    1337                 :             :       }
    1338                 :             : 
    1339                 :           0 :     ok = true;
    1340                 :             :   }
    1341                 :             : 
    1342                 :             : private:
    1343                 :           0 :   const BaseType *get_base () const override { return base; }
    1344                 :             :   const PointerType *base;
    1345                 :             : };
    1346                 :             : 
    1347                 :             : class ParamCmp : public BaseCmp
    1348                 :             : {
    1349                 :             :   using Rust::TyTy::BaseCmp::visit;
    1350                 :             : 
    1351                 :             : public:
    1352                 :       24211 :   ParamCmp (const ParamType *base, bool emit_errors)
    1353                 :       24211 :     : BaseCmp (base, emit_errors), base (base)
    1354                 :             :   {}
    1355                 :             : 
    1356                 :             :   // param types are a placeholder we shouldn't have cases where we unify
    1357                 :             :   // against it. eg: struct foo<T> { a: T }; When we invoke it we can do either:
    1358                 :             :   //
    1359                 :             :   // foo<i32>{ a: 123 }.
    1360                 :             :   // Then this enforces the i32 type to be referenced on the
    1361                 :             :   // field via an hirid.
    1362                 :             :   //
    1363                 :             :   // rust also allows for a = foo{a:123}; Where we can use an Inference Variable
    1364                 :             :   // to handle the typing of the struct
    1365                 :       24211 :   bool can_eq (const BaseType *other) override
    1366                 :             :   {
    1367                 :       24211 :     if (!base->can_resolve ())
    1368                 :       13206 :       return BaseCmp::can_eq (other);
    1369                 :             : 
    1370                 :       11005 :     auto lookup = base->resolve ();
    1371                 :       11005 :     return lookup->can_eq (other, emit_error_flag);
    1372                 :             :   }
    1373                 :             : 
    1374                 :             :   // imagine the case where we have:
    1375                 :             :   // struct Foo<T>(T);
    1376                 :             :   // Then we declare a generic impl block
    1377                 :             :   // impl <X>Foo<X> { ... }
    1378                 :             :   // both of these types are compatible so we mostly care about the number of
    1379                 :             :   // generic arguments
    1380                 :        4627 :   void visit (const ParamType &) override { ok = true; }
    1381                 :             : 
    1382                 :           0 :   void visit (const TupleType &) override { ok = true; }
    1383                 :             : 
    1384                 :          36 :   void visit (const InferType &) override { ok = true; }
    1385                 :             : 
    1386                 :           0 :   void visit (const FnType &) override { ok = true; }
    1387                 :             : 
    1388                 :           0 :   void visit (const FnPtr &) override { ok = true; }
    1389                 :             : 
    1390                 :         802 :   void visit (const ADTType &) override { ok = true; }
    1391                 :             : 
    1392                 :         240 :   void visit (const ArrayType &) override { ok = true; }
    1393                 :             : 
    1394                 :          49 :   void visit (const SliceType &) override { ok = true; }
    1395                 :             : 
    1396                 :           0 :   void visit (const BoolType &) override { ok = true; }
    1397                 :             : 
    1398                 :         647 :   void visit (const IntType &) override { ok = true; }
    1399                 :             : 
    1400                 :        3792 :   void visit (const UintType &) override { ok = true; }
    1401                 :             : 
    1402                 :        1849 :   void visit (const USizeType &) override { ok = true; }
    1403                 :             : 
    1404                 :          70 :   void visit (const ISizeType &) override { ok = true; }
    1405                 :             : 
    1406                 :         721 :   void visit (const FloatType &) override { ok = true; }
    1407                 :             : 
    1408                 :           0 :   void visit (const CharType &) override { ok = true; }
    1409                 :             : 
    1410                 :         229 :   void visit (const ReferenceType &) override { ok = true; }
    1411                 :             : 
    1412                 :           0 :   void visit (const PointerType &) override { ok = true; }
    1413                 :             : 
    1414                 :           0 :   void visit (const StrType &) override { ok = true; }
    1415                 :             : 
    1416                 :          48 :   void visit (const NeverType &) override { ok = true; }
    1417                 :             : 
    1418                 :          96 :   void visit (const DynamicObjectType &) override { ok = true; }
    1419                 :             : 
    1420                 :           0 :   void visit (const PlaceholderType &type) override
    1421                 :             :   {
    1422                 :           0 :     ok = base->get_symbol ().compare (type.get_symbol ()) == 0;
    1423                 :           0 :   }
    1424                 :             : 
    1425                 :             : private:
    1426                 :           0 :   const BaseType *get_base () const override { return base; }
    1427                 :             :   const ParamType *base;
    1428                 :             : };
    1429                 :             : 
    1430                 :             : class StrCmp : public BaseCmp
    1431                 :             : {
    1432                 :             :   // FIXME we will need a enum for the StrType like ByteBuf etc..
    1433                 :             :   using Rust::TyTy::BaseCmp::visit;
    1434                 :             : 
    1435                 :             : public:
    1436                 :           7 :   StrCmp (const StrType *base, bool emit_errors)
    1437                 :           7 :     : BaseCmp (base, emit_errors), base (base)
    1438                 :             :   {}
    1439                 :             : 
    1440                 :           0 :   void visit (const StrType &type) override { ok = true; }
    1441                 :             : 
    1442                 :           0 :   void visit (const InferType &type) override
    1443                 :             :   {
    1444                 :           0 :     if (type.get_infer_kind () != InferType::InferTypeKind::GENERAL)
    1445                 :             :       {
    1446                 :           0 :         BaseCmp::visit (type);
    1447                 :           0 :         return;
    1448                 :             :       }
    1449                 :             : 
    1450                 :           0 :     ok = true;
    1451                 :             :   }
    1452                 :             : 
    1453                 :             : private:
    1454                 :           0 :   const BaseType *get_base () const override { return base; }
    1455                 :             :   const StrType *base;
    1456                 :             : };
    1457                 :             : 
    1458                 :             : class NeverCmp : public BaseCmp
    1459                 :             : {
    1460                 :             :   using Rust::TyTy::BaseCmp::visit;
    1461                 :             : 
    1462                 :             : public:
    1463                 :         752 :   NeverCmp (const NeverType *base, bool emit_errors)
    1464                 :         752 :     : BaseCmp (base, emit_errors), base (base)
    1465                 :             :   {}
    1466                 :             : 
    1467                 :           0 :   void visit (const NeverType &type) override { ok = true; }
    1468                 :             : 
    1469                 :           0 :   void visit (const InferType &type) override
    1470                 :             :   {
    1471                 :           0 :     if (type.get_infer_kind () != InferType::InferTypeKind::GENERAL)
    1472                 :             :       {
    1473                 :           0 :         BaseCmp::visit (type);
    1474                 :           0 :         return;
    1475                 :             :       }
    1476                 :             : 
    1477                 :           0 :     ok = true;
    1478                 :             :   }
    1479                 :             : 
    1480                 :             : private:
    1481                 :           0 :   const BaseType *get_base () const override { return base; }
    1482                 :             :   const NeverType *base;
    1483                 :             : };
    1484                 :             : 
    1485                 :             : class PlaceholderCmp : public BaseCmp
    1486                 :             : {
    1487                 :             :   using Rust::TyTy::BaseCmp::visit;
    1488                 :             : 
    1489                 :             : public:
    1490                 :        2309 :   PlaceholderCmp (const PlaceholderType *base, bool emit_errors)
    1491                 :        2309 :     : BaseCmp (base, emit_errors), base (base)
    1492                 :             :   {}
    1493                 :             : 
    1494                 :        2309 :   bool can_eq (const BaseType *other) override
    1495                 :             :   {
    1496                 :        2309 :     if (!base->can_resolve ())
    1497                 :        2271 :       return BaseCmp::can_eq (other);
    1498                 :             : 
    1499                 :          38 :     BaseType *lookup = base->resolve ();
    1500                 :          38 :     return lookup->can_eq (other, emit_error_flag);
    1501                 :             :   }
    1502                 :             : 
    1503                 :           0 :   void visit (const TupleType &) override { ok = true; }
    1504                 :             : 
    1505                 :          16 :   void visit (const ADTType &) override { ok = true; }
    1506                 :             : 
    1507                 :           0 :   void visit (const InferType &) override { ok = true; }
    1508                 :             : 
    1509                 :           0 :   void visit (const FnType &) override { ok = true; }
    1510                 :             : 
    1511                 :           0 :   void visit (const FnPtr &) override { ok = true; }
    1512                 :             : 
    1513                 :           0 :   void visit (const ArrayType &) override { ok = true; }
    1514                 :             : 
    1515                 :          48 :   void visit (const BoolType &) override { ok = true; }
    1516                 :             : 
    1517                 :         225 :   void visit (const IntType &) override { ok = true; }
    1518                 :             : 
    1519                 :         637 :   void visit (const UintType &) override { ok = true; }
    1520                 :             : 
    1521                 :         147 :   void visit (const USizeType &) override { ok = true; }
    1522                 :             : 
    1523                 :          65 :   void visit (const ISizeType &) override { ok = true; }
    1524                 :             : 
    1525                 :         417 :   void visit (const FloatType &) override { ok = true; }
    1526                 :             : 
    1527                 :           0 :   void visit (const ErrorType &) override { ok = true; }
    1528                 :             : 
    1529                 :          48 :   void visit (const CharType &) override { ok = true; }
    1530                 :             : 
    1531                 :           0 :   void visit (const ReferenceType &) override { ok = true; }
    1532                 :             : 
    1533                 :         498 :   void visit (const ParamType &) override { ok = true; }
    1534                 :             : 
    1535                 :           0 :   void visit (const StrType &) override { ok = true; }
    1536                 :             : 
    1537                 :           9 :   void visit (const NeverType &) override { ok = true; }
    1538                 :             : 
    1539                 :         105 :   void visit (const SliceType &) override { ok = true; }
    1540                 :             : 
    1541                 :             : private:
    1542                 :           0 :   const BaseType *get_base () const override { return base; }
    1543                 :             : 
    1544                 :             :   const PlaceholderType *base;
    1545                 :             : };
    1546                 :             : 
    1547                 :             : class DynamicCmp : public BaseCmp
    1548                 :             : {
    1549                 :             :   using Rust::TyTy::BaseCmp::visit;
    1550                 :             : 
    1551                 :             : public:
    1552                 :        5387 :   DynamicCmp (const DynamicObjectType *base, bool emit_errors)
    1553                 :        5387 :     : BaseCmp (base, emit_errors), base (base)
    1554                 :             :   {}
    1555                 :             : 
    1556                 :           7 :   void visit (const DynamicObjectType &type) override
    1557                 :             :   {
    1558                 :           7 :     if (base->num_specified_bounds () != type.num_specified_bounds ())
    1559                 :             :       {
    1560                 :           0 :         BaseCmp::visit (type);
    1561                 :           0 :         return;
    1562                 :             :       }
    1563                 :             : 
    1564                 :           7 :     location_t ref_locus = mappings->lookup_location (type.get_ref ());
    1565                 :           7 :     ok = base->bounds_compatible (type, ref_locus, false);
    1566                 :             :   }
    1567                 :             : 
    1568                 :             : private:
    1569                 :           0 :   const BaseType *get_base () const override { return base; }
    1570                 :             : 
    1571                 :             :   const DynamicObjectType *base;
    1572                 :             : };
    1573                 :             : 
    1574                 :             : } // namespace TyTy
    1575                 :             : } // namespace Rust
    1576                 :             : 
    1577                 :             : #endif // RUST_TYTY_CMP_H
        

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.