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

[Merged by Bors] - chore: replace removed typfify::TypeSpace::to_string() with prettyplease #73

Closed
wants to merge 1 commit into from

Conversation

ahl
Copy link
Contributor

@ahl ahl commented Mar 17, 2023

The use of typify assumed that rustfmt was installed... which turned out not to be a great assumption. We've modified typify to remove the dependency on rustfmt-wrapper and have removed the interface that used it ToString::to_string(). Instead we recommend that consumers use prettyplease for build.rs uses such as the one in this crate. See oxidecomputer/typify#221

Alternatively, the build.rs could just emit the tokens unformatted (to remove the build-time dependency on prettyplease and syn), but that seems annoying if and when you need to look at the generated code.

FWIW syn is an existing dependency; prettyplease is the only new new crate I see in Cargo.lock.

I can share the full diff between the old and new versions of the substrait_text.rs, but here's a sample:

@@ -1593,22 +1831,27 @@
             T: std::convert::TryInto<Option<super::SessionDependent>>,
             T::Error: std::fmt::Display,
         {
-            self.session_dependent = value.try_into().map_err(|e| {
-                format!(
-                    "error converting supplied value for session_dependent: {}",
-                    e
-                )
-            });
             self
+                .session_dependent = value
+                .try_into()
+                .map_err(|e| {
+                    format!(
+                        "error converting supplied value for session_dependent: {}", e
+                    )
+                });
+            self
         }
         pub fn variadic<T>(mut self, value: T) -> Self
         where
             T: std::convert::TryInto<Option<super::VariadicBehavior>>,
             T::Error: std::fmt::Display,
         {
-            self.variadic = value
+            self
+                .variadic = value
                 .try_into()
-                .map_err(|e| format!("error converting supplied value for variadic: {}", e));
+                .map_err(|e| {
+                    format!("error converting supplied value for variadic: {}", e)
+                });
             self
         }
         pub fn window_type<T>(mut self, value: T) -> Self

@CLAassistant
Copy link

CLAassistant commented Mar 17, 2023

CLA assistant check
All committers have signed the CLA.

@ahl
Copy link
Contributor Author

ahl commented Mar 18, 2023

I see that CI has failed, but I'm not sure how to fix it.

Copy link
Member

@mbrobbel mbrobbel left a comment

Choose a reason for hiding this comment

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

prost-build = { version = "0.11", default-features = false }
prost-types = "0.11"
prost-wkt-build = { version = "0.4", optional = true }
protobuf-src = { version = "1", optional = true }
schemars = "0.8"
serde_yaml = "0.9"
syn = "1.0.109"
Copy link
Member

@mbrobbel mbrobbel Mar 19, 2023

Choose a reason for hiding this comment

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

We just need the parsing feature of syn, and it seems version 2 was just released:

Suggested change
syn = "1.0.109"
syn = { version = "2.0.2", default-features = false, features = ["parsing"] }

@ahl
Copy link
Contributor Author

ahl commented Mar 19, 2023

prettyplease uses syn 1 so I didn't think this would work, and indeed it didn't:

error[E0308]: `?` operator has incompatible types
  --> build.rs:74:36
   |
74 |             prettyplease::unparse(&syn::parse2::<syn::File>(type_space.to_stream())?),
   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `syn::file::File`, found struct `syn::File`
   |
   = note: `?` operator cannot convert from `syn::File` to `syn::file::File`
   = note: struct `syn::File` and struct `syn::file::File` have similar names, but are actually distinct types
note: struct `syn::File` is defined in crate `syn`
  --> /Users/ahl/.cargo/registry/src/github.com-1ecc6299db9ec823/syn-2.0.2/src/file.rs:3:1
   |
3  | / ast_struct! {
4  | |     /// A complete file of Rust source code.
5  | |     ///
6  | |     /// Typically `File` objects are created with [`parse_file`].
...  |
85 | |     }
86 | | }
   | |_^
note: struct `syn::file::File` is defined in crate `syn`
  --> /Users/ahl/.cargo/registry/src/github.com-1ecc6299db9ec823/syn-1.0.109/src/file.rs:3:1
   |
3  | / ast_struct! {
4  | |     /// A complete file of Rust source code.
5  | |     ///
6  | |     /// *This type is available only if Syn is built with the `"full"` feature.*
...  |
85 | |     }
86 | | }
   | |_^
   = note: perhaps two different versions of crate `syn` are being used?
   = note: this error originates in the macro `strip_attrs_pub` which comes from the expansion of the macro `ast_struct` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0308`.
error: could not compile `substrait` due to previous error

I'll change syn to only use the parsing feature... but prettyplease already uses full so I don't think there will be a material change in build times.

@ahl
Copy link
Contributor Author

ahl commented Mar 19, 2023

Actually, it turns out that syn::File requires "full" which is the default. "parsing" is insufficient.

https://docs.rs/syn/1.0.109/syn/struct.File.html

@ahl
Copy link
Contributor Author

ahl commented Mar 27, 2023

Let me know if there's something you need me to do to get this merged

@mbrobbel
Copy link
Member

Let me know if there's something you need me to do to get this merged

To fix the failing check can you please update the PR title to follow Conventional Commits. Maybe something like:

chore: replace removed `typfify::TypeSpace::to_string()` with `prettyplease`

@westonpace can you please help review this?

@ahl ahl changed the title remove use of typify::TypeSpace::to_string() which is going away chore: replace removed typfify::TypeSpace::to_string() with prettyplease Mar 28, 2023
@westonpace
Copy link
Member

bors try

bors bot added a commit that referenced this pull request Mar 28, 2023
@westonpace
Copy link
Member

bors r+

bors bot pushed a commit that referenced this pull request Mar 28, 2023
…please` (#73)

The use of `typify` assumed that `rustfmt` was installed... which turned out not to be a great assumption. We've modified `typify` to remove the dependency on `rustfmt-wrapper` and have removed the interface that used it `ToString::to_string()`. Instead we recommend that consumers use `prettyplease` for `build.rs` uses such as the one in this crate. See oxidecomputer/typify#221

Alternatively, the `build.rs` could just emit the tokens unformatted (to remove the build-time dependency on `prettyplease` and `syn`), but that seems annoying if and when you need to look at the generated code.

FWIW `syn` is an existing dependency; `prettyplease` is the only new new crate I see in `Cargo.lock`.

I can share the full diff between the old and new versions of the `substrait_text.rs`, but here's a sample:

```diff
@@ -1593,22 +1831,27 @@
             T: std::convert::TryInto<Option<super::SessionDependent>>,
             T::Error: std::fmt::Display,
         {
-            self.session_dependent = value.try_into().map_err(|e| {
-                format!(
-                    "error converting supplied value for session_dependent: {}",
-                    e
-                )
-            });
             self
+                .session_dependent = value
+                .try_into()
+                .map_err(|e| {
+                    format!(
+                        "error converting supplied value for session_dependent: {}", e
+                    )
+                });
+            self
         }
         pub fn variadic<T>(mut self, value: T) -> Self
         where
             T: std::convert::TryInto<Option<super::VariadicBehavior>>,
             T::Error: std::fmt::Display,
         {
-            self.variadic = value
+            self
+                .variadic = value
                 .try_into()
-                .map_err(|e| format!("error converting supplied value for variadic: {}", e));
+                .map_err(|e| {
+                    format!("error converting supplied value for variadic: {}", e)
+                });
             self
         }
         pub fn window_type<T>(mut self, value: T) -> Self
```
@bors bors bot changed the title chore: replace removed typfify::TypeSpace::to_string() with prettyplease [Merged by Bors] - chore: replace removed typfify::TypeSpace::to_string() with prettyplease Mar 28, 2023
@bors bors bot closed this Mar 28, 2023
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.

4 participants