Skip to content

eliminate id function for inferred partial constraints in desugaring#3195

Closed
matthewleon wants to merge 4 commits intopurescript:masterfrom
matthewleon:unused-partial-fn
Closed

eliminate id function for inferred partial constraints in desugaring#3195
matthewleon wants to merge 4 commits intopurescript:masterfrom
matthewleon:unused-partial-fn

Conversation

@matthewleon
Copy link
Copy Markdown
Contributor

fixes #3157

This depends on #3194. If that is merged, I'll rebase accordingly.

During exhaustivity checking, an id function with a Partial constraint is created whenever a partial function is encountered, for the purposes of typechecking. During desugaring, typechecking is complete, so we can remove this construct.

hdgarrood and others added 4 commits January 5, 2018 14:17
* Revert "pretty print proxy types when rendering docs (purescript#3144)"

This reverts commit 14227c7.

* Revert "Print proxy type as an operator (purescript#3124)"

This reverts commit cfd1db3.

* Revert "Fix proxies: synonyms, inference, traversals, instances (purescript#3095)"

This reverts commit fe0aa0d.

* Revert "Add proxies (purescript#2846)"

This reverts commit 74bc4a9.

* Remove one last occurrence of the ProxyType constructor

* Update tests to not use new proxies
Fixes purescript#3187

Rather than using the magic string "__unused" to represent generated
names that are meant to go unused, we create a new Ident constructor for
them. Instead of eliminating them as arguments in the optimization
phase, they are stripped during the conversion from CoreFn to CoreImp.
fixes purescript#3157

During exhaustivity checking, an id function with a Partial constraint
is created whenever a partial function is encountered, for the purposes
of typechecking. During desugaring, typechecking is complete, so we can
remove this construct.
The __unused constant for names is now fully supplanted by the use of
UnusedIdent. We can get rid of it.
@matthewleon matthewleon mentioned this pull request Jan 7, 2018
@matthewleon
Copy link
Copy Markdown
Contributor Author

I discussed this with @kritzcreek and came to the conclusion that it shouldn't be sitting in the middle of the desugaring code. That said, it makes sense to perform this optimization between typechecking (the source of the generated block) and the functional core, as alternative backends shouldn't need to duplicate the optimization. Any ideas?

@garyb
Copy link
Copy Markdown
Member

garyb commented Jan 20, 2018

Shall we close this then, since the approach is going to be different?

@matthewleon
Copy link
Copy Markdown
Contributor Author

Shall we close this then, since the approach is going to be different?

sure

@garyb
Copy link
Copy Markdown
Member

garyb commented Jan 20, 2018

I'm not sure how much you talked with @kritzcreek about this, but I chatted about it briefly with him a while ago too. My thinking was that there would also be an UnusedIdent constructor in the names for the CoreFn (/ CoreImp? not sure how long we need it for) ASTs, perhaps. That'd give us more options for doing passes on the other form or something like that to apply the optimisation instead.

I was going to suggest making that change on the other PR even, and then keeping the "remove unused" pass in the optimizer there, but just having it less fragile since it'd have the constructor to match on... but in the end I figured it was fine to just not generate it at all.

@matthewleon
Copy link
Copy Markdown
Contributor Author

My thinking was that there would also be an UnusedIdent constructor in the names for the CoreFn (/ CoreImp? not sure how long we need it for) ASTs, perhaps. That'd give us more options for doing passes on the other form or something like that to apply the optimisation instead.

I did have a chat with @kritzcreek about this one. I think what you are proposing makes sense broadly speaking. As it stands, CoreFn does "inherit" the UnusedIdent constructor from the unsugared AST... It gets erased in the transition to CoreImp.

That said, for this particular problem, I believe it makes sense to do the optimization before even getting to CoreFn. Recall that the only reason that this extra function is introduced is for type checking. Given that alternate backends might want to work with CoreFn, I can't see any reason for this particular artifact to be kept around after desugaring.

Thoughts?

@matthewleon
Copy link
Copy Markdown
Contributor Author

Another clarification here is that the particular way that UnusedIdent is used in creating the partial constraints is fundamentally different from its usage elsewhere. Elsewhere, it is always a name given to a generated function parameter. Here, it is the name of a function itself.

@garyb
Copy link
Copy Markdown
Member

garyb commented Jan 20, 2018

CoreFn currently lacks an optimiser, but there's a bunch of things we could in theory do there, so it just seemed like this would be the first pass - any backend would still benefit from it, as it'd use the post-optimised version anyway. Unless I misunderstand?

The reason CoreFn exists is to make things like this easier, in fact! Since doing anything to the "full" AST is unpleasant just because of the number of cases that need considering. We're basically getting no benefit from CoreFn at all at the moment, as it goes directly into "CoreImp" (which is still just JS at this point really).

@matthewleon
Copy link
Copy Markdown
Contributor Author

The reason CoreFn exists is to make things like this easier, in fact! Since doing anything to the "full" AST is unpleasant just because of the number of cases that need considering. We're basically getting no benefit from CoreFn at all at the moment, as it goes directly into "CoreImp" (which is still just JS at this point really).

Okay, cool. I will try to rewrite this in a CoreFn optimization pass.

@garyb
Copy link
Copy Markdown
Member

garyb commented Jan 20, 2018

If it doesn't work out for some reason, that's fine too - perhaps we'll need to reconsider how the intermediate parts fit together to make them more useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Partial functions can foil TCO

4 participants