Daily bump.
[official-gcc.git] / gcc / rust / typecheck / rust-unify.h
blob20f7b4e8a5c7ecf44e937fac2a62ed58f6973205
1 // Copyright (C) 2020-2025 Free Software Foundation, Inc.
3 // This file is part of GCC.
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.
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.
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/>.
19 #ifndef RUST_UNIFY
20 #define RUST_UNIFY
22 #include "rust-tyty-util.h"
23 #include "rust-hir-type-check.h"
25 namespace Rust {
26 namespace Resolver {
28 class UnifyRules
30 public:
31 struct InferenceSite
33 HirId pref;
34 HirId ptyref;
35 TyTy::ParamType *param;
36 TyTy::InferType *infer;
38 struct CommitSite
40 TyTy::BaseType *lhs;
41 TyTy::BaseType *rhs;
42 TyTy::BaseType *resolved;
45 static TyTy::BaseType *Resolve (TyTy::TyWithLocation lhs,
46 TyTy::TyWithLocation rhs, location_t locus,
47 bool commit_flag, bool emit_error, bool infer,
48 std::vector<CommitSite> &commits,
49 std::vector<InferenceSite> &infers);
51 static void commit (TyTy::BaseType *base, TyTy::BaseType *other,
52 TyTy::BaseType *resolved);
54 protected:
55 TyTy::BaseType *expect_inference_variable (TyTy::InferType *ltype,
56 TyTy::BaseType *rtype);
57 TyTy::BaseType *expect_adt (TyTy::ADTType *ltype, TyTy::BaseType *rtype);
58 TyTy::BaseType *expect_str (TyTy::StrType *ltype, TyTy::BaseType *rtype);
59 TyTy::BaseType *expect_reference (TyTy::ReferenceType *ltype,
60 TyTy::BaseType *rtype);
61 TyTy::BaseType *expect_pointer (TyTy::PointerType *ltype,
62 TyTy::BaseType *rtype);
63 TyTy::BaseType *expect_param (TyTy::ParamType *ltype, TyTy::BaseType *rtype);
64 TyTy::BaseType *expect_array (TyTy::ArrayType *ltype, TyTy::BaseType *rtype);
65 TyTy::BaseType *expect_slice (TyTy::SliceType *ltype, TyTy::BaseType *rtype);
66 TyTy::BaseType *expect_fndef (TyTy::FnType *ltype, TyTy::BaseType *rtype);
67 TyTy::BaseType *expect_fnptr (TyTy::FnPtr *ltype, TyTy::BaseType *rtype);
68 TyTy::BaseType *expect_tuple (TyTy::TupleType *ltype, TyTy::BaseType *rtype);
69 TyTy::BaseType *expect_bool (TyTy::BoolType *ltype, TyTy::BaseType *rtype);
70 TyTy::BaseType *expect_char (TyTy::CharType *ltype, TyTy::BaseType *rtype);
71 TyTy::BaseType *expect_int (TyTy::IntType *ltype, TyTy::BaseType *rtype);
72 TyTy::BaseType *expect_uint (TyTy::UintType *ltype, TyTy::BaseType *rtype);
73 TyTy::BaseType *expect_float (TyTy::FloatType *ltype, TyTy::BaseType *rtype);
74 TyTy::BaseType *expect_isize (TyTy::ISizeType *ltype, TyTy::BaseType *rtype);
75 TyTy::BaseType *expect_usize (TyTy::USizeType *ltype, TyTy::BaseType *rtype);
76 TyTy::BaseType *expect_never (TyTy::NeverType *ltype, TyTy::BaseType *rtype);
77 TyTy::BaseType *expect_placeholder (TyTy::PlaceholderType *ltype,
78 TyTy::BaseType *rtype);
79 TyTy::BaseType *expect_projection (TyTy::ProjectionType *ltype,
80 TyTy::BaseType *rtype);
81 TyTy::BaseType *expect_dyn (TyTy::DynamicObjectType *ltype,
82 TyTy::BaseType *rtype);
83 TyTy::BaseType *expect_closure (TyTy::ClosureType *ltype,
84 TyTy::BaseType *rtype);
86 private:
87 UnifyRules (TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs,
88 location_t locus, bool commit_flag, bool emit_error, bool infer,
89 std::vector<CommitSite> &commits,
90 std::vector<InferenceSite> &infers);
92 void emit_type_mismatch () const;
93 void emit_abi_mismatch (const TyTy::FnType &expected,
94 const TyTy::FnType &got) const;
96 TyTy::BaseType *go ();
98 TyTy::BaseType *get_base ();
99 TyTy::BaseType *get_other ();
101 TyTy::TyWithLocation lhs;
102 TyTy::TyWithLocation rhs;
103 location_t locus;
104 bool commit_flag;
105 bool emit_error;
106 bool infer_flag;
107 std::vector<CommitSite> &commits;
108 std::vector<InferenceSite> &infers;
110 Analysis::Mappings &mappings;
111 TypeCheckContext &context;
114 } // namespace Resolver
115 } // namespace Rust
117 #endif // RUST_UNIFY