Comments (7)
Awesome, thanks!
from data-encoding.
Hi @chinedufn! Thanks for raising this issue!
are you open to not using syn in data-encoding-macro?
Could you expand as to why this dependency is an issue? This could help me find out how to best solve the issue.
I'm not seeing anything that couldn't be accomplished with regular macro_rules! declarative macros
I'm not convinced Rust compile-time functionality is good enough yet for what data-encoding-macro is doing. But I'll take a look. Otherwise, it might indeed be possible to write the proc-macro without syn. But I'll need to check what it would cost and compare with the issue that it would solve.
from data-encoding.
Regarding compile-time functions, nightly would be needed and even then it's not sure. Also I don't really want to split the code base between stable and nightly unless there's a very good reason (or I release as a nightly-only v3). Ideally I'll prefer to wait until compile-time functions get more stable.
from data-encoding.
Hey! Thanks for taking the time to engage!
Could you expand as to why this dependency is an issue? This could help me find out how to best solve the issue.
Sure! Syn is very powerful, but that power comes at a cost of higher compile times.
So I think that it's best to avoid it when it isn't necessary.
To illustrate. Given the following:
cargo new --lib syn-compile-time
cd syn-compile-time
echo "syn = \"1\"" >> Cargo.toml
echo "pub use syn;" >> src/lib.rs
cargo check # Generate a Cargo.lock and download dependencies
cargo clean && cargo build --release
After running this on the following hardware:
MacBook Pro (16-inch, 2019)
2.4 GHz 8-Core Intel Core i9
64 GB 2667 MHz DDR4
I see a compile time of around 7 seconds:
Finished release [optimized] target(s) in 7.19s
Regarding compile-time functions, nightly would be needed and even then it's not sure.
Sorry, to clarify: I'm just talking about defining a macro_rules!
declarative macro. I'm not talking about const fn
s.
I'm not convinced Rust compile-time functionality is good enough yet for what data-encoding-macro is doing.
Which aspect are you thinking can't be handled by a regular declarative macro?
I'm thinking that a proc macro might be required at all, but I haven't looked into what's going on deeply enough yet to feel sure. So I might be missing something here.
I'd be happy to try to submit a PR that works on stable without a proc macro if you're open to reviewing it. (Unless you're saying that there are things going on that would require nightly const fn
s? In which case I won't.)
Hopefully I've given enough context to answer everything that you asked? Let me know! Thanks.
from data-encoding.
Ahhhhh ok I started looking at the code more deeply and I think I see what you're saying.
The proc macro lets you run this on the inputs at compile time:
data-encoding/lib/macro/internal/src/lib.rs
Line 159 in cbc6752
Makes sense.
Ok cool so a proc macro is necessary until if/when const fns let that decode function run at compile time on stable.
Makes sense.
As for me.. Now that I understand that a proc macro is a requirement I'm comfortable pulling in the dependency.
Thanks for walking me through that. I'm good to go.
Removing syn
would still be nice but I haven't explored whether or not that's even possible.
At any rate.. I'm going move forward with using data-encoding
.
Feel free to close this if you like, or to keep it open if we ever want to investigate whether or not removing syn
is practical.
Cheers!
from data-encoding.
Thanks for your feedback! Indeed compile-time is an interesting concern I didn't think of (I was thinking about possible supply-chain attacks, code bloat, or code performance).
I'll take a stab at removing syn if possible and update on this issue with my conclusion.
from data-encoding.
I don't think it is possible to get rid of syn. Here is the reasoning:
- The macro format uses Rust syntax, i.e. in
symbols: "01234567"
the symbols are given with the Rust String syntax (with double-quote and possible escaping for symbols, likesymbols: "\x00\"\\\x03"
). FromStr
forString
is the identity function, it doesn't assume the input is a Rust String.- Implementing a custom parsing for Rust-like syntax when there is already a crate for that is not maintainable.
However, I managed to reduce the compile time of syn by only using the features I need, from 2.25 seconds to 0.99 seconds.
from data-encoding.
Related Issues (20)
- Consider `check_trailing_bits=false` for BASE64_MIME decoder HOT 1
- Release 3.0.0
- (std -> core)::fmt::Display for DecodeError and DecodeKind HOT 2
- feature `std` leaking when using macro in no_std env HOT 7
- Missing a new line and decode error HOT 2
- Rust 2021 edition is a major, not a "patch" change HOT 6
- Make `{encode,decode}_len` const fns? HOT 4
- Encode into an "impl std::fmt::Write" and/or "impl std::io::Write" HOT 5
- Breaking change wish list
- Use doc_auto_cfg once stable HOT 2
- Use as_chunks family of functions once stable
- Internal symbols array is publicly exposed and unsound HOT 4
- Deny warnings in rustdoc
- Partial encoding with padding HOT 3
- Question about Specification HOT 6
- Release 2.5.0
- SIMD optimization HOT 4
- `Encoding::encode_mut` is very code-size heavy HOT 15
- feature request - base58 d/encoding HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from data-encoding.