Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

copilot-prettyprinter: Support pretty-printing struct updates #526

Closed
RyanGlScott opened this issue Jul 8, 2024 · 7 comments · Fixed by #528
Closed

copilot-prettyprinter: Support pretty-printing struct updates #526

RyanGlScott opened this issue Jul 8, 2024 · 7 comments · Fixed by #528
Assignees
Labels
CR:Status:Closed Admin only: Change request that has been completed CR:Type:Bug Admin only: Change request pertaining to error detected
Milestone

Comments

@RyanGlScott
Copy link
Collaborator

Copilot 3.20 added support for struct updates via the new UpdateField operation. At the moment, there is no support in the copilot-prettyprinter package for pretty-printing UpdateField operations. For example, this means that the following Copilot specification will fail when executed:

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Main (main) where

import Data.Foldable (for_)
import Data.Functor (void)
import Data.Word (Word32)

import qualified Copilot.PrettyPrint as PP
import Language.Copilot

data S = S
  { unS :: Field "unS" Word32
  }

instance Struct S where
  typeName _ = "s"
  toValues s = [Value typeOf (unS s)]

instance Typed S where
  typeOf = Struct (S (Field 0))

spec :: Spec
spec = do
  let externS :: Stream S
      externS = extern "extern_s" Nothing

      example :: Stream Word32
      example = (externS ## unS =: 42) # unS

  trigger "example" (example == example) [arg externS, arg example]

main :: IO ()
main = do
  spec' <- reify spec
  putStrLn $ PP.prettyPrint spec'
$ runghc UpdateFieldPP.hs 
UpdateFieldPP.hs: src/Copilot/PrettyPrint.hs:(79,12)-(102,31): Non-exhaustive patterns in case

I have a prototype fix available in this branch, which could be used as a starting point for a patch.

@ivanperez-keera
Copy link
Member

ivanperez-keera commented Aug 21, 2024

Description

Copilot currently supports modifying values from streams of structs, but not pretty-printing them using copilot-prettyprinter.

Type

  • Bug: exception produced when executing valid specification.

Additional context

Requester

  • Ryan Scott (Galois)

Method to check presence of bug

Running the following specification that pretty-prints a spec with a struct update:

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Main (main) where

import Data.Foldable (for_)
import Data.Functor (void)
import Data.Word (Word32)

import qualified Copilot.PrettyPrint as PP
import Language.Copilot

data S = S
  { unS :: Field "unS" Word32
  }

instance Struct S where
  typeName _ = "s"
  toValues s = [Value typeOf (unS s)]

instance Typed S where
  typeOf = Struct (S (Field 0))

spec :: Spec
spec = do
  let externS :: Stream S
      externS = extern "extern_s" Nothing

      example :: Stream Word32
      example = (externS ## unS =: 42) # unS

  trigger "example" (example == example) [arg externS, arg example]

main :: IO ()
main = do
  spec' <- reify spec
  putStrLn $ PP.prettyPrint spec'

produces an error message:

$ runghc UpdateFieldPP.hs 
UpdateFieldPP.hs: src/Copilot/PrettyPrint.hs:(79,12)-(102,31): Non-exhaustive patterns in case

when it should instead execute correctly and pretty-print the spec.

Expected result

Copilot allows pretty-printing struct updates in copilot-prettyprinter.

Desired result

Copilot allows pretty-printing struct updates in copilot-prettyprinter.

Proposed solution

Introduce a case for pretty-printing struct updates.

Further notes

None.

@ivanperez-keera ivanperez-keera added CR:Type:Bug Admin only: Change request pertaining to error detected CR:Status:Initiated Admin only: Change request that has been initiated labels Aug 21, 2024
@ivanperez-keera
Copy link
Member

Change Manager: Confirmed that the issue exists.

@ivanperez-keera ivanperez-keera added CR:Status:Confirmed Admin only: Change request that has been acknowledged by the change manager and removed CR:Status:Initiated Admin only: Change request that has been initiated labels Aug 21, 2024
@ivanperez-keera
Copy link
Member

Technical Lead: Confirmed that the issue should be addressed.

@ivanperez-keera ivanperez-keera added CR:Status:Accepted Admin only: Change request accepted by technical lead and removed CR:Status:Confirmed Admin only: Change request that has been acknowledged by the change manager labels Aug 21, 2024
@ivanperez-keera
Copy link
Member

Technical Lead: Issue scheduled for fixing in Copilot 4.

Fix assigned to: @RyanGlScott .

@ivanperez-keera ivanperez-keera added CR:Status:Scheduled Admin only: Change requested scheduled and removed CR:Status:Accepted Admin only: Change request accepted by technical lead labels Aug 21, 2024
@ivanperez-keera ivanperez-keera added this to the Copilot 4 milestone Aug 21, 2024
RyanGlScott added a commit to GaloisInc/copilot-1 that referenced this issue Aug 21, 2024
…opilot-Language#526.

This commit adds pretty-printing of expressions that update fields of a struct.
RyanGlScott added a commit to GaloisInc/copilot-1 that referenced this issue Aug 21, 2024
…opilot-Language#526.

This commit adds pretty-printing of expressions that update fields of a struct.
@RyanGlScott
Copy link
Collaborator Author

Implementor: Solution implemented, review requested.

@ivanperez-keera ivanperez-keera added CR:Status:Implementation Admin only: Change request that is currently being implemented and removed CR:Status:Scheduled Admin only: Change requested scheduled labels Aug 21, 2024
@ivanperez-keera ivanperez-keera added CR:Status:Verification Admin only: Change request that is currently being verified and removed CR:Status:Implementation Admin only: Change request that is currently being implemented labels Aug 30, 2024
RyanGlScott added a commit to GaloisInc/copilot-1 that referenced this issue Aug 30, 2024
…opilot-Language#526.

This commit adds pretty-printing of expressions that update fields of a struct.
@ivanperez-keera
Copy link
Member

Change Manager: Verified that:

  • Solution is implemented:
    • The code proposed compiles and passes all tests. Details:
      Build log: https://app.travis-ci.com/github/Copilot-Language/copilot/builds/272116442

    • The solution proposed produces the expected result. Details:
      The following Dockerfile installs copilot and runs a spec that uses copilot-prettyprinter to pretty print an expression with stream with a struct update in it, followed by "Success":

      --- Dockerfile
      FROM ubuntu:focal
      
      ENV DEBIAN_FRONTEND=noninteractive
      RUN apt-get update
      
      RUN apt-get install --yes libz-dev
      RUN apt-get install --yes git
      
      RUN apt-get install --yes wget
      RUN mkdir -p $HOME/.ghcup/bin
      RUN wget https://downloads.haskell.org/~ghcup/0.1.19.2/x86_64-linux-ghcup-0.1.19.2 -O $HOME/.ghcup/bin/ghcup
      
      RUN chmod a+x $HOME/.ghcup/bin/ghcup
      ENV PATH=$PATH:/root/.ghcup/bin/
      ENV PATH=$PATH:/root/.cabal/bin/
      RUN apt-get install --yes curl
      RUN apt-get install --yes gcc g++ make libgmp3-dev
      RUN apt-get install --yes pkg-config
      
      SHELL ["/bin/bash", "-c"]
      
      RUN ghcup install ghc 9.4
      RUN ghcup install cabal 3.2
      RUN ghcup set ghc 9.4.8
      RUN cabal update
      
      ADD UpdateFieldPP.hs /tmp/UpdateFieldPP.hs
      
      CMD git clone $REPO \
          && cd $NAME \
          && git checkout $COMMIT \
          && cabal v1-sandbox init \
          && cabal v1-install alex happy \
          && cabal v1-install copilot**/ \
          && cabal v1-exec -- runhaskell /tmp/UpdateFieldPP.hs \
          && echo Success
          
      --- UpdateFieldPP.hs
      {-# LANGUAGE DataKinds #-}
      {-# LANGUAGE NoImplicitPrelude #-}
      module Main (main) where
      
      import Data.Foldable (for_)
      import Data.Functor (void)
      import Data.Word (Word32)
      
      import qualified Copilot.PrettyPrint as PP
      import Language.Copilot
      
      data S = S
        { unS :: Field "unS" Word32
        }
      
      instance Struct S where
        typeName _ = "s"
        toValues s = [Value typeOf (unS s)]
      
      instance Typed S where
        typeOf = Struct (S (Field 0))
      
      spec :: Spec
      spec = do
        let externS :: Stream S
            externS = extern "extern_s" Nothing
      
            example :: Stream Word32
            example = (externS ## unS =: 42) # unS
      
        trigger "example" (example == example) [arg externS, arg example]
      
      main :: IO ()
      main = do
        spec' <- reify spec
        putStrLn $ PP.prettyPrint spec'

      Command (substitute variables based on new path after merge):

      $ docker run -e "REPO=https://github.com/GaloisInc/copilot-1" -e "NAME=copilot-1" -e "COMMIT=cc9ca2276e86676ef41393412224cff96c952a61" -it copilot-verify-526
      
  • Implementation is documented. Details:
    No new functions are provided; just an update to an existing function.
  • Change history is clear.
  • Commit messages are clear.
  • Changelogs are updated.
  • Examples are updated. Details:
    No updates needed.
  • Required version bumps are evaluated. Details:
    Bump not needed (bug fix).

@ivanperez-keera
Copy link
Member

Change Manager: Implementation ready to be merged.

@ivanperez-keera ivanperez-keera added CR:Status:Closed Admin only: Change request that has been completed and removed CR:Status:Verification Admin only: Change request that is currently being verified labels Sep 6, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
CR:Status:Closed Admin only: Change request that has been completed CR:Type:Bug Admin only: Change request pertaining to error detected
Development

Successfully merging a pull request may close this issue.

2 participants