@@ -19,12 +19,6 @@ extern crate rustc_driver;
1919extern crate rustc_interface;
2020extern crate stable_mir;
2121
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 } ;
2822use std:: ascii:: Char ;
2923use std:: assert_matches:: assert_matches;
3024use std:: cmp:: { max, min} ;
@@ -33,6 +27,13 @@ use std::ffi::CStr;
3327use std:: io:: Write ;
3428use std:: ops:: ControlFlow ;
3529
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+
3637const CRATE_NAME : & str = "input" ;
3738
3839/// This function uses the Stable MIR APIs to get information about the test crate.
@@ -44,7 +45,6 @@ fn test_stable_mir() -> ControlFlow<()> {
4445 check_len ( * get_item ( & items, ( ItemKind :: Static , "LEN" ) ) . unwrap ( ) ) ;
4546 check_cstr ( * get_item ( & items, ( ItemKind :: Static , "C_STR" ) ) . unwrap ( ) ) ;
4647 check_other_consts ( * get_item ( & items, ( ItemKind :: Fn , "other_consts" ) ) . unwrap ( ) ) ;
47- check_type_id ( * get_item ( & items, ( ItemKind :: Fn , "check_type_id" ) ) . unwrap ( ) ) ;
4848 ControlFlow :: Continue ( ( ) )
4949}
5050
@@ -107,7 +107,9 @@ fn check_other_consts(item: CrateItem) {
107107 // Instance body will force constant evaluation.
108108 let body = Instance :: try_from ( item) . unwrap ( ) . body ( ) . unwrap ( ) ;
109109 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 ;
111113 for ( name, alloc) in assigns {
112114 match name. as_str ( ) {
113115 "_max_u128" => {
@@ -149,35 +151,21 @@ fn check_other_consts(item: CrateItem) {
149151 assert_eq ! ( max( first, second) as u32 , u32 :: MAX ) ;
150152 assert_eq ! ( min( first, second) , 10 ) ;
151153 }
154+ "_bool_id" => {
155+ bool_id = Some ( alloc) ;
156+ }
157+ "_char_id" => {
158+ char_id = Some ( alloc) ;
159+ }
152160 _ => {
153161 unreachable ! ( "{name} -- {alloc:?}" )
154162 }
155163 }
156164 }
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) ;
181169}
182170
183171/// Collects all the constant assignments.
@@ -235,6 +223,7 @@ fn generate_input(path: &str) -> std::io::Result<()> {
235223 file,
236224 r#"
237225 #![feature(core_intrinsics)]
226+ #![expect(internal_features)]
238227 use std::intrinsics::type_id;
239228
240229 static LEN: usize = 2;
@@ -254,11 +243,8 @@ fn generate_input(path: &str) -> std::io::Result<()> {
254243 let _ptr = &BAR;
255244 let _null_ptr: *const u8 = NULL;
256245 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>() }};
262248 }}
263249
264250 pub fn main() {{
0 commit comments