Skip to content

Tidy up Rust RoomVersion structs#19766

Merged
erikjohnston merged 7 commits into
developfrom
erikj/room_versions_rust
May 14, 2026
Merged

Tidy up Rust RoomVersion structs#19766
erikjohnston merged 7 commits into
developfrom
erikj/room_versions_rust

Conversation

@erikjohnston
Copy link
Copy Markdown
Member

@erikjohnston erikjohnston commented May 8, 2026

This is in prep for using the room versions more from Rust.

Main changes:

  • Change it so each room version is defined as a delta to the last one. This is a cosmetic change that makes it easier to ensure the room version definitions are correct (as they're defined as deltas from previous versions).
  • Move constants to RoomVersion constants, like RoomVersion::V1, for convenience.
  • Change visibility of various attributes.

@erikjohnston erikjohnston marked this pull request as ready for review May 8, 2026 12:21
@erikjohnston erikjohnston requested a review from a team as a code owner May 8, 2026 12:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors Synapse’s Rust-side room version definitions (RoomVersion) to make them easier to maintain and more convenient to consume from Rust/PyO3, ahead of increased Rust usage of room versions.

Changes:

  • Reworks room version definitions so each version is expressed as a delta from the previous version via associated RoomVersion::{V1..} constants.
  • Promotes various version constants to pub and updates mapping accessors to use Clone instead of Copy.
  • Adds Display for RoomVersion and a FromStr parser returning references to known room versions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
rust/src/room_versions.rs Refactors RoomVersion constants into associated consts, adds parsing/formatting traits, and updates mapping access patterns.
changelog.d/19766.misc Adds a changelog entry for the Rust room version refactor.
Comments suppressed due to low confidence (2)

rust/src/room_versions.rs:448

  • items() uses self.versions.read().unwrap(), which can panic on a poisoned lock and bring down the Python interpreter. Please handle the poisoning case and return a PyRuntimeError, consistent with add_room_version/__len__.
        let versions = self.versions.read().unwrap();
        Ok(versions.iter().map(|v| (v.identifier, v.clone())).collect())
    }

rust/src/room_versions.rs:466

  • get() uses self.versions.read().unwrap(), which can panic if the lock is poisoned (crashing the process). Consider using read().map_err(|_| PyRuntimeError::new_err(...))? here as well for consistency and safety.
        let versions = self.versions.read().unwrap();
        if let Some(version) = versions.iter().find(|v| v.identifier == key) {
            return Ok(Some(version.clone().into_bound_py_any(py)?));
        }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rust/src/room_versions.rs
Comment thread rust/src/room_versions.rs Outdated
Comment thread rust/src/room_versions.rs
RoomVersion::MSC3757V10,
RoomVersion::MSC3757V11,
RoomVersion::HYDRA_V11,
];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

MSC4242V12 supposed to be in this list? 🤷 I guess it wasn't there before

Overall, I haven't gone through everything with a fine tooth comb to spot this kind of thing if it happened elsewhere but this stood out to me.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, we only add it in to that mapping if the experimental config is set:

# MSC4242: State DAGs
self.msc4242_enabled: bool = experimental.get("msc4242_enabled", False)
if self.msc4242_enabled:
# Enable the room version
KNOWN_ROOM_VERSIONS.add_room_version(RoomVersions.MSC4242v12)

@erikjohnston erikjohnston merged commit ace8447 into develop May 14, 2026
78 of 81 checks passed
@erikjohnston erikjohnston deleted the erikj/room_versions_rust branch May 14, 2026 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants