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

Added zeroWidthSpec transformation #1891

Merged
merged 1 commit into from
Aug 6, 2021
Merged

Added zeroWidthSpec transformation #1891

merged 1 commit into from
Aug 6, 2021

Conversation

alex-mckenna
Copy link
Contributor

@alex-mckenna alex-mckenna commented Aug 5, 2021

A new transformation has been defined, which replaces lambda-bound variables for a zero-width type with the only possible value of that type in the body of the lambda. e.g.

data AB = A | B

ab :: KnownNat n => Index n -> AB -> AB
ab n A = if n >  0 then A else B
ab n B = if n == 0 then B else A

would see the values of n in the function body be replaced with 0 (the only possible value of the type Index 1)

ab _ A = if 0 > 0 then A else B
ab _ B = if 0 == 0 then B else A

the normalizer is then free to further normalize this to

ab _ _ = B

where previously it would not be able to improve this during normalization.

Fixes #508

Still TODO:

  • Write a changelog entry (see changelog/README.md)
  • Check copyright notices are up to date in edited files

@alex-mckenna
Copy link
Contributor Author

I've changed the hard-coded strings for type constructors / fromInteger# to be TH quotes for @martijnbastiaan

A new transformation has been defined, which replaces lambda-bound variables
for a zero-width value with the value itself in the body of the lambda. e.g.

```haskell
data AB = A | B

ab :: KnownNat n => Index n -> AB -> AB
ab n A = if n >  0 then A else B
ab n B = if n == 0 then B else A
```

would see the values of n in the function body be replaced with 0 (the only
possible value of the type `Index 1`)

```haskell
ab _ A = if 0 > 0 then A else B
ab _ B = if 0 == 0 then B else A
```

the normalizer is then free to further normalize this to

```haskell
ab _ _ = B
```

where previously it would not be able to improve this during normalization.

Fixes #508
@alex-mckenna alex-mckenna enabled auto-merge (rebase) August 6, 2021 09:53
@alex-mckenna alex-mckenna merged commit 2725f90 into master Aug 6, 2021
@alex-mckenna alex-mckenna deleted the issue-508 branch August 6, 2021 10:03
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.

Clash isn't smart enough when constant folding zero-width constructs
2 participants