code: def _sanity_check_all_marked_locations_are_registered(ir_blocks, query_metadata_table):
      
      # Grab all the registered locations, then make sure that:
      # - Any location that appears in a MarkLocation block is also registered.
      # - There are no registered locations that do not appear in a MarkLocation block.
      registered_locations = {
          location
          for location, _ in query_metadata_table.registered_locations
      }
  
      ir_encountered_locations = {
          block.location
          for block in ir_blocks
          if isinstance(block, MarkLocation)
      }
  
      unregistered_locations = ir_encountered_locations - registered_locations
      unencountered_locations = registered_locations - ir_encountered_locations
      if unregistered_locations:
          raise AssertionError(u'IR blocks unexpectedly contain locations not registered in the '
                               u'QueryMetadataTable: {}'.format(unregistered_locations))
      if unencountered_locations:
          raise AssertionError(u'QueryMetadataTable unexpectedly contains registered locations that '
                               u'never appear in the IR blocks: {}'.format(unencountered_locations))
docs: Assert that all locations in MarkLocation blocks have registered and valid metadata.