23
23
from .metadata import QueryMetadataTable
24
24
25
25
26
- def sanity_check_ir_blocks_from_frontend (
26
+ def self_consistency_check_ir_blocks_from_frontend (
27
27
ir_blocks : List [BasicBlock ], query_metadata_table : QueryMetadataTable
28
28
) -> None :
29
29
"""Assert that IR blocks originating from the frontend do not have nonsensical structure.
30
30
31
31
Args:
32
- ir_blocks: list of BasicBlocks representing the IR to sanity- check
33
- query_metadata_table: QueryMetadataTable object that captures information about the query
32
+ ir_blocks: list of BasicBlocks representing the IR to self-consistency check.
33
+ query_metadata_table: QueryMetadataTable object that captures information about the query.
34
34
35
35
Raises:
36
36
AssertionError, if the IR has unexpected structure. If the IR produced by the front-end
@@ -40,19 +40,19 @@ def sanity_check_ir_blocks_from_frontend(
40
40
if not ir_blocks :
41
41
raise AssertionError ("Received no ir_blocks: {}" .format (ir_blocks ))
42
42
43
- _sanity_check_fold_scope_locations_are_unique (ir_blocks )
44
- _sanity_check_no_nested_folds (ir_blocks )
45
- _sanity_check_query_root_block (ir_blocks )
46
- _sanity_check_output_source_follower_blocks (ir_blocks )
47
- _sanity_check_block_pairwise_constraints (ir_blocks )
48
- _sanity_check_mark_location_preceding_optional_traverse (ir_blocks )
49
- _sanity_check_every_location_is_marked (ir_blocks )
50
- _sanity_check_coerce_type_outside_of_fold (ir_blocks )
51
- _sanity_check_all_marked_locations_are_registered (ir_blocks , query_metadata_table )
52
- _sanity_check_registered_locations_parent_locations (query_metadata_table )
43
+ _assert_fold_scope_locations_are_unique (ir_blocks )
44
+ _assert_no_nested_folds (ir_blocks )
45
+ _assert_query_root_block (ir_blocks )
46
+ _assert_output_source_follower_blocks (ir_blocks )
47
+ _assert_block_pairwise_constraints (ir_blocks )
48
+ _assert_mark_location_preceding_optional_traverse (ir_blocks )
49
+ _assert_every_location_is_marked (ir_blocks )
50
+ _assert_coerce_type_outside_of_fold (ir_blocks )
51
+ _assert_all_marked_locations_are_registered (ir_blocks , query_metadata_table )
52
+ _assert_registered_locations_parent_locations (query_metadata_table )
53
53
54
54
55
- def _sanity_check_registered_locations_parent_locations (
55
+ def _assert_registered_locations_parent_locations (
56
56
query_metadata_table : QueryMetadataTable ,
57
57
) -> None :
58
58
"""Assert that all registered locations' parent locations are also registered."""
@@ -76,7 +76,7 @@ def _sanity_check_registered_locations_parent_locations(
76
76
query_metadata_table .get_location_info (location_info .parent_location )
77
77
78
78
79
- def _sanity_check_all_marked_locations_are_registered (
79
+ def _assert_all_marked_locations_are_registered (
80
80
ir_blocks : List [BasicBlock ], query_metadata_table : QueryMetadataTable
81
81
) -> None :
82
82
"""Assert that all locations in MarkLocation blocks have registered and valid metadata."""
@@ -103,7 +103,7 @@ def _sanity_check_all_marked_locations_are_registered(
103
103
)
104
104
105
105
106
- def _sanity_check_fold_scope_locations_are_unique (ir_blocks : List [BasicBlock ]) -> None :
106
+ def _assert_fold_scope_locations_are_unique (ir_blocks : List [BasicBlock ]) -> None :
107
107
"""Assert that every FoldScopeLocation that exists on a Fold block is unique."""
108
108
observed_locations : Dict [FoldScopeLocation , Fold ] = dict ()
109
109
for block in ir_blocks :
@@ -117,7 +117,7 @@ def _sanity_check_fold_scope_locations_are_unique(ir_blocks: List[BasicBlock]) -
117
117
observed_locations [block .fold_scope_location ] = block
118
118
119
119
120
- def _sanity_check_no_nested_folds (ir_blocks : List [BasicBlock ]) -> None :
120
+ def _assert_no_nested_folds (ir_blocks : List [BasicBlock ]) -> None :
121
121
"""Assert that there are no nested Fold contexts, and that every Fold has a matching Unfold."""
122
122
fold_seen = False
123
123
for block in ir_blocks :
@@ -135,7 +135,7 @@ def _sanity_check_no_nested_folds(ir_blocks: List[BasicBlock]) -> None:
135
135
fold_seen = False
136
136
137
137
138
- def _sanity_check_query_root_block (ir_blocks : List [BasicBlock ]) -> None :
138
+ def _assert_query_root_block (ir_blocks : List [BasicBlock ]) -> None :
139
139
"""Assert that QueryRoot is always the first block, and only the first block."""
140
140
if not isinstance (ir_blocks [0 ], QueryRoot ):
141
141
raise AssertionError ("The first block was not QueryRoot: {}" .format (ir_blocks ))
@@ -144,7 +144,7 @@ def _sanity_check_query_root_block(ir_blocks: List[BasicBlock]) -> None:
144
144
raise AssertionError ("Found QueryRoot after the first block: {}" .format (ir_blocks ))
145
145
146
146
147
- def _sanity_check_construct_result_block (ir_blocks : List [BasicBlock ]) -> None :
147
+ def _self_consistency_check_construct_result_block (ir_blocks : List [BasicBlock ]) -> None :
148
148
"""Assert that ConstructResult is always the last block, and only the last block."""
149
149
if not isinstance (ir_blocks [- 1 ], ConstructResult ):
150
150
raise AssertionError ("The last block was not ConstructResult: {}" .format (ir_blocks ))
@@ -155,7 +155,7 @@ def _sanity_check_construct_result_block(ir_blocks: List[BasicBlock]) -> None:
155
155
)
156
156
157
157
158
- def _sanity_check_output_source_follower_blocks (ir_blocks : List [BasicBlock ]) -> None :
158
+ def _assert_output_source_follower_blocks (ir_blocks : List [BasicBlock ]) -> None :
159
159
"""Ensure there are no Traverse / Backtrack / Recurse blocks after an OutputSource block."""
160
160
seen_output_source = False
161
161
for block in ir_blocks :
@@ -170,7 +170,7 @@ def _sanity_check_output_source_follower_blocks(ir_blocks: List[BasicBlock]) ->
170
170
)
171
171
172
172
173
- def _sanity_check_block_pairwise_constraints (ir_blocks : List [BasicBlock ]) -> None :
173
+ def _assert_block_pairwise_constraints (ir_blocks : List [BasicBlock ]) -> None :
174
174
"""Assert that adjacent blocks obey all invariants."""
175
175
for first_block , second_block in pairwise (ir_blocks ):
176
176
# Always Filter before MarkLocation, never after.
@@ -207,7 +207,9 @@ def _sanity_check_block_pairwise_constraints(ir_blocks: List[BasicBlock]) -> Non
207
207
)
208
208
209
209
210
- def _sanity_check_mark_location_preceding_optional_traverse (ir_blocks : List [BasicBlock ]) -> None :
210
+ def _assert_mark_location_preceding_optional_traverse (
211
+ ir_blocks : List [BasicBlock ],
212
+ ) -> None :
211
213
"""Assert that optional Traverse blocks are preceded by a MarkLocation."""
212
214
# Once all fold blocks are removed, each optional Traverse must have
213
215
# a MarkLocation block immediately before it.
@@ -222,7 +224,7 @@ def _sanity_check_mark_location_preceding_optional_traverse(ir_blocks: List[Basi
222
224
)
223
225
224
226
225
- def _sanity_check_every_location_is_marked (ir_blocks : List [BasicBlock ]) -> None :
227
+ def _assert_every_location_is_marked (ir_blocks : List [BasicBlock ]) -> None :
226
228
"""Ensure that every new location is marked with a MarkLocation block."""
227
229
# Exactly one MarkLocation block is found between any block that starts an interval of blocks
228
230
# that all affect the same query position, and the first subsequent block that affects a
@@ -255,7 +257,7 @@ def _sanity_check_every_location_is_marked(ir_blocks: List[BasicBlock]) -> None:
255
257
mark_location_blocks_count = 0
256
258
257
259
258
- def _sanity_check_coerce_type_outside_of_fold (ir_blocks : List [BasicBlock ]):
260
+ def _assert_coerce_type_outside_of_fold (ir_blocks : List [BasicBlock ]) -> None :
259
261
"""Ensure that CoerceType not in a @fold are followed by a MarkLocation or Filter block."""
260
262
is_in_fold = False
261
263
for first_block , second_block in pairwise (ir_blocks ):
0 commit comments