Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,251
    • Issues 5,251
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 583
    • Merge requests 583
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #20156
Closed
Open
Issue created Jul 23, 2021 by Krzysztof Gogolewski@monoidalDeveloper

Linear types and RULES

RULES can be used to rewrite a linear function to an unrestricted one, violating invariants.

For example, this program fails with -O -dlinear-core-lint.

{-# LANGUAGE LinearTypes, EmptyCase #-}

module Main where

{-# NOINLINE silly #-}
silly :: Bool %1 -> Bool
silly True = False
silly False = True

{-# RULES "silly" forall x. silly x = not x #-}

{-# NOINLINE g #-}
g :: Bool %1 -> Bool
g x = silly x

main :: IO ()
main = print (silly True)

The only solution I see is computing the usage environment of both sides and refusing to perform the rule if the usage environment or the RHS of the rule is disallowed in that context.

Originally reported by Richard at https://github.com/tweag/ghc/issues/413.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking