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

Partially fix #611 with Cow #743

Closed
wants to merge 8 commits into from
Closed

Partially fix #611 with Cow #743

wants to merge 8 commits into from

Conversation

scrabsha
Copy link
Contributor

@scrabsha scrabsha commented Aug 5, 2020

This PR attempts to eliminate some useless copies. It introduced a lot of lifetime constraints which I tried to resolve in the most conservative way. In a lot of situation, this resulted in heavy use of Cow, which introduced type errors. That's why this pull request is very big. I was unfortunately unable to split it into smaller PR.

Feel free to post a comment if you see a situation in which a modification was not necessary.

The butcher crate has been used to remove most of the duplicate introduced in a previous attempt to fix this issue

This partially fix #611. There is still some work to do, such as removing as much calls to unbutcher as possible.

The Text variant of Document now contains a Cow<str> instead of a String. This
small modification triggered a lot of lifetime and type errors accross the
codebase.

This commits fixes these errors, in the most conservative way possible. Tests
have been fixed too, so that they still compile (and pass).

Next commits will focus on completely removing the usage of String in Document.
This commit removes every usage of String in Document, replacing it with the
Cow<str> type.

The work is not finished yet! A lot of clone still have to be removed. This will
be the goal of the next few commits.

Tests have been updated, and still pass.
The call to clone was removed in the implementation of Documentable for &str.

Warning: the code currently does not compile. The compilation errors are due to
pattern-matching. These errors *should* be fixed with the `butcher` crate,
which *should* significantly reduce the amount of duplication generated by
pattern-matching on enums wrapped in Cow.
Butcher will make Cow handling a bit less painfull, and will remove a lot of code
duplication.
@scrabsha
Copy link
Contributor Author

scrabsha commented Aug 5, 2020

I'm a bit worried by the fact that CI fails for MacOS, but not for other targets. Also the provided error seems to be lalrpop-related, but the PR does not change anything related to parsing.

What am I missing?

@thehabbos007
Copy link
Contributor

I'm a bit worried by the fact that CI fails for MacOS, but not for other targets.

This has happened to me before too on the MacOS CI. It was fixed when Louis reran the actions. Looks like an open issue on GitHub's end :)

This conflict comes from commit d4e11ea.
@scrabsha
Copy link
Contributor Author

I'm a bit worried by the fact that CI fails for MacOS, but not for other targets.

This has happened to me before too on the MacOS CI. It was fixed when Louis reran the actions. Looks like an open issue on GitHub's end :)

Thanks for your comment @thehabbos007! Fixing merge conflicts triggered CI, which successfully pass :)

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Thanks for taking this on.

From reading the butcher crate I don't understand what exactly it does, and I'm reluctant to introduce a library that has such a wide impact on the codebase. I don't think that a performance optimisation in the pretty printers should require changes throughout the compiler which result in all contributors learning a new library + set of conventions.

Is it possible to use the library in a fashion that only impacts the algebra? At the moment this seems like a larger change than having Document::String and Document::Str variants, while also being more conceptually complex

@scrabsha
Copy link
Contributor Author

Hi,

To be honest, I share your opinion in the fact that this PR has way to much impact in the codebase. This is not directly caused by the Butcher derive macro. The goal of this macro is to remove the duplication you pointed out in my previous attempt to fix issue #611. For example, the big match expression in the expr function contained a lot of duplicated patterns in my previous attempt which are removed thanks to the Butcher derive macro in this attempt.

Anyway, I do think that other developers are not wiling to learn the butcher crate works.

After some reflection, I am pretty sure I misunderstood what should be done to address such issue, and that I went way too deep in the codebase to fix it (hence the huge amount of changes). As such, I'll come back in a few days in the issue thread to ask more questions about what should be done.

This issue was opened a long time ago, and there I still have not properly fixed it. I do thank you for your infinite patience here.

@scrabsha scrabsha closed this Aug 13, 2020
@lpil
Copy link
Member

lpil commented Aug 16, 2020

This issue was opened a long time ago, and there I still have not properly fixed it. I do thank you for your infinite patience here.

Please do not feel bad in any way!

I don't expect any particular contribution to Gleam from anyone and I do not think I am entitled to anyone's time. I am thankful for your contributions (even if we haven't figured this specific problem out yet) and I have learnt quite a few things from reading your Rust code :)

Work on whatever is fun, that is the most important thing for open source work in my opinion :)

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.

Support &str in the printer algebra
3 participants