@@ -619,35 +619,40 @@ impl<'tcx> BuilderSpirv<'tcx> {
619
619
Ok ( ( ) )
620
620
}
621
621
622
- SpirvConst :: Composite ( v) => v. iter ( ) . fold ( Ok ( ( ) ) , |composite_legal, field| {
623
- let field_entry = & self . id_to_const . borrow ( ) [ field] ;
624
- let field_legal_in_composite = field_entry. legal . and (
625
- // `field` is itself some legal `SpirvConst`, but can we have
626
- // it as part of an `OpConstantComposite`?
627
- match field_entry. val {
628
- SpirvConst :: PtrTo { .. } => Err ( IllegalConst :: Shallow (
629
- LeafIllegalConst :: CompositeContainsPtrTo ,
630
- ) ) ,
631
- _ => Ok ( ( ) ) ,
632
- } ,
633
- ) ;
634
-
635
- match ( composite_legal, field_legal_in_composite) {
636
- ( Ok ( ( ) ) , Ok ( ( ) ) ) => Ok ( ( ) ) ,
637
- ( Err ( illegal) , Ok ( ( ) ) ) | ( Ok ( ( ) ) , Err ( illegal) ) => Err ( illegal) ,
638
-
639
- // Combining two causes of an illegal `SpirvConst` has to
640
- // take into account which is "worse", i.e. which imposes
641
- // more restrictions on how the resulting value can be used.
642
- // `Indirect` is worse than `Shallow` because it cannot be
643
- // materialized at runtime in the same way `Shallow` can be.
644
- ( Err ( illegal @ IllegalConst :: Indirect ( _) ) , Err ( _) )
645
- | ( Err ( _) , Err ( illegal @ IllegalConst :: Indirect ( _) ) )
646
- | ( Err ( illegal @ IllegalConst :: Shallow ( _) ) , Err ( IllegalConst :: Shallow ( _) ) ) => {
647
- Err ( illegal)
622
+ SpirvConst :: Composite ( v) => v
623
+ . iter ( )
624
+ . map ( |field| {
625
+ let field_entry = & self . id_to_const . borrow ( ) [ field] ;
626
+ field_entry. legal . and (
627
+ // `field` is itself some legal `SpirvConst`, but can we have
628
+ // it as part of an `OpConstantComposite`?
629
+ match field_entry. val {
630
+ SpirvConst :: PtrTo { .. } => Err ( IllegalConst :: Shallow (
631
+ LeafIllegalConst :: CompositeContainsPtrTo ,
632
+ ) ) ,
633
+ _ => Ok ( ( ) ) ,
634
+ } ,
635
+ )
636
+ } )
637
+ . reduce ( |a, b| {
638
+ match ( a, b) {
639
+ ( Ok ( ( ) ) , Ok ( ( ) ) ) => Ok ( ( ) ) ,
640
+ ( Err ( illegal) , Ok ( ( ) ) ) | ( Ok ( ( ) ) , Err ( illegal) ) => Err ( illegal) ,
641
+
642
+ // Combining two causes of an illegal `SpirvConst` has to
643
+ // take into account which is "worse", i.e. which imposes
644
+ // more restrictions on how the resulting value can be used.
645
+ // `Indirect` is worse than `Shallow` because it cannot be
646
+ // materialized at runtime in the same way `Shallow` can be.
647
+ ( Err ( illegal @ IllegalConst :: Indirect ( _) ) , Err ( _) )
648
+ | ( Err ( _) , Err ( illegal @ IllegalConst :: Indirect ( _) ) )
649
+ | (
650
+ Err ( illegal @ IllegalConst :: Shallow ( _) ) ,
651
+ Err ( IllegalConst :: Shallow ( _) ) ,
652
+ ) => Err ( illegal) ,
648
653
}
649
- }
650
- } ) ,
654
+ } )
655
+ . unwrap_or ( Ok ( ( ) ) ) ,
651
656
652
657
SpirvConst :: PtrTo { pointee } => match self . id_to_const . borrow ( ) [ & pointee] . legal {
653
658
Ok ( ( ) ) => Ok ( ( ) ) ,
0 commit comments