Opened 20 months ago

Last modified 4 months ago

#11197 new bug

Overeager deferred type errors

Reported by: goldfire Owned by: goldfire
Priority: normal Milestone: 8.4.1
Component: Compiler (Type checker) Version: 7.11
Keywords: TypeInType Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

With TypeInType, the solver now works in terms of unlifted equality. The only place this matters is in deferred type errors, which now are more eager than they were before. For example:

{-# OPTIONS_GHC -fdefer-type-errors #-}

module Main where

main = do
  putStrLn "Hi there."
  putStrLn True

This used to print

Hi there.
Defer: Defer.hs:7:12: error:
   ...

Now it prints

Defer: Defer.hs:7:12: error:
   ...

No more Hi there..

Thinking about Core, this change should be expected. GHC puts all evidence bindings for main at the top, and with unlifted equality in the solver, these bindings now contain case typeError ... of ..., which forces the type error eagerly. Previously, there was a lazy binding for a lifted equality witness, unpacked only at the last moment by magic in the desugarer, thus the lazier warning.

Simon has proposed customizing the FloatIn pass to deal with this scenario. I do believe this would work nicely, but I have not yet implemented it.

Change History (11)

comment:1 Changed 20 months ago by goldfire

This regression affects test cases Defer02 and T7861. I'm less concerned about the latter, as it requires ImpredicativeTypes.

comment:2 Changed 20 months ago by Richard Eisenberg <eir@…>

In 67465497/ghc:

Add kind equalities to GHC.

This implements the ideas originally put forward in
"System FC with Explicit Kind Equality" (ICFP'13).

There are several noteworthy changes with this patch:
 * We now have casts in types. These change the kind
   of a type. See new constructor `CastTy`.

 * All types and all constructors can be promoted.
   This includes GADT constructors. GADT pattern matches
   take place in type family equations. In Core,
   types can now be applied to coercions via the
   `CoercionTy` constructor.

 * Coercions can now be heterogeneous, relating types
   of different kinds. A coercion proving `t1 :: k1 ~ t2 :: k2`
   proves both that `t1` and `t2` are the same and also that
   `k1` and `k2` are the same.

 * The `Coercion` type has been significantly enhanced.
   The documentation in `docs/core-spec/core-spec.pdf` reflects
   the new reality.

 * The type of `*` is now `*`. No more `BOX`.

 * Users can write explicit kind variables in their code,
   anywhere they can write type variables. For backward compatibility,
   automatic inference of kind-variable binding is still permitted.

 * The new extension `TypeInType` turns on the new user-facing
   features.

 * Type families and synonyms are now promoted to kinds. This causes
   trouble with parsing `*`, leading to the somewhat awkward new
   `HsAppsTy` constructor for `HsType`. This is dispatched with in
   the renamer, where the kind `*` can be told apart from a
   type-level multiplication operator. Without `-XTypeInType` the
   old behavior persists. With `-XTypeInType`, you need to import
   `Data.Kind` to get `*`, also known as `Type`.

 * The kind-checking algorithms in TcHsType have been significantly
   rewritten to allow for enhanced kinds.

 * The new features are still quite experimental and may be in flux.

 * TODO: Several open tickets: #11195, #11196, #11197, #11198, #11203.

 * TODO: Update user manual.

Tickets addressed: #9017, #9173, #7961, #10524, #8566, #11142.
Updates Haddock submodule.

comment:3 Changed 19 months ago by simonpj

Keywords: TypeInType added

comment:4 Changed 18 months ago by goldfire

See also #2988, which discusses other improvements to floating-in.

comment:5 Changed 18 months ago by thomie

Component: CompilerCompiler (Type checker)

comment:6 Changed 16 months ago by Ben Gamari <ben@…>

In aa61174/ghc:

users-guide: Add references to various issues in bugs section

Test Plan: Read it

Reviewers: austin

Reviewed By: austin

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2052

GHC Trac Issues: #7411, #11197, #11554, #11715

comment:7 Changed 16 months ago by thoughtpolice

Milestone: 8.0.18.0.2

comment:8 Changed 15 months ago by bgamari

It looks like this is already affecting users: https://github.com/CRogers/should-not-typecheck/pull/6.

comment:9 Changed 15 months ago by goldfire

The commentary on the PR linked to in comment:8 contains a workaround in that case.

comment:10 Changed 11 months ago by bgamari

Milestone: 8.0.28.2.1

This won't happen for 8.0.2.

comment:11 Changed 4 months ago by bgamari

Milestone: 8.2.18.4.1

Given that 8.2.1-rc1 is imminent, I'm bumping these off to the 8.4

Note: See TracTickets for help on using tickets.