Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform property migrations in rbx_binary serializer #339

Merged

Conversation

kennethloeffler
Copy link
Member

@kennethloeffler kennethloeffler commented Aug 3, 2023

Related: #335

Yeah, so this sucked pretty hard. rbx_xml will be easier (I hope)...

I've added descriptions to some of the commits here in an attempt to elucidate my thought process, if anything is unclear please ask questions

Contains both migrated and migrated-to properties
This is necessary because if collect_type_info processes a
migrated-to property first, and then processes a migrated property
later, PropInfo.migration will still be None and we won't be able to
apply migrations

This would not work if a logical property had multiple, different
migration operations associated with it, but thankfully that is not
the case!
This is kind of ugly...

Because migrated and migrated-to properties can both exist in the same
DOM, we're won't necessarily get a consistent variant type here, so we just ignore
any migration failures and assume values that fail are already the
correct type
Woo, lookin good!
Copy link
Member

@Dekkonot Dekkonot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new migration field on PropInfo needs documentation but otherwise looks good.

rbx_binary/src/serializer/state.rs Outdated Show resolved Hide resolved
Comment on lines +615 to +622
if let Some(migration) = prop_info.migration {
match migration.perform(&value) {
Ok(new_value) => Cow::Owned(new_value),
Err(_) => value,
}
} else {
value
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migrations seem unlikely to fail anyway, so I think this is fine. The one we might run into is someone setting an invalid Font enum value, but I don't think that's something we can reasonably account for right now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be a little stranger than you're realizing - the Err branch will be hit under normal operation. The reason why is because in this PR, all migrated properties are collated under a single PropInfo. For reference, here's what PropInfo looks like during the migrated properties test:

PropInfo {
    prop_type: Color3uint8,
    serialized_name: "Color3uint8",
    aliases: {
        "BrickColor",
        "brickColor",
    },
    default_value: Color3uint8(
        Color3uint8 {
            r: 163,
            g: 162,
            b: 165,
        },
    ),
    migration: Some(
        PropertyMigration {
            new_property_name: "Color",
            migration: BrickColorToColor,
        },
    ),
}

This means that in serialize_properties, some properties will be Variant::BrickColor, some properties will be Variant::Color3uint8 or Variant::Color3, and the migration will fail - but we expect it to!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh that's kinda gross. I wonder if it's worth attempting a conversion in the same way we do with rbx_xml or if it's just a lost cause?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is likely throwaway code I'm not sure if it matters too much - any mismatches will be caught later in the match prop_info.prop_type. I tried to make this less ugly, but I wasn't able to do so while still having one prop chunk per logical property. I don't think there's a good way to do it without significantly changing the binary serializer

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose another option is we make the migration catch multiple types of variants? That feels less technically correct but is probably safer anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's necessary. Besides applying migrations for select properties, there's no other changes to the behavior of serialize_properties as a result of this, and I'll want to delete this code ASAP regardless

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair enough. We're probably good to merge this then.

@Dekkonot Dekkonot merged commit 9a6e991 into rojo-rbx:master Aug 4, 2023
2 checks passed
@kennethloeffler kennethloeffler deleted the serializer-resolve-migrations-early branch August 4, 2023 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants