Rewrite Partial optimization to be cleaner#4208
Merged
rhendric merged 1 commit intopurescript:masterfrom Jan 30, 2022
Merged
Conversation
JordanMartinez
approved these changes
Nov 24, 2021
Contributor
JordanMartinez
left a comment
There was a problem hiding this comment.
LGTM as far as I can tell.
Contributor
|
We should check that the entire package set still compiles with this PR. |
Member
Author
Just checked—it does. However, this is a bunch of tweaks to optimizations; compilation errors aren't the lurking bugs I would have expected. This is more likely to cause problems at run time, not that I'm anticipating any. |
Contributor
|
Right. But the package set compiling is just a sanity check that nothing unexpected was affected by this. |
7b5b3e2 to
d6a6232
Compare
Contributor
|
Package set compiles. Any other core team members want to weigh in on this? |
Member
Author
This feature shrinks the generated JS code for declarations that use empty type classes, such as `Partial`, but is otherwise not expected to have user-visible consequences. A previous issue involving `Partial` resulted in an ad-hoc optimization pass added to the CoreFn phase. This pass consumed code generated by the exhaustiveness checker, which used `UnusedIdent` in a questionable manner, and ran a rewrite on it that assumed that the only part of the compile that would use `UnusedIdent` in such a questionable manner was necessarily the exhaustiveness checker. This commit: * simplifies the code generated by the exhaustiveness checker for partial matches, in particular removing any use of `UnusedIdent`s; * removes the offending CoreFn optimization pass; * solves the problem originally motivating said optimization pass by using an `UnusedIdent` for the generated parameter when type-checking a value constrained by an empty type class (such parameters, importantly for our sanity, are actually unused); * and backs out a related hack in TCO that worked around such generated parameters being present but called without an argument. The intended result is simpler compiler code; happy side effects include simpler error messages involving partial pattern matches (seen here in a few golden test output changes) and simpler generated code (fewer unused function parameters, fewer local variables in some TCO-triggering functions).
d6a6232 to
728a681
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 feature shrinks the generated JS code for declarations that use
empty type classes, such as
Partial, but is otherwise not expected tohave user-visible consequences.
A previous issue involving
Partialresulted in an ad-hoc optimizationpass added to the CoreFn phase. This pass consumed code generated by the
exhaustiveness checker, which used
UnusedIdentin a questionablemanner, and ran a rewrite on it that assumed that the only part of the
compile that would use
UnusedIdentin such a questionable manner wasnecessarily the exhaustiveness checker.
This commit:
simplifies the code generated by the exhaustiveness checker for
partial matches, in particular removing any use of
UnusedIdents;removes the offending CoreFn optimization pass;
solves the problem originally motivating said optimization pass by
using an
UnusedIdentfor the generated parameter when type-checkinga value constrained by an empty type class (such parameters,
importantly for our sanity, are actually unused);
and backs out a related hack in TCO that worked around such generated
parameters being present but called without an argument.
The intended result is simpler compiler code; happy side effects include
simpler error messages involving partial pattern matches (seen here in a
few golden test output changes) and simpler generated code (fewer unused
function parameters, fewer local variables in some TCO-triggering
functions).
This backs out #3218 (except for the test) and a small part of #3416.
For the two test files added in those PRs, here are diffs of the generated code before and after this PR:
Checklist:
Added myself to CONTRIBUTORS.md (if this is my first contribution)Linked any existing issues or proposals that this pull request should closeUpdated or added relevant documentationAdded a test for the contribution (if applicable)