Skip to content

Commit

Permalink
!fixup remove the recursion_limit increase.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Dec 18, 2024
1 parent 888082e commit 92cdf2e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
34 changes: 34 additions & 0 deletions crates/matrix-sdk-common/src/deserialized_responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,25 @@ pub struct EncryptionInfo {
/// Previously, this differed from [`TimelineEvent`] by wrapping an
/// [`AnySyncTimelineEvent`] instead of an [`AnyTimelineEvent`], but nowadays
/// they are essentially identical, and one of them should probably be removed.
//
// 🚨 Note about this type, please read! 🚨
//
// `SyncTimelineEvent` is heavily used across the SDK crates. In some cases, we
// are reaching a [`recursion_limit`] when the compiler is trying to figure out
// if `SyncTimelineEvent` implements `Sync` when it's embedded in other types.
//
// We want to help the compiler so that one doesn't need to increase the
// `recursion_limit`. We stop the recursive check by (un)safely implement `Sync`
// and `Send` on `SyncTimelineEvent` directly. However, before doing that, we
// need to ensure that every field of `SyncTimelineEvent` implements `Sync` and
// `Send` too. That's why we have `assert_sync_and_send` in a const expression
// so that it is checked at compile-time. If these checks pass, we can (un)safely
// implement `Sync` and `Send` for `SyncTimelineEvent`.
//
// If a field must be added to this type, please update the calls to
// `assert_sync_and_send`.
//
// [`recursion_limit`]: https://doc.rust-lang.org/reference/attributes/limits.html#the-recursion_limit-attribute
#[derive(Clone, Debug, Serialize)]
pub struct SyncTimelineEvent {
/// The event itself, together with any information on decryption.
Expand All @@ -316,6 +335,21 @@ pub struct SyncTimelineEvent {
pub push_actions: Vec<Action>,
}

const _: fn() = || {
fn assert_sync_and_send<T: ?Sized + Sync + Send>() {}

// `SyncTimelineEvent::kind` is of type `TimelineEventKind`.
assert_sync_and_send::<TimelineEventKind>();

// `SyncTimelineEvent::push_actions` is of type `Vec<Action>`.
assert_sync_and_send::<Vec<Action>>();
};

// All fields of `SyncTimelineEvent` implements `Sync` and `Send`: we can safely
// implement `Sync` and `Send` for `SyncTimelineEvent` directly.
unsafe impl Sync for SyncTimelineEvent {}
unsafe impl Send for SyncTimelineEvent {}

impl SyncTimelineEvent {
/// Create a new `SyncTimelineEvent` from the given raw event.
///
Expand Down
2 changes: 0 additions & 2 deletions crates/matrix-sdk-ui/tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#![recursion_limit = "256"]

use itertools::Itertools as _;
use matrix_sdk::deserialized_responses::TimelineEvent;
use ruma::{events::AnyStateEvent, serde::Raw, EventId, RoomId};
Expand Down

0 comments on commit 92cdf2e

Please sign in to comment.