Skip to content
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

Can DeltaPos of the first pattern not depend on the position of "case"? #97

Open
zliu41 opened this issue Nov 14, 2020 · 2 comments
Open

Comments

@zliu41
Copy link
Collaborator

zliu41 commented Nov 14, 2020

When refactoring

f = \x -> case scrut of
  pat -> body

initially the annEntryDelta of pat is relative to the starting position of "case", in this case DP (1, -8).

Once it is refactored to

f x = case scrut of
  pat -> body

the annEntryDelta of pat must be updated based on the new position of "case". The problem is that there doesn't seem to be an easy and non-hacky way to obtain the new position of "case".

On the other hand this is fine:

f = \x -> foo
  bar

in this case the annEntryDelta of bar does not depend on the position of foo, and is always DP (1, 2).

Is it possible to make the annEntryDelta of the first pattern not depend on where the "case" is?

@alanz
Copy link
Owner

alanz commented Dec 23, 2020

See the discussion on the Rigidity type at

data Rigidity = NormalLayout | RigidLayout deriving (Eq, Ord, Show)
{-
Rigidity logic. The same type is used for two different things
1. As a flag in Annotate to the "SetLayoutFlag" operation, which specifies
NormalLayout - Layout should be captured unconditionally
RigidLayout - Layout should be captured or not depending on a parameter kept
in the interpreter Read state
2. As the controlling parameter for the optional (Rigid) layout
The nett effect is the following, where flag is the hard-coded flag value in
Annotate, and param is the interpreter param set when the interpreter is run
flag | param | result
-------------+--------------+--------------------
NormalLayout | either | layout captured
RigidLayout | NormalLayout | layout NOT captured
RigidLayout | RigidLayout | layout captured
The flag is only used on HsIf and HsCase
So
state | HsCase | HsIf
----------------------------|-----------+------
before rigidity flag (AZ) | no layout | layout
param NormalLayout | no layout | no layout
param RigidLayout | layout | layout
----------------------------+-----------+-------
desired future HaRe | no layout | layout
desired future apply-refact | layout | layout
-}

@zliu41
Copy link
Collaborator Author

zliu41 commented Jan 14, 2021

I tried using NormalLayout for DeltaOptions in apply-refact, but it then refactors

f = \x -> case scrut of
  pat -> body

into

f x = case scrut of
        pat -> body

rather than the more desirable

f x = case scrut of
  pat -> body

And it also led to a few test failures. So.. I'll leave this issue open for now, and hopefully we can find a better solution.

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

No branches or pull requests

2 participants