[GHC] #13211: NegativeLiterals -0.0 :: Double

#13211: NegativeLiterals -0.0 :: Double -------------------------------------+------------------------------------- Reporter: rwbarton | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Keywords: newcomer | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Compare {{{ rwbarton@morphism:~$ ghc-8.0.1 -e '-0.0' -0.0 rwbarton@morphism:~$ ghc-8.0.1 -XNegativeLiterals -e '-0.0' 0.0 }}} This behavior is logical, but unexpected. The logic is that with `NegativeLiterals` the literal `-0.0` means `fromRational ((-0)%0)`, which equals `fromRational 0`, which for `Double` is positive zero, not negative zero. But this seems unfortunate. Perhaps it would be best if `-0.0` (or `-` applied to any other literal mathematically equal to zero) was desugared as `negate 0.0` even under `NegativeLiterals`, since there doesn't seem to be any other reason to write `-0.0`. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13211 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13211: NegativeLiterals -0.0 :: Double -------------------------------------+------------------------------------- Reporter: rwbarton | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by Nolan): * Attachment "Lexer.x.patch" added. patch to ./compiler/parser/Lexer.x -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13211 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13211: NegativeLiterals -0.0 :: Double -------------------------------------+------------------------------------- Reporter: rwbarton | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Nolan): I'm new to ghc and this is my first ticket. Patch above dosn't work as expected. I changed rule for negative floating point literals so that it triggers(as I believe) only on non zero literals. Having that this shouldn't change default(without -XNegativeLiterals) behaviour of lexer for such cases. But for some reason it doesn't work. Non zero literals look to be correct as well as positive zero but negative zero produces such error. I don't know what it means and can't find source of this error. Searching though whole project for those messages and function it didn't help. What can it be? {{{ nolan@NolanPC:~/ghc$ ./inplace/bin/ghc-stage2 -XNegativeLiterals -e "-0.0" <interactive>:0:1: error: • Non type-variable argument in the constraint: Num (a -> b) (Use FlexibleContexts to permit this) • When checking the inferred type it :: forall b c a. (Num (a -> b), Num (b -> c)) => a -> c }}} Maybe I get this wrong and this trick will not work. Do you have any ideas of how this feature should be implemented? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13211#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13211: NegativeLiterals -0.0 :: Double -------------------------------------+------------------------------------- Reporter: rwbarton | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton): It must be lexing `-0.0` as `-0 . 0` (which is then interpreted as an application of `(.)`), not `- 0.0`. The same logic should also apply to `-0`, since someone could write `-0 :: Double`. I suspect fixing that would also fix your problem here. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13211#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13211: NegativeLiterals -0.0 :: Double -------------------------------------+------------------------------------- Reporter: rwbarton | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Nolan): Yeah, I got it and probably fixed. I'm testing changes now. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13211#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13211: NegativeLiterals -0.0 :: Double -------------------------------------+------------------------------------- Reporter: rwbarton | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by Nolan): * Attachment "patchToLexer.x" added. I fixed this error. Now it works as expected. It passes tests but 3 of them report slight performance drop(I forgot their ids, now retesting...). Here's patch to ```compiler/parser/Lexer.x``` -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13211 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13211: NegativeLiterals -0.0 :: Double -------------------------------------+------------------------------------- Reporter: rwbarton | Owner: Nolan Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by Nolan): * owner: (none) => Nolan -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13211#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13211: NegativeLiterals -0.0 :: Double -------------------------------------+------------------------------------- Reporter: rwbarton | Owner: Nolan Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Nolan): Oops, it failed. Testing summary: {{{ Unexpected results from: TEST="T2762 BinaryLiterals0 T4029" SUMMARY for test run started at Sat Feb 25 19:00:27 2017 MSK 2:45:29 spent to go through 5766 total tests, which gave rise to 18079 test cases, of which 12034 were skipped 72 had missing libraries 5830 expected passes 140 expected failures 0 caused framework failures 0 unexpected passes 1 unexpected failures 2 unexpected stat failures Unexpected failures: parser/should_run/BinaryLiterals0.run BinaryLiterals0 [exit code non-0] (normal) Unexpected stat failures: perf/space_leaks/T2762.run T2762 [stat too good] (normal) perf/space_leaks/T4029.run T4029 [stat not good enough] (ghci) }}} T4029: {{{ testsuite/tests/parser/should_run/BinaryLiterals0.hs:14:13: error: • Couldn't match expected type ‘(Int, Int)’ with actual type ‘a0 -> b0 -> (a0, b0)’ • Probable cause: ‘(-)’ is applied to too few arguments In the expression: (,) - 0 b0 In the expression: [(,) 0 b0, (,) 0 b1, (,) 0 b10, (,) 0 b11, ....] :: [(Int, Int)] In an equation for ‘lst’: lst = [(,) 0 b0, (,) 0 b1, (,) 0 b10, ....] :: [(Int, Int)] | 14 | , (,) -0b0, (,) -0b1, (,) -0b10, (,) -0b11 | ^^^^^^^^ ... and 3 similar }}} T2762: {{{ Expected T2762(normal) peak_megabytes_allocated: 3 +/-0% Lower bound T2762(normal) peak_megabytes_allocated: 3 Upper bound T2762(normal) peak_megabytes_allocated: 3 Actual T2762(normal) peak_megabytes_allocated: 2 Deviation T2762(normal) peak_megabytes_allocated: -33.3 % }}} T4029 {{{ peak_megabytes_allocated value is too high: Expected T4029(ghci) peak_megabytes_allocated: 76 +/-10% Lower bound T4029(ghci) peak_megabytes_allocated: 68 Upper bound T4029(ghci) peak_megabytes_allocated: 84 Actual T4029(ghci) peak_megabytes_allocated: 94 Deviation T4029(ghci) peak_megabytes_allocated: 23.7 % max_bytes_used value is too high: Expected T4029(ghci) max_bytes_used: 22016200 +/-5% Lower bound T4029(ghci) max_bytes_used: 20915390 Upper bound T4029(ghci) max_bytes_used: 23117010 Actual T4029(ghci) max_bytes_used: 27596592 Deviation T4029(ghci) max_bytes_used: 25.3 % }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13211#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13211: NegativeLiterals -0.0 :: Double -------------------------------------+------------------------------------- Reporter: rwbarton | Owner: Nolan Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): Nolan, perhaps you could put your patch up on [https://ghc.haskell.org/trac/ghc/wiki/Phabricator Phabricator] so that people can more easily help you? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13211#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

Nolan, perhaps you could put your patch up on [https://ghc.haskell.org/trac/ghc/wiki/Phabricator Phabricator] so that
#13211: NegativeLiterals -0.0 :: Double -------------------------------------+------------------------------------- Reporter: rwbarton | Owner: Nolan Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Nolan): Replying to [comment:6 mpickering]: people can more easily help you? Thank you for advice, now it can be found [https://phabricator.haskell.org/D3212 here]. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13211#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13211: NegativeLiterals -0.0 :: Double -------------------------------------+------------------------------------- Reporter: rwbarton | Owner: Nolan Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Nolan): I faced with a problem. There's a test BinaryLiterals0 which breaks after my patch. Problem is that before the patch expressions like `(,) -0b0` were valid because `-0` was single lexeme. Patch changed this behavior for zeroes and now `-` is distinct lexeme if followed by zero literal. I see 3 of ways of dealing with that fail. 1) Remove this test. Which doesn't look like a good idea for me though. 2) Change lexer such that `-0` is single lexeme but `-0.0` is two distinct ones. The test should pass. But think of this. `id -0.0` is now legal code but after such change it will fail. So I think this is not good solution as well. 3) To come up with another way of solving this issue that will not break those tests. 4) Consider this is not bug but a feature. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13211#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13211: NegativeLiterals -0.0 :: Double -------------------------------------+------------------------------------- Reporter: rwbarton | Owner: Nolan Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by rwbarton): I see. I guess we could continue to parse `-0b0` and `-0.0` as single lexemes, but record that they have the form of negative zero. Then convert them to `negate (fromInteger 0)` or `negate (fromRational 0)` during desugaring. However when I took a quick look earlier that didn't look particularly convenient to do. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13211#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13211: NegativeLiterals -0.0 :: Double -------------------------------------+------------------------------------- Reporter: rwbarton | Owner: Nolan Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 8.1 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3212 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => patch * differential: => Phab:D3212 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13211#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13211: NegativeLiterals -0.0 :: Double
-------------------------------------+-------------------------------------
Reporter: rwbarton | Owner: Nolan
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Compiler | Version: 8.1
Resolution: | Keywords: newcomer
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D3212
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#13211: NegativeLiterals -0.0 :: Double -------------------------------------+------------------------------------- Reporter: rwbarton | Owner: Nolan Type: bug | Status: closed Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 8.1 Resolution: fixed | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D3212 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: patch => closed * resolution: => fixed * milestone: => 8.4.1 Comment: Thanks Nolan! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13211#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC