@@ -425,6 +425,10 @@ pub trait TypeReflection<'gcc, 'tcx> {
425
425
fn is_u128 ( & self , cx : & CodegenCx < ' gcc , ' tcx > ) -> bool ;
426
426
427
427
fn is_vector ( & self ) -> bool ;
428
+ /// Checks if 2 types are "known to be equal". Returns Some(true) if types are equal(e.g. bool and bool),
429
+ /// Some(false) if they can't possibly be equal(e.g. a struct and a float), and None if there is no way
430
+ /// to check for their equality(struct and struct)
431
+ fn known_eq ( & self , rhs : & Self , cx : & CodegenCx < ' gcc , ' tcx > ) -> Option < bool > ;
428
432
}
429
433
430
434
impl < ' gcc , ' tcx > TypeReflection < ' gcc , ' tcx > for Type < ' gcc > {
@@ -524,4 +528,43 @@ impl<'gcc, 'tcx> TypeReflection<'gcc, 'tcx> for Type<'gcc> {
524
528
525
529
false
526
530
}
531
+ fn known_eq ( & self , other : & Self , cx : & CodegenCx < ' gcc , ' tcx > ) -> Option < bool > {
532
+ // "Happy" path: types represented using the same pointer
533
+ if self == other {
534
+ return Some ( true ) ;
535
+ }
536
+ if self . is_bool ( ) {
537
+ return Some ( other. is_bool ( ) ) ;
538
+ } else if self . is_integral ( ) {
539
+ if !other. is_integral ( ) {
540
+ return Some ( false ) ;
541
+ }
542
+ return Some (
543
+ ( self . get_size ( ) == other. get_size ( ) )
544
+ && ( self . is_signed ( cx) == other. is_signed ( cx) ) ,
545
+ ) ;
546
+ } else if self . is_floating_point ( ) {
547
+ if !other. is_floating_point ( ) {
548
+ return Some ( false ) ;
549
+ }
550
+ return Some ( self . get_size ( ) == other. get_size ( ) ) ;
551
+ } else if self . is_vector ( ) {
552
+ if !other. is_vector ( ) {
553
+ return Some ( false ) ;
554
+ }
555
+ return None ;
556
+ } else if self . is_struct ( ) . is_some ( ) {
557
+ if other. is_struct ( ) . is_none ( ) {
558
+ return Some ( false ) ;
559
+ }
560
+ return None ;
561
+ } else if let Some ( s_ptr) = self . get_pointee ( ) {
562
+ let Some ( other_ptr) = other. get_pointee ( ) else {
563
+ return Some ( false ) ;
564
+ } ;
565
+ return s_ptr. known_eq ( & other_ptr, cx) ;
566
+ }
567
+ // Unknown type...
568
+ None
569
+ }
527
570
}
0 commit comments