code: def lower_context_field_existence(ir_blocks, query_metadata_table):
      
      def regular_visitor_fn(expression):
          """Expression visitor function that rewrites ContextFieldExistence expressions."""
          if not isinstance(expression, ContextFieldExistence):
              return expression
  
          location_type = query_metadata_table.get_location_info(expression.location).type
  
          # Since this function is only used in blocks that aren't ConstructResult,
          # the location check is performed using a regular ContextField expression.
          return BinaryComposition(
              u'!=',
              ContextField(expression.location, location_type),
              NullLiteral)
  
      def construct_result_visitor_fn(expression):
          """Expression visitor function that rewrites ContextFieldExistence expressions."""
          if not isinstance(expression, ContextFieldExistence):
              return expression
  
          location_type = query_metadata_table.get_location_info(expression.location).type
  
          # Since this function is only used in ConstructResult blocks,
          # the location check is performed using the special OutputContextVertex expression.
          return BinaryComposition(
              u'!=',
              OutputContextVertex(expression.location, location_type),
              NullLiteral)
  
      new_ir_blocks = []
      for block in ir_blocks:
          new_block = None
          if isinstance(block, ConstructResult):
              new_block = block.visit_and_update_expressions(construct_result_visitor_fn)
          else:
              new_block = block.visit_and_update_expressions(regular_visitor_fn)
          new_ir_blocks.append(new_block)
  
      return new_ir_blocks
docs: Lower ContextFieldExistence expressions into lower-level expressions.