8000 Printer improvements to fuse JS emitting and printing by gzm0 · Pull Request #4920 · scala-js/scala-js · GitHub
[go: up one dir, main page]

Skip to content

Printer improvements to fuse JS emitting and printing #4920

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

Merged
merged 9 commits into from
Jan 28, 2024

Conversation

gzm0
Copy link
Contributor
@gzm0 gzm0 commented Dec 28, 2023

The core of the change is to print semicolons and newlines as part of a statement.

This is necessary for a subsequent change, where we pre-print
statements into byte buffers. When we later assemble the statement
into the surrounding block, we do not have type information
anymore (and hence cannot judge whether a semicolon is necessary).

Note that this now prints a semicolon after the last statement in a
block (which we didn't previously). This does increase fastopt
size (somewhat artificially), but more closely corresponds:

@gzm0
Copy link
Contributor Author
gzm0 commented Dec 28, 2023

Full diff on helloworld: https://gist.github.com/gzm0/c8602ac8b4f928d6bc4598d04e18dee9

@gzm0 gzm0 marked this pull request as ready for review December 28, 2023 17:46
@gzm0 gzm0 force-pushed the better-printer branch 3 times, most recently from 205b4a3 to 3370329 Compare December 30, 2023 09:21
@gzm0 gzm0 force-pushed the better-printer branch 2 times, most recently from a0f0f72 to a2706cd Compare December 31, 2023 07:12
@gzm0 gzm0 requested a review from sjrd December 31, 2023 07:16
Copy link
Member
@sjrd sjrd left a comment

Choose a reason for hiding this comment

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

Sorry for the super long delay in reviewing this.

My last month has been vacation-always-moving then sick leave then exam preparation. But I'm finally out of it all, so I can pick things up again.

Comment on lines 506 to 512
8000
indent()
println()
indent()
Copy link
Member

Choose a reason for hiding this comment

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

This swap does not seem needed, and makes this spot inconsistent with other places that increase the indentation (for example printBlock). Consider reverting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The swap is indeed not needed (indent() and println() are now independent of each other). I originally did the swap since it seemed more logical (what a human would write, newline, then indent). However, it is indeed less consistent with the rest of the class (where the swap cannot be so easily done due to pre element println). So I think sticking with the existing order is fine.

fullLinkGz = 35000 to 36000,
))

case `default213Version` =>
Some(ExpectedSizes(
fastLink = 481000 to 483000,
fastLink = 479000 to 480000,
Copy link
Member

Choose a reason for hiding this comment

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

I'm surprised not to see changes in LibrarySizeTest. Weren't there any /*<skip>*/ there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They were within tolerance, but I have adjusted / tightened them.

gzm0 added 9 commits January 28, 2024 11:55
We're going to do modifications, so we add some tests.
This is necesary for a subsequent change, where we pre-print
statements into byte buffers. When we later assemble the statement
into the surrounding block, we do not have type information
anymore (and hence cannot judge whether a semicolon is necessary).

Note that this now prints a semicolon after the last statement in a
block (which we didn't previously). This does increase fastopt
size (somewhat artificially), but more closely corresponds:

- to what a human would write
- the ECMAScript spec (e.g. https://tc39.es/ecma262/#sec-expression-statement)
Because it does not need to flatten blocks anymore, we can simply
print it as a statement and add a trailing newline.
They were unnecessarily protected.
This is necessary so we can partially print substatements more
easily (which we'll do in a subsequent PR). It will also allow us to
fully remove the concept of "top-level" tree.
Copy link
Contributor Author
@gzm0 gzm0 left a comment

Choose a reason for hiding this comment

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

Updated. I believe I have addressed all comments.

fullLinkGz = 35000 to 36000,
))

case `default213Version` =>
Some(ExpectedSizes(
fastLink = 481000 to 483000,
fastLink = 479000 to 480000,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

They were within tolerance, but I have adjusted / tightened them.

protected def printBlock(tree: Tree): Unit = {
print('{'); indent();
private def printBlock(tree: Tree): Unit = {
print('{'); indent(); println()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: This change should be in the next commit. I've moved it.

Comment on lines 506 to 512
indent()
println()
indent()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The swap is indeed not needed (indent() and println() are now independent of each other). I originally did the swap since it seemed more logical (what a human would write, newline, then indent). However, it is indeed less consistent with the rest of the class (where the swap cannot be so easily done due to pre element println). So I think sticking with the existing order is fine.

@gzm0 gzm0 requested a review from sjrd January 28, 2024 11:09
@gzm0 gzm0 merged commit 0a5844e into scala-js:main Jan 28, 2024
@gzm0 gzm0 deleted the better-printer branch January 28, 2024 15:42
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.

2 participants
0