mojo/public/tools/mojom/mojom/generate/module.py
def IsBackwardCompatible(self, older_union, checker):
    """This union is backward-compatible with older_union if and only if all
    of the following conditions hold:
      - Any newly added field is tagged with a [MinVersion] attribute specifying
        a version number greater than all previously used [MinVersion]
        attributes within the union.
      - All fields present in older_union remain present in the new union,
        with the same ordinal value, same optional or non-optional status,
        same (or backward-compatible) type, and where applicable, the same
        [MinVersion] attribute value.
    """

    def buildOrdinalFieldMap(union):
      fields_by_ordinal = {}
      for field in union.fields:
        if field.ordinal in fields_by_ordinal:
          raise Exception('Multiple fields with ordinal %s in union %s.' %
                          (field.ordinal, union.mojom_name))
        fields_by_ordinal[field.ordinal] = field
      return fields_by_ordinal

    new_fields = buildOrdinalFieldMap(self)
    old_fields = buildOrdinalFieldMap(older_union)
    if len(new_fields) < len(old_fields):
      # At least one field was removed, which is not OK.
      return False

    max_old_min_version = 0
    for ordinal, old_field in old_fields.items():
      new_field = new_fields.get(ordinal)
      if not new_field:
        # A field was removed, which is not OK.
        return False
      if not _IsFieldBackwardCompatible(new_field, old_field, checker):
        # An field changed its type or MinVersion, which is not OK.
        return False
      old_min_version = old_field.min_version or 0
      if old_min_version > max_old_min_version:
        max_old_min_version = old_min_version

    new_ordinals = set(new_fields.keys()) - set(old_fields.keys())
    for ordinal in new_ordinals:
      if (new_fields[ordinal].min_version or 0) <= max_old_min_version:
        # New fields must use a MinVersion greater than any old fields.
        return False

    return True
This union is backward-compatible with older_union if and only if all
    of the following conditions hold:
      - Any newly added field is tagged with a [MinVersion] attribute specifying
        a version number greater than all previously used [MinVersion]
        attributes within the union.
      - All fields present in older_union remain present in the new union,
        with the same ordinal value, same optional or non-optional status,
        same (or backward-compatible) type, and where applicable, the same
        [MinVersion] attribute value.
    
This union is backward-compatible with older_union if and only if all
of the following conditions hold:
Any newly added field is tagged with a [MinVersion] attribute specifying
a version number greater than all previously used [MinVersion]
attributes within the union.
All fields present in older_union remain present in the new union,
with the same ordinal value, same optional or non-optional status,
same (or backward-compatible) type, and where applicable, the same
[MinVersion] attribute value.
This union is backward - compatible with older_union if and only if all of the following conditions hold : Any newly added field is tagged with a [ MinVersion ] attribute specifying a version number greater than all previously used [ MinVersion ] attributes within the union . All fields present in older_union remain present in the new union with the same ordinal value same optional or non - optional status same ( or backward - compatible ) type and where applicable the same [ MinVersion ] attribute value .
def IsBackwardCompatible(self, older_union, checker):
    def buildOrdinalFieldMap(union):
      fields_by_ordinal = {}
      for field in union.fields:
        if field.ordinal in fields_by_ordinal:
          raise Exception('Multiple fields with ordinal %s in union %s.' %
                          (field.ordinal, union.mojom_name))
        fields_by_ordinal[field.ordinal] = field
      return fields_by_ordinal
    new_fields = buildOrdinalFieldMap(self)
    old_fields = buildOrdinalFieldMap(older_union)
    if len(new_fields) < len(old_fields):
      return False
    max_old_min_version = 0
    for ordinal, old_field in old_fields.items():
      new_field = new_fields.get(ordinal)
      if not new_field:
        return False
      if not _IsFieldBackwardCompatible(new_field, old_field, checker):
        return False
      old_min_version = old_field.min_version or 0
      if old_min_version > max_old_min_version:
        max_old_min_version = old_min_version
    new_ordinals = set(new_fields.keys()) - set(old_fields.keys())
    for ordinal in new_ordinals:
      if (new_fields[ordinal].min_version or 0) <= max_old_min_version:
        return False
    return True
def IsBackwardCompatible ( self , older_union , checker ) : def buildOrdinalFieldMap ( union ) : fields_by_ordinal = { } for field in union . fields : if field . ordinal in fields_by_ordinal : raise Exception ( 'Multiple fields with ordinal %s in union %s.' % ( field . ordinal , union . mojom_name ) ) fields_by_ordinal [ field . ordinal ] = field return fields_by_ordinal new_fields = buildOrdinalFieldMap ( self ) old_fields = buildOrdinalFieldMap ( older_union ) if len ( new_fields ) < len ( old_fields ) : return False max_old_min_version = 0 for ordinal , old_field in old_fields . items ( ) : new_field = new_fields . get ( ordinal ) if not new_field : return False if not _IsFieldBackwardCompatible ( new_field , old_field , checker ) : return False old_min_version = old_field . min_version or 0 if old_min_version > max_old_min_version : max_old_min_version = old_min_version new_ordinals = set ( new_fields . keys ( ) ) - set ( old_fields . keys ( ) ) for ordinal in new_ordinals : if ( new_fields [ ordinal ] . min_version or 0 ) <= max_old_min_version : return False return True
This union is backward-compatible with older_union if and only if all
of the following conditions hold:
 Any newly added field is tagged with a [MinVersion] attribute specifying
a version number greater than all previously used [MinVersion]
attributes within the union.
This union is backward - compatible with older_union if and only if all of the following conditions hold : Any newly added field is tagged with a [ MinVersion ] attribute specifying a version number greater than all previously used [ MinVersion ] attributes within the union .
"""This union is backward-compatible with older_union if and only if all
    of the following conditions hold:
      - Any newly added field is tagged with a [MinVersion] attribute specifying
        a version number greater than all previously used [MinVersion]
        attributes within the union.
      - All fields present in older_union remain present in the new union,
        with the same ordinal value, same optional or non-optional status,
        same (or backward-compatible) type, and where applicable, the same
        [MinVersion] attribute value.
    """ # At least one field was removed, which is not OK. # A field was removed, which is not OK. # An field changed its type or MinVersion, which is not OK. # New fields must use a MinVersion greater than any old fields.
self
older_union
checker