Skip to content
Snippets Groups Projects
Forked from Glasgow Haskell Compiler / GHC
18051 commits behind the upstream repository.
Tao He's avatar
Tao He authored
Currently, we parse both the **integral literal** value and the patterns
as `OverLit HsIntegral`.  For example:

```
  case 0::Int of
      0 -> putStrLn "A"
      1 -> putStrLn "B"
      _ -> putStrLn "C"
```

When checking the exhaustiveness of pattern matching, we translate the
`0` in value position as `PmOLit`, but translate the `0` and `1` in
pattern position as `PmSLit`. The inconsistency leads to the failure of
`eqPmLit` to detect the equality and report warning of "Pattern match is
redundant" on pattern `0`, as reported in #14546. In this patch we
remove the specialization of `OverLit` patterns, and keep the overloaded
number literal in pattern as it is to maintain the consistency.  Now we
can capture the exhaustiveness of pattern `0` and the redundancy of
pattern `1` and `_`.

For **string literals**, we parse the string literals as `HsString`.
When  `OverloadedStrings` is enabled, it further be turned as `HsOverLit
HsIsString`, whether it's type is `String` or not. For example:

```
  case "foo" of
      "foo" -> putStrLn "A"
      "bar" -> putStrLn "B"
      "baz" -> putStrLn "C"
```

Previously, the overloaded string values are translated to `PmOLit` and
the non-overloaded string values are translated to `PmSLit`. However the
string patterns, both overloaded and non-overloaded, are translated to
list of characters. The inconsistency leads to wrong warnings about
redundant and non-exhaustive pattern matching warnings, as reported
in #14546.

In order to catch the redundant pattern in following case:

```
  case "foo" of
      ('f':_) -> putStrLn "A"
      "bar" -> putStrLn "B"
```

In this patch, we translate non-overloaded string literals, both in
value position and pattern position, as list of characters. For
overloaded string literals, we only translate it to list of characters
only when it's type is `stringTy`, since we know nothing about the
`toString` methods.  But we know that if two overloaded strings are
syntax equal, then they are equal. Then if it's type is not `stringTy`,
we just translate it to `PmOLit`. We can still capture the
exhaustiveness of pattern `"foo"` and the redundancy of pattern `"bar"`
and `"baz"` in the following code:

```
{-# LANGUAGE OverloadedStrings #-}
main = do
  case "foo" of
      "foo" -> putStrLn "A"
      "bar" -> putStrLn "B"
      "baz" -> putStrLn "C"
```

Test Plan: make test TEST="T14546"

Reviewers: bgamari, simonpj

Reviewed By: bgamari, simonpj

Subscribers: simonpj, thomie, carter

GHC Trac Issues: #14546

Differential Revision: https://phabricator.haskell.org/D4571
1f88f541
History

GHC Testsuite Readme

For the full testsuite documentation, please see here.

Quick Guide

Commands to run testsuite:

  • Full testsuite: make
  • Using more threads: make THREADS=12
  • Reduced (fast) testsuite: make fast
  • Run a specific test: make TEST=tc054
  • Test a specific 'way': make WAY=optllvm
  • Keeping the run directory after test run: make CLEANUP=0. You will find a directory {test_name}.run in the test's source directory.
  • Test a specifc stage of GHC: make stage=1
  • Skip performance tests: make SKIP_PERF_TESTS=YES
  • Set verbosity: make VERBOSE=n where n=0: No per-test output, n=1: Only failures, n=2: Progress output, n=3: Include commands called (default), n=4: Include perf test results unconditionally, n=5: Echo commands in subsidiary make invocations
  • Pass in extra GHC options: make EXTRA_HC_OPTS=-fvectorize

You can also change directory to a specific test folder to run that individual test or group of tests. For example:

$ cd tests/array
$ make

Testsuite Ways

The testsuite can be run in a variety of 'ways'. This concept refers to different ways that GHC can compile the code. For example, using the native code generator (-fasm) is one way, while using the LLVM code generator (-fllvm) is another way.

The various ways that GHC supports are defined in config/ghc

Adding Tests

Please see the more extensive documentation here.