-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat(swc/common): wrap serialized struct with versioned (#5060: Part 3) #5128
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we add something like into_inner()
instead of using .take()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong Default
impl should not exist.
We should use Take::dummy()
instead
crates/swc_common/src/comments.rs
Outdated
@@ -548,6 +548,16 @@ pub struct Comment { | |||
pub text: String, | |||
} | |||
|
|||
impl Default for Comment { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still required, even if we add into_inner()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default was added to satisfy mem::take in VersionedSerializable::take
. if there's other way default is not required mandatoriliy.
I'm bit unsure if I understood the suggestion correctly, mind elaborate bit more? The way I understood is let each struct implement Take::dummy()
instead of default, and VersionedSerializable should utilize it for the take
. Not sure where into_inner
plays in here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
into_inner
take ownership of VersionedSerializable
so it does not require take(&mut self.0.1)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Default
constraint comes from it.
@@ -36,6 +36,19 @@ pub struct Diagnostic { | |||
pub suggestions: Vec<CodeSuggestion>, | |||
} | |||
|
|||
impl Default for Diagnostic { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
crates/swc_common/src/plugin.rs
Outdated
@@ -41,6 +41,12 @@ pub enum PluginError { | |||
Serialize(String), | |||
} | |||
|
|||
impl Default for PluginError { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
crates/swc_common/src/syntax_pos.rs
Outdated
@@ -130,6 +130,12 @@ pub enum FileName { | |||
Custom(String), | |||
} | |||
|
|||
impl Default for FileName { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
crates/swc_common/src/syntax_pos.rs
Outdated
@@ -805,7 +811,7 @@ impl Sub<BytePos> for NonNarrowChar { | |||
derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) | |||
)] | |||
#[cfg_attr(feature = "rkyv", archive_attr(repr(C), derive(bytecheck::CheckBytes)))] | |||
#[derive(Clone)] | |||
#[derive(Clone, Default)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
crates/swc_plugin_proxy/src/memory_interop/read_returned_result_from_host.rs
Show resolved
Hide resolved
@@ -60,7 +62,7 @@ where | |||
pub fn read_returned_result_from_host<F, R>(f: F) -> Option<R> | |||
where | |||
F: FnOnce(i32) -> i32, | |||
R: rkyv::Archive, | |||
R: rkyv::Archive + std::default::Default, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
crates/swc_common/src/syntax_pos.rs
Outdated
@@ -1193,6 +1210,7 @@ pub struct LineCol { | |||
pub col: u32, | |||
} | |||
|
|||
#[derive(Default)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
crates/swc_plugin_proxy/src/memory_interop/read_returned_result_from_host.rs
Outdated
Show resolved
Hide resolved
@@ -85,11 +88,11 @@ where | |||
pub fn read_returned_result_from_host_fallible<F, R>(f: F) -> Option<R> | |||
where | |||
F: FnOnce(i32) -> i32, | |||
R: rkyv::Archive, | |||
R: rkyv::Archive + std::default::Default, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
89966ab
to
e48bcbd
Compare
e48bcbd
to
509e766
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
swc-bump:
- swc_common --breaking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Automated review comment generated by auto-rebase script
Description:
This PR actually wraps up structs with
VersionedSerializable
for the plugins.PluginSerializedBytes
's serialize / deserialize interface now explicitly acceptsVersionedSerializable
only. Most changes are straightforward, with implementingdefault
for few structs & couple ofcopy
around diagnostic / comment to workaround moves.There is one item I need to revisit later (main...kwonoj:swc:feat-versioned-serialized#diff-b2b47f82dd3bafcc79a1e0e6ec2ccb75624c020e295e2a65c03d01058b56da92R178) since
Result<T>
is not possible to useVersionedSerializable::take()
due to lacks of default.BREAKING CHANGE:
Related issue (if exists):
#5060