code: def _sanity_check_block_pairwise_constraints(ir_blocks):
      
      for first_block, second_block in pairwise(ir_blocks):
          # Always Filter before MarkLocation, never after.
          if isinstance(first_block, MarkLocation) and isinstance(second_block, Filter):
              raise AssertionError(u'Found Filter after MarkLocation block: {}'.format(ir_blocks))
  
          # There's no point in marking the same location twice in a row.
          if isinstance(first_block, MarkLocation) and isinstance(second_block, MarkLocation):
              raise AssertionError(u'Found consecutive MarkLocation blocks: {}'.format(ir_blocks))
  
          # Traverse blocks with optional=True are immediately followed
          # by a MarkLocation, CoerceType or Filter block.
          if isinstance(first_block, Traverse) and first_block.optional:
              if not isinstance(second_block, (MarkLocation, CoerceType, Filter)):
                  raise AssertionError(u'Expected MarkLocation, CoerceType or Filter after Traverse '
                                       u'with optional=True. Found: {}'.format(ir_blocks))
  
          # Backtrack blocks with optional=True are immediately followed by a MarkLocation block.
          if isinstance(first_block, Backtrack) and first_block.optional:
              if not isinstance(second_block, MarkLocation):
                  raise AssertionError(u'Expected MarkLocation after Backtrack with optional=True, '
                                       u'but none was found: {}'.format(ir_blocks))
  
          # Recurse blocks are immediately preceded by a MarkLocation or Backtrack block.
          if isinstance(second_block, Recurse):
              if not (isinstance(first_block, MarkLocation) or isinstance(first_block, Backtrack)):
                  raise AssertionError(u'Expected MarkLocation or Backtrack before Recurse, but none '
                                       u'was found: {}'.format(ir_blocks))
docs: Assert that adjacent blocks obey all invariants.