@@ -232,7 +232,10 @@ pub fn init_loop(
232232 if let Some ( index_cursor_id) = index_cursor_id {
233233 program. emit_insn ( Insn :: OpenRead {
234234 cursor_id : index_cursor_id,
235- root_page : index. as_ref ( ) . unwrap ( ) . root_page ,
235+ root_page : index
236+ . as_ref ( )
237+ . expect ( "index must exist when index_cursor_id is Some" )
238+ . root_page ,
236239 db : table. database_id ,
237240 } ) ;
238241 }
@@ -248,7 +251,11 @@ pub fn init_loop(
248251 if let Some ( index_cursor_id) = index_cursor_id {
249252 program. emit_insn ( Insn :: OpenWrite {
250253 cursor_id : index_cursor_id,
251- root_page : index. as_ref ( ) . unwrap ( ) . root_page . into ( ) ,
254+ root_page : index
255+ . as_ref ( )
256+ . expect ( "index must exist when index_cursor_id is Some" )
257+ . root_page
258+ . into ( ) ,
252259 db : table. database_id ,
253260 } ) ;
254261 }
@@ -289,15 +296,23 @@ pub fn init_loop(
289296 . resolve_cursor_id ( & CursorKey :: table ( target_table. internal_id ) ) ;
290297 program. emit_insn ( Insn :: OpenWrite {
291298 cursor_id : target_table_cursor_id,
292- root_page : target_table. btree ( ) . unwrap ( ) . root_page . into ( ) ,
299+ root_page : target_table
300+ . btree ( )
301+ . expect ( "target table must be a BTree table" )
302+ . root_page
303+ . into ( ) ,
293304 db : table. database_id ,
294305 } ) ;
295306 }
296307 }
297308 if let Some ( index_cursor_id) = index_cursor_id {
298309 program. emit_insn ( Insn :: OpenWrite {
299310 cursor_id : index_cursor_id,
300- root_page : index. as_ref ( ) . unwrap ( ) . root_page . into ( ) ,
311+ root_page : index
312+ . as_ref ( )
313+ . expect ( "index must exist when index_cursor_id is Some" )
314+ . root_page
315+ . into ( ) ,
301316 db : table. database_id ,
302317 } ) ;
303318 }
@@ -413,10 +428,15 @@ pub fn init_loop(
413428 db : table. database_id ,
414429 } ) ;
415430 }
416- let index_cursor_id = index_cursor_id. unwrap ( ) ;
431+ let index_cursor_id = index_cursor_id
432+ . expect ( "index_cursor_id must be Some for index method query" ) ;
417433 program. emit_insn ( Insn :: OpenRead {
418434 cursor_id : index_cursor_id,
419- root_page : table. op . index ( ) . unwrap ( ) . root_page ,
435+ root_page : table
436+ . op
437+ . index ( )
438+ . expect ( "operation must be index method query" )
439+ . root_page ,
420440 db : table. database_id ,
421441 } ) ;
422442 }
@@ -433,8 +453,12 @@ pub fn init_loop(
433453 let meta = ConditionMetadata {
434454 jump_if_condition_is_true : false ,
435455 jump_target_when_true : jump_target,
436- jump_target_when_false : t_ctx. label_main_loop_end . unwrap ( ) ,
437- jump_target_when_null : t_ctx. label_main_loop_end . unwrap ( ) ,
456+ jump_target_when_false : t_ctx
457+ . label_main_loop_end
458+ . expect ( "label_main_loop_end must be set" ) ,
459+ jump_target_when_null : t_ctx
460+ . label_main_loop_end
461+ . expect ( "label_main_loop_end must be set" ) ,
438462 } ;
439463 translate_condition_expr ( program, tables, & cond. expr , meta, & t_ctx. resolver ) ?;
440464 program. preassign_label_to_next_insn ( jump_target) ;
@@ -474,7 +498,9 @@ pub fn open_loop(
474498 // This is used to determine whether to emit actual columns or NULLs for the columns of the right table.
475499 if let Some ( join_info) = table. join_info . as_ref ( ) {
476500 if join_info. outer {
477- let lj_meta = t_ctx. meta_left_joins [ joined_table_index] . as_ref ( ) . unwrap ( ) ;
501+ let lj_meta = t_ctx. meta_left_joins [ joined_table_index]
502+ . as_ref ( )
503+ . expect ( "left join metadata must exist for outer join" ) ;
478504 program. emit_insn ( Insn :: Integer {
479505 value : 0 ,
480506 dest : lj_meta. reg_match_flag ,
@@ -744,7 +770,9 @@ pub fn open_loop(
744770 // for the right table's cursor.
745771 if let Some ( join_info) = table. join_info . as_ref ( ) {
746772 if join_info. outer {
747- let lj_meta = t_ctx. meta_left_joins [ joined_table_index] . as_ref ( ) . unwrap ( ) ;
773+ let lj_meta = t_ctx. meta_left_joins [ joined_table_index]
774+ . as_ref ( )
775+ . expect ( "left join metadata must exist for outer join" ) ;
748776 program. resolve_label ( lj_meta. label_match_flag_set_true , program. offset ( ) ) ;
749777 program. emit_insn ( Insn :: Integer {
750778 value : 1 ,
@@ -912,7 +940,10 @@ fn emit_loop_source(
912940 row_source,
913941 registers,
914942 ..
915- } = t_ctx. meta_group_by . as_ref ( ) . unwrap ( ) ;
943+ } = t_ctx
944+ . meta_group_by
945+ . as_ref ( )
946+ . expect ( "meta_group_by must be set when emitting to group by" ) ;
916947
917948 let start_reg = registers. reg_group_by_source_cols_start ;
918949 let mut cur_reg = start_reg;
@@ -1024,7 +1055,9 @@ fn emit_loop_source(
10241055 None
10251056 } ;
10261057
1027- let col_start = t_ctx. reg_result_cols_start . unwrap ( ) ;
1058+ let col_start = t_ctx
1059+ . reg_result_cols_start
1060+ . expect ( "reg_result_cols_start must be set" ) ;
10281061
10291062 // Process only non-aggregate columns
10301063 let non_agg_columns = plan
@@ -1046,7 +1079,9 @@ fn emit_loop_source(
10461079 }
10471080 if let Some ( label) = label_emit_nonagg_only_once {
10481081 program. resolve_label ( label, program. offset ( ) ) ;
1049- let flag = t_ctx. reg_nonagg_emit_once_flag . unwrap ( ) ;
1082+ let flag = t_ctx
1083+ . reg_nonagg_emit_once_flag
1084+ . expect ( "reg_nonagg_emit_once_flag must be set" ) ;
10501085 program. emit_int ( 1 , flag) ;
10511086 }
10521087
@@ -1070,7 +1105,9 @@ fn emit_loop_source(
10701105 offset_jump_to,
10711106 t_ctx. reg_nonagg_emit_once_flag ,
10721107 t_ctx. reg_offset ,
1073- t_ctx. reg_result_cols_start . unwrap ( ) ,
1108+ t_ctx
1109+ . reg_result_cols_start
1110+ . expect ( "reg_result_cols_start must be set" ) ,
10741111 t_ctx. limit_ctx ,
10751112 ) ?;
10761113
@@ -1210,7 +1247,8 @@ pub fn close_loop(
12101247 Operation :: IndexMethodQuery ( _) => {
12111248 program. resolve_label ( loop_labels. next , program. offset ( ) ) ;
12121249 program. emit_insn ( Insn :: Next {
1213- cursor_id : index_cursor_id. unwrap ( ) ,
1250+ cursor_id : index_cursor_id
1251+ . expect ( "index_cursor_id must be Some for index method query" ) ,
12141252 pc_if_next : loop_labels. loop_start ,
12151253 } ) ;
12161254 program. preassign_label_to_next_insn ( loop_labels. loop_end ) ;
@@ -1221,7 +1259,9 @@ pub fn close_loop(
12211259 // and emit a row with NULLs for the right table, and then jump back to the next row of the left table.
12221260 if let Some ( join_info) = table. join_info . as_ref ( ) {
12231261 if join_info. outer {
1224- let lj_meta = t_ctx. meta_left_joins [ table_index] . as_ref ( ) . unwrap ( ) ;
1262+ let lj_meta = t_ctx. meta_left_joins [ table_index]
1263+ . as_ref ( )
1264+ . expect ( "left join metadata must exist for outer join" ) ;
12251265 // The left join match flag is set to 1 when there is any match on the right table
12261266 // (e.g. SELECT * FROM t1 LEFT JOIN t2 ON t1.a = t2.a).
12271267 // If the left join match flag has been set to 1, we jump to the next row on the outer table,
@@ -1385,7 +1425,7 @@ fn emit_seek(
13851425 if affinities. chars ( ) . any ( |c| c != affinity:: SQLITE_AFF_NONE ) {
13861426 program. emit_insn ( Insn :: Affinity {
13871427 start_reg,
1388- count : std:: num:: NonZeroUsize :: new ( num_regs) . unwrap ( ) ,
1428+ count : std:: num:: NonZeroUsize :: new ( num_regs) . expect ( "num_regs must be non-zero" ) ,
13891429 affinities : seek_def
13901430 . iter_affinity ( & seek_def. start )
13911431 . map ( |affinity| affinity. aff_mask ( ) )
@@ -1507,7 +1547,7 @@ fn emit_seek_termination(
15071547 rowid_reg = Some ( program. alloc_register ( ) ) ;
15081548 program. emit_insn ( Insn :: RowId {
15091549 cursor_id : seek_cursor_id,
1510- dest : rowid_reg. unwrap ( ) ,
1550+ dest : rowid_reg. expect ( "rowid_reg was just set to Some" ) ,
15111551 } ) ;
15121552
15131553 affinity = if let Some ( table_ref) = tables
@@ -1551,39 +1591,39 @@ fn emit_seek_termination(
15511591 target_pc : loop_end,
15521592 } ) ,
15531593 ( false , SeekOp :: GE { .. } ) => program. emit_insn ( Insn :: Ge {
1554- lhs : rowid_reg. unwrap ( ) ,
1594+ lhs : rowid_reg. expect ( "rowid_reg must be Some when is_index is false" ) ,
15551595 rhs : start_reg,
15561596 target_pc : loop_end,
15571597 flags : CmpInsFlags :: default ( )
15581598 . jump_if_null ( )
1559- . with_affinity ( affinity. unwrap ( ) ) ,
1599+ . with_affinity ( affinity. expect ( "affinity must be Some when is_index is false" ) ) ,
15601600 collation : program. curr_collation ( ) ,
15611601 } ) ,
15621602 ( false , SeekOp :: GT ) => program. emit_insn ( Insn :: Gt {
1563- lhs : rowid_reg. unwrap ( ) ,
1603+ lhs : rowid_reg. expect ( "rowid_reg must be Some when is_index is false" ) ,
15641604 rhs : start_reg,
15651605 target_pc : loop_end,
15661606 flags : CmpInsFlags :: default ( )
15671607 . jump_if_null ( )
1568- . with_affinity ( affinity. unwrap ( ) ) ,
1608+ . with_affinity ( affinity. expect ( "affinity must be Some when is_index is false" ) ) ,
15691609 collation : program. curr_collation ( ) ,
15701610 } ) ,
15711611 ( false , SeekOp :: LE { .. } ) => program. emit_insn ( Insn :: Le {
1572- lhs : rowid_reg. unwrap ( ) ,
1612+ lhs : rowid_reg. expect ( "rowid_reg must be Some when is_index is false" ) ,
15731613 rhs : start_reg,
15741614 target_pc : loop_end,
15751615 flags : CmpInsFlags :: default ( )
15761616 . jump_if_null ( )
1577- . with_affinity ( affinity. unwrap ( ) ) ,
1617+ . with_affinity ( affinity. expect ( "affinity must be Some when is_index is false" ) ) ,
15781618 collation : program. curr_collation ( ) ,
15791619 } ) ,
15801620 ( false , SeekOp :: LT ) => program. emit_insn ( Insn :: Lt {
1581- lhs : rowid_reg. unwrap ( ) ,
1621+ lhs : rowid_reg. expect ( "rowid_reg must be Some when is_index is false" ) ,
15821622 rhs : start_reg,
15831623 target_pc : loop_end,
15841624 flags : CmpInsFlags :: default ( )
15851625 . jump_if_null ( )
1586- . with_affinity ( affinity. unwrap ( ) ) ,
1626+ . with_affinity ( affinity. expect ( "affinity must be Some when is_index is false" ) ) ,
15871627 collation : program. curr_collation ( ) ,
15881628 } ) ,
15891629 } ;
0 commit comments