Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

refactor(rome_formatter): Use custom trait for unique LabelIds #4599

Merged
merged 2 commits into from
Jun 22, 2023

Conversation

MichaReiser
Copy link
Contributor

@MichaReiser MichaReiser commented Jun 21, 2023

Summary

See astral-sh/ruff#5263

Rust 1.72.0 changes TypeId from a u64 to a u128. This breaks Rome's release build because it increases the size of FormatElement.

This PR removes the dependency on TypeId for LabelId and instead introduces a new trait that downstream crates should implement on an enum defining all labels for that project.

This approach has two downsides:

  • The API cannot statically enforce that a project uses a single Label. Mixing two Label could result in two labels being equal that should not be equal. I added a
    debug assertion that compares the names of the labels to mitigate the risk.
  • Implementing the first Label requires more boilerplate code than before

One main upside is that it allows a project to define all labels in a single place (and search for all label usages).

Test Plan

cargo test and cargo build --release -p rome_formatter with Rust 1.72.0

Changelog

  • The PR requires a changelog line

Documentation

  • The PR requires documentation
  • I will create a new PR to update the documentation

@netlify
Copy link

netlify bot commented Jun 21, 2023

Deploy Preview for docs-rometools ready!

Name Link
🔨 Latest commit a79e6ea
🔍 Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/6494ac9b7139450008228605
😎 Deploy Preview https://deploy-preview-4599--docs-rometools.netlify.app/playground
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions github-actions bot added the A-Formatter Area: formatter label Jun 21, 2023
@@ -196,143 +197,7 @@ use crate::context::{JsFormatContext, JsFormatOptions};
use crate::cst::FormatJsSyntaxNode;
use crate::syntax_rewriter::transform;

/// Used to get an object that knows how to format this object.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is unrelated to the change. Happy to undo. But we should either remove the shared_traits.rs file or include it.

Copy link
Contributor

@ematipico ematipico Jun 22, 2023

Choose a reason for hiding this comment

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

Probably, we want to remove the file and keep the code.

This code would fail when publishing the crate, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay. I'll undo

@MichaReiser MichaReiser marked this pull request as ready for review June 21, 2023 22:02
@MichaReiser MichaReiser force-pushed the replace-typeid-for-label-with-trait branch from 9c012b6 to a5243d4 Compare June 21, 2023 22:17
Copy link
Contributor

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Thank you @MichaReiser !! 🙏

Signed-off-by: Micha Reiser <micha@reiser.io>
@MichaReiser MichaReiser merged commit def1bac into main Jun 22, 2023
@MichaReiser MichaReiser deleted the replace-typeid-for-label-with-trait branch June 22, 2023 20:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Formatter Area: formatter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants