Linear let and where bindings
For expediency, the initial implementation of linear types in GHC made it so that let and where binders would always be considered unrestricted. This was rather unpleasant, and probably a big obstacle to adoption. At any rate, this was not how the proposal was designed. This patch fixes this infelicity. It was surprisingly difficult to build, which explains, in part, why it took so long to materialise. As of this patch, let or where bindings marked with %1 will be linear (respectively %p for an arbitrary multiplicity p). Unmarked let will infer their multiplicity. Here is a prototypical example of program that used to be rejected and is accepted with this patch: ```haskell f :: A %1 -> B g :: B %1 -> C h :: A %1 -> C h x = g y where y = f x ``` Exceptions: - Recursive let are unrestricted, as there isn't a clear semantics of what a linear recursive binding would be. - Destructive lets with lazy bindings are unrestricted, as their desugaring isn't linear (see also #23461). - (Strict) destructive lets with inferred polymorphic type are unrestricted. Because the desugaring isn't linear (See #18461 down-thread). Closes #18461 and #18739 Co-authored-by: @jackohughes
Showing
- compiler/GHC/Core.hs 13 additions, 0 deletionscompiler/GHC/Core.hs
- compiler/GHC/Driver/Session.hs 1 addition, 1 deletioncompiler/GHC/Driver/Session.hs
- compiler/GHC/Hs/Binds.hs 18 additions, 2 deletionscompiler/GHC/Hs/Binds.hs
- compiler/GHC/Hs/Instances.hs 7 additions, 0 deletionscompiler/GHC/Hs/Instances.hs
- compiler/GHC/Hs/Utils.hs 5 additions, 1 deletioncompiler/GHC/Hs/Utils.hs
- compiler/GHC/HsToCore/Arrows.hs 3 additions, 3 deletionscompiler/GHC/HsToCore/Arrows.hs
- compiler/GHC/HsToCore/Binds.hs 59 additions, 0 deletionscompiler/GHC/HsToCore/Binds.hs
- compiler/GHC/HsToCore/Expr.hs 31 additions, 5 deletionscompiler/GHC/HsToCore/Expr.hs
- compiler/GHC/HsToCore/ListComp.hs 2 additions, 2 deletionscompiler/GHC/HsToCore/ListComp.hs
- compiler/GHC/HsToCore/Match.hs 7 additions, 11 deletionscompiler/GHC/HsToCore/Match.hs
- compiler/GHC/HsToCore/Match.hs-boot 2 additions, 1 deletioncompiler/GHC/HsToCore/Match.hs-boot
- compiler/GHC/HsToCore/Utils.hs 5 additions, 2 deletionscompiler/GHC/HsToCore/Utils.hs
- compiler/GHC/Parser.y 12 additions, 1 deletioncompiler/GHC/Parser.y
- compiler/GHC/Parser/PostProcess.hs 29 additions, 11 deletionscompiler/GHC/Parser/PostProcess.hs
- compiler/GHC/Rename/Bind.hs 17 additions, 2 deletionscompiler/GHC/Rename/Bind.hs
- compiler/GHC/Tc/Gen/Arrow.hs 8 additions, 8 deletionscompiler/GHC/Tc/Gen/Arrow.hs
- compiler/GHC/Tc/Gen/Bind.hs 200 additions, 85 deletionscompiler/GHC/Tc/Gen/Bind.hs
- compiler/GHC/Tc/Gen/Expr.hs 7 additions, 5 deletionscompiler/GHC/Tc/Gen/Expr.hs
- compiler/GHC/Tc/Gen/Match.hs 57 additions, 48 deletionscompiler/GHC/Tc/Gen/Match.hs
- compiler/GHC/Tc/Gen/Match.hs-boot 4 additions, 2 deletionscompiler/GHC/Tc/Gen/Match.hs-boot
Loading
Please register or sign in to comment