feat(stdlib): Rewrite toString to use a layout tree#2385
Open
spotandjake wants to merge 6 commits intograin-lang:oscar/gc-rebasedfrom
Open
feat(stdlib): Rewrite toString to use a layout tree#2385spotandjake wants to merge 6 commits intograin-lang:oscar/gc-rebasedfrom
toString to use a layout tree#2385spotandjake wants to merge 6 commits intograin-lang:oscar/gc-rebasedfrom
Conversation
cadd6d9 to
6e4f63b
Compare
6e4f63b to
e7b1b19
Compare
It seems that refmt removes extra whitespace in raw strings, which breaks our testing so I had to go back to using a slightly more ugly regular string.
I noticed that the builders being global allocations were causing some optimization issues, that can easily be avoided by turning them into functions. This has a slight performance drawback however it is used very sparingly so it should be reasonable.
c390917 to
84e6f27
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pr refactors

toStringto improve the formatting of printed items. Previously, we were naively concatenating strings while stringifying. While this approach was relatively performant and very compact, it meant we weren't able to support high-quality formatting akin to how we format grain code itself. In order to solve this problem, I ported thedoc printing engineused in the formatter into Grain and rewrote our implementation of it.More information on the implementation itself and design decisions can be found here: https://github.com/spotandjake/Grain-toString/tree/spotandjake/gc, along with some more in-depth notes on both the size and performance changes.
A few more notable things:
40%increase in the size of Hello World.doc.gr, these are capable of being optimized away however I don't think our current passes handle them very well.doc,miniBufferandvector, all of which are generic enough to be used elsewhere.doclibrary for grain, I didn't change the api from the formatter; this means that we can use it in other places, such as improving JSON stringification in the future.print("Hello World").unknownwhen we don't have type metadata for a variant or record we print the data inside and leave the fields or variant itself as unknown.This work is based on: #2378
Closes: #2087
Work towards: #1794, #2127