@@ -61,7 +61,18 @@ pub(super) trait Strategy:
6161 input : & Input < ' _ > ,
6262 ) -> Option < HalfMatch > ;
6363
64- fn is_match ( & self , cache : & mut Cache , input : & Input < ' _ > ) -> bool ;
64+ fn is_match ( & self , cache : & mut Cache , input : & Input < ' _ > ) -> bool {
65+ self . try_is_match ( cache, input)
66+ . expect ( "PikeVM is disabled, use Regex::try_is_match_with" )
67+ }
68+
69+ // Returns an error only when the search needed the PikeVM but it was
70+ // disabled via 'Config::pikevm'.
71+ fn try_is_match (
72+ & self ,
73+ cache : & mut Cache ,
74+ input : & Input < ' _ > ,
75+ ) -> Result < bool , RetryFailError > ;
6576
6677 fn search_slots (
6778 & self ,
@@ -414,8 +425,12 @@ impl<P: PrefilterI> Strategy for Pre<P> {
414425 }
415426
416427 #[ cfg_attr( feature = "perf-inline" , inline( always) ) ]
417- fn is_match ( & self , cache : & mut Cache , input : & Input < ' _ > ) -> bool {
418- self . search ( cache, input) . is_some ( )
428+ fn try_is_match (
429+ & self ,
430+ cache : & mut Cache ,
431+ input : & Input < ' _ > ,
432+ ) -> Result < bool , RetryFailError > {
433+ Ok ( self . search ( cache, input) . is_some ( ) )
419434 }
420435
421436 #[ cfg_attr( feature = "perf-inline" , inline( always) ) ]
@@ -590,7 +605,7 @@ impl Core {
590605 e. search_slots ( & mut cache. backtrack , input, caps. slots_mut ( ) )
591606 } else {
592607 trace ! ( "using PikeVM for search at {:?}" , input. get_span( ) ) ;
593- let e = self . pikevm . get ( ) ;
608+ let e = self . pikevm . get ( ) . expect ( "PikeVM is required" ) ;
594609 e. search_slots ( & mut cache. pikevm , input, caps. slots_mut ( ) )
595610 } ;
596611 caps. set_pattern ( pid) ;
@@ -633,31 +648,38 @@ impl Core {
633648 "using PikeVM for capture search at {:?}" ,
634649 input. get_span( )
635650 ) ;
636- let e = self . pikevm . get ( ) ;
651+ let e = self . pikevm . get ( ) . expect ( "PikeVM is required" ) ;
637652 e. search_slots ( & mut cache. pikevm , input, slots)
638653 }
639654 }
640655
641- fn is_match_nofail ( & self , cache : & mut Cache , input : & Input < ' _ > ) -> bool {
656+ fn try_is_match_nofail (
657+ & self ,
658+ cache : & mut Cache ,
659+ input : & Input < ' _ > ,
660+ ) -> Result < bool , RetryFailError > {
642661 if let Some ( ref e) = self . onepass . get ( input) {
643662 trace ! (
644663 "using OnePass for is-match search at {:?}" ,
645664 input. get_span( )
646665 ) ;
647- e. search_slots ( & mut cache. onepass , input, & mut [ ] ) . is_some ( )
666+ Ok ( e. search_slots ( & mut cache. onepass , input, & mut [ ] ) . is_some ( ) )
648667 } else if let Some ( ref e) = self . backtrack . get ( input) {
649668 trace ! (
650669 "using BoundedBacktracker for is-match search at {:?}" ,
651670 input. get_span( )
652671 ) ;
653- e. is_match ( & mut cache. backtrack , input)
672+ Ok ( e. is_match ( & mut cache. backtrack , input) )
654673 } else {
655674 trace ! (
656675 "using PikeVM for is-match search at {:?}" ,
657676 input. get_span( )
658677 ) ;
659- let e = self . pikevm . get ( ) ;
660- e. is_match ( & mut cache. pikevm , input)
678+ let e = self
679+ . pikevm
680+ . get ( )
681+ . ok_or_else ( || RetryFailError :: from_offset ( input. start ( ) ) ) ?;
682+ Ok ( e. is_match ( & mut cache. pikevm , input) )
661683 }
662684 }
663685
@@ -769,17 +791,21 @@ impl Strategy for Core {
769791 }
770792
771793 #[ cfg_attr( feature = "perf-inline" , inline( always) ) ]
772- fn is_match ( & self , cache : & mut Cache , input : & Input < ' _ > ) -> bool {
794+ fn try_is_match (
795+ & self ,
796+ cache : & mut Cache ,
797+ input : & Input < ' _ > ,
798+ ) -> Result < bool , RetryFailError > {
773799 if let Some ( e) = self . dfa . get ( input) {
774800 trace ! (
775801 "using full DFA for is-match search at {:?}" ,
776802 input. get_span( )
777803 ) ;
778804 match e. try_search_half_fwd ( input) {
779- Ok ( x) => x. is_some ( ) ,
805+ Ok ( x) => Ok ( x. is_some ( ) ) ,
780806 Err ( _err) => {
781807 trace ! ( "full DFA half search failed: {_err}" ) ;
782- self . is_match_nofail ( cache, input)
808+ self . try_is_match_nofail ( cache, input)
783809 }
784810 }
785811 } else if let Some ( e) = self . hybrid . get ( input) {
@@ -788,14 +814,14 @@ impl Strategy for Core {
788814 input. get_span( )
789815 ) ;
790816 match e. try_search_half_fwd ( & mut cache. hybrid , input) {
791- Ok ( x) => x. is_some ( ) ,
817+ Ok ( x) => Ok ( x. is_some ( ) ) ,
792818 Err ( _err) => {
793819 trace ! ( "lazy DFA half search failed: {_err}" ) ;
794- self . is_match_nofail ( cache, input)
820+ self . try_is_match_nofail ( cache, input)
795821 }
796822 }
797823 } else {
798- self . is_match_nofail ( cache, input)
824+ self . try_is_match_nofail ( cache, input)
799825 }
800826 }
801827
@@ -902,7 +928,7 @@ impl Strategy for Core {
902928 "using PikeVM for overlapping search at {:?}" ,
903929 input. get_span( )
904930 ) ;
905- let e = self . pikevm . get ( ) ;
931+ let e = self . pikevm . get ( ) . expect ( "PikeVM is required" ) ;
906932 e. which_overlapping_matches ( & mut cache. pikevm , input, patset)
907933 }
908934}
@@ -1061,17 +1087,21 @@ impl Strategy for ReverseAnchored {
10611087 }
10621088
10631089 #[ cfg_attr( feature = "perf-inline" , inline( always) ) ]
1064- fn is_match ( & self , cache : & mut Cache , input : & Input < ' _ > ) -> bool {
1090+ fn try_is_match (
1091+ & self ,
1092+ cache : & mut Cache ,
1093+ input : & Input < ' _ > ,
1094+ ) -> Result < bool , RetryFailError > {
10651095 if input. get_anchored ( ) . is_anchored ( ) {
1066- return self . core . is_match ( cache, input) ;
1096+ return self . core . try_is_match ( cache, input) ;
10671097 }
10681098 match self . try_search_half_anchored_rev ( cache, input) {
10691099 Err ( _err) => {
10701100 trace ! ( "fast reverse anchored search failed: {_err}" ) ;
1071- self . core . is_match_nofail ( cache, input)
1101+ self . core . try_is_match_nofail ( cache, input)
10721102 }
1073- Ok ( None ) => false ,
1074- Ok ( Some ( _) ) => true ,
1103+ Ok ( None ) => Ok ( false ) ,
1104+ Ok ( Some ( _) ) => Ok ( true ) ,
10751105 }
10761106 }
10771107
@@ -1446,23 +1476,27 @@ impl Strategy for ReverseSuffix {
14461476 }
14471477
14481478 #[ cfg_attr( feature = "perf-inline" , inline( always) ) ]
1449- fn is_match ( & self , cache : & mut Cache , input : & Input < ' _ > ) -> bool {
1479+ fn try_is_match (
1480+ & self ,
1481+ cache : & mut Cache ,
1482+ input : & Input < ' _ > ,
1483+ ) -> Result < bool , RetryFailError > {
14501484 if input. get_anchored ( ) . is_anchored ( ) {
1451- return self . core . is_match ( cache, input) ;
1485+ return self . core . try_is_match ( cache, input) ;
14521486 }
14531487 match self . try_search_half_start ( cache, input) {
14541488 Err ( RetryError :: Quadratic ( _err) ) => {
14551489 trace ! ( "reverse suffix half optimization failed: {_err}" ) ;
1456- self . core . is_match_nofail ( cache, input)
1490+ self . core . try_is_match_nofail ( cache, input)
14571491 }
14581492 Err ( RetryError :: Fail ( _err) ) => {
14591493 trace ! (
14601494 "reverse suffix reverse fast half search failed: {_err}"
14611495 ) ;
1462- self . core . is_match_nofail ( cache, input)
1496+ self . core . try_is_match_nofail ( cache, input)
14631497 }
1464- Ok ( None ) => false ,
1465- Ok ( Some ( _) ) => true ,
1498+ Ok ( None ) => Ok ( false ) ,
1499+ Ok ( Some ( _) ) => Ok ( true ) ,
14661500 }
14671501 }
14681502
@@ -1851,21 +1885,25 @@ impl Strategy for ReverseInner {
18511885 }
18521886
18531887 #[ cfg_attr( feature = "perf-inline" , inline( always) ) ]
1854- fn is_match ( & self , cache : & mut Cache , input : & Input < ' _ > ) -> bool {
1888+ fn try_is_match (
1889+ & self ,
1890+ cache : & mut Cache ,
1891+ input : & Input < ' _ > ,
1892+ ) -> Result < bool , RetryFailError > {
18551893 if input. get_anchored ( ) . is_anchored ( ) {
1856- return self . core . is_match ( cache, input) ;
1894+ return self . core . try_is_match ( cache, input) ;
18571895 }
18581896 match self . try_search_full ( cache, input) {
18591897 Err ( RetryError :: Quadratic ( _err) ) => {
18601898 trace ! ( "reverse inner half optimization failed: {_err}" ) ;
1861- self . core . is_match_nofail ( cache, input)
1899+ self . core . try_is_match_nofail ( cache, input)
18621900 }
18631901 Err ( RetryError :: Fail ( _err) ) => {
18641902 trace ! ( "reverse inner fast half search failed: {_err}" ) ;
1865- self . core . is_match_nofail ( cache, input)
1903+ self . core . try_is_match_nofail ( cache, input)
18661904 }
1867- Ok ( None ) => false ,
1868- Ok ( Some ( _) ) => true ,
1905+ Ok ( None ) => Ok ( false ) ,
1906+ Ok ( Some ( _) ) => Ok ( true ) ,
18691907 }
18701908 }
18711909
0 commit comments