-
-
Notifications
You must be signed in to change notification settings - Fork 261
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
[WIP] No std #243
[WIP] No std #243
Conversation
Works on __my__ machine
@@ -83,7 +85,7 @@ impl<R: RuleType> BitOr for Operator<R> { | |||
/// [1]: https://en.wikipedia.org/wiki/Operator-precedence_parser#Precedence_climbing_method | |||
#[derive(Debug)] | |||
pub struct PrecClimber<R: RuleType> { | |||
ops: HashMap<R, (u32, Assoc)> | |||
ops: BTreeMap<R, (u32, Assoc)> |
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.
I'm curious about this change. It seems like this isn't relevant for no_std. Why the change?
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.
It is relevant, HashMap isn't in alloc
(it uses rand or something).
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.
Maybe it could be cfg
'd though, if it were any slower (is it? benching required)
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.
I think that the best approach here is to limit the Vec
in the contractor to 256. (assert + document with # Panics
section) Then use a Box<[Assoc; 256]>
to store the ops
.
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.
We'll definitely want to test to see if there's a notable difference. I suspect for most of our use-cases it'll be similar enough.
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.
Thanks for the PR. Things look good, however, I might have some second thoughts on the complexity that this adds.
Adding no-std is definitely a good way to move forward, however. @jstnlef what do you think about changes?
pub use core::*; | ||
pub use core::{fmt, str}; | ||
|
||
/// Cheap-ish knockoff of std::erorr. Just does what we need it to, nothing more. |
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.
I'm wondering if this is compatible with failure
. Truth be told, I guess it doesn't matter too much in the context of no-std.
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.
Hmm... How could we test?
macro_rules! generate_rule { | ||
($name: ident, $pattern: expr) => { | ||
quote! { | ||
#[inline] | ||
#[allow(dead_code, non_snake_case, unused_variables)] | ||
fn $name(state: Box<::pest::ParserState<Rule>>) -> ::pest::ParseResult<Box<::pest::ParserState<Rule>>> { | ||
fn $name( | ||
state: Box<::pest::ParserState<Rule>> |
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.
Maybe there should be a macro that returns the type here behind some cfg
s in order to eliminate the duplication.
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.
Yeah perhaps
@@ -24,3 +24,6 @@ syn = "^0.13" | |||
codecov = { repository = "pest-parser/pest" } | |||
maintenance = { status = "actively-developed" } | |||
travis-ci = { repository = "pest-parser/pest" } | |||
|
|||
[features] | |||
no_std = [] |
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.
What I dislike about this solution is that you need to specify no_std
in both crates in that it let's the end user use an incompatible configuration (e.g., std + no-std), while providing shallow feedback. (some compile error down the line most likely) Is there any way to specify this in one single place?
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.
Actually I probably can make them depend on eachother. I'll try that.
Also looks like the build is broken. Seems like some changes need to happen to pest_vm. |
Yeah, that's a bit weird. Strangely it Works On My Machine (as you can see from the screenshot), but I'll look at that soonish. Unfortunately I am writing exams right now and for the next few weeks so I may not be able to get to it that soon, but after exams I will. |
#![cfg_attr(feature = "no_std", feature(alloc))] | ||
#![cfg_attr(feature = "no_std", feature(slice_concat_ext))] | ||
|
||
#![cfg(feature = "no_std")] |
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.
Looks like this exclamation mark should be removed.
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.
Yes, haha.
@dragostis Does Travis need to be updated to test both regular and |
@wirelyre unfortunately to get rustc to properly face the fact that there is no |
@wirelyre Yes, but that shouldn't be a huge issue. I would simply add another @Restioson Travis issue might stem from the fact that it's running the tests on stable and you might have a different configuration. |
Probably I forgot to test it with std enabled. |
OK - I'm done exams so hopefully I'll be able to look at this soon. |
How's the status of this PR? Would be fantastic to have it in. |
Hi! Unfortunately, it's been years since I've worked on this, and I imagine that both the rust no_std ecosystem as well as pest itself has evolved beyond this change. Therefore, I'll close this now as it'd probably be easier to implement this from scratch from HEAD than to update it from my 4 year old fork 😅 If someone else wants to, feel free to reuse any code from this or the approach, but personally I don't have the bandwidth to see this through right now. |
Fixes #240.
TODO: