@@ -19,12 +19,6 @@ extern crate rustc_driver;
19
19
extern crate rustc_interface;
20
20
extern crate stable_mir;
21
21
22
- use stable_mir:: crate_def:: CrateDef ;
23
- use stable_mir:: mir:: alloc:: GlobalAlloc ;
24
- use stable_mir:: mir:: mono:: { Instance , InstanceKind , StaticDef } ;
25
- use stable_mir:: mir:: { Body , TerminatorKind } ;
26
- use stable_mir:: ty:: { Allocation , ConstantKind , RigidTy , TyKind } ;
27
- use stable_mir:: { CrateItem , CrateItems , ItemKind } ;
28
22
use std:: ascii:: Char ;
29
23
use std:: assert_matches:: assert_matches;
30
24
use std:: cmp:: { max, min} ;
@@ -33,6 +27,13 @@ use std::ffi::CStr;
33
27
use std:: io:: Write ;
34
28
use std:: ops:: ControlFlow ;
35
29
30
+ use stable_mir:: crate_def:: CrateDef ;
31
+ use stable_mir:: mir:: Body ;
32
+ use stable_mir:: mir:: alloc:: GlobalAlloc ;
33
+ use stable_mir:: mir:: mono:: { Instance , StaticDef } ;
34
+ use stable_mir:: ty:: { Allocation , ConstantKind } ;
35
+ use stable_mir:: { CrateItem , CrateItems , ItemKind } ;
36
+
36
37
const CRATE_NAME : & str = "input" ;
37
38
38
39
/// This function uses the Stable MIR APIs to get information about the test crate.
@@ -44,7 +45,6 @@ fn test_stable_mir() -> ControlFlow<()> {
44
45
check_len ( * get_item ( & items, ( ItemKind :: Static , "LEN" ) ) . unwrap ( ) ) ;
45
46
check_cstr ( * get_item ( & items, ( ItemKind :: Static , "C_STR" ) ) . unwrap ( ) ) ;
46
47
check_other_consts ( * get_item ( & items, ( ItemKind :: Fn , "other_consts" ) ) . unwrap ( ) ) ;
47
- check_type_id ( * get_item ( & items, ( ItemKind :: Fn , "check_type_id" ) ) . unwrap ( ) ) ;
48
48
ControlFlow :: Continue ( ( ) )
49
49
}
50
50
@@ -107,7 +107,9 @@ fn check_other_consts(item: CrateItem) {
107
107
// Instance body will force constant evaluation.
108
108
let body = Instance :: try_from ( item) . unwrap ( ) . body ( ) . unwrap ( ) ;
109
109
let assigns = collect_consts ( & body) ;
110
- assert_eq ! ( assigns. len( ) , 8 ) ;
110
+ assert_eq ! ( assigns. len( ) , 10 ) ;
111
+ let mut char_id = None ;
112
+ let mut bool_id = None ;
111
113
for ( name, alloc) in assigns {
112
114
match name. as_str ( ) {
113
115
"_max_u128" => {
@@ -149,35 +151,21 @@ fn check_other_consts(item: CrateItem) {
149
151
assert_eq ! ( max( first, second) as u32 , u32 :: MAX ) ;
150
152
assert_eq ! ( min( first, second) , 10 ) ;
151
153
}
154
+ "_bool_id" => {
155
+ bool_id = Some ( alloc) ;
156
+ }
157
+ "_char_id" => {
158
+ char_id = Some ( alloc) ;
159
+ }
152
160
_ => {
153
161
unreachable ! ( "{name} -- {alloc:?}" )
154
162
}
155
163
}
156
164
}
157
- }
158
-
159
- /// Check that we can retrieve the type id of char and bool, and that they have different values.
160
- fn check_type_id ( item : CrateItem ) {
161
- let body = Instance :: try_from ( item) . unwrap ( ) . body ( ) . unwrap ( ) ;
162
- let mut ids: Vec < u128 > = vec ! [ ] ;
163
- for term in body. blocks . iter ( ) . map ( |bb| & bb. terminator ) {
164
- match & term. kind {
165
- TerminatorKind :: Call { func, destination, .. } => {
166
- let TyKind :: RigidTy ( ty) = func. ty ( body. locals ( ) ) . unwrap ( ) . kind ( ) else {
167
- unreachable ! ( )
168
- } ;
169
- let RigidTy :: FnDef ( def, args) = ty else { unreachable ! ( ) } ;
170
- let instance = Instance :: resolve ( def, & args) . unwrap ( ) ;
171
- assert_eq ! ( instance. kind, InstanceKind :: Intrinsic ) ;
172
- let dest_ty = destination. ty ( body. locals ( ) ) . unwrap ( ) ;
173
- let alloc = instance. try_const_eval ( dest_ty) . unwrap ( ) ;
174
- ids. push ( alloc. read_uint ( ) . unwrap ( ) ) ;
175
- }
176
- _ => { /* Do nothing */ }
177
- }
178
- }
179
- assert_eq ! ( ids. len( ) , 2 ) ;
180
- assert_ne ! ( ids[ 0 ] , ids[ 1 ] ) ;
165
+ let bool_id = bool_id. unwrap ( ) ;
166
+ let char_id = char_id. unwrap ( ) ;
167
+ // FIXME(stable_mir): add `read_ptr` to `Allocation`
168
+ assert_ne ! ( bool_id, char_id) ;
181
169
}
182
170
183
171
/// Collects all the constant assignments.
@@ -235,6 +223,7 @@ fn generate_input(path: &str) -> std::io::Result<()> {
235
223
file,
236
224
r#"
237
225
#![feature(core_intrinsics)]
226
+ #![expect(internal_features)]
238
227
use std::intrinsics::type_id;
239
228
240
229
static LEN: usize = 2;
@@ -254,11 +243,8 @@ fn generate_input(path: &str) -> std::io::Result<()> {
254
243
let _ptr = &BAR;
255
244
let _null_ptr: *const u8 = NULL;
256
245
let _tuple = TUPLE;
257
- }}
258
-
259
- fn check_type_id() {{
260
- let _char_id = type_id::<char>();
261
- let _bool_id = type_id::<bool>();
246
+ let _char_id = const {{ type_id::<char>() }};
247
+ let _bool_id = const {{ type_id::<bool>() }};
262
248
}}
263
249
264
250
pub fn main() {{
0 commit comments