Branch data Line data Source code
1 : : // Copyright (C) 2020-2024 Free Software Foundation, Inc.
2 : :
3 : : // This file is part of GCC.
4 : :
5 : : // GCC is free software; you can redistribute it and/or modify it under
6 : : // the terms of the GNU General Public License as published by the Free
7 : : // Software Foundation; either version 3, or (at your option) any later
8 : : // version.
9 : :
10 : : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 : : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : : // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 : : // for more details.
14 : :
15 : : // You should have received a copy of the GNU General Public License
16 : : // along with GCC; see the file COPYING3. If not see
17 : : // <http://www.gnu.org/licenses/>.
18 : :
19 : : #include "rust-tyty.h"
20 : :
21 : : #include "rust-tyty-visitor.h"
22 : : #include "rust-hir-map.h"
23 : : #include "rust-location.h"
24 : : #include "rust-linemap.h"
25 : :
26 : : #include "rust-substitution-mapper.h"
27 : : #include "rust-hir-trait-reference.h"
28 : : #include "rust-hir-trait-resolve.h"
29 : : #include "rust-tyty-cmp.h"
30 : : #include "rust-type-util.h"
31 : : #include "rust-hir-type-bounds.h"
32 : :
33 : : #include "options.h"
34 : :
35 : : namespace Rust {
36 : : namespace TyTy {
37 : :
38 : : std::string
39 : 17045 : TypeKindFormat::to_string (TypeKind kind)
40 : : {
41 : 17045 : switch (kind)
42 : : {
43 : 0 : case TypeKind::INFER:
44 : 0 : return "Infer";
45 : :
46 : 7 : case TypeKind::ADT:
47 : 7 : return "ADT";
48 : :
49 : 0 : case TypeKind::STR:
50 : 0 : return "STR";
51 : :
52 : 8 : case TypeKind::REF:
53 : 8 : return "REF";
54 : :
55 : 0 : case TypeKind::POINTER:
56 : 0 : return "POINTER";
57 : :
58 : 0 : case TypeKind::PARAM:
59 : 0 : return "PARAM";
60 : :
61 : 0 : case TypeKind::ARRAY:
62 : 0 : return "ARRAY";
63 : :
64 : 0 : case TypeKind::SLICE:
65 : 0 : return "SLICE";
66 : :
67 : 16956 : case TypeKind::FNDEF:
68 : 16956 : return "FnDef";
69 : :
70 : 0 : case TypeKind::FNPTR:
71 : 0 : return "FnPtr";
72 : :
73 : 1 : case TypeKind::TUPLE:
74 : 1 : return "Tuple";
75 : :
76 : 0 : case TypeKind::BOOL:
77 : 0 : return "Bool";
78 : :
79 : 0 : case TypeKind::CHAR:
80 : 0 : return "Char";
81 : :
82 : 21 : case TypeKind::INT:
83 : 21 : return "Int";
84 : :
85 : 0 : case TypeKind::UINT:
86 : 0 : return "Uint";
87 : :
88 : 0 : case TypeKind::FLOAT:
89 : 0 : return "Float";
90 : :
91 : 1 : case TypeKind::USIZE:
92 : 1 : return "Usize";
93 : :
94 : 0 : case TypeKind::ISIZE:
95 : 0 : return "Isize";
96 : :
97 : 0 : case TypeKind::NEVER:
98 : 0 : return "Never";
99 : :
100 : 0 : case TypeKind::PLACEHOLDER:
101 : 0 : return "Placeholder";
102 : :
103 : 0 : case TypeKind::PROJECTION:
104 : 0 : return "Projection";
105 : :
106 : 0 : case TypeKind::DYNAMIC:
107 : 0 : return "Dynamic";
108 : :
109 : 51 : case TypeKind::CLOSURE:
110 : 51 : return "Closure";
111 : :
112 : 0 : case TypeKind::ERROR:
113 : 0 : return "ERROR";
114 : : }
115 : 0 : rust_unreachable ();
116 : : }
117 : :
118 : : bool
119 : 188 : is_primitive_type_kind (TypeKind kind)
120 : : {
121 : 188 : switch (kind)
122 : : {
123 : : case TypeKind::BOOL:
124 : : case TypeKind::CHAR:
125 : : case TypeKind::INT:
126 : : case TypeKind::UINT:
127 : : case TypeKind::ISIZE:
128 : : case TypeKind::USIZE:
129 : : case TypeKind::FLOAT:
130 : : case TypeKind::NEVER:
131 : : case TypeKind::STR:
132 : : return true;
133 : 98 : default:
134 : 98 : return false;
135 : : }
136 : : }
137 : :
138 : : // BASE TYPE
139 : :
140 : 732312 : BaseType::BaseType (HirId ref, HirId ty_ref, TypeKind kind, RustIdent ident,
141 : 732312 : std::set<HirId> refs)
142 : 732312 : : TypeBoundsMappings ({}), kind (kind), ref (ref), ty_ref (ty_ref),
143 : 732312 : orig_ref (ref), combined (refs), ident (ident),
144 : 1464624 : mappings (Analysis::Mappings::get ())
145 : 732312 : {}
146 : :
147 : 12372564 : BaseType::BaseType (HirId ref, HirId ty_ref, TypeKind kind, RustIdent ident,
148 : : std::vector<TypeBoundPredicate> specified_bounds,
149 : 12372564 : std::set<HirId> refs)
150 : 12372564 : : TypeBoundsMappings (specified_bounds), kind (kind), ref (ref),
151 : 12372564 : ty_ref (ty_ref), orig_ref (ref), combined (refs), ident (ident),
152 : 24745128 : mappings (Analysis::Mappings::get ())
153 : 12372564 : {}
154 : :
155 : 44256 : BaseType::~BaseType () {}
156 : :
157 : : HirId
158 : 15299852 : BaseType::get_ref () const
159 : : {
160 : 15299852 : return ref;
161 : : }
162 : :
163 : : void
164 : 175111 : BaseType::set_ref (HirId id)
165 : : {
166 : 175111 : if (id != ref)
167 : 139405 : append_reference (ref);
168 : 175111 : ref = id;
169 : 175111 : }
170 : :
171 : : HirId
172 : 14636903 : BaseType::get_ty_ref () const
173 : : {
174 : 14636903 : return ty_ref;
175 : : }
176 : :
177 : : void
178 : 66630 : BaseType::set_ty_ref (HirId id)
179 : : {
180 : 66630 : ty_ref = id;
181 : 66630 : }
182 : : HirId
183 : 0 : BaseType::get_orig_ref () const
184 : : {
185 : 0 : return orig_ref;
186 : : }
187 : :
188 : : bool
189 : 118714 : BaseType::is_equal (const BaseType &other) const
190 : : {
191 : 118714 : return get_kind () == other.get_kind ();
192 : : }
193 : :
194 : : bool
195 : 44757 : BaseType::is_unit () const
196 : : {
197 : 44757 : const TyTy::BaseType *x = destructure ();
198 : 44757 : switch (x->get_kind ())
199 : : {
200 : : case PARAM:
201 : : case PROJECTION:
202 : : case PLACEHOLDER:
203 : : case FNPTR:
204 : : case FNDEF:
205 : : case ARRAY:
206 : : case SLICE:
207 : : case POINTER:
208 : : case REF:
209 : : case CLOSURE:
210 : : case INFER:
211 : : case BOOL:
212 : : case CHAR:
213 : : case INT:
214 : : case UINT:
215 : : case FLOAT:
216 : : case USIZE:
217 : : case ISIZE:
218 : :
219 : : case STR:
220 : : case DYNAMIC:
221 : : case ERROR:
222 : : return false;
223 : :
224 : : // FIXME ! is coerceable to () so we need to fix that
225 : : case NEVER:
226 : : return true;
227 : :
228 : 8022 : case TUPLE: {
229 : 8022 : return x->as<const TupleType> ()->num_fields () == 0;
230 : : }
231 : :
232 : 18857 : case ADT: {
233 : 18857 : auto adt = x->as<const ADTType> ();
234 : 18857 : if (adt->is_enum ())
235 : : return false;
236 : :
237 : 19724 : for (const auto &variant : adt->get_variants ())
238 : : {
239 : 17206 : if (variant->num_fields () > 0)
240 : 34202 : return false;
241 : : }
242 : :
243 : : return true;
244 : : }
245 : : }
246 : : return false;
247 : : }
248 : :
249 : : TypeKind
250 : 15585622 : BaseType::get_kind () const
251 : : {
252 : 15585622 : return kind;
253 : : }
254 : :
255 : : std::set<HirId>
256 : 13131795 : BaseType::get_combined_refs () const
257 : : {
258 : 13131795 : return combined;
259 : : }
260 : :
261 : : void
262 : 6388175 : BaseType::append_reference (HirId id)
263 : : {
264 : 6388175 : combined.insert (id);
265 : 6388175 : }
266 : :
267 : : const RustIdent &
268 : 90344 : BaseType::get_ident () const
269 : : {
270 : 90344 : return ident;
271 : : }
272 : :
273 : : location_t
274 : 24678 : BaseType::get_locus () const
275 : : {
276 : 24678 : return ident.locus;
277 : : }
278 : :
279 : : // FIXME this is missing locus
280 : : bool
281 : 15504 : BaseType::satisfies_bound (const TypeBoundPredicate &predicate,
282 : : bool emit_error) const
283 : : {
284 : 15504 : const Resolver::TraitReference *query = predicate.get ();
285 : 16433 : for (const auto &bound : specified_bounds)
286 : : {
287 : 8658 : const Resolver::TraitReference *item = bound.get ();
288 : 8658 : if (item->satisfies_bound (*query))
289 : 8049 : return true;
290 : : }
291 : :
292 : 7775 : if (destructure ()->is<InferType> ())
293 : : return true;
294 : :
295 : 7455 : bool satisfied = false;
296 : 7455 : auto probed = Resolver::TypeBoundsProbe::Probe (this);
297 : 11111 : for (const auto &b : probed)
298 : : {
299 : 10724 : const Resolver::TraitReference *bound = b.first;
300 : 10724 : if (bound->satisfies_bound (*query))
301 : : {
302 : : satisfied = true;
303 : : break;
304 : : }
305 : : }
306 : :
307 : 7455 : if (!satisfied)
308 : : return false;
309 : :
310 : 17862 : for (const auto &b : probed)
311 : : {
312 : 17862 : const Resolver::TraitReference *bound = b.first;
313 : 17862 : if (!bound->is_equal (*query))
314 : 10794 : continue;
315 : :
316 : : // builtin ones have no impl-block this needs fixed and use a builtin node
317 : : // of somekind
318 : 7068 : if (b.second == nullptr)
319 : : return true;
320 : :
321 : : // need to check that associated types can match as well
322 : 7068 : const HIR::ImplBlock &impl = *(b.second);
323 : 10117 : for (const auto &item : impl.get_impl_items ())
324 : : {
325 : 3051 : bool is_associated_type = item->get_impl_item_type ()
326 : 3051 : == HIR::ImplItem::ImplItemType::TYPE_ALIAS;
327 : 3051 : if (!is_associated_type)
328 : 1862 : continue;
329 : :
330 : 1189 : TyTy::BaseType *impl_item_ty = nullptr;
331 : 1189 : Analysis::NodeMapping i = item->get_impl_mappings ();
332 : 1189 : bool query_ok = Resolver::query_type (i.get_hirid (), &impl_item_ty);
333 : 1189 : if (!query_ok)
334 : 2 : return false;
335 : :
336 : 1189 : std::string item_name = item->get_impl_item_name ();
337 : 1189 : TypeBoundPredicateItem lookup
338 : 1189 : = predicate.lookup_associated_item (item_name);
339 : 1189 : if (lookup.is_error ())
340 : : return false;
341 : :
342 : 1189 : const auto *item_ref = lookup.get_raw_item ();
343 : 1189 : TyTy::BaseType *bound_ty = item_ref->get_tyty ();
344 : :
345 : : // compare the types
346 : 1189 : if (!bound_ty->can_eq (impl_item_ty, false))
347 : : {
348 : 23 : if (!impl_item_ty->can_eq (bound_ty, false))
349 : : {
350 : 2 : if (emit_error)
351 : : {
352 : 1 : rich_location r (line_table,
353 : 1 : mappings->lookup_location (get_ref ()));
354 : 1 : r.add_range (predicate.get_locus ());
355 : 1 : r.add_range (mappings->lookup_location (i.get_hirid ()));
356 : :
357 : 1 : std::string rich_msg
358 : 2 : = "expected " + bound_ty->destructure ()->get_name ()
359 : 2 : + ", found "
360 : 2 : + impl_item_ty->destructure ()->get_name ();
361 : 1 : r.add_fixit_replace (rich_msg.c_str ());
362 : :
363 : 1 : rust_error_at (
364 : : r, ErrorCode::E0271,
365 : : "type mismatch, expected %qs but got %qs",
366 : 2 : bound_ty->destructure ()->get_name ().c_str (),
367 : 2 : impl_item_ty->destructure ()->get_name ().c_str ());
368 : 1 : }
369 : 2 : return false;
370 : : }
371 : : }
372 : 1189 : }
373 : :
374 : : return true;
375 : : }
376 : :
377 : : return false;
378 : 7455 : }
379 : :
380 : : bool
381 : 14144 : BaseType::bounds_compatible (const BaseType &other, location_t locus,
382 : : bool emit_error) const
383 : : {
384 : 14144 : std::vector<std::reference_wrapper<const TypeBoundPredicate>>
385 : 14144 : unsatisfied_bounds;
386 : 29648 : for (auto &bound : get_specified_bounds ())
387 : : {
388 : 15504 : if (!other.satisfies_bound (bound, emit_error))
389 : 389 : unsatisfied_bounds.push_back (bound);
390 : : }
391 : :
392 : : // lets emit a single error for this
393 : 14144 : if (unsatisfied_bounds.size () > 0)
394 : : {
395 : 389 : rich_location r (line_table, locus);
396 : 389 : std::string missing_preds;
397 : 778 : for (size_t i = 0; i < unsatisfied_bounds.size (); i++)
398 : : {
399 : 389 : const TypeBoundPredicate &pred = unsatisfied_bounds.at (i);
400 : 389 : r.add_range (pred.get_locus ());
401 : 389 : missing_preds += pred.get_name ();
402 : :
403 : 389 : bool have_next = (i + 1) < unsatisfied_bounds.size ();
404 : 389 : if (have_next)
405 : 0 : missing_preds += ", ";
406 : : }
407 : :
408 : 389 : if (emit_error)
409 : : {
410 : 8 : rust_error_at (r, ErrorCode::E0277,
411 : : "bounds not satisfied for %s %<%s%> is not satisfied",
412 : 16 : other.get_name ().c_str (), missing_preds.c_str ());
413 : : // rust_assert (!emit_error);
414 : : }
415 : 389 : }
416 : :
417 : 14144 : return unsatisfied_bounds.size () == 0;
418 : 14144 : }
419 : :
420 : : void
421 : 4989 : BaseType::inherit_bounds (const BaseType &other)
422 : : {
423 : 4989 : inherit_bounds (other.get_specified_bounds ());
424 : 4989 : }
425 : :
426 : : void
427 : 17095 : BaseType::inherit_bounds (
428 : : const std::vector<TyTy::TypeBoundPredicate> &specified_bounds)
429 : : {
430 : 34855 : for (auto &bound : specified_bounds)
431 : : {
432 : 17760 : add_bound (bound);
433 : : }
434 : 17095 : }
435 : :
436 : : const BaseType *
437 : 8299 : BaseType::get_root () const
438 : : {
439 : : // FIXME this needs to be it its own visitor class with a vector adjustments
440 : 9688 : const TyTy::BaseType *root = this;
441 : :
442 : 9688 : if (const auto r = root->try_as<const ReferenceType> ())
443 : : {
444 : 816 : root = r->get_base ()->get_root ();
445 : : }
446 : 8872 : else if (const auto r = root->try_as<const PointerType> ())
447 : : {
448 : 303 : root = r->get_base ()->get_root ();
449 : : }
450 : : // these are an unsize
451 : 8569 : else if (const auto r = root->try_as<const SliceType> ())
452 : : {
453 : 270 : root = r->get_element_type ()->get_root ();
454 : : }
455 : : // else if (const auto r = root->try_as<const ArrayType> ())
456 : : // {
457 : : // root = r->get_element_type ()->get_root ();
458 : : // }
459 : :
460 : 8299 : return root;
461 : : }
462 : :
463 : : BaseType *
464 : 632595 : BaseType::destructure ()
465 : : {
466 : 632595 : int recurisve_ops = 0;
467 : 632595 : BaseType *x = this;
468 : 689463 : while (true)
469 : : {
470 : 689463 : if (recurisve_ops++ >= rust_max_recursion_depth)
471 : : {
472 : 0 : rust_error_at (
473 : : UNDEF_LOCATION,
474 : : "%<recursion depth%> count exceeds limit of %i (use "
475 : : "%<frust-max-recursion-depth=%> to increase the limit)",
476 : : rust_max_recursion_depth);
477 : 0 : return new ErrorType (get_ref ());
478 : : }
479 : :
480 : 689463 : if (auto p = x->try_as<ParamType> ())
481 : : {
482 : 72220 : auto pr = p->resolve ();
483 : 72220 : if (pr == x)
484 : 19454 : return pr;
485 : :
486 : : x = pr;
487 : : }
488 : 617243 : else if (auto p = x->try_as<PlaceholderType> ())
489 : : {
490 : 3406 : if (!p->can_resolve ())
491 : 1857 : return p;
492 : :
493 : 1549 : x = p->resolve ();
494 : : }
495 : 613837 : else if (auto p = x->try_as<ProjectionType> ())
496 : : {
497 : 2553 : x = p->get ();
498 : : }
499 : : else
500 : : {
501 : 611284 : return x;
502 : : }
503 : : }
504 : :
505 : : return x;
506 : : }
507 : :
508 : : const BaseType *
509 : 648675 : BaseType::destructure () const
510 : : {
511 : 648675 : int recurisve_ops = 0;
512 : 648675 : const BaseType *x = this;
513 : 823011 : while (true)
514 : : {
515 : 823011 : if (recurisve_ops++ >= rust_max_recursion_depth)
516 : : {
517 : 0 : rust_error_at (
518 : : UNDEF_LOCATION,
519 : : "%<recursion depth%> count exceeds limit of %i (use "
520 : : "%<frust-max-recursion-depth=%> to increase the limit)",
521 : : rust_max_recursion_depth);
522 : 0 : return new ErrorType (get_ref ());
523 : : }
524 : :
525 : 823011 : if (auto p = x->try_as<const ParamType> ())
526 : : {
527 : 261614 : auto pr = p->resolve ();
528 : 261614 : if (pr == x)
529 : 92907 : return pr;
530 : :
531 : : x = pr;
532 : : }
533 : 561397 : else if (auto p = x->try_as<const PlaceholderType> ())
534 : : {
535 : 4646 : if (!p->can_resolve ())
536 : 2172 : return p;
537 : :
538 : 2474 : x = p->resolve ();
539 : : }
540 : 556751 : else if (auto p = x->try_as<const ProjectionType> ())
541 : : {
542 : 3155 : x = p->get ();
543 : : }
544 : : else
545 : : {
546 : 553596 : return x;
547 : : }
548 : : }
549 : :
550 : : return x;
551 : : }
552 : :
553 : : BaseType *
554 : 2201 : BaseType::monomorphized_clone () const
555 : : {
556 : 2201 : const TyTy::BaseType *x = destructure ();
557 : :
558 : 2201 : if (auto arr = x->try_as<const ArrayType> ())
559 : : {
560 : 1 : TyVar elm = arr->get_var_element_type ().monomorphized_clone ();
561 : 1 : return new ArrayType (arr->get_ref (), arr->get_ty_ref (), ident.locus,
562 : : arr->get_capacity_expr (), elm,
563 : 1 : arr->get_combined_refs ());
564 : : }
565 : 2200 : else if (auto slice = x->try_as<const SliceType> ())
566 : : {
567 : 112 : TyVar elm = slice->get_var_element_type ().monomorphized_clone ();
568 : 112 : return new SliceType (slice->get_ref (), slice->get_ty_ref (),
569 : 112 : ident.locus, elm, slice->get_combined_refs ());
570 : : }
571 : 2088 : else if (auto ptr = x->try_as<const PointerType> ())
572 : : {
573 : 334 : TyVar elm = ptr->get_var_element_type ().monomorphized_clone ();
574 : 334 : return new PointerType (ptr->get_ref (), ptr->get_ty_ref (), elm,
575 : 334 : ptr->mutability (), ptr->get_combined_refs ());
576 : : }
577 : 1754 : else if (auto ref = x->try_as<const ReferenceType> ())
578 : : {
579 : 204 : TyVar elm = ref->get_var_element_type ().monomorphized_clone ();
580 : 204 : return new ReferenceType (ref->get_ref (), ref->get_ty_ref (), elm,
581 : 408 : ref->mutability (), ref->get_region (),
582 : 612 : ref->get_combined_refs ());
583 : : }
584 : 1550 : else if (auto tuple = x->try_as<const TupleType> ())
585 : : {
586 : 251 : std::vector<TyVar> cloned_fields;
587 : 373 : for (const auto &f : tuple->get_fields ())
588 : 122 : cloned_fields.push_back (f.monomorphized_clone ());
589 : :
590 : 251 : return new TupleType (tuple->get_ref (), tuple->get_ty_ref (),
591 : 251 : ident.locus, cloned_fields,
592 : 251 : tuple->get_combined_refs ());
593 : 251 : }
594 : 1299 : else if (auto fn = x->try_as<const FnType> ())
595 : : {
596 : 0 : std::vector<std::pair<HIR::Pattern *, BaseType *>> cloned_params;
597 : 0 : for (auto &p : fn->get_params ())
598 : 0 : cloned_params.push_back ({p.first, p.second->monomorphized_clone ()});
599 : :
600 : 0 : BaseType *retty = fn->get_return_type ()->monomorphized_clone ();
601 : 0 : return new FnType (fn->get_ref (), fn->get_ty_ref (), fn->get_id (),
602 : 0 : fn->get_identifier (), fn->ident, fn->get_flags (),
603 : : fn->get_abi (), std::move (cloned_params), retty,
604 : 0 : fn->clone_substs (), fn->get_substitution_arguments (),
605 : : fn->get_region_constraints (),
606 : 0 : fn->get_combined_refs ());
607 : 0 : }
608 : 1299 : else if (auto fn = x->try_as<const FnPtr> ())
609 : : {
610 : 0 : std::vector<TyVar> cloned_params;
611 : 0 : for (auto &p : fn->get_params ())
612 : 0 : cloned_params.push_back (p.monomorphized_clone ());
613 : :
614 : 0 : TyVar retty = fn->get_var_return_type ().monomorphized_clone ();
615 : 0 : return new FnPtr (fn->get_ref (), fn->get_ty_ref (), ident.locus,
616 : : std::move (cloned_params), retty,
617 : 0 : fn->get_combined_refs ());
618 : 0 : }
619 : 1299 : else if (auto adt = x->try_as<const ADTType> ())
620 : : {
621 : 77 : std::vector<VariantDef *> cloned_variants;
622 : 178 : for (auto &variant : adt->get_variants ())
623 : 101 : cloned_variants.push_back (variant->monomorphized_clone ());
624 : :
625 : 77 : return new ADTType (adt->get_ref (), adt->get_ty_ref (),
626 : 154 : adt->get_identifier (), adt->ident,
627 : : adt->get_adt_kind (), cloned_variants,
628 : 77 : adt->clone_substs (), adt->get_repr_options (),
629 : : adt->get_used_arguments (),
630 : : adt->get_region_constraints (),
631 : 231 : adt->get_combined_refs ());
632 : 77 : }
633 : : else
634 : : {
635 : 1222 : return x->clone ();
636 : : }
637 : :
638 : : rust_unreachable ();
639 : : return nullptr;
640 : : }
641 : :
642 : : std::string
643 : 17045 : BaseType::mappings_str () const
644 : : {
645 : 34090 : std::string buffer = "Ref: " + std::to_string (get_ref ())
646 : 51135 : + " TyRef: " + std::to_string (get_ty_ref ());
647 : 17045 : buffer += "[";
648 : 26832 : for (auto &ref : combined)
649 : 19574 : buffer += std::to_string (ref) + ",";
650 : 17045 : buffer += "]";
651 : 34090 : return "(" + buffer + ")";
652 : 17045 : }
653 : :
654 : : std::string
655 : 771902 : BaseType::debug_str () const
656 : : {
657 : : // return TypeKindFormat::to_string (get_kind ()) + ":" + as_string () + ":"
658 : : // + mappings_str () + ":" + bounds_as_string ();
659 : 771902 : return get_name ();
660 : : }
661 : :
662 : : void
663 : 339 : BaseType::debug () const
664 : : {
665 : 339 : rust_debug ("[%p] %s", static_cast<const void *> (this),
666 : : debug_str ().c_str ());
667 : 339 : }
668 : :
669 : : bool
670 : 98230 : BaseType::is_concrete () const
671 : : {
672 : 129973 : const TyTy::BaseType *x = destructure ();
673 : :
674 : 215681 : if (x->is<ParamType> () || x->is<ProjectionType> ())
675 : : {
676 : 44265 : return false;
677 : : }
678 : : // placeholder is a special case for this case when it is not resolvable
679 : : // it means we its just an empty placeholder associated type which is
680 : : // concrete
681 : 85708 : else if (x->is<PlaceholderType> ())
682 : : {
683 : : return true;
684 : : }
685 : 84015 : else if (auto fn = x->try_as<const FnType> ())
686 : : {
687 : 6932 : for (const auto ¶m : fn->get_params ())
688 : : {
689 : 4440 : if (!param.second->is_concrete ())
690 : 46882 : return false;
691 : : }
692 : 2492 : return fn->get_return_type ()->is_concrete ();
693 : : }
694 : 80495 : else if (auto fn = x->try_as<const FnPtr> ())
695 : : {
696 : 0 : for (const auto ¶m : fn->get_params ())
697 : : {
698 : 0 : if (!param.get_tyty ()->is_concrete ())
699 : 46882 : return false;
700 : : }
701 : 0 : return fn->get_return_type ()->is_concrete ();
702 : : }
703 : 80495 : else if (auto adt = x->try_as<const ADTType> ())
704 : : {
705 : 9387 : if (adt->is_unit ())
706 : 937 : return !adt->needs_substitution ();
707 : :
708 : 15723 : for (auto &variant : adt->get_variants ())
709 : : {
710 : 8636 : bool is_num_variant
711 : 8636 : = variant->get_variant_type () == VariantDef::VariantType::NUM;
712 : 8636 : if (is_num_variant)
713 : 186 : continue;
714 : :
715 : 18063 : for (auto &field : variant->get_fields ())
716 : : {
717 : 10976 : const BaseType *field_type = field->get_field_type ();
718 : 10976 : if (!field_type->is_concrete ())
719 : 46882 : return false;
720 : : }
721 : : }
722 : : return true;
723 : : }
724 : 71108 : else if (auto arr = x->try_as<const ArrayType> ())
725 : : {
726 : 520 : return arr->get_element_type ()->is_concrete ();
727 : : }
728 : 70588 : else if (auto slice = x->try_as<const SliceType> ())
729 : : {
730 : 4929 : return slice->get_element_type ()->is_concrete ();
731 : : }
732 : 65659 : else if (auto ptr = x->try_as<const PointerType> ())
733 : : {
734 : 3144 : return ptr->get_base ()->is_concrete ();
735 : : }
736 : 62515 : else if (auto ref = x->try_as<const ReferenceType> ())
737 : : {
738 : 20658 : return ref->get_base ()->is_concrete ();
739 : : }
740 : 41857 : else if (auto tuple = x->try_as<const TupleType> ())
741 : : {
742 : 1890 : for (size_t i = 0; i < tuple->num_fields (); i++)
743 : : {
744 : 524 : if (!tuple->get_field (i)->is_concrete ())
745 : : return false;
746 : : }
747 : : return true;
748 : : }
749 : 40339 : else if (auto closure = x->try_as<const ClosureType> ())
750 : : {
751 : 74 : if (closure->get_parameters ().is_concrete ())
752 : : return false;
753 : 0 : return closure->get_result_type ().is_concrete ();
754 : : }
755 : 111244 : else if (x->is<InferType> () || x->is<BoolType> () || x->is<CharType> ()
756 : 69667 : || x->is<IntType> () || x->is<UintType> () || x->is<FloatType> ()
757 : 14672 : || x->is<USizeType> () || x->is<ISizeType> () || x->is<NeverType> ()
758 : 1819 : || x->is<StrType> () || x->is<DynamicObjectType> ()
759 : 40265 : || x->is<ErrorType> ())
760 : : {
761 : 40265 : return true;
762 : : }
763 : :
764 : : return false;
765 : : }
766 : :
767 : : bool
768 : 69315 : BaseType::has_substitutions_defined () const
769 : : {
770 : 69315 : const TyTy::BaseType *x = destructure ();
771 : 69315 : switch (x->get_kind ())
772 : : {
773 : : case INFER:
774 : : case BOOL:
775 : : case CHAR:
776 : : case INT:
777 : : case UINT:
778 : : case FLOAT:
779 : : case USIZE:
780 : : case ISIZE:
781 : : case NEVER:
782 : : case STR:
783 : : case DYNAMIC:
784 : : case ERROR:
785 : : case FNPTR:
786 : : case ARRAY:
787 : : case SLICE:
788 : : case POINTER:
789 : : case REF:
790 : : case TUPLE:
791 : : case PARAM:
792 : : case PLACEHOLDER:
793 : : return false;
794 : :
795 : 0 : case PROJECTION: {
796 : 0 : const ProjectionType &p = *static_cast<const ProjectionType *> (x);
797 : 0 : const SubstitutionRef &ref = static_cast<const SubstitutionRef &> (p);
798 : 0 : return ref.has_substitutions ();
799 : : }
800 : 37360 : break;
801 : :
802 : 37360 : case FNDEF: {
803 : 37360 : const FnType &fn = *static_cast<const FnType *> (x);
804 : 37360 : const SubstitutionRef &ref = static_cast<const SubstitutionRef &> (fn);
805 : 37360 : return ref.has_substitutions ();
806 : : }
807 : 25704 : break;
808 : :
809 : 25704 : case ADT: {
810 : 25704 : const ADTType &adt = *static_cast<const ADTType *> (x);
811 : 25704 : const SubstitutionRef &ref = static_cast<const SubstitutionRef &> (adt);
812 : 25704 : return ref.has_substitutions ();
813 : : }
814 : 0 : break;
815 : :
816 : 0 : case CLOSURE: {
817 : 0 : const ClosureType &closure = *static_cast<const ClosureType *> (x);
818 : 0 : const SubstitutionRef &ref
819 : : = static_cast<const SubstitutionRef &> (closure);
820 : 0 : return ref.has_substitutions ();
821 : : }
822 : : break;
823 : : }
824 : :
825 : : return false;
826 : : }
827 : :
828 : : bool
829 : 59570 : BaseType::needs_generic_substitutions () const
830 : : {
831 : 59570 : const TyTy::BaseType *x = destructure ();
832 : 59570 : switch (x->get_kind ())
833 : : {
834 : : case INFER:
835 : : case BOOL:
836 : : case CHAR:
837 : : case INT:
838 : : case UINT:
839 : : case FLOAT:
840 : : case USIZE:
841 : : case ISIZE:
842 : : case NEVER:
843 : : case STR:
844 : : case DYNAMIC:
845 : : case ERROR:
846 : : case FNPTR:
847 : : case ARRAY:
848 : : case SLICE:
849 : : case POINTER:
850 : : case REF:
851 : : case TUPLE:
852 : : case PARAM:
853 : : case PLACEHOLDER:
854 : : return false;
855 : :
856 : 0 : case PROJECTION: {
857 : 0 : const ProjectionType &p = *static_cast<const ProjectionType *> (x);
858 : 0 : const SubstitutionRef &ref = static_cast<const SubstitutionRef &> (p);
859 : 0 : return ref.needs_substitution ();
860 : : }
861 : 7662 : break;
862 : :
863 : 7662 : case FNDEF: {
864 : 7662 : const FnType &fn = *static_cast<const FnType *> (x);
865 : 7662 : const SubstitutionRef &ref = static_cast<const SubstitutionRef &> (fn);
866 : 7662 : return ref.needs_substitution ();
867 : : }
868 : 8582 : break;
869 : :
870 : 8582 : case ADT: {
871 : 8582 : const ADTType &adt = *static_cast<const ADTType *> (x);
872 : 8582 : const SubstitutionRef &ref = static_cast<const SubstitutionRef &> (adt);
873 : 8582 : return ref.needs_substitution ();
874 : : }
875 : 46 : break;
876 : :
877 : 46 : case CLOSURE: {
878 : 46 : const ClosureType &closure = *static_cast<const ClosureType *> (x);
879 : 46 : const SubstitutionRef &ref
880 : : = static_cast<const SubstitutionRef &> (closure);
881 : 46 : return ref.needs_substitution ();
882 : : }
883 : : break;
884 : : }
885 : :
886 : : return false;
887 : : }
888 : :
889 : : // InferType
890 : :
891 : 55875 : InferType::InferType (HirId ref, InferTypeKind infer_kind, TypeHint hint,
892 : 55875 : location_t locus, std::set<HirId> refs)
893 : 55875 : : BaseType (ref, ref, KIND, {Resolver::CanonicalPath::create_empty (), locus},
894 : : refs),
895 : 111750 : infer_kind (infer_kind), default_hint (hint)
896 : 55875 : {}
897 : :
898 : 0 : InferType::InferType (HirId ref, HirId ty_ref, InferTypeKind infer_kind,
899 : 0 : TypeHint hint, location_t locus, std::set<HirId> refs)
900 : : : BaseType (ref, ty_ref, KIND,
901 : 0 : {Resolver::CanonicalPath::create_empty (), locus}, refs),
902 : 0 : infer_kind (infer_kind), default_hint (hint)
903 : 0 : {}
904 : :
905 : : InferType::InferTypeKind
906 : 147137 : InferType::get_infer_kind () const
907 : : {
908 : 147137 : return infer_kind;
909 : : }
910 : :
911 : : std::string
912 : 151421 : InferType::get_name () const
913 : : {
914 : 151421 : return as_string ();
915 : : }
916 : :
917 : : void
918 : 0 : InferType::accept_vis (TyVisitor &vis)
919 : : {
920 : 0 : vis.visit (*this);
921 : 0 : }
922 : :
923 : : void
924 : 477 : InferType::accept_vis (TyConstVisitor &vis) const
925 : : {
926 : 477 : vis.visit (*this);
927 : 477 : }
928 : :
929 : : std::string
930 : 197600 : InferType::as_string () const
931 : : {
932 : 197600 : switch (infer_kind)
933 : : {
934 : 39694 : case GENERAL:
935 : 39694 : return "T?";
936 : 155156 : case INTEGRAL:
937 : 155156 : return "<integer>";
938 : 2750 : case FLOAT:
939 : 2750 : return "<float>";
940 : : }
941 : 0 : return "<infer::error>";
942 : : }
943 : :
944 : : bool
945 : 7247 : InferType::can_eq (const BaseType *other, bool emit_errors) const
946 : : {
947 : 7247 : InferCmp r (this, emit_errors);
948 : 7247 : return r.can_eq (other);
949 : : }
950 : :
951 : : BaseType *
952 : 39739 : InferType::clone () const
953 : : {
954 : : // clones for inference variables are special in that they _must_ exist within
955 : : // the type check context and we must ensure we don't loose the chain
956 : : // otherwise we will end up in the missing type annotations case
957 : : //
958 : : // This means we cannot simply take over the same reference we must generate a
959 : : // new ref just like the get_implicit_infer_var code then we can setup the
960 : : // chain of references accordingly to ensure we don't loose the ability to
961 : : // update the inference variables when we solve the type
962 : :
963 : 39739 : auto mappings = Analysis::Mappings::get ();
964 : 39739 : auto context = Resolver::TypeCheckContext::get ();
965 : :
966 : 39739 : InferType *clone
967 : : = new InferType (mappings->get_next_hir_id (), get_infer_kind (),
968 : 39739 : default_hint, get_ident ().locus, get_combined_refs ());
969 : :
970 : 39739 : context->insert_type (Analysis::NodeMapping (mappings->get_current_crate (),
971 : : UNKNOWN_NODEID,
972 : : clone->get_ref (),
973 : : UNKNOWN_LOCAL_DEFID),
974 : : clone);
975 : 39739 : mappings->insert_location (clone->get_ref (),
976 : : mappings->lookup_location (get_ref ()));
977 : :
978 : : // setup the chain to reference this
979 : 39739 : clone->append_reference (get_ref ());
980 : :
981 : 39739 : return clone;
982 : : }
983 : :
984 : : bool
985 : 32831 : InferType::default_type (BaseType **type) const
986 : : {
987 : 32831 : auto context = Resolver::TypeCheckContext::get ();
988 : 32831 : bool ok = false;
989 : :
990 : : // NOTE: Calling this error is misleading.
991 : 32831 : if (default_hint.kind == TypeKind::ERROR)
992 : : {
993 : 32697 : switch (infer_kind)
994 : : {
995 : : case GENERAL:
996 : : return false;
997 : :
998 : 32363 : case INTEGRAL: {
999 : 32363 : ok = context->lookup_builtin ("i32", type);
1000 : 32363 : rust_assert (ok);
1001 : : return ok;
1002 : : }
1003 : :
1004 : 322 : case FLOAT: {
1005 : 322 : ok = context->lookup_builtin ("f64", type);
1006 : 322 : rust_assert (ok);
1007 : : return ok;
1008 : : }
1009 : : }
1010 : : return false;
1011 : : }
1012 : :
1013 : 134 : switch (default_hint.kind)
1014 : : {
1015 : 21 : case ISIZE:
1016 : 21 : ok = context->lookup_builtin ("isize", type);
1017 : 21 : rust_assert (ok);
1018 : : return ok;
1019 : :
1020 : 0 : case USIZE:
1021 : 0 : ok = context->lookup_builtin ("usize", type);
1022 : 0 : rust_assert (ok);
1023 : : return ok;
1024 : :
1025 : 113 : case INT:
1026 : 113 : switch (default_hint.szhint)
1027 : : {
1028 : 0 : case TypeHint::SizeHint::S8:
1029 : 0 : ok = context->lookup_builtin ("i8", type);
1030 : 0 : rust_assert (ok);
1031 : : return ok;
1032 : :
1033 : 0 : case TypeHint::SizeHint::S16:
1034 : 0 : ok = context->lookup_builtin ("i16", type);
1035 : 0 : rust_assert (ok);
1036 : : return ok;
1037 : :
1038 : 113 : case TypeHint::SizeHint::S32:
1039 : 113 : ok = context->lookup_builtin ("i32", type);
1040 : 113 : rust_assert (ok);
1041 : : return ok;
1042 : :
1043 : 0 : case TypeHint::SizeHint::S64:
1044 : 0 : ok = context->lookup_builtin ("i64", type);
1045 : 0 : rust_assert (ok);
1046 : : return ok;
1047 : :
1048 : 0 : case TypeHint::SizeHint::S128:
1049 : 0 : ok = context->lookup_builtin ("i128", type);
1050 : 0 : rust_assert (ok);
1051 : : return ok;
1052 : :
1053 : : default:
1054 : : return false;
1055 : : }
1056 : 0 : break;
1057 : :
1058 : 0 : case UINT:
1059 : 0 : switch (default_hint.szhint)
1060 : : {
1061 : 0 : case TypeHint::SizeHint::S8:
1062 : 0 : ok = context->lookup_builtin ("u8", type);
1063 : 0 : rust_assert (ok);
1064 : : return ok;
1065 : :
1066 : 0 : case TypeHint::SizeHint::S16:
1067 : 0 : ok = context->lookup_builtin ("u16", type);
1068 : 0 : rust_assert (ok);
1069 : : return ok;
1070 : :
1071 : 0 : case TypeHint::SizeHint::S32:
1072 : 0 : ok = context->lookup_builtin ("u32", type);
1073 : 0 : rust_assert (ok);
1074 : : return ok;
1075 : :
1076 : 0 : case TypeHint::SizeHint::S64:
1077 : 0 : ok = context->lookup_builtin ("u64", type);
1078 : 0 : rust_assert (ok);
1079 : : return ok;
1080 : :
1081 : 0 : case TypeHint::SizeHint::S128:
1082 : 0 : ok = context->lookup_builtin ("u128", type);
1083 : 0 : rust_assert (ok);
1084 : : return ok;
1085 : :
1086 : : default:
1087 : : return false;
1088 : : }
1089 : 0 : break;
1090 : :
1091 : 0 : case TypeKind::FLOAT:
1092 : 0 : switch (default_hint.szhint)
1093 : : {
1094 : 0 : case TypeHint::SizeHint::S32:
1095 : 0 : ok = context->lookup_builtin ("f32", type);
1096 : 0 : rust_assert (ok);
1097 : : return ok;
1098 : :
1099 : 0 : case TypeHint::SizeHint::S64:
1100 : 0 : ok = context->lookup_builtin ("f64", type);
1101 : 0 : rust_assert (ok);
1102 : : return ok;
1103 : :
1104 : : default:
1105 : : return false;
1106 : : }
1107 : : break;
1108 : :
1109 : : default:
1110 : : return false;
1111 : : }
1112 : :
1113 : : return false;
1114 : : }
1115 : :
1116 : : void
1117 : 42823 : InferType::apply_primitive_type_hint (const BaseType &hint)
1118 : : {
1119 : 42823 : switch (hint.get_kind ())
1120 : : {
1121 : 1675 : case ISIZE:
1122 : 1675 : case USIZE:
1123 : 1675 : infer_kind = INTEGRAL;
1124 : 1675 : default_hint.kind = hint.get_kind ();
1125 : 1675 : break;
1126 : :
1127 : 38313 : case INT: {
1128 : 38313 : infer_kind = INTEGRAL;
1129 : 38313 : default_hint.kind = hint.get_kind ();
1130 : 38313 : default_hint.shint = TypeHint::SignedHint::SIGNED;
1131 : 38313 : switch (hint.as<const IntType> ()->get_int_kind ())
1132 : : {
1133 : 85 : case IntType::I8:
1134 : 85 : default_hint.szhint = TypeHint::SizeHint::S8;
1135 : 85 : break;
1136 : 38 : case IntType::I16:
1137 : 38 : default_hint.szhint = TypeHint::SizeHint::S16;
1138 : 38 : break;
1139 : 38086 : case IntType::I32:
1140 : 38086 : default_hint.szhint = TypeHint::SizeHint::S32;
1141 : 38086 : break;
1142 : 41 : case IntType::I64:
1143 : 41 : default_hint.szhint = TypeHint::SizeHint::S64;
1144 : 41 : break;
1145 : 63 : case IntType::I128:
1146 : 63 : default_hint.szhint = TypeHint::SizeHint::S128;
1147 : 63 : break;
1148 : : }
1149 : : }
1150 : : break;
1151 : :
1152 : 1781 : case UINT: {
1153 : 1781 : infer_kind = INTEGRAL;
1154 : 1781 : default_hint.kind = hint.get_kind ();
1155 : 1781 : default_hint.shint = TypeHint::SignedHint::UNSIGNED;
1156 : 1781 : switch (hint.as<const UintType> ()->get_uint_kind ())
1157 : : {
1158 : 564 : case UintType::U8:
1159 : 564 : default_hint.szhint = TypeHint::SizeHint::S8;
1160 : 564 : break;
1161 : 210 : case UintType::U16:
1162 : 210 : default_hint.szhint = TypeHint::SizeHint::S16;
1163 : 210 : break;
1164 : 736 : case UintType::U32:
1165 : 736 : default_hint.szhint = TypeHint::SizeHint::S32;
1166 : 736 : break;
1167 : 233 : case UintType::U64:
1168 : 233 : default_hint.szhint = TypeHint::SizeHint::S64;
1169 : 233 : break;
1170 : 38 : case UintType::U128:
1171 : 38 : default_hint.szhint = TypeHint::SizeHint::S128;
1172 : 38 : break;
1173 : : }
1174 : : }
1175 : : break;
1176 : :
1177 : 1054 : case TypeKind::FLOAT: {
1178 : 1054 : infer_kind = FLOAT;
1179 : 1054 : default_hint.shint = TypeHint::SignedHint::SIGNED;
1180 : 1054 : default_hint.kind = hint.get_kind ();
1181 : 1054 : switch (hint.as<const FloatType> ()->get_float_kind ())
1182 : : {
1183 : 417 : case FloatType::F32:
1184 : 417 : default_hint.szhint = TypeHint::SizeHint::S32;
1185 : 417 : break;
1186 : :
1187 : 637 : case FloatType::F64:
1188 : 637 : default_hint.szhint = TypeHint::SizeHint::S64;
1189 : 637 : break;
1190 : : }
1191 : : }
1192 : : break;
1193 : :
1194 : : default:
1195 : : // TODO bool, char, never??
1196 : : break;
1197 : : }
1198 : 42823 : }
1199 : :
1200 : : // ErrorType
1201 : :
1202 : 104460 : ErrorType::ErrorType (HirId ref, std::set<HirId> refs)
1203 : : : BaseType (ref, ref, KIND,
1204 : 104460 : {Resolver::CanonicalPath::create_empty (), UNDEF_LOCATION}, refs)
1205 : 104460 : {}
1206 : :
1207 : 43 : ErrorType::ErrorType (HirId ref, HirId ty_ref, std::set<HirId> refs)
1208 : : : BaseType (ref, ty_ref, KIND,
1209 : 43 : {Resolver::CanonicalPath::create_empty (), UNDEF_LOCATION}, refs)
1210 : 43 : {}
1211 : :
1212 : : std::string
1213 : 17 : ErrorType::get_name () const
1214 : : {
1215 : 17 : return as_string ();
1216 : : }
1217 : :
1218 : : void
1219 : 0 : ErrorType::accept_vis (TyVisitor &vis)
1220 : : {
1221 : 0 : vis.visit (*this);
1222 : 0 : }
1223 : :
1224 : : void
1225 : 2 : ErrorType::accept_vis (TyConstVisitor &vis) const
1226 : : {
1227 : 2 : vis.visit (*this);
1228 : 2 : }
1229 : :
1230 : : std::string
1231 : 18 : ErrorType::as_string () const
1232 : : {
1233 : 18 : return "<tyty::error>";
1234 : : }
1235 : :
1236 : : bool
1237 : 1 : ErrorType::can_eq (const BaseType *other, bool emit_errors) const
1238 : : {
1239 : 1 : return get_kind () == other->get_kind ();
1240 : : }
1241 : :
1242 : : BaseType *
1243 : 43 : ErrorType::clone () const
1244 : : {
1245 : 43 : return new ErrorType (get_ref (), get_ty_ref (), get_combined_refs ());
1246 : : }
1247 : :
1248 : : // Struct Field type
1249 : :
1250 : 60480 : StructFieldType::StructFieldType (HirId ref, std::string name, BaseType *ty,
1251 : 60480 : location_t locus)
1252 : 60480 : : ref (ref), name (name), ty (ty), locus (locus)
1253 : 60480 : {}
1254 : :
1255 : : HirId
1256 : 60254 : StructFieldType::get_ref () const
1257 : : {
1258 : 60254 : return ref;
1259 : : }
1260 : :
1261 : : std::string
1262 : 170352 : StructFieldType::get_name () const
1263 : : {
1264 : 170352 : return name;
1265 : : }
1266 : :
1267 : : BaseType *
1268 : 178135 : StructFieldType::get_field_type () const
1269 : : {
1270 : 178135 : return ty;
1271 : : }
1272 : :
1273 : : void
1274 : 2057 : StructFieldType::set_field_type (BaseType *fty)
1275 : : {
1276 : 2057 : ty = fty;
1277 : 2057 : }
1278 : :
1279 : : void
1280 : 0 : StructFieldType::debug () const
1281 : : {
1282 : 0 : rust_debug ("%s", as_string ().c_str ());
1283 : 0 : }
1284 : :
1285 : : location_t
1286 : 1531 : StructFieldType::get_locus () const
1287 : : {
1288 : 1531 : return locus;
1289 : : }
1290 : :
1291 : : std::string
1292 : 15227 : StructFieldType::as_string () const
1293 : : {
1294 : 15227 : return name + ":" + get_field_type ()->debug_str ();
1295 : : }
1296 : :
1297 : : bool
1298 : 12539 : StructFieldType::is_equal (const StructFieldType &other) const
1299 : : {
1300 : 12539 : bool names_eq = get_name () == other.get_name ();
1301 : :
1302 : 12539 : TyTy::BaseType *o = other.get_field_type ();
1303 : 12539 : if (auto op = o->try_as<ParamType> ())
1304 : 1002 : o = op->resolve ();
1305 : :
1306 : 12539 : bool types_eq = get_field_type ()->is_equal (*o);
1307 : :
1308 : 12539 : return names_eq && types_eq;
1309 : : }
1310 : :
1311 : : StructFieldType *
1312 : 57300 : StructFieldType::clone () const
1313 : : {
1314 : 57300 : return new StructFieldType (get_ref (), get_name (),
1315 : 114600 : get_field_type ()->clone (), locus);
1316 : : }
1317 : :
1318 : : StructFieldType *
1319 : 100 : StructFieldType::monomorphized_clone () const
1320 : : {
1321 : 100 : return new StructFieldType (get_ref (), get_name (),
1322 : 200 : get_field_type ()->monomorphized_clone (), locus);
1323 : : }
1324 : :
1325 : : // VariantDef
1326 : :
1327 : : std::string
1328 : 2 : VariantDef::variant_type_string (VariantType type)
1329 : : {
1330 : 2 : switch (type)
1331 : : {
1332 : 0 : case NUM:
1333 : 0 : return "enumeral";
1334 : 1 : case TUPLE:
1335 : 1 : return "tuple";
1336 : 1 : case STRUCT:
1337 : 1 : return "struct";
1338 : : }
1339 : 0 : rust_unreachable ();
1340 : : return "";
1341 : : }
1342 : :
1343 : 2483 : VariantDef::VariantDef (HirId id, DefId defid, std::string identifier,
1344 : 2483 : RustIdent ident, HIR::Expr *discriminant)
1345 : 2483 : : id (id), defid (defid), identifier (identifier), ident (ident),
1346 : 2483 : discriminant (discriminant)
1347 : :
1348 : : {
1349 : 2483 : type = VariantType::NUM;
1350 : 2483 : fields = {};
1351 : 2483 : }
1352 : :
1353 : 47621 : VariantDef::VariantDef (HirId id, DefId defid, std::string identifier,
1354 : : RustIdent ident, VariantType type,
1355 : : HIR::Expr *discriminant,
1356 : 47621 : std::vector<StructFieldType *> fields)
1357 : 47621 : : id (id), defid (defid), identifier (identifier), ident (ident), type (type),
1358 : 47621 : discriminant (discriminant), fields (fields)
1359 : : {
1360 : 47621 : rust_assert ((type == VariantType::NUM && fields.empty ())
1361 : : || (type == VariantType::TUPLE || type == VariantType::STRUCT));
1362 : 47621 : }
1363 : :
1364 : 0 : VariantDef::VariantDef (const VariantDef &other)
1365 : 0 : : id (other.id), defid (other.defid), identifier (other.identifier),
1366 : 0 : ident (other.ident), type (other.type), discriminant (other.discriminant),
1367 : 0 : fields (other.fields)
1368 : 0 : {}
1369 : :
1370 : : VariantDef &
1371 : 929 : VariantDef::operator= (const VariantDef &other)
1372 : : {
1373 : 929 : id = other.id;
1374 : 929 : identifier = other.identifier;
1375 : 929 : type = other.type;
1376 : 929 : discriminant = other.discriminant;
1377 : 929 : fields = other.fields;
1378 : 929 : ident = other.ident;
1379 : :
1380 : 929 : return *this;
1381 : : }
1382 : :
1383 : : VariantDef &
1384 : 7569 : VariantDef::get_error_node ()
1385 : : {
1386 : 7569 : static VariantDef node
1387 : : = VariantDef (UNKNOWN_HIRID, UNKNOWN_DEFID, "",
1388 : 2295 : {Resolver::CanonicalPath::create_empty (), UNKNOWN_LOCATION},
1389 : 9864 : nullptr);
1390 : :
1391 : 7569 : return node;
1392 : : }
1393 : :
1394 : : bool
1395 : 929 : VariantDef::is_error () const
1396 : : {
1397 : 929 : return get_id () == UNKNOWN_HIRID;
1398 : : }
1399 : :
1400 : : HirId
1401 : 5104 : VariantDef::get_id () const
1402 : : {
1403 : 5104 : return id;
1404 : : }
1405 : :
1406 : : DefId
1407 : 0 : VariantDef::get_defid () const
1408 : : {
1409 : 0 : return defid;
1410 : : }
1411 : :
1412 : : VariantDef::VariantType
1413 : 11313 : VariantDef::get_variant_type () const
1414 : : {
1415 : 11313 : return type;
1416 : : }
1417 : :
1418 : : bool
1419 : 0 : VariantDef::is_data_variant () const
1420 : : {
1421 : 0 : return type != VariantType::NUM;
1422 : : }
1423 : :
1424 : : bool
1425 : 4522 : VariantDef::is_dataless_variant () const
1426 : : {
1427 : 4522 : return type == VariantType::NUM;
1428 : : }
1429 : :
1430 : : std::string
1431 : 2142 : VariantDef::get_identifier () const
1432 : : {
1433 : 2142 : return identifier;
1434 : : }
1435 : :
1436 : : size_t
1437 : 102512 : VariantDef::num_fields () const
1438 : : {
1439 : 102512 : return fields.size ();
1440 : : }
1441 : :
1442 : : StructFieldType *
1443 : 56270 : VariantDef::get_field_at_index (size_t index)
1444 : : {
1445 : 56270 : rust_assert (index < fields.size ());
1446 : 56270 : return fields.at (index);
1447 : : }
1448 : :
1449 : : std::vector<StructFieldType *> &
1450 : 12994 : VariantDef::get_fields ()
1451 : : {
1452 : 12994 : rust_assert (type != NUM);
1453 : 12994 : return fields;
1454 : : }
1455 : :
1456 : : bool
1457 : 8340 : VariantDef::lookup_field (const std::string &lookup,
1458 : : StructFieldType **field_lookup, size_t *index) const
1459 : : {
1460 : 8340 : size_t i = 0;
1461 : 67601 : for (auto &field : fields)
1462 : : {
1463 : 67599 : if (field->get_name ().compare (lookup) == 0)
1464 : : {
1465 : 8338 : if (index != nullptr)
1466 : 6869 : *index = i;
1467 : :
1468 : 8338 : if (field_lookup != nullptr)
1469 : 5855 : *field_lookup = field;
1470 : :
1471 : 8338 : return true;
1472 : : }
1473 : 59261 : i++;
1474 : : }
1475 : : return false;
1476 : : }
1477 : :
1478 : : HIR::Expr *
1479 : 553 : VariantDef::get_discriminant () const
1480 : : {
1481 : 553 : rust_assert (discriminant != nullptr);
1482 : 553 : return discriminant;
1483 : : }
1484 : :
1485 : : std::string
1486 : 10618 : VariantDef::as_string () const
1487 : : {
1488 : 10618 : if (type == VariantType::NUM)
1489 : 1090 : return identifier + " = " + discriminant->as_string ();
1490 : :
1491 : 9528 : std::string buffer;
1492 : 24755 : for (size_t i = 0; i < fields.size (); ++i)
1493 : : {
1494 : 15227 : buffer += fields.at (i)->as_string ();
1495 : 15227 : if ((i + 1) < fields.size ())
1496 : 6537 : buffer += ", ";
1497 : : }
1498 : :
1499 : 9528 : if (type == VariantType::TUPLE)
1500 : 11332 : return identifier + " (" + buffer + ")";
1501 : : else
1502 : 7724 : return identifier + " {" + buffer + "}";
1503 : 9528 : }
1504 : :
1505 : : bool
1506 : 8288 : VariantDef::is_equal (const VariantDef &other) const
1507 : : {
1508 : 8288 : if (type != other.type)
1509 : : return false;
1510 : :
1511 : 8288 : if (identifier.compare (other.identifier) != 0)
1512 : : return false;
1513 : :
1514 : 8253 : if (discriminant != other.discriminant)
1515 : : return false;
1516 : :
1517 : 8253 : if (fields.size () != other.fields.size ())
1518 : : return false;
1519 : :
1520 : 20479 : for (size_t i = 0; i < fields.size (); i++)
1521 : : {
1522 : 12539 : if (!fields.at (i)->is_equal (*other.fields.at (i)))
1523 : : return false;
1524 : : }
1525 : :
1526 : : return true;
1527 : : }
1528 : :
1529 : : VariantDef *
1530 : 45550 : VariantDef::clone () const
1531 : : {
1532 : 45550 : std::vector<StructFieldType *> cloned_fields;
1533 : 102850 : for (auto &f : fields)
1534 : 57300 : cloned_fields.push_back ((StructFieldType *) f->clone ());
1535 : :
1536 : 45550 : return new VariantDef (id, defid, identifier, ident, type, discriminant,
1537 : 91100 : cloned_fields);
1538 : 45550 : }
1539 : :
1540 : : VariantDef *
1541 : 101 : VariantDef::monomorphized_clone () const
1542 : : {
1543 : 101 : std::vector<StructFieldType *> cloned_fields;
1544 : 201 : for (auto &f : fields)
1545 : 100 : cloned_fields.push_back ((StructFieldType *) f->monomorphized_clone ());
1546 : :
1547 : 101 : return new VariantDef (id, defid, identifier, ident, type, discriminant,
1548 : 202 : cloned_fields);
1549 : 101 : }
1550 : :
1551 : : const RustIdent &
1552 : 4256 : VariantDef::get_ident () const
1553 : : {
1554 : 4256 : return ident;
1555 : : }
1556 : :
1557 : : // ADTType
1558 : :
1559 : : void
1560 : 4468 : ADTType::accept_vis (TyVisitor &vis)
1561 : : {
1562 : 4468 : vis.visit (*this);
1563 : 4468 : }
1564 : :
1565 : : void
1566 : 34876 : ADTType::accept_vis (TyConstVisitor &vis) const
1567 : : {
1568 : 34876 : vis.visit (*this);
1569 : 34876 : }
1570 : :
1571 : : std::string
1572 : 9478 : ADTType::as_string () const
1573 : : {
1574 : 9478 : std::string variants_buffer;
1575 : 20096 : for (size_t i = 0; i < number_of_variants (); ++i)
1576 : : {
1577 : 10618 : TyTy::VariantDef *variant = variants.at (i);
1578 : 10618 : variants_buffer += variant->as_string ();
1579 : 10618 : if ((i + 1) < number_of_variants ())
1580 : 1140 : variants_buffer += ", ";
1581 : : }
1582 : :
1583 : 28434 : return identifier + subst_as_string () + "{" + variants_buffer + "}";
1584 : 9478 : }
1585 : :
1586 : : bool
1587 : 23164 : ADTType::can_eq (const BaseType *other, bool emit_errors) const
1588 : : {
1589 : 23164 : ADTCmp r (this, emit_errors);
1590 : 23164 : return r.can_eq (other);
1591 : : }
1592 : :
1593 : : bool
1594 : 9456 : ADTType::is_equal (const BaseType &other) const
1595 : : {
1596 : 9456 : if (get_kind () != other.get_kind ())
1597 : : return false;
1598 : :
1599 : 8404 : auto other2 = other.as<const ADTType> ();
1600 : 8404 : if (get_adt_kind () != other2->get_adt_kind ())
1601 : : return false;
1602 : :
1603 : 8404 : if (number_of_variants () != other2->number_of_variants ())
1604 : : return false;
1605 : :
1606 : 8404 : if (has_substitutions_defined () != other2->has_substitutions_defined ())
1607 : : return false;
1608 : :
1609 : 8306 : if (has_substitutions_defined ())
1610 : : {
1611 : 3057 : if (get_num_substitutions () != other2->get_num_substitutions ())
1612 : : return false;
1613 : :
1614 : 5007 : for (size_t i = 0; i < get_num_substitutions (); i++)
1615 : : {
1616 : 3173 : const SubstitutionParamMapping &a = substitutions.at (i);
1617 : 3173 : const SubstitutionParamMapping &b = other2->substitutions.at (i);
1618 : :
1619 : 3173 : const ParamType *aa = a.get_param_ty ();
1620 : 3173 : const ParamType *bb = b.get_param_ty ();
1621 : 3173 : BaseType *aaa = aa->resolve ();
1622 : 3173 : BaseType *bbb = bb->resolve ();
1623 : 3173 : if (!aaa->is_equal (*bbb))
1624 : : return false;
1625 : : }
1626 : : }
1627 : :
1628 : 15023 : for (size_t i = 0; i < number_of_variants (); i++)
1629 : : {
1630 : 8288 : const TyTy::VariantDef *a = get_variants ().at (i);
1631 : 8288 : const TyTy::VariantDef *b = other2->get_variants ().at (i);
1632 : :
1633 : 8288 : if (!a->is_equal (*b))
1634 : : return false;
1635 : : }
1636 : :
1637 : : return true;
1638 : : }
1639 : :
1640 : : BaseType *
1641 : 41545 : ADTType::clone () const
1642 : : {
1643 : 41545 : std::vector<VariantDef *> cloned_variants;
1644 : 87095 : for (auto &variant : variants)
1645 : 45550 : cloned_variants.push_back (variant->clone ());
1646 : :
1647 : 41545 : return new ADTType (get_ref (), get_ty_ref (), identifier, ident,
1648 : 41545 : get_adt_kind (), cloned_variants, clone_substs (),
1649 : 41545 : get_repr_options (), used_arguments,
1650 : 83090 : get_region_constraints (), get_combined_refs ());
1651 : 41545 : }
1652 : :
1653 : : static bool
1654 : 5187 : handle_substitions (SubstitutionArgumentMappings &subst_mappings,
1655 : : StructFieldType *field)
1656 : : {
1657 : 5187 : auto fty = field->get_field_type ();
1658 : 5187 : if (auto p = fty->try_as<ParamType> ())
1659 : : {
1660 : 3290 : SubstitutionArg arg = SubstitutionArg::error ();
1661 : 3290 : bool ok = subst_mappings.get_argument_for_symbol (p, &arg);
1662 : 3290 : if (ok)
1663 : : {
1664 : 3255 : auto argt = arg.get_tyty ();
1665 : 3255 : bool arg_is_param = argt->get_kind () == TyTy::TypeKind::PARAM;
1666 : 3255 : bool arg_is_concrete = argt->get_kind () != TyTy::TypeKind::INFER;
1667 : :
1668 : 3255 : if (arg_is_param || arg_is_concrete)
1669 : : {
1670 : 1338 : auto new_field = argt->clone ();
1671 : 1338 : new_field->set_ref (fty->get_ref ());
1672 : 1338 : field->set_field_type (new_field);
1673 : : }
1674 : : else
1675 : : {
1676 : 1917 : field->get_field_type ()->set_ty_ref (argt->get_ref ());
1677 : : }
1678 : : }
1679 : : }
1680 : 1897 : else if (fty->has_substitutions_defined () || !fty->is_concrete ())
1681 : : {
1682 : 719 : BaseType *concrete
1683 : 719 : = Resolver::SubstMapperInternal::Resolve (fty, subst_mappings);
1684 : :
1685 : 719 : if (concrete->get_kind () == TyTy::TypeKind::ERROR)
1686 : : {
1687 : 0 : rust_error_at (subst_mappings.get_locus (),
1688 : : "Failed to resolve field substitution type: %s",
1689 : 0 : fty->as_string ().c_str ());
1690 : 0 : return false;
1691 : : }
1692 : :
1693 : 719 : auto new_field = concrete->clone ();
1694 : 719 : new_field->set_ref (fty->get_ref ());
1695 : 719 : field->set_field_type (new_field);
1696 : : }
1697 : :
1698 : : return true;
1699 : : }
1700 : :
1701 : : ADTType *
1702 : 3534 : ADTType::handle_substitions (SubstitutionArgumentMappings &subst_mappings)
1703 : : {
1704 : 3534 : auto adt = clone ()->as<ADTType> ();
1705 : 3534 : adt->set_ty_ref (mappings->get_next_hir_id ());
1706 : 3534 : adt->used_arguments = subst_mappings;
1707 : :
1708 : 7436 : for (auto &sub : adt->get_substs ())
1709 : : {
1710 : 3902 : SubstitutionArg arg = SubstitutionArg::error ();
1711 : 3902 : bool ok
1712 : 3902 : = subst_mappings.get_argument_for_symbol (sub.get_param_ty (), &arg);
1713 : 3902 : if (ok)
1714 : 3867 : sub.fill_param_ty (subst_mappings, subst_mappings.get_locus ());
1715 : : }
1716 : :
1717 : 8056 : for (auto &variant : adt->get_variants ())
1718 : : {
1719 : 4522 : if (variant->is_dataless_variant ())
1720 : 895 : continue;
1721 : :
1722 : 8814 : for (auto &field : variant->get_fields ())
1723 : : {
1724 : 5187 : bool ok = ::Rust::TyTy::handle_substitions (subst_mappings, field);
1725 : 5187 : if (!ok)
1726 : 3534 : return adt;
1727 : : }
1728 : : }
1729 : :
1730 : : return adt;
1731 : : }
1732 : :
1733 : : // TupleType
1734 : :
1735 : 24841 : TupleType::TupleType (HirId ref, location_t locus, std::vector<TyVar> fields,
1736 : 24841 : std::set<HirId> refs)
1737 : 24841 : : BaseType (ref, ref, KIND, {Resolver::CanonicalPath::create_empty (), locus},
1738 : : refs),
1739 : 49682 : fields (fields)
1740 : 24841 : {}
1741 : :
1742 : 15965 : TupleType::TupleType (HirId ref, HirId ty_ref, location_t locus,
1743 : 15965 : std::vector<TyVar> fields, std::set<HirId> refs)
1744 : : : BaseType (ref, ty_ref, KIND,
1745 : 15965 : {Resolver::CanonicalPath::create_empty (), locus}, refs),
1746 : 31930 : fields (fields)
1747 : 15965 : {}
1748 : :
1749 : : TupleType *
1750 : 24141 : TupleType::get_unit_type (HirId ref)
1751 : : {
1752 : 24141 : return new TupleType (ref, BUILTINS_LOCATION);
1753 : : }
1754 : :
1755 : : size_t
1756 : 73379 : TupleType::num_fields () const
1757 : : {
1758 : 73379 : return fields.size ();
1759 : : }
1760 : :
1761 : : const std::vector<TyVar> &
1762 : 81553 : TupleType::get_fields () const
1763 : : {
1764 : 81553 : return fields;
1765 : : }
1766 : :
1767 : : void
1768 : 168 : TupleType::accept_vis (TyVisitor &vis)
1769 : : {
1770 : 168 : vis.visit (*this);
1771 : 168 : }
1772 : :
1773 : : void
1774 : 12600 : TupleType::accept_vis (TyConstVisitor &vis) const
1775 : : {
1776 : 12600 : vis.visit (*this);
1777 : 12600 : }
1778 : :
1779 : : std::string
1780 : 11356 : TupleType::as_string () const
1781 : : {
1782 : 11356 : size_t i = 0;
1783 : 11356 : std::string fields_buffer;
1784 : 17094 : for (const TyVar &field : get_fields ())
1785 : : {
1786 : 5738 : fields_buffer += field.get_tyty ()->as_string ();
1787 : 5738 : bool has_next = (i + 1) < get_fields ().size ();
1788 : 5738 : fields_buffer += has_next ? ", " : "";
1789 : 5738 : i++;
1790 : : }
1791 : 22712 : return "(" + fields_buffer + ")";
1792 : 11356 : }
1793 : :
1794 : : std::string
1795 : 55789 : TupleType::get_name () const
1796 : : {
1797 : 55789 : size_t i = 0;
1798 : 55789 : std::string fields_buffer;
1799 : 63992 : for (const TyVar &field : get_fields ())
1800 : : {
1801 : 8203 : fields_buffer += field.get_tyty ()->as_string ();
1802 : 8203 : bool has_next = (i + 1) < get_fields ().size ();
1803 : 8203 : fields_buffer += has_next ? ", " : "";
1804 : 8203 : i++;
1805 : : }
1806 : 111578 : return "(" + fields_buffer + ")";
1807 : 55789 : }
1808 : :
1809 : : BaseType *
1810 : 8090 : TupleType::get_field (size_t index) const
1811 : : {
1812 : 8090 : return fields.at (index).get_tyty ();
1813 : : }
1814 : :
1815 : : bool
1816 : 150 : TupleType::can_eq (const BaseType *other, bool emit_errors) const
1817 : : {
1818 : 150 : TupleCmp r (this, emit_errors);
1819 : 150 : return r.can_eq (other);
1820 : : }
1821 : :
1822 : : bool
1823 : 7806 : TupleType::is_equal (const BaseType &other) const
1824 : : {
1825 : 7806 : if (get_kind () != other.get_kind ())
1826 : : return false;
1827 : :
1828 : 7782 : auto other2 = other.as<const TupleType> ();
1829 : 7782 : if (num_fields () != other2->num_fields ())
1830 : : return false;
1831 : :
1832 : 8827 : for (size_t i = 0; i < num_fields (); i++)
1833 : : {
1834 : 1256 : if (!get_field (i)->is_equal (*other2->get_field (i)))
1835 : : return false;
1836 : : }
1837 : : return true;
1838 : : }
1839 : :
1840 : : BaseType *
1841 : 8635 : TupleType::clone () const
1842 : : {
1843 : 8635 : std::vector<TyVar> cloned_fields;
1844 : 13616 : for (const auto &f : fields)
1845 : 4981 : cloned_fields.push_back (f.clone ());
1846 : :
1847 : 8635 : return new TupleType (get_ref (), get_ty_ref (), get_ident ().locus,
1848 : 17270 : cloned_fields, get_combined_refs ());
1849 : 8635 : }
1850 : :
1851 : : TupleType *
1852 : 168 : TupleType::handle_substitions (SubstitutionArgumentMappings &mappings)
1853 : : {
1854 : 168 : auto mappings_table = Analysis::Mappings::get ();
1855 : :
1856 : 168 : auto tuple = clone ()->as<TupleType> ();
1857 : 168 : tuple->set_ref (mappings_table->get_next_hir_id ());
1858 : 168 : tuple->set_ty_ref (mappings_table->get_next_hir_id ());
1859 : :
1860 : 488 : for (size_t i = 0; i < tuple->fields.size (); i++)
1861 : : {
1862 : 320 : TyVar &field = fields.at (i);
1863 : 320 : if (!field.get_tyty ()->is_concrete ())
1864 : : {
1865 : 215 : BaseType *concrete
1866 : 215 : = Resolver::SubstMapperInternal::Resolve (field.get_tyty (),
1867 : : mappings);
1868 : 215 : tuple->fields[i]
1869 : 215 : = TyVar::subst_covariant_var (field.get_tyty (), concrete);
1870 : : }
1871 : : }
1872 : :
1873 : 168 : return tuple;
1874 : : }
1875 : :
1876 : : void
1877 : 10852 : FnType::accept_vis (TyVisitor &vis)
1878 : : {
1879 : 10852 : vis.visit (*this);
1880 : 10852 : }
1881 : :
1882 : : void
1883 : 10547 : FnType::accept_vis (TyConstVisitor &vis) const
1884 : : {
1885 : 10547 : vis.visit (*this);
1886 : 10547 : }
1887 : :
1888 : : std::string
1889 : 35582 : FnType::as_string () const
1890 : : {
1891 : 35582 : std::string params_str = "";
1892 : 73331 : for (auto ¶m : params)
1893 : : {
1894 : 37749 : auto pattern = param.first;
1895 : 37749 : auto ty = param.second;
1896 : 75498 : params_str += pattern->as_string () + " " + ty->as_string ();
1897 : 37749 : params_str += ",";
1898 : : }
1899 : :
1900 : 35582 : std::string ret_str = type->as_string ();
1901 : 106746 : return "fn" + subst_as_string () + " (" + params_str + ") -> " + ret_str;
1902 : 35582 : }
1903 : :
1904 : : bool
1905 : 0 : FnType::can_eq (const BaseType *other, bool emit_errors) const
1906 : : {
1907 : 0 : FnCmp r (this, emit_errors);
1908 : 0 : return r.can_eq (other);
1909 : : }
1910 : :
1911 : : bool
1912 : 3090 : FnType::is_equal (const BaseType &other) const
1913 : : {
1914 : 3090 : if (get_kind () != other.get_kind ())
1915 : : return false;
1916 : :
1917 : 3090 : auto other2 = static_cast<const FnType &> (other);
1918 : 3090 : if (get_identifier ().compare (other2.get_identifier ()) != 0)
1919 : : return false;
1920 : :
1921 : 3090 : if (!get_return_type ()->is_equal (*other2.get_return_type ()))
1922 : : return false;
1923 : :
1924 : 2095 : if (has_substitutions_defined () != other2.has_substitutions_defined ())
1925 : : return false;
1926 : :
1927 : 1130 : if (has_substitutions_defined ())
1928 : : {
1929 : 287 : if (get_num_substitutions () != other2.get_num_substitutions ())
1930 : : return false;
1931 : :
1932 : : const FnType &ofn = static_cast<const FnType &> (other);
1933 : 477 : for (size_t i = 0; i < get_num_substitutions (); i++)
1934 : : {
1935 : 329 : const SubstitutionParamMapping &a = get_substs ().at (i);
1936 : 329 : const SubstitutionParamMapping &b = ofn.get_substs ().at (i);
1937 : :
1938 : 329 : const ParamType *pa = a.get_param_ty ();
1939 : 329 : const ParamType *pb = b.get_param_ty ();
1940 : :
1941 : 329 : if (!pa->is_equal (*pb))
1942 : : return false;
1943 : : }
1944 : : }
1945 : :
1946 : 991 : if (num_params () != other2.num_params ())
1947 : : return false;
1948 : :
1949 : 2298 : for (size_t i = 0; i < num_params (); i++)
1950 : : {
1951 : 1307 : auto lhs = param_at (i).second;
1952 : 1307 : auto rhs = other2.param_at (i).second;
1953 : 1307 : if (!lhs->is_equal (*rhs))
1954 : : return false;
1955 : : }
1956 : : return true;
1957 : 3090 : }
1958 : :
1959 : : BaseType *
1960 : 7597 : FnType::clone () const
1961 : : {
1962 : 7597 : std::vector<std::pair<HIR::Pattern *, BaseType *>> cloned_params;
1963 : 17736 : for (auto &p : params)
1964 : 10139 : cloned_params.push_back ({p.first, p.second->clone ()});
1965 : :
1966 : 15194 : return new FnType (get_ref (), get_ty_ref (), get_id (), get_identifier (),
1967 : 7597 : ident, flags, abi, std::move (cloned_params),
1968 : 7597 : get_return_type ()->clone (), clone_substs (),
1969 : : get_substitution_arguments (), get_region_constraints (),
1970 : 30388 : get_combined_refs ());
1971 : 7597 : }
1972 : :
1973 : : FnType *
1974 : 5257 : FnType::handle_substitions (SubstitutionArgumentMappings &subst_mappings)
1975 : : {
1976 : 5257 : FnType *fn = static_cast<FnType *> (clone ());
1977 : 5257 : fn->set_ty_ref (mappings->get_next_hir_id ());
1978 : 5257 : fn->used_arguments = subst_mappings;
1979 : :
1980 : 11731 : for (auto &sub : fn->get_substs ())
1981 : : {
1982 : 6474 : SubstitutionArg arg = SubstitutionArg::error ();
1983 : :
1984 : 6474 : bool ok
1985 : 6474 : = subst_mappings.get_argument_for_symbol (sub.get_param_ty (), &arg);
1986 : 6474 : if (ok)
1987 : : {
1988 : 6425 : sub.fill_param_ty (subst_mappings, subst_mappings.get_locus ());
1989 : : }
1990 : : }
1991 : :
1992 : 5257 : auto fty = fn->get_return_type ();
1993 : 5257 : bool is_param_ty = fty->get_kind () == TypeKind::PARAM;
1994 : 5257 : if (is_param_ty)
1995 : : {
1996 : 1664 : ParamType *p = static_cast<ParamType *> (fty);
1997 : :
1998 : 1664 : SubstitutionArg arg = SubstitutionArg::error ();
1999 : 1664 : bool ok = subst_mappings.get_argument_for_symbol (p, &arg);
2000 : 1664 : if (ok)
2001 : : {
2002 : 1657 : auto argt = arg.get_tyty ();
2003 : 1657 : bool arg_is_param = argt->get_kind () == TyTy::TypeKind::PARAM;
2004 : 1657 : bool arg_is_concrete = argt->get_kind () != TyTy::TypeKind::INFER;
2005 : :
2006 : 1657 : if (arg_is_param || arg_is_concrete)
2007 : : {
2008 : 906 : auto new_field = argt->clone ();
2009 : 906 : new_field->set_ref (fty->get_ref ());
2010 : 906 : fn->type = new_field;
2011 : : }
2012 : : else
2013 : : {
2014 : 751 : fty->set_ty_ref (argt->get_ref ());
2015 : : }
2016 : : }
2017 : : }
2018 : 3593 : else if (fty->needs_generic_substitutions () || !fty->is_concrete ())
2019 : : {
2020 : 1369 : BaseType *concrete
2021 : 1369 : = Resolver::SubstMapperInternal::Resolve (fty, subst_mappings);
2022 : :
2023 : 1369 : if (concrete == nullptr || concrete->get_kind () == TyTy::TypeKind::ERROR)
2024 : : {
2025 : 0 : rust_error_at (subst_mappings.get_locus (),
2026 : : "Failed to resolve field substitution type: %s",
2027 : 0 : fty->as_string ().c_str ());
2028 : 0 : return nullptr;
2029 : : }
2030 : :
2031 : 1369 : auto new_field = concrete->clone ();
2032 : 1369 : new_field->set_ref (fty->get_ref ());
2033 : 1369 : fn->type = new_field;
2034 : : }
2035 : :
2036 : 12328 : for (auto ¶m : fn->get_params ())
2037 : : {
2038 : 7071 : auto fty = param.second;
2039 : :
2040 : 7071 : bool is_param_ty = fty->get_kind () == TypeKind::PARAM;
2041 : 7071 : if (is_param_ty)
2042 : : {
2043 : 2940 : ParamType *p = static_cast<ParamType *> (fty);
2044 : :
2045 : 2940 : SubstitutionArg arg = SubstitutionArg::error ();
2046 : 2940 : bool ok = subst_mappings.get_argument_for_symbol (p, &arg);
2047 : 2940 : if (ok)
2048 : : {
2049 : 2898 : auto argt = arg.get_tyty ();
2050 : 2898 : bool arg_is_param = argt->get_kind () == TyTy::TypeKind::PARAM;
2051 : 2898 : bool arg_is_concrete = argt->get_kind () != TyTy::TypeKind::INFER;
2052 : :
2053 : 2898 : if (arg_is_param || arg_is_concrete)
2054 : : {
2055 : 1289 : auto new_field = argt->clone ();
2056 : 1289 : new_field->set_ref (fty->get_ref ());
2057 : 1289 : param.second = new_field;
2058 : : }
2059 : : else
2060 : : {
2061 : 1609 : fty->set_ty_ref (argt->get_ref ());
2062 : : }
2063 : : }
2064 : : }
2065 : 4131 : else if (fty->has_substitutions_defined () || !fty->is_concrete ())
2066 : : {
2067 : 3496 : BaseType *concrete
2068 : 3496 : = Resolver::SubstMapperInternal::Resolve (fty, subst_mappings);
2069 : :
2070 : 3496 : if (concrete == nullptr
2071 : 3496 : || concrete->get_kind () == TyTy::TypeKind::ERROR)
2072 : : {
2073 : 0 : rust_error_at (subst_mappings.get_locus (),
2074 : : "Failed to resolve field substitution type: %s",
2075 : 0 : fty->as_string ().c_str ());
2076 : 0 : return nullptr;
2077 : : }
2078 : :
2079 : 3496 : auto new_field = concrete->clone ();
2080 : 3496 : new_field->set_ref (fty->get_ref ());
2081 : 3496 : param.second = new_field;
2082 : : }
2083 : : }
2084 : :
2085 : : return fn;
2086 : : }
2087 : :
2088 : : void
2089 : 29 : FnPtr::accept_vis (TyVisitor &vis)
2090 : : {
2091 : 29 : vis.visit (*this);
2092 : 29 : }
2093 : :
2094 : : void
2095 : 45 : FnPtr::accept_vis (TyConstVisitor &vis) const
2096 : : {
2097 : 45 : vis.visit (*this);
2098 : 45 : }
2099 : :
2100 : : std::string
2101 : 347 : FnPtr::as_string () const
2102 : : {
2103 : 347 : std::string params_str;
2104 : :
2105 : 347 : auto ¶ms = get_params ();
2106 : 688 : for (auto &p : params)
2107 : : {
2108 : 682 : params_str += p.get_tyty ()->as_string () + " ,";
2109 : : }
2110 : :
2111 : 694 : return "fnptr (" + params_str + ") -> " + get_return_type ()->as_string ();
2112 : 347 : }
2113 : :
2114 : : bool
2115 : 0 : FnPtr::can_eq (const BaseType *other, bool emit_errors) const
2116 : : {
2117 : 0 : FnptrCmp r (this, emit_errors);
2118 : 0 : return r.can_eq (other);
2119 : : }
2120 : :
2121 : : bool
2122 : 56 : FnPtr::is_equal (const BaseType &other) const
2123 : : {
2124 : 56 : if (get_kind () != other.get_kind ())
2125 : : return false;
2126 : :
2127 : 28 : auto other2 = static_cast<const FnPtr &> (other);
2128 : 28 : auto this_ret_type = get_return_type ();
2129 : 28 : auto other_ret_type = other2.get_return_type ();
2130 : 28 : if (this_ret_type->is_equal (*other_ret_type))
2131 : : return false;
2132 : :
2133 : 0 : if (num_params () != other2.num_params ())
2134 : : return false;
2135 : :
2136 : 0 : for (size_t i = 0; i < num_params (); i++)
2137 : : {
2138 : 0 : if (!get_param_type_at (i)->is_equal (*other2.get_param_type_at (i)))
2139 : : return false;
2140 : : }
2141 : : return true;
2142 : 28 : }
2143 : :
2144 : : BaseType *
2145 : 58 : FnPtr::clone () const
2146 : : {
2147 : 58 : std::vector<TyVar> cloned_params;
2148 : 115 : for (auto &p : params)
2149 : 57 : cloned_params.push_back (TyVar (p.get_ref ()));
2150 : :
2151 : 58 : return new FnPtr (get_ref (), get_ty_ref (), ident.locus,
2152 : : std::move (cloned_params), result_type,
2153 : 58 : get_combined_refs ());
2154 : 58 : }
2155 : :
2156 : : void
2157 : 0 : ClosureType::accept_vis (TyVisitor &vis)
2158 : : {
2159 : 0 : vis.visit (*this);
2160 : 0 : }
2161 : :
2162 : : void
2163 : 241 : ClosureType::accept_vis (TyConstVisitor &vis) const
2164 : : {
2165 : 241 : vis.visit (*this);
2166 : 241 : }
2167 : :
2168 : : std::string
2169 : 1253 : ClosureType::as_string () const
2170 : : {
2171 : 1253 : std::string params_buf = parameters->as_string ();
2172 : 3759 : return "|" + params_buf + "| {" + result_type.get_tyty ()->as_string () + "}";
2173 : 1253 : }
2174 : :
2175 : : bool
2176 : 60 : ClosureType::can_eq (const BaseType *other, bool emit_errors) const
2177 : : {
2178 : 60 : ClosureCmp r (this, emit_errors);
2179 : 60 : return r.can_eq (other);
2180 : : }
2181 : :
2182 : : bool
2183 : 143 : ClosureType::is_equal (const BaseType &other) const
2184 : : {
2185 : 143 : if (other.get_kind () != TypeKind::CLOSURE)
2186 : : return false;
2187 : :
2188 : 143 : const ClosureType &other2 = static_cast<const ClosureType &> (other);
2189 : 143 : if (get_def_id () != other2.get_def_id ())
2190 : : return false;
2191 : :
2192 : 143 : if (!get_parameters ().is_equal (other2.get_parameters ()))
2193 : : return false;
2194 : :
2195 : 143 : return get_result_type ().is_equal (other2.get_result_type ());
2196 : : }
2197 : :
2198 : : BaseType *
2199 : 374 : ClosureType::clone () const
2200 : : {
2201 : 374 : return new ClosureType (get_ref (), get_ty_ref (), ident, id,
2202 : 374 : (TyTy::TupleType *) parameters->clone (), result_type,
2203 : 748 : clone_substs (), captures, get_combined_refs (),
2204 : 1496 : specified_bounds);
2205 : : }
2206 : :
2207 : : ClosureType *
2208 : 0 : ClosureType::handle_substitions (SubstitutionArgumentMappings &mappings)
2209 : : {
2210 : 0 : rust_unreachable ();
2211 : : return nullptr;
2212 : : }
2213 : :
2214 : : void
2215 : 89 : ClosureType::setup_fn_once_output () const
2216 : : {
2217 : : // lookup the lang items
2218 : 89 : auto fn_once_lang_item = Analysis::RustLangItem::ItemType::FN_ONCE;
2219 : 89 : auto fn_once_output_lang_item
2220 : : = Analysis::RustLangItem::ItemType::FN_ONCE_OUTPUT;
2221 : :
2222 : 89 : DefId trait_id = UNKNOWN_DEFID;
2223 : 89 : bool trait_lang_item_defined
2224 : 89 : = mappings->lookup_lang_item (fn_once_lang_item, &trait_id);
2225 : 89 : rust_assert (trait_lang_item_defined);
2226 : :
2227 : 89 : DefId trait_item_id = UNKNOWN_DEFID;
2228 : 89 : bool trait_item_lang_item_defined
2229 : 89 : = mappings->lookup_lang_item (fn_once_output_lang_item, &trait_item_id);
2230 : 89 : rust_assert (trait_item_lang_item_defined);
2231 : :
2232 : : // resolve to the trait
2233 : 89 : HIR::Item *item = mappings->lookup_defid (trait_id);
2234 : 89 : rust_assert (item->get_item_kind () == HIR::Item::ItemKind::Trait);
2235 : 89 : HIR::Trait *trait = static_cast<HIR::Trait *> (item);
2236 : :
2237 : 89 : Resolver::TraitReference *trait_ref
2238 : 89 : = Resolver::TraitResolver::Resolve (*trait);
2239 : 89 : rust_assert (!trait_ref->is_error ());
2240 : :
2241 : : // resolve to trait item
2242 : 89 : HIR::TraitItem *trait_item
2243 : 89 : = mappings->lookup_trait_item_defid (trait_item_id);
2244 : 89 : rust_assert (trait_item != nullptr);
2245 : 89 : rust_assert (trait_item->get_item_kind ()
2246 : : == HIR::TraitItem::TraitItemKind::TYPE);
2247 : 89 : std::string item_identifier = trait_item->trait_identifier ();
2248 : :
2249 : : // setup associated types #[lang = "fn_once_output"]
2250 : 89 : Resolver::TraitItemReference *item_reference = nullptr;
2251 : 89 : bool found = trait_ref->lookup_trait_item_by_type (
2252 : : item_identifier, Resolver::TraitItemReference::TraitItemType::TYPE,
2253 : : &item_reference);
2254 : 89 : rust_assert (found);
2255 : :
2256 : : // setup
2257 : 89 : item_reference->associated_type_set (&get_result_type ());
2258 : 89 : }
2259 : :
2260 : : void
2261 : 0 : ArrayType::accept_vis (TyVisitor &vis)
2262 : : {
2263 : 0 : vis.visit (*this);
2264 : 0 : }
2265 : :
2266 : : void
2267 : 6688 : ArrayType::accept_vis (TyConstVisitor &vis) const
2268 : : {
2269 : 6688 : vis.visit (*this);
2270 : 6688 : }
2271 : :
2272 : : std::string
2273 : 10309 : ArrayType::as_string () const
2274 : : {
2275 : 41236 : return "[" + get_element_type ()->as_string () + ":" + "CAPACITY" + "]";
2276 : : }
2277 : :
2278 : : bool
2279 : 4351 : ArrayType::can_eq (const BaseType *other, bool emit_errors) const
2280 : : {
2281 : 4351 : ArrayCmp r (this, emit_errors);
2282 : 4351 : return r.can_eq (other);
2283 : : }
2284 : :
2285 : : bool
2286 : 1422 : ArrayType::is_equal (const BaseType &other) const
2287 : : {
2288 : 1422 : if (get_kind () != other.get_kind ())
2289 : : return false;
2290 : :
2291 : 1371 : auto other2 = static_cast<const ArrayType &> (other);
2292 : :
2293 : 1371 : auto this_element_type = get_element_type ();
2294 : 1371 : auto other_element_type = other2.get_element_type ();
2295 : :
2296 : 1371 : return this_element_type->is_equal (*other_element_type);
2297 : 1371 : }
2298 : :
2299 : : BaseType *
2300 : 18621 : ArrayType::get_element_type () const
2301 : : {
2302 : 18621 : return element_type.get_tyty ();
2303 : : }
2304 : :
2305 : : const TyVar &
2306 : 1 : ArrayType::get_var_element_type () const
2307 : : {
2308 : 1 : return element_type;
2309 : : }
2310 : :
2311 : : BaseType *
2312 : 842 : ArrayType::clone () const
2313 : : {
2314 : 1684 : return new ArrayType (get_ref (), get_ty_ref (), ident.locus, capacity_expr,
2315 : 842 : element_type, get_combined_refs ());
2316 : : }
2317 : :
2318 : : ArrayType *
2319 : 0 : ArrayType::handle_substitions (SubstitutionArgumentMappings &mappings)
2320 : : {
2321 : 0 : auto mappings_table = Analysis::Mappings::get ();
2322 : :
2323 : 0 : ArrayType *ref = static_cast<ArrayType *> (clone ());
2324 : 0 : ref->set_ty_ref (mappings_table->get_next_hir_id ());
2325 : :
2326 : : // might be &T or &ADT so this needs to be recursive
2327 : 0 : auto base = ref->get_element_type ();
2328 : 0 : BaseType *concrete = Resolver::SubstMapperInternal::Resolve (base, mappings);
2329 : 0 : ref->element_type = TyVar::subst_covariant_var (base, concrete);
2330 : :
2331 : 0 : return ref;
2332 : : }
2333 : :
2334 : : void
2335 : 1070 : SliceType::accept_vis (TyVisitor &vis)
2336 : : {
2337 : 1070 : vis.visit (*this);
2338 : 1070 : }
2339 : :
2340 : : void
2341 : 3695 : SliceType::accept_vis (TyConstVisitor &vis) const
2342 : : {
2343 : 3695 : vis.visit (*this);
2344 : 3695 : }
2345 : :
2346 : : std::string
2347 : 23907 : SliceType::as_string () const
2348 : : {
2349 : 47814 : return "[" + get_element_type ()->as_string () + "]";
2350 : : }
2351 : :
2352 : : bool
2353 : 3069 : SliceType::can_eq (const BaseType *other, bool emit_errors) const
2354 : : {
2355 : 3069 : SliceCmp r (this, emit_errors);
2356 : 3069 : return r.can_eq (other);
2357 : : }
2358 : :
2359 : : bool
2360 : 3584 : SliceType::is_equal (const BaseType &other) const
2361 : : {
2362 : 3584 : if (get_kind () != other.get_kind ())
2363 : : return false;
2364 : :
2365 : 2874 : auto other2 = static_cast<const SliceType &> (other);
2366 : :
2367 : 2874 : auto this_element_type = get_element_type ();
2368 : 2874 : auto other_element_type = other2.get_element_type ();
2369 : :
2370 : 2874 : return this_element_type->is_equal (*other_element_type);
2371 : 2874 : }
2372 : :
2373 : : BaseType *
2374 : 42737 : SliceType::get_element_type () const
2375 : : {
2376 : 42737 : return element_type.get_tyty ();
2377 : : }
2378 : :
2379 : : const TyVar &
2380 : 112 : SliceType::get_var_element_type () const
2381 : : {
2382 : 112 : return element_type;
2383 : : }
2384 : :
2385 : : BaseType *
2386 : 37914 : SliceType::clone () const
2387 : : {
2388 : 75828 : return new SliceType (get_ref (), get_ty_ref (), ident.locus,
2389 : 37914 : element_type.clone (), get_combined_refs ());
2390 : : }
2391 : :
2392 : : SliceType *
2393 : 1070 : SliceType::handle_substitions (SubstitutionArgumentMappings &mappings)
2394 : : {
2395 : 1070 : auto mappings_table = Analysis::Mappings::get ();
2396 : :
2397 : 1070 : SliceType *ref = static_cast<SliceType *> (clone ());
2398 : 1070 : ref->set_ty_ref (mappings_table->get_next_hir_id ());
2399 : :
2400 : : // might be &T or &ADT so this needs to be recursive
2401 : 1070 : auto base = ref->get_element_type ();
2402 : 1070 : BaseType *concrete = Resolver::SubstMapperInternal::Resolve (base, mappings);
2403 : 1070 : ref->element_type = TyVar::subst_covariant_var (base, concrete);
2404 : :
2405 : 1070 : return ref;
2406 : : }
2407 : :
2408 : : // BoolType
2409 : :
2410 : 3600 : BoolType::BoolType (HirId ref, std::set<HirId> refs)
2411 : : : BaseType (ref, ref, KIND,
2412 : 3600 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
2413 : 7200 : refs)
2414 : 3600 : {}
2415 : :
2416 : 10536 : BoolType::BoolType (HirId ref, HirId ty_ref, std::set<HirId> refs)
2417 : : : BaseType (ref, ty_ref, KIND,
2418 : 10536 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
2419 : 21072 : refs)
2420 : 10536 : {}
2421 : :
2422 : : std::string
2423 : 23448 : BoolType::get_name () const
2424 : : {
2425 : 23448 : return as_string ();
2426 : : }
2427 : :
2428 : : void
2429 : 0 : BoolType::accept_vis (TyVisitor &vis)
2430 : : {
2431 : 0 : vis.visit (*this);
2432 : 0 : }
2433 : :
2434 : : void
2435 : 13139 : BoolType::accept_vis (TyConstVisitor &vis) const
2436 : : {
2437 : 13139 : vis.visit (*this);
2438 : 13139 : }
2439 : :
2440 : : std::string
2441 : 45486 : BoolType::as_string () const
2442 : : {
2443 : 45486 : return "bool";
2444 : : }
2445 : :
2446 : : bool
2447 : 6609 : BoolType::can_eq (const BaseType *other, bool emit_errors) const
2448 : : {
2449 : 6609 : BoolCmp r (this, emit_errors);
2450 : 6609 : return r.can_eq (other);
2451 : : }
2452 : :
2453 : : BaseType *
2454 : 10536 : BoolType::clone () const
2455 : : {
2456 : 10536 : return new BoolType (get_ref (), get_ty_ref (), get_combined_refs ());
2457 : : }
2458 : :
2459 : : // IntType
2460 : :
2461 : 18000 : IntType::IntType (HirId ref, IntKind kind, std::set<HirId> refs)
2462 : : : BaseType (ref, ref, KIND,
2463 : 18000 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
2464 : : refs),
2465 : 36000 : int_kind (kind)
2466 : 18000 : {}
2467 : :
2468 : 154767 : IntType::IntType (HirId ref, HirId ty_ref, IntKind kind, std::set<HirId> refs)
2469 : : : BaseType (ref, ty_ref, KIND,
2470 : 154767 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
2471 : : refs),
2472 : 309534 : int_kind (kind)
2473 : 154767 : {}
2474 : :
2475 : : std::string
2476 : 226416 : IntType::get_name () const
2477 : : {
2478 : 226416 : return as_string ();
2479 : : }
2480 : :
2481 : : IntType::IntKind
2482 : 340870 : IntType::get_int_kind () const
2483 : : {
2484 : 340870 : return int_kind;
2485 : : }
2486 : :
2487 : : void
2488 : 0 : IntType::accept_vis (TyVisitor &vis)
2489 : : {
2490 : 0 : vis.visit (*this);
2491 : 0 : }
2492 : :
2493 : : void
2494 : 91339 : IntType::accept_vis (TyConstVisitor &vis) const
2495 : : {
2496 : 91339 : vis.visit (*this);
2497 : 91339 : }
2498 : :
2499 : : std::string
2500 : 433864 : IntType::as_string () const
2501 : : {
2502 : 433864 : switch (int_kind)
2503 : : {
2504 : 99204 : case I8:
2505 : 99204 : return "i8";
2506 : 52985 : case I16:
2507 : 52985 : return "i16";
2508 : 241956 : case I32:
2509 : 241956 : return "i32";
2510 : 20433 : case I64:
2511 : 20433 : return "i64";
2512 : 19286 : case I128:
2513 : 19286 : return "i128";
2514 : : }
2515 : 0 : rust_unreachable ();
2516 : : return "__unknown_int_type";
2517 : : }
2518 : :
2519 : : bool
2520 : 40141 : IntType::can_eq (const BaseType *other, bool emit_errors) const
2521 : : {
2522 : 40141 : IntCmp r (this, emit_errors);
2523 : 40141 : return r.can_eq (other);
2524 : : }
2525 : :
2526 : : BaseType *
2527 : 138337 : IntType::clone () const
2528 : : {
2529 : 138337 : return new IntType (get_ref (), get_ty_ref (), get_int_kind (),
2530 : 138337 : get_combined_refs ());
2531 : : }
2532 : :
2533 : : bool
2534 : 35984 : IntType::is_equal (const BaseType &other) const
2535 : : {
2536 : 35984 : if (!BaseType::is_equal (other))
2537 : : return false;
2538 : :
2539 : 27568 : const IntType &o = static_cast<const IntType &> (other);
2540 : 27568 : return get_int_kind () == o.get_int_kind ();
2541 : : }
2542 : :
2543 : : // UintType
2544 : :
2545 : 18000 : UintType::UintType (HirId ref, UintKind kind, std::set<HirId> refs)
2546 : : : BaseType (ref, ref, KIND,
2547 : 18000 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
2548 : : refs),
2549 : 36000 : uint_kind (kind)
2550 : 18000 : {}
2551 : :
2552 : 36258 : UintType::UintType (HirId ref, HirId ty_ref, UintKind kind,
2553 : 36258 : std::set<HirId> refs)
2554 : : : BaseType (ref, ty_ref, KIND,
2555 : 36258 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
2556 : : refs),
2557 : 72516 : uint_kind (kind)
2558 : 36258 : {}
2559 : :
2560 : : std::string
2561 : 71219 : UintType::get_name () const
2562 : : {
2563 : 71219 : return as_string ();
2564 : : }
2565 : :
2566 : : UintType::UintKind
2567 : 209804 : UintType::get_uint_kind () const
2568 : : {
2569 : 209804 : return uint_kind;
2570 : : }
2571 : :
2572 : : void
2573 : 0 : UintType::accept_vis (TyVisitor &vis)
2574 : : {
2575 : 0 : vis.visit (*this);
2576 : 0 : }
2577 : :
2578 : : void
2579 : 161592 : UintType::accept_vis (TyConstVisitor &vis) const
2580 : : {
2581 : 161592 : vis.visit (*this);
2582 : 161592 : }
2583 : :
2584 : : std::string
2585 : 337314 : UintType::as_string () const
2586 : : {
2587 : 337314 : switch (uint_kind)
2588 : : {
2589 : 80747 : case U8:
2590 : 80747 : return "u8";
2591 : 63905 : case U16:
2592 : 63905 : return "u16";
2593 : 77091 : case U32:
2594 : 77091 : return "u32";
2595 : 65095 : case U64:
2596 : 65095 : return "u64";
2597 : 50476 : case U128:
2598 : 50476 : return "u128";
2599 : : }
2600 : 0 : rust_unreachable ();
2601 : : return "__unknown_uint_type";
2602 : : }
2603 : :
2604 : : bool
2605 : 127422 : UintType::can_eq (const BaseType *other, bool emit_errors) const
2606 : : {
2607 : 127422 : UintCmp r (this, emit_errors);
2608 : 127422 : return r.can_eq (other);
2609 : : }
2610 : :
2611 : : BaseType *
2612 : 28245 : UintType::clone () const
2613 : : {
2614 : 28245 : return new UintType (get_ref (), get_ty_ref (), get_uint_kind (),
2615 : 28245 : get_combined_refs ());
2616 : : }
2617 : :
2618 : : bool
2619 : 13798 : UintType::is_equal (const BaseType &other) const
2620 : : {
2621 : 13798 : if (!BaseType::is_equal (other))
2622 : : return false;
2623 : :
2624 : 12382 : const UintType &o = static_cast<const UintType &> (other);
2625 : 12382 : return get_uint_kind () == o.get_uint_kind ();
2626 : : }
2627 : :
2628 : : // FloatType
2629 : :
2630 : 7200 : FloatType::FloatType (HirId ref, FloatKind kind, std::set<HirId> refs)
2631 : : : BaseType (ref, ref, KIND,
2632 : 7200 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
2633 : : refs),
2634 : 14400 : float_kind (kind)
2635 : 7200 : {}
2636 : :
2637 : 23387 : FloatType::FloatType (HirId ref, HirId ty_ref, FloatKind kind,
2638 : 23387 : std::set<HirId> refs)
2639 : : : BaseType (ref, ty_ref, KIND,
2640 : 23387 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
2641 : : refs),
2642 : 46774 : float_kind (kind)
2643 : 23387 : {}
2644 : :
2645 : : std::string
2646 : 37566 : FloatType::get_name () const
2647 : : {
2648 : 37566 : return as_string ();
2649 : : }
2650 : :
2651 : : FloatType::FloatKind
2652 : 69186 : FloatType::get_float_kind () const
2653 : : {
2654 : 69186 : return float_kind;
2655 : : }
2656 : :
2657 : : void
2658 : 0 : FloatType::accept_vis (TyVisitor &vis)
2659 : : {
2660 : 0 : vis.visit (*this);
2661 : 0 : }
2662 : :
2663 : : void
2664 : 51421 : FloatType::accept_vis (TyConstVisitor &vis) const
2665 : : {
2666 : 51421 : vis.visit (*this);
2667 : 51421 : }
2668 : :
2669 : : std::string
2670 : 69902 : FloatType::as_string () const
2671 : : {
2672 : 69902 : switch (float_kind)
2673 : : {
2674 : 37456 : case F32:
2675 : 37456 : return "f32";
2676 : 32446 : case F64:
2677 : 32446 : return "f64";
2678 : : }
2679 : 0 : rust_unreachable ();
2680 : : return "__unknown_float_type";
2681 : : }
2682 : :
2683 : : bool
2684 : 38197 : FloatType::can_eq (const BaseType *other, bool emit_errors) const
2685 : : {
2686 : 38197 : FloatCmp r (this, emit_errors);
2687 : 38197 : return r.can_eq (other);
2688 : : }
2689 : :
2690 : : BaseType *
2691 : 18548 : FloatType::clone () const
2692 : : {
2693 : 18548 : return new FloatType (get_ref (), get_ty_ref (), get_float_kind (),
2694 : 18548 : get_combined_refs ());
2695 : : }
2696 : :
2697 : : bool
2698 : 8262 : FloatType::is_equal (const BaseType &other) const
2699 : : {
2700 : 8262 : if (!BaseType::is_equal (other))
2701 : : return false;
2702 : :
2703 : 7638 : const FloatType &o = static_cast<const FloatType &> (other);
2704 : 7638 : return get_float_kind () == o.get_float_kind ();
2705 : : }
2706 : :
2707 : : // UsizeType
2708 : :
2709 : 3600 : USizeType::USizeType (HirId ref, std::set<HirId> refs)
2710 : : : BaseType (ref, ref, KIND,
2711 : 3600 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
2712 : 7200 : refs)
2713 : 3600 : {}
2714 : :
2715 : 29434 : USizeType::USizeType (HirId ref, HirId ty_ref, std::set<HirId> refs)
2716 : : : BaseType (ref, ty_ref, KIND,
2717 : 29434 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
2718 : 58868 : refs)
2719 : 29434 : {}
2720 : :
2721 : : std::string
2722 : 44478 : USizeType::get_name () const
2723 : : {
2724 : 44478 : return as_string ();
2725 : : }
2726 : :
2727 : : void
2728 : 0 : USizeType::accept_vis (TyVisitor &vis)
2729 : : {
2730 : 0 : vis.visit (*this);
2731 : 0 : }
2732 : :
2733 : : void
2734 : 71791 : USizeType::accept_vis (TyConstVisitor &vis) const
2735 : : {
2736 : 71791 : vis.visit (*this);
2737 : 71791 : }
2738 : :
2739 : : std::string
2740 : 65773 : USizeType::as_string () const
2741 : : {
2742 : 65773 : return "usize";
2743 : : }
2744 : :
2745 : : bool
2746 : 47424 : USizeType::can_eq (const BaseType *other, bool emit_errors) const
2747 : : {
2748 : 47424 : USizeCmp r (this, emit_errors);
2749 : 47424 : return r.can_eq (other);
2750 : : }
2751 : :
2752 : : BaseType *
2753 : 29434 : USizeType::clone () const
2754 : : {
2755 : 29434 : return new USizeType (get_ref (), get_ty_ref (), get_combined_refs ());
2756 : : }
2757 : :
2758 : : // ISizeType
2759 : :
2760 : 3601 : ISizeType::ISizeType (HirId ref, std::set<HirId> refs)
2761 : : : BaseType (ref, ref, KIND,
2762 : 3601 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
2763 : 7202 : refs)
2764 : 3601 : {}
2765 : :
2766 : 6057 : ISizeType::ISizeType (HirId ref, HirId ty_ref, std::set<HirId> refs)
2767 : : : BaseType (ref, ty_ref, KIND,
2768 : 6057 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
2769 : 12114 : refs)
2770 : 6057 : {}
2771 : :
2772 : : std::string
2773 : 10874 : ISizeType::get_name () const
2774 : : {
2775 : 10874 : return as_string ();
2776 : : }
2777 : :
2778 : : void
2779 : 56 : ISizeType::accept_vis (TyVisitor &vis)
2780 : : {
2781 : 56 : vis.visit (*this);
2782 : 56 : }
2783 : :
2784 : : void
2785 : 14262 : ISizeType::accept_vis (TyConstVisitor &vis) const
2786 : : {
2787 : 14262 : vis.visit (*this);
2788 : 14262 : }
2789 : :
2790 : : std::string
2791 : 15318 : ISizeType::as_string () const
2792 : : {
2793 : 15318 : return "isize";
2794 : : }
2795 : :
2796 : : bool
2797 : 8716 : ISizeType::can_eq (const BaseType *other, bool emit_errors) const
2798 : : {
2799 : 8716 : ISizeCmp r (this, emit_errors);
2800 : 8716 : return r.can_eq (other);
2801 : : }
2802 : :
2803 : : BaseType *
2804 : 6057 : ISizeType::clone () const
2805 : : {
2806 : 6057 : return new ISizeType (get_ref (), get_ty_ref (), get_combined_refs ());
2807 : : }
2808 : :
2809 : : // Char Type
2810 : :
2811 : 3600 : CharType::CharType (HirId ref, std::set<HirId> refs)
2812 : : : BaseType (ref, ref, KIND,
2813 : 3600 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
2814 : 7200 : refs)
2815 : 3600 : {}
2816 : :
2817 : 3932 : CharType::CharType (HirId ref, HirId ty_ref, std::set<HirId> refs)
2818 : : : BaseType (ref, ty_ref, KIND,
2819 : 3932 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
2820 : 7864 : refs)
2821 : 3932 : {}
2822 : :
2823 : : std::string
2824 : 4723 : CharType::get_name () const
2825 : : {
2826 : 4723 : return as_string ();
2827 : : }
2828 : :
2829 : : void
2830 : 0 : CharType::accept_vis (TyVisitor &vis)
2831 : : {
2832 : 0 : vis.visit (*this);
2833 : 0 : }
2834 : :
2835 : : void
2836 : 10021 : CharType::accept_vis (TyConstVisitor &vis) const
2837 : : {
2838 : 10021 : vis.visit (*this);
2839 : 10021 : }
2840 : :
2841 : : std::string
2842 : 7615 : CharType::as_string () const
2843 : : {
2844 : 7615 : return "char";
2845 : : }
2846 : :
2847 : : bool
2848 : 5533 : CharType::can_eq (const BaseType *other, bool emit_errors) const
2849 : : {
2850 : 5533 : CharCmp r (this, emit_errors);
2851 : 5533 : return r.can_eq (other);
2852 : : }
2853 : :
2854 : : BaseType *
2855 : 3932 : CharType::clone () const
2856 : : {
2857 : 3932 : return new CharType (get_ref (), get_ty_ref (), get_combined_refs ());
2858 : : }
2859 : :
2860 : : // Reference Type
2861 : :
2862 : 10072 : ReferenceType::ReferenceType (HirId ref, TyVar base, Mutability mut,
2863 : 10072 : Region region, std::set<HirId> refs)
2864 : : : BaseType (ref, ref, KIND,
2865 : 10072 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
2866 : : std::move (refs)),
2867 : 20144 : base (base), mut (mut), region (region)
2868 : 10072 : {}
2869 : :
2870 : 38879 : ReferenceType::ReferenceType (HirId ref, HirId ty_ref, TyVar base,
2871 : : Mutability mut, Region region,
2872 : 38879 : std::set<HirId> refs)
2873 : : : BaseType (ref, ty_ref, KIND,
2874 : 38879 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
2875 : : std::move (refs)),
2876 : 77758 : base (base), mut (mut), region (region)
2877 : 38879 : {}
2878 : :
2879 : : Mutability
2880 : 72502 : ReferenceType::mutability () const
2881 : : {
2882 : 72502 : return mut;
2883 : : }
2884 : :
2885 : : bool
2886 : 111868 : ReferenceType::is_mutable () const
2887 : : {
2888 : 111868 : return mut == Mutability::Mut;
2889 : : }
2890 : : Region
2891 : 32871 : ReferenceType::get_region () const
2892 : : {
2893 : 32871 : return region;
2894 : : }
2895 : :
2896 : : bool
2897 : 752 : ReferenceType::is_dyn_object () const
2898 : : {
2899 : 752 : return is_dyn_slice_type () || is_dyn_str_type () || is_dyn_obj_type ();
2900 : : }
2901 : :
2902 : : bool
2903 : 7702 : ReferenceType::is_dyn_slice_type (const TyTy::SliceType **slice) const
2904 : : {
2905 : 7702 : const TyTy::BaseType *element = get_base ()->destructure ();
2906 : 7702 : if (element->get_kind () != TyTy::TypeKind::SLICE)
2907 : : return false;
2908 : 463 : if (slice == nullptr)
2909 : : return true;
2910 : :
2911 : 463 : *slice = static_cast<const TyTy::SliceType *> (element);
2912 : 463 : return true;
2913 : : }
2914 : :
2915 : : bool
2916 : 7281 : ReferenceType::is_dyn_str_type (const TyTy::StrType **str) const
2917 : : {
2918 : 7281 : const TyTy::BaseType *element = get_base ()->destructure ();
2919 : 7281 : if (element->get_kind () != TyTy::TypeKind::STR)
2920 : : return false;
2921 : 2535 : if (str == nullptr)
2922 : : return true;
2923 : :
2924 : 2526 : *str = static_cast<const TyTy::StrType *> (element);
2925 : 2526 : return true;
2926 : : }
2927 : :
2928 : : bool
2929 : 4713 : ReferenceType::is_dyn_obj_type (const TyTy::DynamicObjectType **dyn) const
2930 : : {
2931 : 4713 : const TyTy::BaseType *element = get_base ()->destructure ();
2932 : 4713 : if (element->get_kind () != TyTy::TypeKind::DYNAMIC)
2933 : : return false;
2934 : 342 : if (dyn == nullptr)
2935 : : return true;
2936 : :
2937 : 342 : *dyn = static_cast<const TyTy::DynamicObjectType *> (element);
2938 : 342 : return true;
2939 : : }
2940 : :
2941 : : void
2942 : 3170 : ReferenceType::accept_vis (TyVisitor &vis)
2943 : : {
2944 : 3170 : vis.visit (*this);
2945 : 3170 : }
2946 : :
2947 : : void
2948 : 29132 : ReferenceType::accept_vis (TyConstVisitor &vis) const
2949 : : {
2950 : 29132 : vis.visit (*this);
2951 : 29132 : }
2952 : :
2953 : : std::string
2954 : 17330 : ReferenceType::as_string () const
2955 : : {
2956 : 68070 : return std::string ("&") + (is_mutable () ? "mut" : "") + " "
2957 : 34660 : + get_base ()->as_string ();
2958 : : }
2959 : :
2960 : : std::string
2961 : 77774 : ReferenceType::get_name () const
2962 : : {
2963 : 299699 : return std::string ("&") + (is_mutable () ? "mut" : "") + " "
2964 : 155548 : + get_base ()->get_name ();
2965 : : }
2966 : :
2967 : : bool
2968 : 20948 : ReferenceType::can_eq (const BaseType *other, bool emit_errors) const
2969 : : {
2970 : 20948 : ReferenceCmp r (this, emit_errors);
2971 : 20948 : return r.can_eq (other);
2972 : : }
2973 : :
2974 : : bool
2975 : 9502 : ReferenceType::is_equal (const BaseType &other) const
2976 : : {
2977 : 9502 : if (get_kind () != other.get_kind ())
2978 : : return false;
2979 : :
2980 : 9007 : auto other2 = static_cast<const ReferenceType &> (other);
2981 : 9007 : if (mutability () != other2.mutability ())
2982 : : return false;
2983 : :
2984 : 8560 : return get_base ()->is_equal (*other2.get_base ());
2985 : 9007 : }
2986 : :
2987 : : BaseType *
2988 : 194034 : ReferenceType::get_base () const
2989 : : {
2990 : 194034 : return base.get_tyty ();
2991 : : }
2992 : :
2993 : : const TyVar &
2994 : 743 : ReferenceType::get_var_element_type () const
2995 : : {
2996 : 743 : return base;
2997 : : }
2998 : :
2999 : : BaseType *
3000 : 32667 : ReferenceType::clone () const
3001 : : {
3002 : 32667 : return new ReferenceType (get_ref (), get_ty_ref (), base, mutability (),
3003 : 32667 : get_region (), get_combined_refs ());
3004 : : }
3005 : :
3006 : : ReferenceType *
3007 : 3170 : ReferenceType::handle_substitions (SubstitutionArgumentMappings &mappings)
3008 : : {
3009 : 3170 : auto mappings_table = Analysis::Mappings::get ();
3010 : :
3011 : 3170 : ReferenceType *ref = static_cast<ReferenceType *> (clone ());
3012 : 3170 : ref->set_ty_ref (mappings_table->get_next_hir_id ());
3013 : :
3014 : : // might be &T or &ADT so this needs to be recursive
3015 : 3170 : auto base = ref->get_base ();
3016 : 3170 : BaseType *concrete = Resolver::SubstMapperInternal::Resolve (base, mappings);
3017 : 3170 : ref->base = TyVar::subst_covariant_var (base, concrete);
3018 : :
3019 : 3170 : return ref;
3020 : : }
3021 : :
3022 : : // PointerType
3023 : :
3024 : 11274 : PointerType::PointerType (HirId ref, TyVar base, Mutability mut,
3025 : 11274 : std::set<HirId> refs)
3026 : : : BaseType (ref, ref, KIND,
3027 : 11274 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
3028 : : refs),
3029 : 22548 : base (base), mut (mut)
3030 : 11274 : {}
3031 : :
3032 : 20404 : PointerType::PointerType (HirId ref, HirId ty_ref, TyVar base, Mutability mut,
3033 : 20404 : std::set<HirId> refs)
3034 : : : BaseType (ref, ty_ref, KIND,
3035 : 20404 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
3036 : : refs),
3037 : 40808 : base (base), mut (mut)
3038 : 20404 : {}
3039 : :
3040 : : Mutability
3041 : 58991 : PointerType::mutability () const
3042 : : {
3043 : 58991 : return mut;
3044 : : }
3045 : :
3046 : : bool
3047 : 120529 : PointerType::is_mutable () const
3048 : : {
3049 : 120529 : return mut == Mutability::Mut;
3050 : : }
3051 : :
3052 : : bool
3053 : 0 : PointerType::is_const () const
3054 : : {
3055 : 0 : return mut == Mutability::Imm;
3056 : : }
3057 : :
3058 : : bool
3059 : 2911 : PointerType::is_dyn_object () const
3060 : : {
3061 : 2911 : return is_dyn_slice_type () || is_dyn_str_type () || is_dyn_obj_type ();
3062 : : }
3063 : :
3064 : : bool
3065 : 10186 : PointerType::is_dyn_slice_type (const TyTy::SliceType **slice) const
3066 : : {
3067 : 10186 : const TyTy::BaseType *element = get_base ()->destructure ();
3068 : 10186 : if (element->get_kind () != TyTy::TypeKind::SLICE)
3069 : : return false;
3070 : 505 : if (slice == nullptr)
3071 : : return true;
3072 : :
3073 : 505 : *slice = static_cast<const TyTy::SliceType *> (element);
3074 : 505 : return true;
3075 : : }
3076 : :
3077 : : bool
3078 : 9681 : PointerType::is_dyn_str_type (const TyTy::StrType **str) const
3079 : : {
3080 : 9681 : const TyTy::BaseType *element = get_base ()->destructure ();
3081 : 9681 : if (element->get_kind () != TyTy::TypeKind::STR)
3082 : : return false;
3083 : 1997 : if (str == nullptr)
3084 : : return true;
3085 : :
3086 : 1997 : *str = static_cast<const TyTy::StrType *> (element);
3087 : 1997 : return true;
3088 : : }
3089 : :
3090 : : bool
3091 : 7684 : PointerType::is_dyn_obj_type (const TyTy::DynamicObjectType **dyn) const
3092 : : {
3093 : 7684 : const TyTy::BaseType *element = get_base ()->destructure ();
3094 : 7684 : if (element->get_kind () != TyTy::TypeKind::DYNAMIC)
3095 : : return false;
3096 : 0 : if (dyn == nullptr)
3097 : : return true;
3098 : :
3099 : 0 : *dyn = static_cast<const TyTy::DynamicObjectType *> (element);
3100 : 0 : return true;
3101 : : }
3102 : :
3103 : : void
3104 : 2074 : PointerType::accept_vis (TyVisitor &vis)
3105 : : {
3106 : 2074 : vis.visit (*this);
3107 : 2074 : }
3108 : :
3109 : : void
3110 : 8393 : PointerType::accept_vis (TyConstVisitor &vis) const
3111 : : {
3112 : 8393 : vis.visit (*this);
3113 : 8393 : }
3114 : :
3115 : : std::string
3116 : 7265 : PointerType::as_string () const
3117 : : {
3118 : 27801 : return std::string ("* ") + (is_mutable () ? "mut" : "const") + " "
3119 : 14530 : + get_base ()->as_string ();
3120 : : }
3121 : :
3122 : : std::string
3123 : 94408 : PointerType::get_name () const
3124 : : {
3125 : 370933 : return std::string ("* ") + (is_mutable () ? "mut" : "const") + " "
3126 : 188816 : + get_base ()->get_name ();
3127 : : }
3128 : :
3129 : : bool
3130 : 425 : PointerType::can_eq (const BaseType *other, bool emit_errors) const
3131 : : {
3132 : 425 : PointerCmp r (this, emit_errors);
3133 : 425 : return r.can_eq (other);
3134 : : }
3135 : :
3136 : : bool
3137 : 12341 : PointerType::is_equal (const BaseType &other) const
3138 : : {
3139 : 12341 : if (get_kind () != other.get_kind ())
3140 : : return false;
3141 : :
3142 : 12341 : auto other2 = static_cast<const PointerType &> (other);
3143 : 12341 : if (mutability () != other2.mutability ())
3144 : : return false;
3145 : :
3146 : 12329 : return get_base ()->is_equal (*other2.get_base ());
3147 : 12341 : }
3148 : :
3149 : : BaseType *
3150 : 201264 : PointerType::get_base () const
3151 : : {
3152 : 201264 : return base.get_tyty ();
3153 : : }
3154 : :
3155 : : const TyVar &
3156 : 334 : PointerType::get_var_element_type () const
3157 : : {
3158 : 334 : return base;
3159 : : }
3160 : :
3161 : : BaseType *
3162 : 9391 : PointerType::clone () const
3163 : : {
3164 : 9391 : return new PointerType (get_ref (), get_ty_ref (), base, mutability (),
3165 : 9391 : get_combined_refs ());
3166 : : }
3167 : :
3168 : : PointerType *
3169 : 2074 : PointerType::handle_substitions (SubstitutionArgumentMappings &mappings)
3170 : : {
3171 : 2074 : auto mappings_table = Analysis::Mappings::get ();
3172 : :
3173 : 2074 : PointerType *ref = static_cast<PointerType *> (clone ());
3174 : 2074 : ref->set_ty_ref (mappings_table->get_next_hir_id ());
3175 : :
3176 : : // might be &T or &ADT so this needs to be recursive
3177 : 2074 : auto base = ref->get_base ();
3178 : 2074 : BaseType *concrete = Resolver::SubstMapperInternal::Resolve (base, mappings);
3179 : 2074 : ref->base = TyVar::subst_covariant_var (base, concrete);
3180 : :
3181 : 2074 : return ref;
3182 : : }
3183 : :
3184 : : // PARAM Type
3185 : :
3186 : 8767 : ParamType::ParamType (std::string symbol, location_t locus, HirId ref,
3187 : : HIR::GenericParam ¶m,
3188 : : std::vector<TypeBoundPredicate> specified_bounds,
3189 : 8767 : std::set<HirId> refs)
3190 : : : BaseType (ref, ref, KIND,
3191 : 8767 : {Resolver::CanonicalPath::new_seg (UNKNOWN_NODEID, symbol),
3192 : : locus},
3193 : : specified_bounds, refs),
3194 : 17534 : is_trait_self (false), symbol (symbol), param (param)
3195 : 8767 : {}
3196 : :
3197 : 12361055 : ParamType::ParamType (bool is_trait_self, std::string symbol, location_t locus,
3198 : : HirId ref, HirId ty_ref, HIR::GenericParam ¶m,
3199 : : std::vector<TypeBoundPredicate> specified_bounds,
3200 : 12361055 : std::set<HirId> refs)
3201 : : : BaseType (ref, ty_ref, KIND,
3202 : 12361055 : {Resolver::CanonicalPath::new_seg (UNKNOWN_NODEID, symbol),
3203 : : locus},
3204 : : specified_bounds, refs),
3205 : 24722110 : is_trait_self (is_trait_self), symbol (symbol), param (param)
3206 : 12361055 : {}
3207 : :
3208 : : HIR::GenericParam &
3209 : 0 : ParamType::get_generic_param ()
3210 : : {
3211 : 0 : return param;
3212 : : }
3213 : :
3214 : : bool
3215 : 630339 : ParamType::can_resolve () const
3216 : : {
3217 : 630339 : return get_ref () != get_ty_ref ();
3218 : : }
3219 : :
3220 : : void
3221 : 21812 : ParamType::accept_vis (TyVisitor &vis)
3222 : : {
3223 : 21812 : vis.visit (*this);
3224 : 21812 : }
3225 : :
3226 : : void
3227 : 15546 : ParamType::accept_vis (TyConstVisitor &vis) const
3228 : : {
3229 : 15546 : vis.visit (*this);
3230 : 15546 : }
3231 : :
3232 : : std::string
3233 : 67766 : ParamType::as_string () const
3234 : : {
3235 : 67766 : if (!can_resolve ())
3236 : : {
3237 : 46548 : return get_symbol () + " REF: " + std::to_string (get_ref ());
3238 : : }
3239 : :
3240 : 44492 : BaseType *lookup = resolve ();
3241 : 88984 : return get_symbol () + "=" + lookup->as_string ();
3242 : : }
3243 : :
3244 : : std::string
3245 : 201650 : ParamType::get_name () const
3246 : : {
3247 : 201650 : if (!can_resolve ())
3248 : 80202 : return get_symbol ();
3249 : :
3250 : 121448 : return destructure ()->get_name ();
3251 : : }
3252 : :
3253 : : bool
3254 : 24211 : ParamType::can_eq (const BaseType *other, bool emit_errors) const
3255 : : {
3256 : 24211 : ParamCmp r (this, emit_errors);
3257 : 24211 : return r.can_eq (other);
3258 : : }
3259 : :
3260 : : BaseType *
3261 : 12361055 : ParamType::clone () const
3262 : : {
3263 : 12361055 : return new ParamType (is_trait_self, get_symbol (), ident.locus, get_ref (),
3264 : : get_ty_ref (), param, get_specified_bounds (),
3265 : 24722110 : get_combined_refs ());
3266 : : }
3267 : :
3268 : : std::string
3269 : 12658518 : ParamType::get_symbol () const
3270 : : {
3271 : 12658518 : return symbol;
3272 : : }
3273 : :
3274 : : BaseType *
3275 : 458747 : ParamType::resolve () const
3276 : : {
3277 : 458747 : TyVar var (get_ty_ref ());
3278 : 458747 : BaseType *r = var.get_tyty ();
3279 : :
3280 : 917794 : while (r->get_kind () == TypeKind::PARAM)
3281 : : {
3282 : 286807 : ParamType *rr = static_cast<ParamType *> (r);
3283 : 286807 : if (!rr->can_resolve ())
3284 : : break;
3285 : :
3286 : 300 : TyVar v (rr->get_ty_ref ());
3287 : 300 : BaseType *n = v.get_tyty ();
3288 : :
3289 : : // fix infinite loop
3290 : 300 : if (r == n)
3291 : : break;
3292 : :
3293 : 300 : r = n;
3294 : : }
3295 : :
3296 : 458747 : if (r->get_kind () == TypeKind::PARAM && (r->get_ref () == r->get_ty_ref ()))
3297 : 286507 : return TyVar (r->get_ty_ref ()).get_tyty ();
3298 : :
3299 : : return r;
3300 : : }
3301 : :
3302 : : bool
3303 : 18352 : ParamType::is_equal (const BaseType &other) const
3304 : : {
3305 : 18352 : if (get_kind () != other.get_kind ())
3306 : : {
3307 : 5774 : if (!can_resolve ())
3308 : : return false;
3309 : :
3310 : 3655 : return resolve ()->is_equal (other);
3311 : : }
3312 : :
3313 : 12578 : auto other2 = static_cast<const ParamType &> (other);
3314 : 12578 : if (can_resolve () != other2.can_resolve ())
3315 : : return false;
3316 : :
3317 : 11093 : if (can_resolve ())
3318 : 5787 : return resolve ()->can_eq (other2.resolve (), false);
3319 : :
3320 : 5306 : return get_symbol ().compare (other2.get_symbol ()) == 0;
3321 : 12578 : }
3322 : :
3323 : : ParamType *
3324 : 21812 : ParamType::handle_substitions (SubstitutionArgumentMappings &subst_mappings)
3325 : : {
3326 : 21812 : SubstitutionArg arg = SubstitutionArg::error ();
3327 : 21812 : bool ok = subst_mappings.get_argument_for_symbol (this, &arg);
3328 : 21812 : if (!ok || arg.is_error ())
3329 : 6538 : return this;
3330 : :
3331 : 15274 : ParamType *p = static_cast<ParamType *> (clone ());
3332 : 15274 : subst_mappings.on_param_subst (*p, arg);
3333 : :
3334 : : // there are two cases one where we substitute directly to a new PARAM and
3335 : : // otherwise
3336 : 15274 : if (arg.get_tyty ()->get_kind () == TyTy::TypeKind::PARAM)
3337 : : {
3338 : 922 : p->set_ty_ref (arg.get_tyty ()->get_ref ());
3339 : 922 : return p;
3340 : : }
3341 : :
3342 : : // this is the new subst that this needs to pass
3343 : 14352 : p->set_ref (mappings->get_next_hir_id ());
3344 : 14352 : p->set_ty_ref (arg.get_tyty ()->get_ref ());
3345 : :
3346 : 14352 : return p;
3347 : : }
3348 : :
3349 : : void
3350 : 2081 : ParamType::set_implicit_self_trait ()
3351 : : {
3352 : 2081 : is_trait_self = true;
3353 : 2081 : }
3354 : :
3355 : : bool
3356 : 12279 : ParamType::is_implicit_self_trait () const
3357 : : {
3358 : 12279 : return is_trait_self;
3359 : : }
3360 : :
3361 : : // StrType
3362 : :
3363 : 3600 : StrType::StrType (HirId ref, std::set<HirId> refs)
3364 : : : BaseType (ref, ref, KIND,
3365 : 3600 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
3366 : 7200 : refs)
3367 : 3600 : {}
3368 : :
3369 : 5349 : StrType::StrType (HirId ref, HirId ty_ref, std::set<HirId> refs)
3370 : : : BaseType (ref, ty_ref, KIND,
3371 : 5349 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
3372 : 10698 : refs)
3373 : 5349 : {}
3374 : :
3375 : : std::string
3376 : 50853 : StrType::get_name () const
3377 : : {
3378 : 50853 : return as_string ();
3379 : : }
3380 : :
3381 : : BaseType *
3382 : 5349 : StrType::clone () const
3383 : : {
3384 : 5349 : return new StrType (get_ref (), get_ty_ref (), get_combined_refs ());
3385 : : }
3386 : :
3387 : : void
3388 : 0 : StrType::accept_vis (TyVisitor &vis)
3389 : : {
3390 : 0 : vis.visit (*this);
3391 : 0 : }
3392 : :
3393 : : void
3394 : 3383 : StrType::accept_vis (TyConstVisitor &vis) const
3395 : : {
3396 : 3383 : vis.visit (*this);
3397 : 3383 : }
3398 : :
3399 : : std::string
3400 : 52657 : StrType::as_string () const
3401 : : {
3402 : 52657 : return "str";
3403 : : }
3404 : :
3405 : : bool
3406 : 7 : StrType::can_eq (const BaseType *other, bool emit_errors) const
3407 : : {
3408 : 7 : StrCmp r (this, emit_errors);
3409 : 7 : return r.can_eq (other);
3410 : : }
3411 : :
3412 : : bool
3413 : 8098 : StrType::is_equal (const BaseType &other) const
3414 : : {
3415 : 8098 : return get_kind () == other.get_kind ();
3416 : : }
3417 : :
3418 : : // Never Type
3419 : :
3420 : 4292 : NeverType::NeverType (HirId ref, std::set<HirId> refs)
3421 : : : BaseType (ref, ref, KIND,
3422 : 4292 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
3423 : 8584 : refs)
3424 : 4292 : {}
3425 : :
3426 : 165 : NeverType::NeverType (HirId ref, HirId ty_ref, std::set<HirId> refs)
3427 : : : BaseType (ref, ty_ref, KIND,
3428 : 165 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
3429 : 330 : refs)
3430 : 165 : {}
3431 : :
3432 : : std::string
3433 : 435 : NeverType::get_name () const
3434 : : {
3435 : 435 : return as_string ();
3436 : : }
3437 : :
3438 : : void
3439 : 0 : NeverType::accept_vis (TyVisitor &vis)
3440 : : {
3441 : 0 : vis.visit (*this);
3442 : 0 : }
3443 : :
3444 : : void
3445 : 4187 : NeverType::accept_vis (TyConstVisitor &vis) const
3446 : : {
3447 : 4187 : vis.visit (*this);
3448 : 4187 : }
3449 : :
3450 : : std::string
3451 : 535 : NeverType::as_string () const
3452 : : {
3453 : 535 : return "!";
3454 : : }
3455 : :
3456 : : bool
3457 : 752 : NeverType::can_eq (const BaseType *other, bool emit_errors) const
3458 : : {
3459 : 752 : NeverCmp r (this, emit_errors);
3460 : 752 : return r.can_eq (other);
3461 : : }
3462 : :
3463 : : BaseType *
3464 : 165 : NeverType::clone () const
3465 : : {
3466 : 165 : return new NeverType (get_ref (), get_ty_ref (), get_combined_refs ());
3467 : : }
3468 : :
3469 : : // placeholder type
3470 : :
3471 : 473 : PlaceholderType::PlaceholderType (std::string symbol, HirId ref,
3472 : 473 : std::set<HirId> refs)
3473 : : : BaseType (ref, ref, KIND,
3474 : 473 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
3475 : : refs),
3476 : 946 : symbol (symbol)
3477 : 473 : {}
3478 : :
3479 : 3528 : PlaceholderType::PlaceholderType (std::string symbol, HirId ref, HirId ty_ref,
3480 : 3528 : std::set<HirId> refs)
3481 : : : BaseType (ref, ty_ref, KIND,
3482 : 3528 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
3483 : : refs),
3484 : 7056 : symbol (symbol)
3485 : 3528 : {}
3486 : :
3487 : : std::string
3488 : 5116 : PlaceholderType::get_name () const
3489 : : {
3490 : 5116 : return as_string ();
3491 : : }
3492 : :
3493 : : std::string
3494 : 4958 : PlaceholderType::get_symbol () const
3495 : : {
3496 : 4958 : return symbol;
3497 : : }
3498 : :
3499 : : void
3500 : 404 : PlaceholderType::accept_vis (TyVisitor &vis)
3501 : : {
3502 : 404 : vis.visit (*this);
3503 : 404 : }
3504 : :
3505 : : void
3506 : 56 : PlaceholderType::accept_vis (TyConstVisitor &vis) const
3507 : : {
3508 : 56 : vis.visit (*this);
3509 : 56 : }
3510 : :
3511 : : std::string
3512 : 7696 : PlaceholderType::as_string () const
3513 : : {
3514 : 15392 : return "<placeholder:" + (can_resolve () ? resolve ()->as_string () : "")
3515 : 7696 : + ">";
3516 : : }
3517 : :
3518 : : bool
3519 : 2309 : PlaceholderType::can_eq (const BaseType *other, bool emit_errors) const
3520 : : {
3521 : 2309 : PlaceholderCmp r (this, emit_errors);
3522 : 2309 : return r.can_eq (other);
3523 : : }
3524 : :
3525 : : BaseType *
3526 : 3528 : PlaceholderType::clone () const
3527 : : {
3528 : 7056 : return new PlaceholderType (get_symbol (), get_ref (), get_ty_ref (),
3529 : 7056 : get_combined_refs ());
3530 : : }
3531 : :
3532 : : void
3533 : 1798 : PlaceholderType::set_associated_type (HirId ref)
3534 : : {
3535 : 1798 : auto context = Resolver::TypeCheckContext::get ();
3536 : 1798 : context->insert_associated_type_mapping (get_ty_ref (), ref);
3537 : 1798 : }
3538 : :
3539 : : void
3540 : 725 : PlaceholderType::clear_associated_type ()
3541 : : {
3542 : 725 : auto context = Resolver::TypeCheckContext::get ();
3543 : 725 : context->clear_associated_type_mapping (get_ty_ref ());
3544 : 725 : }
3545 : :
3546 : : bool
3547 : 19587 : PlaceholderType::can_resolve () const
3548 : : {
3549 : 19587 : auto context = Resolver::TypeCheckContext::get ();
3550 : 19587 : return context->lookup_associated_type_mapping (get_ty_ref (), nullptr);
3551 : : }
3552 : :
3553 : : BaseType *
3554 : 7333 : PlaceholderType::resolve () const
3555 : : {
3556 : 7333 : auto context = Resolver::TypeCheckContext::get ();
3557 : :
3558 : 7333 : HirId mapping;
3559 : 7333 : bool ok = context->lookup_associated_type_mapping (get_ty_ref (), &mapping);
3560 : 7333 : rust_assert (ok);
3561 : :
3562 : 7333 : return TyVar (mapping).get_tyty ();
3563 : : }
3564 : :
3565 : : bool
3566 : 1635 : PlaceholderType::is_equal (const BaseType &other) const
3567 : : {
3568 : 1635 : if (get_kind () != other.get_kind ())
3569 : : {
3570 : 920 : if (!can_resolve ())
3571 : : return false;
3572 : :
3573 : 247 : return resolve ()->is_equal (other);
3574 : : }
3575 : :
3576 : 715 : auto other2 = static_cast<const PlaceholderType &> (other);
3577 : 715 : return get_symbol ().compare (other2.get_symbol ()) == 0;
3578 : 715 : }
3579 : :
3580 : : // Projection type
3581 : :
3582 : 710 : ProjectionType::ProjectionType (
3583 : : HirId ref, BaseType *base, const Resolver::TraitReference *trait, DefId item,
3584 : : std::vector<SubstitutionParamMapping> subst_refs,
3585 : : SubstitutionArgumentMappings generic_arguments,
3586 : 710 : RegionConstraints region_constraints, std::set<HirId> refs)
3587 : : : BaseType (ref, ref, KIND,
3588 : 710 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
3589 : : std::move (refs)),
3590 : : SubstitutionRef (std::move (subst_refs), std::move (generic_arguments),
3591 : : std::move (region_constraints)),
3592 : 1420 : base (base), trait (trait), item (item)
3593 : 710 : {}
3594 : :
3595 : 701 : ProjectionType::ProjectionType (
3596 : : HirId ref, HirId ty_ref, BaseType *base,
3597 : : const Resolver::TraitReference *trait, DefId item,
3598 : : std::vector<SubstitutionParamMapping> subst_refs,
3599 : : SubstitutionArgumentMappings generic_arguments,
3600 : 701 : RegionConstraints region_constraints, std::set<HirId> refs)
3601 : : : BaseType (ref, ty_ref, KIND,
3602 : 701 : {Resolver::CanonicalPath::create_empty (), BUILTINS_LOCATION},
3603 : : refs),
3604 : : SubstitutionRef (std::move (subst_refs), std::move (generic_arguments),
3605 : : std::move (region_constraints)),
3606 : 1402 : base (base), trait (trait), item (item)
3607 : 701 : {}
3608 : :
3609 : : std::string
3610 : 1302 : ProjectionType::get_name () const
3611 : : {
3612 : 1302 : return as_string ();
3613 : : }
3614 : :
3615 : : const BaseType *
3616 : 3887 : ProjectionType::get () const
3617 : : {
3618 : 3887 : return base;
3619 : : }
3620 : :
3621 : : BaseType *
3622 : 2553 : ProjectionType::get ()
3623 : : {
3624 : 2553 : return base;
3625 : : }
3626 : :
3627 : : void
3628 : 564 : ProjectionType::accept_vis (TyVisitor &vis)
3629 : : {
3630 : 564 : vis.visit (*this);
3631 : 564 : }
3632 : :
3633 : : void
3634 : 0 : ProjectionType::accept_vis (TyConstVisitor &vis) const
3635 : : {
3636 : 0 : vis.visit (*this);
3637 : 0 : }
3638 : :
3639 : : std::string
3640 : 4783 : ProjectionType::as_string () const
3641 : : {
3642 : 14349 : return "<Projection=" + subst_as_string () + "::" + base->as_string () + ">";
3643 : : }
3644 : :
3645 : : bool
3646 : 91 : ProjectionType::can_eq (const BaseType *other, bool emit_errors) const
3647 : : {
3648 : 91 : return base->can_eq (other, emit_errors);
3649 : : }
3650 : :
3651 : : BaseType *
3652 : 701 : ProjectionType::clone () const
3653 : : {
3654 : 1402 : return new ProjectionType (get_ref (), get_ty_ref (), base->clone (), trait,
3655 : 1402 : item, clone_substs (), used_arguments,
3656 : 2804 : region_constraints, get_combined_refs ());
3657 : : }
3658 : :
3659 : : ProjectionType *
3660 : 564 : ProjectionType::handle_substitions (
3661 : : SubstitutionArgumentMappings &subst_mappings)
3662 : : {
3663 : : // // do we really need to substitute this?
3664 : : // if (base->needs_generic_substitutions () ||
3665 : : // base->contains_type_parameters
3666 : : // ())
3667 : : // {
3668 : : // return this;
3669 : : // }
3670 : :
3671 : 564 : ProjectionType *projection = static_cast<ProjectionType *> (clone ());
3672 : 564 : projection->set_ty_ref (mappings->get_next_hir_id ());
3673 : 564 : projection->used_arguments = subst_mappings;
3674 : :
3675 : 564 : auto context = Resolver::TypeCheckContext::get ();
3676 : 564 : context->insert_implicit_type (projection->get_ty_ref (), projection);
3677 : :
3678 : 808 : for (auto &sub : projection->get_substs ())
3679 : : {
3680 : 244 : SubstitutionArg arg = SubstitutionArg::error ();
3681 : 244 : bool ok
3682 : 244 : = subst_mappings.get_argument_for_symbol (sub.get_param_ty (), &arg);
3683 : 244 : if (ok)
3684 : 244 : sub.fill_param_ty (subst_mappings, subst_mappings.get_locus ());
3685 : : }
3686 : :
3687 : 564 : auto fty = projection->base;
3688 : 564 : bool is_param_ty = fty->get_kind () == TypeKind::PARAM;
3689 : 564 : if (is_param_ty)
3690 : : {
3691 : 156 : ParamType *p = static_cast<ParamType *> (fty);
3692 : :
3693 : 156 : SubstitutionArg arg = SubstitutionArg::error ();
3694 : 156 : bool ok = subst_mappings.get_argument_for_symbol (p, &arg);
3695 : 156 : if (ok)
3696 : : {
3697 : 156 : auto argt = arg.get_tyty ();
3698 : 156 : bool arg_is_param = argt->get_kind () == TyTy::TypeKind::PARAM;
3699 : 156 : bool arg_is_concrete = argt->get_kind () != TyTy::TypeKind::INFER;
3700 : :
3701 : 156 : if (arg_is_param || arg_is_concrete)
3702 : : {
3703 : 134 : auto new_field = argt->clone ();
3704 : 134 : new_field->set_ref (fty->get_ref ());
3705 : 134 : projection->base = new_field;
3706 : : }
3707 : : else
3708 : : {
3709 : 22 : fty->set_ty_ref (argt->get_ref ());
3710 : : }
3711 : : }
3712 : : }
3713 : 408 : else if (fty->needs_generic_substitutions () || !fty->is_concrete ())
3714 : : {
3715 : 70 : BaseType *concrete
3716 : 70 : = Resolver::SubstMapperInternal::Resolve (fty, subst_mappings);
3717 : :
3718 : 70 : if (concrete == nullptr || concrete->get_kind () == TyTy::TypeKind::ERROR)
3719 : : {
3720 : 0 : rust_error_at (subst_mappings.get_locus (),
3721 : : "Failed to resolve field substitution type: %s",
3722 : 0 : fty->as_string ().c_str ());
3723 : 0 : return nullptr;
3724 : : }
3725 : :
3726 : 70 : projection->base = concrete;
3727 : : }
3728 : :
3729 : : return projection;
3730 : : }
3731 : :
3732 : : // DynObjectType
3733 : :
3734 : 2277 : DynamicObjectType::DynamicObjectType (
3735 : : HirId ref, RustIdent ident, std::vector<TypeBoundPredicate> specified_bounds,
3736 : 2277 : std::set<HirId> refs)
3737 : 2277 : : BaseType (ref, ref, KIND, ident, specified_bounds, refs)
3738 : 2277 : {}
3739 : :
3740 : 465 : DynamicObjectType::DynamicObjectType (
3741 : : HirId ref, HirId ty_ref, RustIdent ident,
3742 : 465 : std::vector<TypeBoundPredicate> specified_bounds, std::set<HirId> refs)
3743 : 465 : : BaseType (ref, ty_ref, KIND, ident, specified_bounds, refs)
3744 : 465 : {}
3745 : :
3746 : : void
3747 : 0 : DynamicObjectType::accept_vis (TyVisitor &vis)
3748 : : {
3749 : 0 : vis.visit (*this);
3750 : 0 : }
3751 : :
3752 : : void
3753 : 5401 : DynamicObjectType::accept_vis (TyConstVisitor &vis) const
3754 : : {
3755 : 5401 : vis.visit (*this);
3756 : 5401 : }
3757 : :
3758 : : std::string
3759 : 481 : DynamicObjectType::as_string () const
3760 : : {
3761 : 962 : return "dyn [" + raw_bounds_as_string () + "]";
3762 : : }
3763 : :
3764 : : bool
3765 : 5387 : DynamicObjectType::can_eq (const BaseType *other, bool emit_errors) const
3766 : : {
3767 : 5387 : DynamicCmp r (this, emit_errors);
3768 : 5387 : return r.can_eq (other);
3769 : : }
3770 : :
3771 : : BaseType *
3772 : 465 : DynamicObjectType::clone () const
3773 : : {
3774 : 465 : return new DynamicObjectType (get_ref (), get_ty_ref (), ident,
3775 : 930 : specified_bounds, get_combined_refs ());
3776 : : }
3777 : :
3778 : : std::string
3779 : 4287 : DynamicObjectType::get_name () const
3780 : : {
3781 : 8574 : return "dyn [" + raw_bounds_as_name () + "]";
3782 : : }
3783 : :
3784 : : bool
3785 : 595 : DynamicObjectType::is_equal (const BaseType &other) const
3786 : : {
3787 : 595 : if (get_kind () != other.get_kind ())
3788 : : return false;
3789 : :
3790 : 593 : if (num_specified_bounds () != other.num_specified_bounds ())
3791 : : return false;
3792 : :
3793 : 593 : return bounds_compatible (other, UNDEF_LOCATION, false);
3794 : : }
3795 : :
3796 : : const std::vector<
3797 : : std::pair<const Resolver::TraitItemReference *, const TypeBoundPredicate *>>
3798 : 489 : DynamicObjectType::get_object_items () const
3799 : : {
3800 : 489 : std::vector<
3801 : : std::pair<const Resolver::TraitItemReference *, const TypeBoundPredicate *>>
3802 : 489 : items;
3803 : 978 : for (auto &bound : get_specified_bounds ())
3804 : : {
3805 : 489 : const Resolver::TraitReference *trait = bound.get ();
3806 : 489 : std::vector<const Resolver::TraitItemReference *> trait_items;
3807 : 489 : trait->get_trait_items_and_supers (trait_items);
3808 : :
3809 : 1039 : for (auto &item : trait_items)
3810 : : {
3811 : 550 : if (item->get_trait_item_type ()
3812 : : == Resolver::TraitItemReference::TraitItemType::FN
3813 : 550 : && item->is_object_safe ())
3814 : 550 : items.push_back ({item, &bound});
3815 : : }
3816 : 489 : }
3817 : 489 : return items;
3818 : : }
3819 : :
3820 : : } // namespace TyTy
3821 : : } // namespace Rust
|