Line data Source code
1 : // Copyright (C) 2026 Free Software Foundation, Inc.
2 :
3 : // This file is part of GCC.
4 :
5 : // GCC is free software; you can redistribute it and/or modify it under
6 : // the terms of the GNU General Public License as published by the Free
7 : // Software Foundation; either version 3, or (at your option) any later
8 : // version.
9 :
10 : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 : // for more details.
14 :
15 : // You should have received a copy of the GNU General Public License
16 : // along with GCC; see the file COPYING3. If not see
17 : // <http://www.gnu.org/licenses/>.
18 :
19 : #ifndef RUST_HIR_TYPE_CHECK_INTRINSIC_H
20 : #define RUST_HIR_TYPE_CHECK_INTRINSIC_H
21 :
22 : #include "rust-tyty.h"
23 :
24 : namespace Rust {
25 : namespace Resolver {
26 :
27 : enum class IntrinsicRuleType
28 : {
29 : Bool,
30 : F32,
31 : F64,
32 : I32,
33 : Isize,
34 : U8,
35 : U64,
36 : Usize,
37 : Unit,
38 : Never,
39 :
40 : FirstGeneric, // <T>
41 : SecondGeneric, // <U>
42 :
43 : ConstPtrFirstGeneric, // *const T
44 : MutPtrFirstGeneric, // *mut T
45 : RefFirstGeneric, // &T
46 :
47 : RefAdt, // for caller_location() -> &'static crate::panic::Location<'static>
48 : MutPtrU8, // *mut u8
49 : RefStaticStr, // &'static str
50 : AssocTypePlaceholder,
51 : // for discriminant_value<T>(v: &T) -> <T as DiscriminantKind>::Discriminant
52 :
53 : TupleFirstGenericAndBool, // (T, bool)
54 :
55 : Fn_MutPtrU8, // fn(*mut u8)
56 : Fn_MutPtrU8MutPtrU8, // fn(*mut u8, *mut u8)
57 : };
58 :
59 1561380 : struct IntrinsicRules
60 : {
61 : size_t generic_count;
62 : std::vector<IntrinsicRuleType> param_types;
63 : IntrinsicRuleType return_type;
64 : };
65 :
66 : enum class IntrinsicCheckResult
67 : {
68 : Valid,
69 : Invalid,
70 : };
71 :
72 : class IntrinsicChecker
73 : {
74 : public:
75 : static IntrinsicCheckResult check (const TyTy::FnType *fntype);
76 :
77 : private:
78 : static const std::unordered_map<std::string, IntrinsicRules> intrinsic_rules;
79 : static bool check_type (const TyTy::BaseType *actual,
80 : IntrinsicRuleType expected,
81 : const TyTy::FnType *fntype);
82 : static std::string expected_intrinsic_as_string (const TyTy::FnType *fntype);
83 : static std::string found_intrinsic_as_string (const TyTy::FnType *fntype);
84 : };
85 :
86 : } // namespace Resolver
87 : } // namespace Rust
88 :
89 : #endif
|