Skip to content

Commit 2f105a7

Browse files
Merge branch 'develop-prettyprinter'. Close #383.
**Description** Currently, the architecture of Copilot mixes backends with other libraries, which makes the result not uniform. For example, the pretty-printer is part of `copilot-core`, while the C99 backend and the interpreter are in separate libraries. The implementation does not match our desired architecture according to our design documents, and it makes the code partly harder to maintain. A better solution would be to move the pretty-printer to a separate library, and to deprecate any pretty-printer modules exported from `copilot-core`. **Type** - Maintenance: match proposed design. **Additional context** None. **Requester** - Ivan Perez **Method to check presence of bug** None (not a bug). **Expected result** There should be a `copilot-prettyprinter` library, and all pretty-printer modules in `copilot-core` should be deprecated. The following Dockerfile checks that the new library is installed and the modules in the pretty-printer can be used from their new location, in which case it prints the message `Success`: ```Dockerfile FROM ubuntu:trusty RUN apt-get update RUN apt-get install --yes software-properties-common RUN add-apt-repository ppa:hvr/ghc RUN apt-get update RUN apt-get install --yes ghc-8.6.5 cabal-install-2.4 RUN apt-get install --yes libz-dev ENV PATH=/opt/ghc/8.6.5/bin:/opt/cabal/2.4/bin:$PWD/.cabal-sandbox/bin:$PATH RUN cabal update RUN cabal v1-sandbox init RUN cabal v1-install alex happy RUN apt-get install --yes git SHELL ["/bin/bash", "-c"] CMD git clone $REPO && cd $NAME && git checkout $COMMIT && cd .. \ && cabal v1-install copilot/copilot**/ --enable-tests --enable-documentation --run-tests \ && cabal v1-exec -- runhaskell -Wall -Werror=deprecations <<< "import Copilot.PrettyPrint(); main :: IO (); main = return ()" \ && echo "Success" ``` Command (substitute variables based on new path after merge): ``` $ docker run -e "REPO=https://github.com/Copilot-Language/copilot" -e "NAME=copilot" -e "COMMIT=<HASH>" -it copilot-verify-383 ``` **Solution implemented** Deprecate `Copilot.Core.PrettyPrinter`. Move module to a different name-space and library (e.g., `copilot-prettyprinter`). Modify the tests accordingly. Deprecate `Copilot.Core.PrettyPrint`. Move module to a new library `copilot-prettyprinter` and place it under a new namespace (`Copilot.PrettyPrint`). Copy over the necessary definitions from `Copilot.Core.Type.ShowInternal`, as well as `Copilot.Core.Error`. Adapt cabal file in new library, minimizing dependencies. Adapt README in new library to reflect the purpose of the library. Modify copilot-language, copilot-theorem, and copilot-interpreter so that the definitions used and exported (when appropriate) are taken from copilot-prettyprinter. **Further notes** None.
2 parents 1456f12 + 395217d commit 2f105a7

File tree

19 files changed

+463
-31
lines changed

19 files changed

+463
-31
lines changed

copilot-core/CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2022-10-21
2+
* Deprecate Copilot.Core.PrettyPrinter. (#383)
3+
14
2022-09-07
25
* Version bump (3.11). (#376)
36
* Deprecate Copilot.Core.PrettyDot. (#359)

copilot-core/src/Copilot/Core/PrettyPrint.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
{-# LANGUAGE Safe #-}
77

88
module Copilot.Core.PrettyPrint
9+
{-# DEPRECATED "This module is deprecated in Copilot 3.12. Use copilot-prettyprinter instead." #-}
910
( prettyPrint
1011
, ppExpr
1112
) where

copilot-interpreter/CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2022-10-21
2+
* Use pretty-printer from copilot-prettyprinter. (#383)
3+
14
2022-09-07
25
* Version bump (3.11). (#376)
36
* Split copilot-interpreter into separate library. (#361)

copilot-interpreter/copilot-interpreter.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ test-suite unit-tests
7676

7777
, copilot-core
7878
, copilot-interpreter
79+
, copilot-prettyprinter
7980

8081
hs-source-dirs:
8182
tests

copilot-interpreter/tests/Test/Copilot/Interpret/Eval.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ import Text.PrettyPrint.HughesPJ (render)
2828
import Copilot.Core.Expr (Expr (Const, Drop, Op1, Op2, Op3),
2929
UExpr (UExpr))
3030
import Copilot.Core.Operators (Op1 (..), Op2 (..), Op3 (..))
31-
import Copilot.Core.PrettyPrint (ppExpr)
3231
import Copilot.Core.Spec (Observer (..), Spec (..), Stream (Stream))
3332
import Copilot.Core.Type (Type (..), Typed (typeOf))
3433
import Copilot.Interpret.Eval (ExecTrace (interpObservers),
3534
ShowType (Haskell), eval)
35+
import Copilot.PrettyPrint (ppExpr)
3636

3737
-- Internal imports: auxiliary functions
3838
import Test.Extra (apply1, apply2, apply3)

copilot-language/CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2022-10-21
2+
* Use pretty-printer from copilot-prettyprinter. (#383)
3+
14
2022-09-07
25
* Version bump (3.11). (#376)
36
* Deprecate prettyPrint. (#362)

copilot-language/copilot-language.cabal

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,17 @@ source-repository head
3535
library
3636
default-language: Haskell2010
3737
hs-source-dirs: src
38-
build-depends: base >= 4.9 && < 5
38+
build-depends: base >= 4.9 && < 5
3939

40-
, array >= 0.5 && < 0.6
41-
, containers >= 0.4 && < 0.7
42-
, data-reify >= 0.6 && < 0.7
43-
, mtl >= 2.0 && < 3
40+
, array >= 0.5 && < 0.6
41+
, containers >= 0.4 && < 0.7
42+
, data-reify >= 0.6 && < 0.7
43+
, mtl >= 2.0 && < 3
4444

45-
, copilot-core >= 3.11 && < 3.12
46-
, copilot-interpreter >= 3.11 && < 3.12
47-
, copilot-theorem >= 3.11 && < 3.12
45+
, copilot-core >= 3.11 && < 3.12
46+
, copilot-interpreter >= 3.11 && < 3.12
47+
, copilot-prettyprinter >= 3.11 && < 3.12
48+
, copilot-theorem >= 3.11 && < 3.12
4849

4950
exposed-modules: Copilot.Language
5051
, Copilot.Language.Operators.BitWise

copilot-language/src/Copilot/Language.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import Data.Word
4747
import Copilot.Core (Name, Typed)
4848
import Copilot.Core.Type
4949
import Copilot.Core.Type.Array
50-
import qualified Copilot.Core.PrettyPrint as PP
5150
import Copilot.Language.Error
5251
import Copilot.Language.Interpret
5352
import Copilot.Language.Operators.Boolean
@@ -68,6 +67,7 @@ import Copilot.Language.Reify
6867
import Copilot.Language.Prelude
6968
import Copilot.Language.Spec
7069
import Copilot.Language.Stream (Stream)
70+
import qualified Copilot.PrettyPrint as PP
7171

7272
-- | Transform a high-level Copilot Language specification into a low-level
7373
-- Copilot Core specification and pretty-print it to stdout.

copilot-prettyprinter/CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2022-10-21
2+
* Create new library for pretty-printer. (#383)

copilot-prettyprinter/LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2009
2+
BSD3 License terms
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions
6+
are met:
7+
8+
Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the distribution.
14+
15+
Neither the name of the developers nor the names of its contributors
16+
may be used to endorse or promote products derived from this software
17+
without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0 commit comments

Comments
 (0)