-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix Printer group modes #6815
Fix Printer group modes #6815
Conversation
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
PR Check ResultsBenchmarkLinux
Windows
|
c8543f8
to
04d372f
Compare
5051db4
to
c80afd8
Compare
c80afd8
to
3fa14d5
Compare
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 out of my depth here as I've never grappled with the printer -- but I did spend 10 minutes or so reading the PR summary and the code.
StartTagMissing { kind: TagKind }, | ||
StartTagMissing { | ||
kind: TagKind, | ||
}, |
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.
Nice
Summary
This fixes a bug in the Printer where the mode for a group was stale when testing if some content fits.
The input must have been of the form
What happened is:
Expanded
mode to theprint_modes
state that is shared between printing and measuringFits::No
, because the line ultimately doesn't fit, but it doesn't undo the writtengroup_modes[2] = Expand
if_group_breaks
looks up the value of group2
ingroup_modes
which still contains the staleExpand
entry (it breaks)(
. It won't print the(
, but it assumes the layout as if group 2 breaks when measuring if it fitsThis PR implements a fix by always writing
group_modes[group_id] = Flat
of the current group that should be measured. We already do this after measuring and inside offits_groups
. This only extends it to override any stale entry for the outermost group too.This seems to come at a performance cost because there's now one additional write for every group (and there are many!). What would be nice is if there's a cheap way to restore
group_modes
after measuring fits but that would require that the group ids in the document are monotonic. While it's true that group ids are always increasing, it isn't guaranteed that their groups are written in the same order as the ids have been created.I used the chance to remove the (last?)
unwrap
in thePrinter
by returning ganErr
if a document uses agroup_id
that hasn't been seen to this point.