-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
[#27] Introduce Terminating constraint for preventing hanging showMemory #46
[#27] Introduce Terminating constraint for preventing hanging showMemory #46
Conversation
Hi, a little bit context on why reduction length has increased from 201 to 250: If left as 201, reduction depth prevents ghc from calculating "Terminating" condition for We need a depth of at least 250 for reducing |
@@ -50,6 +50,7 @@ common common-options | |||
-fhide-source-paths | |||
-Wmissing-export-lists | |||
-Wpartial-fields | |||
-freduction-depth=250 |
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.
Sorry, I can't find documentation for this. (I'm looking into https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/flags.html )
Could you please explain why this is needed?
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 want to add from my side that adding custom and rare flags (that apparently doesn't have documentation) might be a stopper for merging. This constant might work for natural 7000. But GHC might require a much higher constant for bigger naturals. This can slow down compilation significantly for the membrain
users or produce difficult errors. The fact that this constant needs to patched to make the library work looks like an undesirable property to me.
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.
Hi, answers inline.
Sorry, I can't find documentation for this
Yes, flag not being documented is in fact a ghc bug: https://gitlab.haskell.org/ghc/ghc/issues/15756
GHC manpage seems to have this documented though:
https://manpages.debian.org/stretch/ghc/haskell-compiler.1.en.html#Language_options
This flag controls how many steps GHC is allowed to take for simplifying a single type expression.
Could you please explain why this is needed?
In order to understand whether large Nats are only dividable by 5 or 2, but not by any other number, we need to continuously divide them by 5 and 2 and see if we end up with 1.
This creates a type expression like (((((7000 Div 5) Div 5) Div 5) Div 5)...
for ghc to simplify and ghc simply has a limit on number of reductions it wants to perform.
For Yobibyte, currently the largest unit, this reduction size is exactly 250
, hence the -freduction-depth=250
flag.
src/Membrain/Memory.hs
Outdated
#if ( __GLASGOW_HASKELL__ >= 804 ) | ||
type IsMemory mem = (KnownNat mem, KnownUnitSymbol mem, Terminating mem) | ||
#else | ||
type IsMemory mem = (KnownNat mem, KnownUnitSymbol mem) |
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 can be a bit picky, but I would call it KnownMem
for better description of what this alias is.
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.
Also, could you please provide some tests for that. At least doctests of the examples you wrote in the PR body would be really appreciated.
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.
What does "factor" mean? I can't really follow your thoughts...
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.
@yigitozkavci thanks for your attempt in solving this problem. But I believe that current implementation contains some serious usability issues and will make membrain
less approachable. The chances of introducing a wrong memory unit are very small but the overhead of this feature is quite significant.
@@ -50,6 +50,7 @@ common common-options | |||
-fhide-source-paths | |||
-Wmissing-export-lists | |||
-Wpartial-fields | |||
-freduction-depth=250 |
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 want to add from my side that adding custom and rare flags (that apparently doesn't have documentation) might be a stopper for merging. This constant might work for natural 7000. But GHC might require a much higher constant for bigger naturals. This can slow down compilation significantly for the membrain
users or produce difficult errors. The fact that this constant needs to patched to make the library work looks like an undesirable property to me.
I completely agree with this and I'm perfectly fine with not proceeding with this PR. This is one of the times where one should stop and think about whether introduced complexity solves a significant problem at all. This is often not the case with type level solutions, and I'm used to that. I'm okay with closing this PR and keeping it as an attempt and demonstration of ghc's ability to prove this property at compile time. Thanks for the review :) |
Thanks for your work anyway! We really appreciate the effort and your time ❤️ |
Resolves #27
Factorizes and validates input to
showMemory
at compile time, eliminating risk for a hangingshowMemory
call.✅ Check list
hlint .
output is: No Hints (there are 4, none of which was caused by this PR).stylish-haskell
][stylish-tool] toolusing [stylish-haskell.yaml][stylish] file in the repository.
details on our style guide check [this document][style-guide]).
Start the first line of the commit with the issue number in square parentheses.
Demonstraition in ghci: