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

Remove HashMap from derive/generate #442

Merged
merged 1 commit into from
Feb 22, 2020
Merged

Conversation

nagisa
Copy link
Contributor

@nagisa nagisa commented Feb 22, 2020

There is a lot of value in outputs produced by compilers being
reproducible. Rust makes it somewhat hard to get it right, but most of
the time rustc’s outputs are also reproducible. This allows us to enjoy
all the benefits as other more primitive toolchains. Most of the time.

Pest was, sadly, one of those examples where reproducibility was not a
concern and HashMap was used to implement some of the code generation
portions. Replacing this HashMap with a Vec and a O(nm) loop is
the easy solution. With the values that n and m get substituted with
in practice, however, this loop should still be approximately as good as
the previous HashMap implementation.

There is a lot of value in outputs produced by compilers being
reproducible. Rust makes it somewhat hard to get it right, but most of
the time rustc’s outputs are also reproducible. This allows us to enjoy
all the benefits as other more primitive toolchains. Most of the time.

Pest was, sadly, one of those examples where reproducibility was not a
concern and HashMap was used to implement some of the  code generation
portions. Replacing this `HashMap` with a `Vec` and a `O(nm)` loop is
the easy solution. With the values that `n` and `m` get substituted with
in practice, however, this loop should still be approximately as good as
the previous `HashMap` implementation.
@CAD97
Copy link
Contributor

CAD97 commented Feb 22, 2020

Another option would be indexmap, which both uses hashes and guarantees a stable (insertion) ordering. It's basically this approach plus a hash-based lookup cache to make lookups amortized constant time. But that said, this is a fine fix and a fix you have is always better than a theoretical one, which can be applied later.

bors: r+

cc @dragostis a release for this fix ASAP would be nice.

bors bot added a commit that referenced this pull request Feb 22, 2020
442: Remove HashMap from derive/generate r=CAD97 a=nagisa

There is a lot of value in outputs produced by compilers being
reproducible. Rust makes it somewhat hard to get it right, but most of
the time rustc’s outputs are also reproducible. This allows us to enjoy
all the benefits as other more primitive toolchains. Most of the time.

Pest was, sadly, one of those examples where reproducibility was not a
concern and HashMap was used to implement some of the  code generation
portions. Replacing this `HashMap` with a `Vec` and a `O(nm)` loop is
the easy solution. With the values that `n` and `m` get substituted with
in practice, however, this loop should still be approximately as good as
the previous `HashMap` implementation.

Co-authored-by: Simonas Kazlauskas <git@kazlauskas.me>
@bors
Copy link
Contributor

bors bot commented Feb 22, 2020

Build failed

@CAD97
Copy link
Contributor

CAD97 commented Feb 22, 2020

Gah, looks like #443 is going to block the build. I need @dragostis to fix this one 😓

Copy link
Contributor

@dragostis dragostis left a comment

Choose a reason for hiding this comment

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

LGTM

@dragostis
Copy link
Contributor

The Vec should be a fine solution here.

@dragostis
Copy link
Contributor

bors r+

@bors
Copy link
Contributor

bors bot commented Feb 22, 2020

Build succeeded

@bors bors bot merged commit 1b0c9c5 into pest-parser:master Feb 22, 2020
@nagisa
Copy link
Contributor Author

nagisa commented Feb 22, 2020

Please release a version of pest_generator with this fix sooner rather than later.

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.

3 participants