@@ -202,12 +202,12 @@ use middle::resolve::DefMap;
202
202
use middle:: trans:: adt;
203
203
use middle:: trans:: base:: * ;
204
204
use middle:: trans:: build:: * ;
205
+ use middle:: trans:: build;
205
206
use middle:: trans:: callee;
206
207
use middle:: trans:: cleanup;
207
208
use middle:: trans:: cleanup:: CleanupMethods ;
208
209
use middle:: trans:: common:: * ;
209
210
use middle:: trans:: consts;
210
- use middle:: trans:: controlflow;
211
211
use middle:: trans:: datum:: * ;
212
212
use middle:: trans:: expr:: Dest ;
213
213
use middle:: trans:: expr;
@@ -220,14 +220,12 @@ use util::ppaux::{Repr, vec_map_to_string};
220
220
221
221
use std;
222
222
use std:: collections:: HashMap ;
223
- use std:: cell:: Cell ;
224
223
use std:: rc:: Rc ;
225
224
use std:: gc:: { Gc } ;
226
225
use syntax:: ast;
227
226
use syntax:: ast:: Ident ;
228
227
use syntax:: codemap:: Span ;
229
228
use syntax:: fold:: Folder ;
230
- use syntax:: parse:: token:: InternedString ;
231
229
232
230
#[ deriving( PartialEq ) ]
233
231
pub enum VecLenOpt {
@@ -301,20 +299,6 @@ fn trans_opt<'a>(mut bcx: &'a Block<'a>, o: &Opt) -> opt_result<'a> {
301
299
}
302
300
}
303
301
304
- fn variant_opt ( bcx : & Block , pat_id : ast:: NodeId ) -> Opt {
305
- let ccx = bcx. ccx ( ) ;
306
- let def = ccx. tcx . def_map . borrow ( ) . get_copy ( & pat_id) ;
307
- match def {
308
- def:: DefVariant ( enum_id, var_id, _) => {
309
- let variant = ty:: enum_variant_with_id ( ccx. tcx ( ) , enum_id, var_id) ;
310
- var ( variant. disr_val , adt:: represent_node ( bcx, pat_id) , var_id)
311
- }
312
- _ => {
313
- ccx. sess ( ) . bug ( "non-variant or struct in variant_opt()" ) ;
314
- }
315
- }
316
- }
317
-
318
302
#[ deriving( Clone ) ]
319
303
pub enum TransBindingMode {
320
304
TrByCopy ( /* llbinding */ ValueRef ) ,
@@ -630,26 +614,15 @@ fn get_options(bcx: &Block, m: &[Match], col: uint) -> Vec<Opt> {
630
614
ast:: PatLit ( l) => {
631
615
add_to_set ( ccx. tcx ( ) , & mut found, lit ( l) ) ;
632
616
}
633
- ast:: PatIdent ( ..) => {
617
+ ast:: PatIdent ( ..) | ast :: PatEnum ( .. ) | ast :: PatStruct ( .. ) => {
634
618
// This is either an enum variant or a variable binding.
635
619
let opt_def = ccx. tcx . def_map . borrow ( ) . find_copy ( & cur. id ) ;
636
620
match opt_def {
637
- Some ( def:: DefVariant ( ..) ) => {
638
- add_to_set ( ccx. tcx ( ) , & mut found,
639
- variant_opt ( bcx, cur. id ) ) ;
640
- }
641
- _ => { }
642
- }
643
- }
644
- ast:: PatEnum ( ..) | ast:: PatStruct ( ..) => {
645
- // This could be one of: a tuple-like enum variant, a
646
- // struct-like enum variant, or a struct.
647
- let opt_def = ccx. tcx . def_map . borrow ( ) . find_copy ( & cur. id ) ;
648
- match opt_def {
649
- Some ( def:: DefFn ( ..) ) |
650
- Some ( def:: DefVariant ( ..) ) => {
621
+ Some ( def:: DefVariant ( enum_id, var_id, _) ) => {
622
+ let variant = ty:: enum_variant_with_id ( ccx. tcx ( ) , enum_id, var_id) ;
651
623
add_to_set ( ccx. tcx ( ) , & mut found,
652
- variant_opt ( bcx, cur. id ) ) ;
624
+ var ( variant. disr_val ,
625
+ adt:: represent_node ( bcx, cur. id ) , var_id) ) ;
653
626
}
654
627
_ => { }
655
628
}
@@ -795,56 +768,33 @@ fn any_irrefutable_adt_pat(bcx: &Block, m: &[Match], col: uint) -> bool {
795
768
} )
796
769
}
797
770
798
- struct DynamicFailureHandler < ' a > {
799
- bcx : & ' a Block < ' a > ,
800
- sp : Span ,
801
- msg : InternedString ,
802
- finished : Cell < Option < BasicBlockRef > > ,
803
- }
804
-
805
- impl < ' a > DynamicFailureHandler < ' a > {
806
- fn handle_fail ( & self ) -> BasicBlockRef {
807
- match self . finished . get ( ) {
808
- Some ( bb) => return bb,
809
- _ => ( ) ,
810
- }
811
-
812
- let fcx = self . bcx . fcx ;
813
- let fail_cx = fcx. new_block ( false , "case_fallthrough" , None ) ;
814
- controlflow:: trans_fail ( fail_cx, self . sp , self . msg . clone ( ) ) ;
815
- self . finished . set ( Some ( fail_cx. llbb ) ) ;
816
- fail_cx. llbb
817
- }
818
- }
819
-
820
771
/// What to do when the pattern match fails.
821
772
enum FailureHandler < ' a > {
822
773
Infallible ,
823
774
JumpToBasicBlock ( BasicBlockRef ) ,
824
- DynamicFailureHandlerClass ( Box < DynamicFailureHandler < ' a > > ) ,
775
+ Unreachable
825
776
}
826
777
827
778
impl < ' a > FailureHandler < ' a > {
828
779
fn is_infallible ( & self ) -> bool {
829
780
match * self {
830
781
Infallible => true ,
831
- _ => false ,
782
+ _ => false
832
783
}
833
784
}
834
785
835
786
fn is_fallible ( & self ) -> bool {
836
787
!self . is_infallible ( )
837
788
}
838
789
839
- fn handle_fail ( & self ) -> BasicBlockRef {
790
+ fn handle_fail ( & self , bcx : & Block ) {
840
791
match * self {
841
- Infallible => {
842
- fail ! ( "attempted to fail in infallible failure handler!" )
843
- }
844
- JumpToBasicBlock ( basic_block) => basic_block,
845
- DynamicFailureHandlerClass ( ref dynamic_failure_handler) => {
846
- dynamic_failure_handler. handle_fail ( )
847
- }
792
+ Infallible =>
793
+ fail ! ( "attempted to fail in infallible failure handler!" ) ,
794
+ JumpToBasicBlock ( basic_block) =>
795
+ Br ( bcx, basic_block) ,
796
+ Unreachable =>
797
+ build:: Unreachable ( bcx)
848
798
}
849
799
}
850
800
}
@@ -1005,7 +955,7 @@ fn compile_guard<'a, 'b>(
1005
955
// condition explicitly rather than (possibly) falling back to
1006
956
// the default arm.
1007
957
& JumpToBasicBlock ( _) if m. len ( ) == 1 && has_genuine_default => {
1008
- Br ( bcx , chk. handle_fail ( ) ) ;
958
+ chk. handle_fail ( bcx ) ;
1009
959
}
1010
960
_ => {
1011
961
compile_submatch ( bcx, m, vals, chk, has_genuine_default) ;
@@ -1030,7 +980,7 @@ fn compile_submatch<'a, 'b>(
1030
980
let mut bcx = bcx;
1031
981
if m. len ( ) == 0 u {
1032
982
if chk. is_fallible ( ) {
1033
- Br ( bcx , chk. handle_fail ( ) ) ;
983
+ chk. handle_fail ( bcx ) ;
1034
984
}
1035
985
return ;
1036
986
}
@@ -1301,7 +1251,7 @@ fn compile_submatch_continue<'a, 'b>(
1301
1251
// condition explicitly rather than (eventually) falling back to
1302
1252
// the last default arm.
1303
1253
& JumpToBasicBlock ( _) if defaults. len ( ) == 1 && has_genuine_default => {
1304
- Br ( else_cx , chk. handle_fail ( ) ) ;
1254
+ chk. handle_fail ( else_cx ) ;
1305
1255
}
1306
1256
_ => {
1307
1257
compile_submatch ( else_cx,
@@ -1395,21 +1345,10 @@ fn trans_match_inner<'a>(scope_cx: &'a Block<'a>,
1395
1345
}
1396
1346
1397
1347
let t = node_id_type ( bcx, discr_expr. id ) ;
1398
- let chk = {
1399
- if ty:: type_is_empty ( tcx, t) {
1400
- // Special case for empty types
1401
- let fail_cx = Cell :: new ( None ) ;
1402
- let fail_handler = box DynamicFailureHandler {
1403
- bcx : scope_cx,
1404
- sp : discr_expr. span ,
1405
- msg : InternedString :: new ( "scrutinizing value that can't \
1406
- exist") ,
1407
- finished : fail_cx,
1408
- } ;
1409
- DynamicFailureHandlerClass ( fail_handler)
1410
- } else {
1411
- Infallible
1412
- }
1348
+ let chk = if ty:: type_is_empty ( tcx, t) {
1349
+ Unreachable
1350
+ } else {
1351
+ Infallible
1413
1352
} ;
1414
1353
1415
1354
let arm_datas: Vec < ArmData > = arms. iter ( ) . map ( |arm| ArmData {
0 commit comments