From 4a9255a76cb912172d6232ffa04c12da025ca76c Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 11:06:11 -0400 Subject: [PATCH 01/61] Stub in a semantic-python package. --- cabal.project | 2 +- semantic-python/README.md | 3 +++ semantic-python/Setup.hs | 2 ++ semantic-python/semantic-python.cabal | 26 ++++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 semantic-python/README.md create mode 100644 semantic-python/Setup.hs create mode 100644 semantic-python/semantic-python.cabal diff --git a/cabal.project b/cabal.project index 5772f08158..7ef06d72bf 100644 --- a/cabal.project +++ b/cabal.project @@ -1,4 +1,4 @@ -packages: . semantic-core +packages: . semantic-core semantic-python jobs: $ncpus diff --git a/semantic-python/README.md b/semantic-python/README.md new file mode 100644 index 0000000000..c8740a81d4 --- /dev/null +++ b/semantic-python/README.md @@ -0,0 +1,3 @@ +# Semantic support for Python + +This package implements `semantic` support for Python using the `semantic-core` intermediate language. diff --git a/semantic-python/Setup.hs b/semantic-python/Setup.hs new file mode 100644 index 0000000000..9a994af677 --- /dev/null +++ b/semantic-python/Setup.hs @@ -0,0 +1,2 @@ +import Distribution.Simple +main = defaultMain diff --git a/semantic-python/semantic-python.cabal b/semantic-python/semantic-python.cabal new file mode 100644 index 0000000000..b7dea34c83 --- /dev/null +++ b/semantic-python/semantic-python.cabal @@ -0,0 +1,26 @@ +cabal-version: 2.2 + +name: semantic-python +version: 0.0.0.0 +synopsis: Semantic support for Python. +description: Semantic support for Python using the semantic-core intermediate language. +homepage: https://github.com/github/semantic/tree/master/semantic-python#readme +-- bug-reports: +license: MIT +license-file: LICENSE +author: The Semantic authors +maintainer: opensource+semantic@github.com +copyright: (c) 2019 GitHub, Inc. +category: Language +build-type: Simple +extra-source-files: README.md + +tested-with: GHC == 8.6.4 + +library + -- exposed-modules: + -- other-modules: + -- other-extensions: + build-depends: base ^>=4.12.0.0 + hs-source-dirs: src + default-language: Haskell2010 From e4e5370296003b969e504fbe3ed2f49d329b7a95 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 11:07:57 -0400 Subject: [PATCH 02/61] Correct some fields for Core. --- semantic-core/semantic-core.cabal | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/semantic-core/semantic-core.cabal b/semantic-core/semantic-core.cabal index 05cf971b23..bffa261183 100644 --- a/semantic-core/semantic-core.cabal +++ b/semantic-core/semantic-core.cabal @@ -4,13 +4,13 @@ name: semantic-core version: 0.0.0.0 synopsis: Semantic core intermediate language -- description: -homepage: https://github.com/github/semantic-core +homepage: https://github.com/github/semantic/tree/master/semantic-core#readme -- bug-reports: license: MIT license-file: LICENSE -author: Rob Rix -maintainer: robrix@github.com --- copyright: +author: The Semantic authors +maintainer: opensource+semantic@github.com +copyright: (c) 2019 GitHub, Inc. category: Language build-type: Simple extra-source-files: README.md From ebc025b60073b16b8cdd8cc6c444c750bd05c040 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 11:12:12 -0400 Subject: [PATCH 03/61] Add some dependencies. --- semantic-python/semantic-python.cabal | 2 ++ 1 file changed, 2 insertions(+) diff --git a/semantic-python/semantic-python.cabal b/semantic-python/semantic-python.cabal index b7dea34c83..bd5b0ee1bc 100644 --- a/semantic-python/semantic-python.cabal +++ b/semantic-python/semantic-python.cabal @@ -22,5 +22,7 @@ library -- other-modules: -- other-extensions: build-depends: base ^>=4.12.0.0 + , semantic-core ^>= 0.0.0.0 + , tree-sitter ^>= 0.1.0.0 hs-source-dirs: src default-language: Haskell2010 From 7ec058c38d9cb9778b73ff4c81cde05a01966c16 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 11:12:58 -0400 Subject: [PATCH 04/61] Fix a disagreement between the LICENSE file and Copyright field. --- semantic.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semantic.cabal b/semantic.cabal index aad72ff482..3f54d8074b 100644 --- a/semantic.cabal +++ b/semantic.cabal @@ -8,7 +8,7 @@ author: The Semantic authors maintainer: opensource+semantic@github.com license: MIT license-file: LICENSE -copyright: (c) 2016-2019 GitHub, Inc. +copyright: (c) 2015-2019 GitHub, Inc. category: Web build-type: Simple stability: alpha From 52fa1a1c4a66b36d899fdfe8f6d1ec1788941d6c Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 11:13:26 -0400 Subject: [PATCH 05/61] =?UTF-8?q?Cabal=20complains=20if=20this=20file=20is?= =?UTF-8?q?n=E2=80=99t=20here.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- semantic-python/LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 semantic-python/LICENSE diff --git a/semantic-python/LICENSE b/semantic-python/LICENSE new file mode 100644 index 0000000000..331b241b36 --- /dev/null +++ b/semantic-python/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 GitHub + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 5563bc19a09faf94208e4c47a408431589fe339c Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 11:20:58 -0400 Subject: [PATCH 06/61] Depend on tree-sitter-python. --- semantic-python/semantic-python.cabal | 1 + 1 file changed, 1 insertion(+) diff --git a/semantic-python/semantic-python.cabal b/semantic-python/semantic-python.cabal index bd5b0ee1bc..946bd8106a 100644 --- a/semantic-python/semantic-python.cabal +++ b/semantic-python/semantic-python.cabal @@ -24,5 +24,6 @@ library build-depends: base ^>=4.12.0.0 , semantic-core ^>= 0.0.0.0 , tree-sitter ^>= 0.1.0.0 + , tree-sitter-python ^>= 0.1.0.1 hs-source-dirs: src default-language: Haskell2010 From 6894a756b16ca222620fec6cbc333c79bb84c833 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 11:22:10 -0400 Subject: [PATCH 07/61] Stub in a Language.Python.Core module. --- semantic-python/semantic-python.cabal | 3 ++- semantic-python/src/Language/Python/Core.hs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 semantic-python/src/Language/Python/Core.hs diff --git a/semantic-python/semantic-python.cabal b/semantic-python/semantic-python.cabal index 946bd8106a..9a6f858ba7 100644 --- a/semantic-python/semantic-python.cabal +++ b/semantic-python/semantic-python.cabal @@ -18,7 +18,8 @@ extra-source-files: README.md tested-with: GHC == 8.6.4 library - -- exposed-modules: + exposed-modules: + Language.Python.Core -- other-modules: -- other-extensions: build-depends: base ^>=4.12.0.0 diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs new file mode 100644 index 0000000000..ddf895f1aa --- /dev/null +++ b/semantic-python/src/Language/Python/Core.hs @@ -0,0 +1 @@ +module Language.Python.Core where From 40e9999b023bfdc0d131815e8a2ed6cddcb8e4da Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 11:23:38 -0400 Subject: [PATCH 08/61] Add bug-reports fields. --- semantic-core/semantic-core.cabal | 2 +- semantic-python/semantic-python.cabal | 2 +- semantic.cabal | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/semantic-core/semantic-core.cabal b/semantic-core/semantic-core.cabal index bffa261183..c916be5bd2 100644 --- a/semantic-core/semantic-core.cabal +++ b/semantic-core/semantic-core.cabal @@ -5,7 +5,7 @@ version: 0.0.0.0 synopsis: Semantic core intermediate language -- description: homepage: https://github.com/github/semantic/tree/master/semantic-core#readme --- bug-reports: +bug-reports: https://github.com/github/semantic/issues license: MIT license-file: LICENSE author: The Semantic authors diff --git a/semantic-python/semantic-python.cabal b/semantic-python/semantic-python.cabal index 9a6f858ba7..da494d9687 100644 --- a/semantic-python/semantic-python.cabal +++ b/semantic-python/semantic-python.cabal @@ -5,7 +5,7 @@ version: 0.0.0.0 synopsis: Semantic support for Python. description: Semantic support for Python using the semantic-core intermediate language. homepage: https://github.com/github/semantic/tree/master/semantic-python#readme --- bug-reports: +bug-reports: https://github.com/github/semantic/issues license: MIT license-file: LICENSE author: The Semantic authors diff --git a/semantic.cabal b/semantic.cabal index 3f54d8074b..e066bc968b 100644 --- a/semantic.cabal +++ b/semantic.cabal @@ -4,6 +4,7 @@ version: 0.6.0.0 synopsis: Framework and executable for analyzing and diffing untrusted code. description: Semantic is a library for parsing, analyzing, and comparing source code across many languages. homepage: http://github.com/github/semantic#readme +bug-reports: https://github.com/github/semantic/issues author: The Semantic authors maintainer: opensource+semantic@github.com license: MIT From 83a6c6ca78339c75893a43ebd24fb44b6fe8086e Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 11:25:11 -0400 Subject: [PATCH 09/61] Make the different cabal files line up. --- semantic.cabal | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/semantic.cabal b/semantic.cabal index e066bc968b..0a0a501b2e 100644 --- a/semantic.cabal +++ b/semantic.cabal @@ -1,14 +1,15 @@ cabal-version: 2.2 + name: semantic version: 0.6.0.0 synopsis: Framework and executable for analyzing and diffing untrusted code. description: Semantic is a library for parsing, analyzing, and comparing source code across many languages. homepage: http://github.com/github/semantic#readme bug-reports: https://github.com/github/semantic/issues -author: The Semantic authors -maintainer: opensource+semantic@github.com license: MIT license-file: LICENSE +author: The Semantic authors +maintainer: opensource+semantic@github.com copyright: (c) 2015-2019 GitHub, Inc. category: Web build-type: Simple From d09ab401c03e833dc1eff01b02b36ac00fa16229 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 11:25:20 -0400 Subject: [PATCH 10/61] Add stability fields to core & python. --- semantic-core/semantic-core.cabal | 1 + semantic-python/semantic-python.cabal | 1 + 2 files changed, 2 insertions(+) diff --git a/semantic-core/semantic-core.cabal b/semantic-core/semantic-core.cabal index c916be5bd2..8ba5253309 100644 --- a/semantic-core/semantic-core.cabal +++ b/semantic-core/semantic-core.cabal @@ -13,6 +13,7 @@ maintainer: opensource+semantic@github.com copyright: (c) 2019 GitHub, Inc. category: Language build-type: Simple +stability: alpha extra-source-files: README.md tested-with: GHC == 8.6.4 diff --git a/semantic-python/semantic-python.cabal b/semantic-python/semantic-python.cabal index da494d9687..5d72f8b190 100644 --- a/semantic-python/semantic-python.cabal +++ b/semantic-python/semantic-python.cabal @@ -13,6 +13,7 @@ maintainer: opensource+semantic@github.com copyright: (c) 2019 GitHub, Inc. category: Language build-type: Simple +stability: alpha extra-source-files: README.md tested-with: GHC == 8.6.4 From 32c7698aba9906413203ff103d430c5696153857 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 11:25:34 -0400 Subject: [PATCH 11/61] Change the category for semantic to Language. --- semantic.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semantic.cabal b/semantic.cabal index 0a0a501b2e..c858c8d36c 100644 --- a/semantic.cabal +++ b/semantic.cabal @@ -11,7 +11,7 @@ license-file: LICENSE author: The Semantic authors maintainer: opensource+semantic@github.com copyright: (c) 2015-2019 GitHub, Inc. -category: Web +category: Language build-type: Simple stability: alpha From dd352cb9c5564eef1fefcf238e1abbea266cb5f4 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 11:25:56 -0400 Subject: [PATCH 12/61] Add extra-source-files to semantic. --- semantic.cabal | 1 + 1 file changed, 1 insertion(+) diff --git a/semantic.cabal b/semantic.cabal index c858c8d36c..fe9ffc817f 100644 --- a/semantic.cabal +++ b/semantic.cabal @@ -14,6 +14,7 @@ copyright: (c) 2015-2019 GitHub, Inc. category: Language build-type: Simple stability: alpha +extra-source-files: README.md tested-with: GHC == 8.6.4 From b09e1a65bac280f8916137ee83e8199a1d57a0de Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 11:26:47 -0400 Subject: [PATCH 13/61] Add a description to semantic-core. --- semantic-core/semantic-core.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semantic-core/semantic-core.cabal b/semantic-core/semantic-core.cabal index 8ba5253309..3be1c4cb49 100644 --- a/semantic-core/semantic-core.cabal +++ b/semantic-core/semantic-core.cabal @@ -3,7 +3,7 @@ cabal-version: 2.2 name: semantic-core version: 0.0.0.0 synopsis: Semantic core intermediate language --- description: +description: Core intermediate language for program analysis using abstract definitional interpretation. homepage: https://github.com/github/semantic/tree/master/semantic-core#readme bug-reports: https://github.com/github/semantic/issues license: MIT From b8d5747941ffb8d0e22127a1ad48930d71674d7c Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 11:38:55 -0400 Subject: [PATCH 14/61] =?UTF-8?q?We=E2=80=99re=20only=20supporting=208.6?= =?UTF-8?q?=20at=20present=20anyway.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- semantic-core/semantic-core.cabal | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/semantic-core/semantic-core.cabal b/semantic-core/semantic-core.cabal index 3be1c4cb49..f8a0cfc7f5 100644 --- a/semantic-core/semantic-core.cabal +++ b/semantic-core/semantic-core.cabal @@ -52,9 +52,7 @@ library , unordered-containers ^>= 0.2.10 hs-source-dirs: src default-language: Haskell2010 - ghc-options: -Weverything -Wno-missing-local-signatures -Wno-missing-import-lists -Wno-implicit-prelude -Wno-safe -Wno-unsafe -Wno-name-shadowing -Wno-monomorphism-restriction -Wno-missed-specialisations -Wno-all-missed-specialisations - if (impl(ghc >= 8.6)) - ghc-options: -Wno-star-is-type + ghc-options: -Weverything -Wno-missing-local-signatures -Wno-missing-import-lists -Wno-implicit-prelude -Wno-safe -Wno-unsafe -Wno-name-shadowing -Wno-monomorphism-restriction -Wno-missed-specialisations -Wno-all-missed-specialisations -Wno-star-is-type test-suite doctest type: exitcode-stdio-1.0 From afa8b7914bcadc7b45384a8f541561c71e0c3a04 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 11:39:59 -0400 Subject: [PATCH 15/61] Wrap. --- semantic-core/semantic-core.cabal | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/semantic-core/semantic-core.cabal b/semantic-core/semantic-core.cabal index f8a0cfc7f5..49c7ba3fb8 100644 --- a/semantic-core/semantic-core.cabal +++ b/semantic-core/semantic-core.cabal @@ -52,7 +52,18 @@ library , unordered-containers ^>= 0.2.10 hs-source-dirs: src default-language: Haskell2010 - ghc-options: -Weverything -Wno-missing-local-signatures -Wno-missing-import-lists -Wno-implicit-prelude -Wno-safe -Wno-unsafe -Wno-name-shadowing -Wno-monomorphism-restriction -Wno-missed-specialisations -Wno-all-missed-specialisations -Wno-star-is-type + ghc-options: + -Weverything + -Wno-missing-local-signatures + -Wno-missing-import-lists + -Wno-implicit-prelude + -Wno-safe + -Wno-unsafe + -Wno-name-shadowing + -Wno-monomorphism-restriction + -Wno-missed-specialisations + -Wno-all-missed-specialisations + -Wno-star-is-type test-suite doctest type: exitcode-stdio-1.0 From 5a2a9f4532a773fa2258793827750b5e96d364db Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 11:44:43 -0400 Subject: [PATCH 16/61] Turn on warnings. --- semantic-python/semantic-python.cabal | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/semantic-python/semantic-python.cabal b/semantic-python/semantic-python.cabal index 5d72f8b190..735e383875 100644 --- a/semantic-python/semantic-python.cabal +++ b/semantic-python/semantic-python.cabal @@ -29,3 +29,15 @@ library , tree-sitter-python ^>= 0.1.0.1 hs-source-dirs: src default-language: Haskell2010 + ghc-options: + -Weverything + -Wno-missing-local-signatures + -Wno-missing-import-lists + -Wno-implicit-prelude + -Wno-safe + -Wno-unsafe + -Wno-name-shadowing + -Wno-monomorphism-restriction + -Wno-missed-specialisations + -Wno-all-missed-specialisations + -Wno-star-is-type From 04762dcbc4dd5a5e768d1937ca9f3eb86ffc57de Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 11:45:46 -0400 Subject: [PATCH 17/61] Add an export list. --- semantic-python/src/Language/Python/Core.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index ddf895f1aa..598c170949 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -1 +1,2 @@ -module Language.Python.Core where +module Language.Python.Core +() where From dd0831962bbcdaa6a0366353ed091a05c1acb6f5 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 11:47:48 -0400 Subject: [PATCH 18/61] Stub in a function to compile a Python module. --- semantic-python/src/Language/Python/Core.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index 598c170949..61adfef38f 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -1,2 +1,8 @@ module Language.Python.Core -() where +( compileModule +) where + +import TreeSitter.Python.AST + +compileModule :: Module -> () +compileModule _ = () From fb5b89817c73cfa198edd477ad0e3756d9e96307 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 11:54:39 -0400 Subject: [PATCH 19/61] Qualify Python stuff if we need to. --- semantic-python/src/Language/Python/Core.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index 61adfef38f..06eec43c7c 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -2,7 +2,7 @@ module Language.Python.Core ( compileModule ) where -import TreeSitter.Python.AST +import TreeSitter.Python.AST as Py -compileModule :: Module -> () +compileModule :: Py.Module -> () compileModule _ = () From 598000c3ab25b1dfe58053550e89b81817f43c3e Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 11:59:29 -0400 Subject: [PATCH 20/61] Stub in compilation to Core. --- semantic-python/src/Language/Python/Core.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index 06eec43c7c..dde03227ed 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -2,7 +2,10 @@ module Language.Python.Core ( compileModule ) where +import Control.Applicative +import Data.Core as Core import TreeSitter.Python.AST as Py -compileModule :: Py.Module -> () -compileModule _ = () +compileModule :: Alternative m => Py.Module -> m Core +compileModule (Module Nothing) = pure Unit +compileModule (Module (Just _)) = pure Unit From 7da6b959f103da21347b85dd611ebe27762f0cae Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 12:03:48 -0400 Subject: [PATCH 21/61] Error messages are good, actually. --- semantic-python/src/Language/Python/Core.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index dde03227ed..7abefce5ca 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -2,10 +2,11 @@ module Language.Python.Core ( compileModule ) where -import Control.Applicative +import Control.Monad.Fail import Data.Core as Core +import Prelude hiding (fail) import TreeSitter.Python.AST as Py -compileModule :: Alternative m => Py.Module -> m Core +compileModule :: MonadFail m => Py.Module -> m Core compileModule (Module Nothing) = pure Unit compileModule (Module (Just _)) = pure Unit From 41afbd6a91f46f2c364180e16ddf6dda6ea53587 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 12:04:12 -0400 Subject: [PATCH 22/61] Rename compileModule to compile. --- semantic-python/src/Language/Python/Core.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index 7abefce5ca..9aa523aa18 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -1,5 +1,5 @@ module Language.Python.Core -( compileModule +( compile ) where import Control.Monad.Fail @@ -7,6 +7,6 @@ import Data.Core as Core import Prelude hiding (fail) import TreeSitter.Python.AST as Py -compileModule :: MonadFail m => Py.Module -> m Core -compileModule (Module Nothing) = pure Unit -compileModule (Module (Just _)) = pure Unit +compile :: MonadFail m => Py.Module -> m Core +compile (Module Nothing) = pure Unit +compile (Module (Just _)) = pure Unit From 23e18ade2e4dcef0e3273796fa8a81f629aafccc Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 12:05:06 -0400 Subject: [PATCH 23/61] Note a FIXME. --- semantic-python/src/Language/Python/Core.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index 9aa523aa18..aa1e9721b2 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -7,6 +7,7 @@ import Data.Core as Core import Prelude hiding (fail) import TreeSitter.Python.AST as Py +-- FIXME: we should really try not to fail compile :: MonadFail m => Py.Module -> m Core compile (Module Nothing) = pure Unit compile (Module (Just _)) = pure Unit From 37cab16c95120fde1449fc17bf7d98c98dc677b2 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 12:06:11 -0400 Subject: [PATCH 24/61] Rephrase Compile as a typeclass. --- semantic-python/src/Language/Python/Core.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index aa1e9721b2..8c024ef335 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -7,7 +7,10 @@ import Data.Core as Core import Prelude hiding (fail) import TreeSitter.Python.AST as Py --- FIXME: we should really try not to fail -compile :: MonadFail m => Py.Module -> m Core -compile (Module Nothing) = pure Unit -compile (Module (Just _)) = pure Unit +class Compile t where + -- FIXME: we should really try not to fail + compile :: MonadFail m => t -> m Core + +instance Compile Py.Module where + compile (Module Nothing) = pure Unit + compile (Module (Just _)) = pure Unit From f09b3614d6479895ba6cf0f76b54e60e18966ef3 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 12:08:52 -0400 Subject: [PATCH 25/61] Define compilation of Either. --- semantic-python/src/Language/Python/Core.hs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index 8c024ef335..75d8dd79a1 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -14,3 +14,6 @@ class Compile t where instance Compile Py.Module where compile (Module Nothing) = pure Unit compile (Module (Just _)) = pure Unit + +instance (Compile l, Compile r) => Compile (Either l r) where + compile = either compile compile From 07fa5567e5578a0667985b28b6247d6d90768e15 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 12:09:38 -0400 Subject: [PATCH 26/61] Move the Either instance up. --- semantic-python/src/Language/Python/Core.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index 75d8dd79a1..fd3ccb91a0 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -11,9 +11,9 @@ class Compile t where -- FIXME: we should really try not to fail compile :: MonadFail m => t -> m Core +instance (Compile l, Compile r) => Compile (Either l r) where + compile = either compile compile + instance Compile Py.Module where compile (Module Nothing) = pure Unit compile (Module (Just _)) = pure Unit - -instance (Compile l, Compile r) => Compile (Either l r) where - compile = either compile compile From 135b8b11c3a787450c0d453334c38f77b40995c5 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 12:12:04 -0400 Subject: [PATCH 27/61] Give a default definition for Compile which just fails. --- semantic-python/src/Language/Python/Core.hs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index fd3ccb91a0..f9bee634fe 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE DefaultSignatures #-} module Language.Python.Core ( compile ) where @@ -10,6 +11,8 @@ import TreeSitter.Python.AST as Py class Compile t where -- FIXME: we should really try not to fail compile :: MonadFail m => t -> m Core + default compile :: (MonadFail m, Show t) => t -> m Core + compile t = fail $ "compilation unimplemented for " <> show t instance (Compile l, Compile r) => Compile (Either l r) where compile = either compile compile From 0a329ae55b6963520fa6c76a5b3d2f9077b49323 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 12:12:28 -0400 Subject: [PATCH 28/61] Stub in compilation of statements. --- semantic-python/src/Language/Python/Core.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index f9bee634fe..9f52f6aebe 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -19,4 +19,7 @@ instance (Compile l, Compile r) => Compile (Either l r) where instance Compile Py.Module where compile (Module Nothing) = pure Unit - compile (Module (Just _)) = pure Unit + compile (Module (Just statements)) = block <$> traverse compile statements + +instance Compile Py.CompoundStatement +instance Compile Py.SimpleStatement From c3184f0354ad92eb3238a165e8168c2b695a451f Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 12:13:21 -0400 Subject: [PATCH 29/61] Extract the default definition. --- semantic-python/src/Language/Python/Core.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index 9f52f6aebe..2a3acb6cf4 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -12,7 +12,10 @@ class Compile t where -- FIXME: we should really try not to fail compile :: MonadFail m => t -> m Core default compile :: (MonadFail m, Show t) => t -> m Core - compile t = fail $ "compilation unimplemented for " <> show t + compile = defaultCompile + +defaultCompile :: (MonadFail m, Show t) => t -> m Core +defaultCompile t = fail $ "compilation unimplemented for " <> show t instance (Compile l, Compile r) => Compile (Either l r) where compile = either compile compile From c4351553cb22b0cb861abf833b33f67f8598a40f Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 12:29:09 -0400 Subject: [PATCH 30/61] Compile IfStatement. --- semantic-python/src/Language/Python/Core.hs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index 2a3acb6cf4..102004ff77 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE DefaultSignatures #-} +{-# LANGUAGE DefaultSignatures, RecordWildCards #-} module Language.Python.Core ( compile ) where @@ -24,5 +24,18 @@ instance Compile Py.Module where compile (Module Nothing) = pure Unit compile (Module (Just statements)) = block <$> traverse compile statements -instance Compile Py.CompoundStatement +instance Compile Py.CompoundStatement where + compile (IfStatementCompoundStatement statement) = compile statement + compile other = defaultCompile other + +instance Compile Py.IfStatement where + compile IfStatement{..} = If <$> compile condition <*> compile consequence <*> case alternative of + Nothing -> pure Unit + Just clauses -> foldr clause (pure Unit) clauses + where clause (Left (ElifClause{..})) rest = If <$> compile condition <*> compile consequence <*> rest + clause (Right (ElseClause body)) _ = compile body + +instance Compile Py.Expression +instance Compile Py.Block + instance Compile Py.SimpleStatement From 602494f6051a9c40b21638b2000c7eb29645517d Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 12:43:20 -0400 Subject: [PATCH 31/61] Define generic compilation of sum types. --- semantic-python/src/Language/Python/Core.hs | 34 ++++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index 102004ff77..8937211bf2 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -1,10 +1,11 @@ -{-# LANGUAGE DefaultSignatures, RecordWildCards #-} +{-# LANGUAGE DefaultSignatures, DeriveGeneric, FlexibleContexts, FlexibleInstances, RecordWildCards, StandaloneDeriving, TypeOperators #-} module Language.Python.Core ( compile ) where import Control.Monad.Fail import Data.Core as Core +import GHC.Generics import Prelude hiding (fail) import TreeSitter.Python.AST as Py @@ -24,9 +25,7 @@ instance Compile Py.Module where compile (Module Nothing) = pure Unit compile (Module (Just statements)) = block <$> traverse compile statements -instance Compile Py.CompoundStatement where - compile (IfStatementCompoundStatement statement) = compile statement - compile other = defaultCompile other +instance Compile Py.CompoundStatement where compile = compileSum instance Compile Py.IfStatement where compile IfStatement{..} = If <$> compile condition <*> compile consequence <*> case alternative of @@ -37,5 +36,32 @@ instance Compile Py.IfStatement where instance Compile Py.Expression instance Compile Py.Block +instance Compile Py.ClassDefinition +instance Compile Py.DecoratedDefinition +instance Compile Py.ForStatement +instance Compile Py.FunctionDefinition +instance Compile Py.TryStatement +instance Compile Py.WhileStatement +instance Compile Py.WithStatement instance Compile Py.SimpleStatement + + +compileSum :: (Generic t, GCompileSum (Rep t), MonadFail m) => t -> m Core +compileSum = gcompileSum . from + +class GCompileSum f where + gcompileSum :: MonadFail m => f a -> m Core + +instance GCompileSum f => GCompileSum (M1 D d f) where + gcompileSum (M1 f) = gcompileSum f + +instance (GCompileSum l, GCompileSum r) => GCompileSum (l :+: r) where + gcompileSum (L1 l) = gcompileSum l + gcompileSum (R1 r) = gcompileSum r + +instance Compile t => GCompileSum (M1 C c (M1 S s (K1 R t))) where + gcompileSum (M1 (M1 (K1 t))) = compile t + + +deriving instance Generic Py.CompoundStatement From 3b7a2f17b00cd6d421678ca8e0f64226b7d7da31 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 12:51:47 -0400 Subject: [PATCH 32/61] DerivingVia. --- semantic-python/src/Language/Python/Core.hs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index 8937211bf2..f82385c143 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE DefaultSignatures, DeriveGeneric, FlexibleContexts, FlexibleInstances, RecordWildCards, StandaloneDeriving, TypeOperators #-} +{-# LANGUAGE DefaultSignatures, DeriveGeneric, DerivingVia, FlexibleContexts, FlexibleInstances, RecordWildCards, StandaloneDeriving, TypeOperators, UndecidableInstances #-} module Language.Python.Core ( compile ) where @@ -25,7 +25,7 @@ instance Compile Py.Module where compile (Module Nothing) = pure Unit compile (Module (Just statements)) = block <$> traverse compile statements -instance Compile Py.CompoundStatement where compile = compileSum +deriving via CompileSum Py.CompoundStatement instance Compile Py.CompoundStatement instance Compile Py.IfStatement where compile IfStatement{..} = If <$> compile condition <*> compile consequence <*> case alternative of @@ -47,9 +47,6 @@ instance Compile Py.WithStatement instance Compile Py.SimpleStatement -compileSum :: (Generic t, GCompileSum (Rep t), MonadFail m) => t -> m Core -compileSum = gcompileSum . from - class GCompileSum f where gcompileSum :: MonadFail m => f a -> m Core @@ -65,3 +62,10 @@ instance Compile t => GCompileSum (M1 C c (M1 S s (K1 R t))) where deriving instance Generic Py.CompoundStatement + + +newtype CompileSum t = CompileSum { unCompileSum :: t } + deriving (Eq, Ord, Show) + +instance (Generic t, GCompileSum (Rep t)) => Compile (CompileSum t) where + compile = gcompileSum . from . unCompileSum From 3728f062671baec5e1cc9a822bd09061f55ab72c Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 12:54:25 -0400 Subject: [PATCH 33/61] Split out the SimpleStatement cases. --- semantic-python/src/Language/Python/Core.hs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index f82385c143..9ddbcfadea 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -44,7 +44,23 @@ instance Compile Py.TryStatement instance Compile Py.WhileStatement instance Compile Py.WithStatement -instance Compile Py.SimpleStatement +deriving via CompileSum Py.SimpleStatement instance Compile Py.SimpleStatement + +instance Compile Py.AssertStatement +instance Compile Py.BreakStatement +instance Compile Py.ContinueStatement +instance Compile Py.DeleteStatement +instance Compile Py.ExecStatement +instance Compile Py.ExpressionStatement +instance Compile Py.FutureImportStatement +instance Compile Py.GlobalStatement +instance Compile Py.ImportFromStatement +instance Compile Py.ImportStatement +instance Compile Py.NonlocalStatement +instance Compile Py.PassStatement +instance Compile Py.PrintStatement +instance Compile Py.ReturnStatement +instance Compile Py.RaiseStatement class GCompileSum f where @@ -62,6 +78,7 @@ instance Compile t => GCompileSum (M1 C c (M1 S s (K1 R t))) where deriving instance Generic Py.CompoundStatement +deriving instance Generic Py.SimpleStatement newtype CompileSum t = CompileSum { unCompileSum :: t } From 5b539e8d4d636a2baeec65b311b75ef9d3f23cf4 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 12:55:46 -0400 Subject: [PATCH 34/61] Add a FIXME re: the orphan instances. --- semantic-python/src/Language/Python/Core.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index 9ddbcfadea..d7474c7946 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -77,6 +77,7 @@ instance Compile t => GCompileSum (M1 C c (M1 S s (K1 R t))) where gcompileSum (M1 (M1 (K1 t))) = compile t +-- FIXME: depend on https://github.com/tree-sitter/haskell-tree-sitter/pull/90 so we can get rid of these orphan instances deriving instance Generic Py.CompoundStatement deriving instance Generic Py.SimpleStatement From c8d1de416dc9e3d7894b574d86e5c16c924e9053 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 12:56:37 -0400 Subject: [PATCH 35/61] Alphabetize. --- semantic-python/src/Language/Python/Core.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index d7474c7946..a2e4c24ba3 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -27,6 +27,11 @@ instance Compile Py.Module where deriving via CompileSum Py.CompoundStatement instance Compile Py.CompoundStatement +instance Compile Py.Block +instance Compile Py.ClassDefinition +instance Compile Py.DecoratedDefinition +instance Compile Py.Expression + instance Compile Py.IfStatement where compile IfStatement{..} = If <$> compile condition <*> compile consequence <*> case alternative of Nothing -> pure Unit @@ -34,10 +39,6 @@ instance Compile Py.IfStatement where where clause (Left (ElifClause{..})) rest = If <$> compile condition <*> compile consequence <*> rest clause (Right (ElseClause body)) _ = compile body -instance Compile Py.Expression -instance Compile Py.Block -instance Compile Py.ClassDefinition -instance Compile Py.DecoratedDefinition instance Compile Py.ForStatement instance Compile Py.FunctionDefinition instance Compile Py.TryStatement From ead494ad3f2ff7da12e16651b01f371ff450a342 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 12:57:27 -0400 Subject: [PATCH 36/61] These are incurred by IfStatement. --- semantic-python/src/Language/Python/Core.hs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index a2e4c24ba3..dc43d6dabf 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -27,10 +27,8 @@ instance Compile Py.Module where deriving via CompileSum Py.CompoundStatement instance Compile Py.CompoundStatement -instance Compile Py.Block instance Compile Py.ClassDefinition instance Compile Py.DecoratedDefinition -instance Compile Py.Expression instance Compile Py.IfStatement where compile IfStatement{..} = If <$> compile condition <*> compile consequence <*> case alternative of @@ -39,6 +37,9 @@ instance Compile Py.IfStatement where where clause (Left (ElifClause{..})) rest = If <$> compile condition <*> compile consequence <*> rest clause (Right (ElseClause body)) _ = compile body +instance Compile Py.Block +instance Compile Py.Expression + instance Compile Py.ForStatement instance Compile Py.FunctionDefinition instance Compile Py.TryStatement From 4e24a1ee9ef1034039854057ae23f432117d3888 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 12:59:27 -0400 Subject: [PATCH 37/61] No, really alphabetize. --- semantic-python/src/Language/Python/Core.hs | 37 ++++++++++----------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index dc43d6dabf..ec16391750 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -27,8 +27,20 @@ instance Compile Py.Module where deriving via CompileSum Py.CompoundStatement instance Compile Py.CompoundStatement +instance Compile Py.AssertStatement +instance Compile Py.Block +instance Compile Py.BreakStatement instance Compile Py.ClassDefinition +instance Compile Py.ContinueStatement instance Compile Py.DecoratedDefinition +instance Compile Py.DeleteStatement +instance Compile Py.ExecStatement +instance Compile Py.Expression +instance Compile Py.ExpressionStatement +instance Compile Py.ForStatement +instance Compile Py.FunctionDefinition +instance Compile Py.FutureImportStatement +instance Compile Py.GlobalStatement instance Compile Py.IfStatement where compile IfStatement{..} = If <$> compile condition <*> compile consequence <*> case alternative of @@ -37,25 +49,6 @@ instance Compile Py.IfStatement where where clause (Left (ElifClause{..})) rest = If <$> compile condition <*> compile consequence <*> rest clause (Right (ElseClause body)) _ = compile body -instance Compile Py.Block -instance Compile Py.Expression - -instance Compile Py.ForStatement -instance Compile Py.FunctionDefinition -instance Compile Py.TryStatement -instance Compile Py.WhileStatement -instance Compile Py.WithStatement - -deriving via CompileSum Py.SimpleStatement instance Compile Py.SimpleStatement - -instance Compile Py.AssertStatement -instance Compile Py.BreakStatement -instance Compile Py.ContinueStatement -instance Compile Py.DeleteStatement -instance Compile Py.ExecStatement -instance Compile Py.ExpressionStatement -instance Compile Py.FutureImportStatement -instance Compile Py.GlobalStatement instance Compile Py.ImportFromStatement instance Compile Py.ImportStatement instance Compile Py.NonlocalStatement @@ -64,6 +57,12 @@ instance Compile Py.PrintStatement instance Compile Py.ReturnStatement instance Compile Py.RaiseStatement +deriving via CompileSum Py.SimpleStatement instance Compile Py.SimpleStatement + +instance Compile Py.TryStatement +instance Compile Py.WhileStatement +instance Compile Py.WithStatement + class GCompileSum f where gcompileSum :: MonadFail m => f a -> m Core From bd9aaa541e294ff84c740186b4aceaed32d8db38 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 13:00:04 -0400 Subject: [PATCH 38/61] Really really. --- semantic-python/src/Language/Python/Core.hs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index ec16391750..3fb815f72a 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -21,16 +21,13 @@ defaultCompile t = fail $ "compilation unimplemented for " <> show t instance (Compile l, Compile r) => Compile (Either l r) where compile = either compile compile -instance Compile Py.Module where - compile (Module Nothing) = pure Unit - compile (Module (Just statements)) = block <$> traverse compile statements - -deriving via CompileSum Py.CompoundStatement instance Compile Py.CompoundStatement - instance Compile Py.AssertStatement instance Compile Py.Block instance Compile Py.BreakStatement instance Compile Py.ClassDefinition + +deriving via CompileSum Py.CompoundStatement instance Compile Py.CompoundStatement + instance Compile Py.ContinueStatement instance Compile Py.DecoratedDefinition instance Compile Py.DeleteStatement @@ -51,6 +48,11 @@ instance Compile Py.IfStatement where instance Compile Py.ImportFromStatement instance Compile Py.ImportStatement + +instance Compile Py.Module where + compile (Module Nothing) = pure Unit + compile (Module (Just statements)) = block <$> traverse compile statements + instance Compile Py.NonlocalStatement instance Compile Py.PassStatement instance Compile Py.PrintStatement From 236771702bcee267b4c831a1465907f62b6603d7 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 13:01:05 -0400 Subject: [PATCH 39/61] Derive the Either instance. --- semantic-python/src/Language/Python/Core.hs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index 3fb815f72a..9fb0368549 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -18,8 +18,7 @@ class Compile t where defaultCompile :: (MonadFail m, Show t) => t -> m Core defaultCompile t = fail $ "compilation unimplemented for " <> show t -instance (Compile l, Compile r) => Compile (Either l r) where - compile = either compile compile +deriving via CompileSum (Either l r) instance (Compile l, Compile r) => Compile (Either l r) instance Compile Py.AssertStatement instance Compile Py.Block From 1a6812ed0653ac72ea75ff2b2a822fd8d8968b62 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 13:03:17 -0400 Subject: [PATCH 40/61] Split out instances for Expression. --- semantic-python/src/Language/Python/Core.hs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index 9fb0368549..2b78016f0c 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -21,17 +21,23 @@ defaultCompile t = fail $ "compilation unimplemented for " <> show t deriving via CompileSum (Either l r) instance (Compile l, Compile r) => Compile (Either l r) instance Compile Py.AssertStatement +instance Compile Py.Await instance Compile Py.Block +instance Compile Py.BooleanOperator instance Compile Py.BreakStatement instance Compile Py.ClassDefinition +instance Compile Py.ComparisonOperator deriving via CompileSum Py.CompoundStatement instance Compile Py.CompoundStatement +instance Compile Py.ConditionalExpression instance Compile Py.ContinueStatement instance Compile Py.DecoratedDefinition instance Compile Py.DeleteStatement instance Compile Py.ExecStatement -instance Compile Py.Expression + +deriving via CompileSum Py.Expression instance Compile Py.Expression + instance Compile Py.ExpressionStatement instance Compile Py.ForStatement instance Compile Py.FunctionDefinition @@ -47,13 +53,17 @@ instance Compile Py.IfStatement where instance Compile Py.ImportFromStatement instance Compile Py.ImportStatement +instance Compile Py.Lambda instance Compile Py.Module where compile (Module Nothing) = pure Unit compile (Module (Just statements)) = block <$> traverse compile statements +instance Compile Py.NamedExpression instance Compile Py.NonlocalStatement +instance Compile Py.NotOperator instance Compile Py.PassStatement +instance Compile Py.PrimaryExpression instance Compile Py.PrintStatement instance Compile Py.ReturnStatement instance Compile Py.RaiseStatement @@ -81,6 +91,7 @@ instance Compile t => GCompileSum (M1 C c (M1 S s (K1 R t))) where -- FIXME: depend on https://github.com/tree-sitter/haskell-tree-sitter/pull/90 so we can get rid of these orphan instances deriving instance Generic Py.CompoundStatement +deriving instance Generic Py.Expression deriving instance Generic Py.SimpleStatement From c15bbcb00b1d81ff8f9a90850fbebc5e8589c4e2 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 13:05:48 -0400 Subject: [PATCH 41/61] Not via. --- semantic-python/src/Language/Python/Core.hs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index 2b78016f0c..2baa0d7fc4 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE DefaultSignatures, DeriveGeneric, DerivingVia, FlexibleContexts, FlexibleInstances, RecordWildCards, StandaloneDeriving, TypeOperators, UndecidableInstances #-} +{-# LANGUAGE DefaultSignatures, DeriveGeneric, FlexibleContexts, FlexibleInstances, RecordWildCards, StandaloneDeriving, TypeOperators #-} module Language.Python.Core ( compile ) where @@ -18,7 +18,7 @@ class Compile t where defaultCompile :: (MonadFail m, Show t) => t -> m Core defaultCompile t = fail $ "compilation unimplemented for " <> show t -deriving via CompileSum (Either l r) instance (Compile l, Compile r) => Compile (Either l r) +instance (Compile l, Compile r) => Compile (Either l r) where compile = compileSum instance Compile Py.AssertStatement instance Compile Py.Await @@ -28,7 +28,7 @@ instance Compile Py.BreakStatement instance Compile Py.ClassDefinition instance Compile Py.ComparisonOperator -deriving via CompileSum Py.CompoundStatement instance Compile Py.CompoundStatement +instance Compile Py.CompoundStatement where compile = compileSum instance Compile Py.ConditionalExpression instance Compile Py.ContinueStatement @@ -36,7 +36,7 @@ instance Compile Py.DecoratedDefinition instance Compile Py.DeleteStatement instance Compile Py.ExecStatement -deriving via CompileSum Py.Expression instance Compile Py.Expression +instance Compile Py.Expression where compile = compileSum instance Compile Py.ExpressionStatement instance Compile Py.ForStatement @@ -68,13 +68,16 @@ instance Compile Py.PrintStatement instance Compile Py.ReturnStatement instance Compile Py.RaiseStatement -deriving via CompileSum Py.SimpleStatement instance Compile Py.SimpleStatement +instance Compile Py.SimpleStatement where compile = compileSum instance Compile Py.TryStatement instance Compile Py.WhileStatement instance Compile Py.WithStatement +compileSum :: (Generic t, GCompileSum (Rep t), MonadFail m) => t -> m Core +compileSum = gcompileSum . from + class GCompileSum f where gcompileSum :: MonadFail m => f a -> m Core @@ -93,10 +96,3 @@ instance Compile t => GCompileSum (M1 C c (M1 S s (K1 R t))) where deriving instance Generic Py.CompoundStatement deriving instance Generic Py.Expression deriving instance Generic Py.SimpleStatement - - -newtype CompileSum t = CompileSum { unCompileSum :: t } - deriving (Eq, Ord, Show) - -instance (Generic t, GCompileSum (Rep t)) => Compile (CompileSum t) where - compile = gcompileSum . from . unCompileSum From eb7244236f2cc7028e9436a8a2bdd9f07611e1f0 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 13:09:14 -0400 Subject: [PATCH 42/61] Split out instances for PrimaryExpression. --- semantic-python/src/Language/Python/Core.hs | 29 ++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index 2baa0d7fc4..a7dc7d0f99 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -21,28 +21,39 @@ defaultCompile t = fail $ "compilation unimplemented for " <> show t instance (Compile l, Compile r) => Compile (Either l r) where compile = compileSum instance Compile Py.AssertStatement +instance Compile Py.Attribute instance Compile Py.Await +instance Compile Py.BinaryOperator instance Compile Py.Block instance Compile Py.BooleanOperator instance Compile Py.BreakStatement +instance Compile Py.Call instance Compile Py.ClassDefinition instance Compile Py.ComparisonOperator instance Compile Py.CompoundStatement where compile = compileSum +instance Compile Py.ConcatenatedString instance Compile Py.ConditionalExpression instance Compile Py.ContinueStatement instance Compile Py.DecoratedDefinition instance Compile Py.DeleteStatement +instance Compile Py.Dictionary +instance Compile Py.DictionaryComprehension +instance Compile Py.Ellipsis instance Compile Py.ExecStatement instance Compile Py.Expression where compile = compileSum instance Compile Py.ExpressionStatement +instance Compile Py.False +instance Compile Py.Float instance Compile Py.ForStatement instance Compile Py.FunctionDefinition instance Compile Py.FutureImportStatement +instance Compile Py.GeneratorExpression instance Compile Py.GlobalStatement +instance Compile Py.Identifier instance Compile Py.IfStatement where compile IfStatement{..} = If <$> compile condition <*> compile consequence <*> case alternative of @@ -53,24 +64,39 @@ instance Compile Py.IfStatement where instance Compile Py.ImportFromStatement instance Compile Py.ImportStatement +instance Compile Py.Integer +instance Compile Py.KeywordIdentifier instance Compile Py.Lambda +instance Compile Py.List +instance Compile Py.ListComprehension instance Compile Py.Module where compile (Module Nothing) = pure Unit compile (Module (Just statements)) = block <$> traverse compile statements instance Compile Py.NamedExpression +instance Compile Py.None instance Compile Py.NonlocalStatement instance Compile Py.NotOperator +instance Compile Py.ParenthesizedExpression instance Compile Py.PassStatement -instance Compile Py.PrimaryExpression + +instance Compile Py.PrimaryExpression where compile = compileSum + instance Compile Py.PrintStatement instance Compile Py.ReturnStatement instance Compile Py.RaiseStatement +instance Compile Py.Set +instance Compile Py.SetComprehension instance Compile Py.SimpleStatement where compile = compileSum +instance Compile Py.String +instance Compile Py.Subscript +instance Compile Py.True instance Compile Py.TryStatement +instance Compile Py.Tuple +instance Compile Py.UnaryOperator instance Compile Py.WhileStatement instance Compile Py.WithStatement @@ -95,4 +121,5 @@ instance Compile t => GCompileSum (M1 C c (M1 S s (K1 R t))) where -- FIXME: depend on https://github.com/tree-sitter/haskell-tree-sitter/pull/90 so we can get rid of these orphan instances deriving instance Generic Py.CompoundStatement deriving instance Generic Py.Expression +deriving instance Generic Py.PrimaryExpression deriving instance Generic Py.SimpleStatement From 9088708c7b2456ab8ea12a5637a5ca670c2c9253 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 13:10:41 -0400 Subject: [PATCH 43/61] Compile boolean literals. --- semantic-python/src/Language/Python/Core.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index a7dc7d0f99..b30ba955c9 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -46,7 +46,9 @@ instance Compile Py.ExecStatement instance Compile Py.Expression where compile = compileSum instance Compile Py.ExpressionStatement -instance Compile Py.False + +instance Compile Py.False where compile _ = pure (Bool Prelude.False) + instance Compile Py.Float instance Compile Py.ForStatement instance Compile Py.FunctionDefinition @@ -93,7 +95,9 @@ instance Compile Py.SimpleStatement where compile = compileSum instance Compile Py.String instance Compile Py.Subscript -instance Compile Py.True + +instance Compile Py.True where compile _ = pure (Bool Prelude.True) + instance Compile Py.TryStatement instance Compile Py.Tuple instance Compile Py.UnaryOperator From 6dd501005993bb80b3da24ca5611f9bad9adc565 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 17:10:09 -0400 Subject: [PATCH 44/61] :fire: the orphan instances. --- semantic-python/src/Language/Python/Core.hs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index b30ba955c9..c52cf599b8 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -120,10 +120,3 @@ instance (GCompileSum l, GCompileSum r) => GCompileSum (l :+: r) where instance Compile t => GCompileSum (M1 C c (M1 S s (K1 R t))) where gcompileSum (M1 (M1 (K1 t))) = compile t - - --- FIXME: depend on https://github.com/tree-sitter/haskell-tree-sitter/pull/90 so we can get rid of these orphan instances -deriving instance Generic Py.CompoundStatement -deriving instance Generic Py.Expression -deriving instance Generic Py.PrimaryExpression -deriving instance Generic Py.SimpleStatement From b1a89c0d0ed554fba352fa42ba2d1b394f7c2ac9 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Jun 2019 17:10:19 -0400 Subject: [PATCH 45/61] :fire: redundant parens. --- semantic-python/src/Language/Python/Core.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index c52cf599b8..5e7c5a2a47 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -61,8 +61,8 @@ instance Compile Py.IfStatement where compile IfStatement{..} = If <$> compile condition <*> compile consequence <*> case alternative of Nothing -> pure Unit Just clauses -> foldr clause (pure Unit) clauses - where clause (Left (ElifClause{..})) rest = If <$> compile condition <*> compile consequence <*> rest - clause (Right (ElseClause body)) _ = compile body + where clause (Left ElifClause{..}) rest = If <$> compile condition <*> compile consequence <*> rest + clause (Right ElseClause{..}) _ = compile body instance Compile Py.ImportFromStatement instance Compile Py.ImportStatement From f2a9ebef39d53fb6e6b7545bc99e20704171c231 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 12 Jun 2019 10:23:42 -0400 Subject: [PATCH 46/61] Qualify the import of TreeSitter.Python.AST. --- semantic-python/src/Language/Python/Core.hs | 26 ++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index 5e7c5a2a47..14a3d10666 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -3,11 +3,11 @@ module Language.Python.Core ( compile ) where -import Control.Monad.Fail -import Data.Core as Core -import GHC.Generics -import Prelude hiding (fail) -import TreeSitter.Python.AST as Py +import Control.Monad.Fail +import Data.Core as Core +import GHC.Generics +import Prelude hiding (fail) +import qualified TreeSitter.Python.AST as Py class Compile t where -- FIXME: we should really try not to fail @@ -47,7 +47,7 @@ instance Compile Py.Expression where compile = compileSum instance Compile Py.ExpressionStatement -instance Compile Py.False where compile _ = pure (Bool Prelude.False) +instance Compile Py.False where compile _ = pure (Bool False) instance Compile Py.Float instance Compile Py.ForStatement @@ -58,11 +58,11 @@ instance Compile Py.GlobalStatement instance Compile Py.Identifier instance Compile Py.IfStatement where - compile IfStatement{..} = If <$> compile condition <*> compile consequence <*> case alternative of - Nothing -> pure Unit + compile Py.IfStatement{..} = If <$> compile condition <*> compile consequence <*> case alternative of + Nothing -> pure Unit Just clauses -> foldr clause (pure Unit) clauses - where clause (Left ElifClause{..}) rest = If <$> compile condition <*> compile consequence <*> rest - clause (Right ElseClause{..}) _ = compile body + where clause (Left Py.ElifClause{..}) rest = If <$> compile condition <*> compile consequence <*> rest + clause (Right Py.ElseClause{..}) _ = compile body instance Compile Py.ImportFromStatement instance Compile Py.ImportStatement @@ -73,8 +73,8 @@ instance Compile Py.List instance Compile Py.ListComprehension instance Compile Py.Module where - compile (Module Nothing) = pure Unit - compile (Module (Just statements)) = block <$> traverse compile statements + compile (Py.Module Nothing) = pure Unit + compile (Py.Module (Just statements)) = block <$> traverse compile statements instance Compile Py.NamedExpression instance Compile Py.None @@ -96,7 +96,7 @@ instance Compile Py.SimpleStatement where compile = compileSum instance Compile Py.String instance Compile Py.Subscript -instance Compile Py.True where compile _ = pure (Bool Prelude.True) +instance Compile Py.True where compile _ = pure (Bool True) instance Compile Py.TryStatement instance Compile Py.Tuple From be842df923c7122904839871e40d9e65486a16bb Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 12 Jun 2019 10:39:54 -0400 Subject: [PATCH 47/61] Represent strings as Text. --- semantic-core/semantic-core.cabal | 1 + semantic-core/src/Analysis/Concrete.hs | 3 ++- semantic-core/src/Analysis/Eval.hs | 7 ++++--- semantic-core/src/Analysis/ImportGraph.hs | 5 +++-- semantic-core/src/Analysis/Typecheck.hs | 2 +- semantic-core/src/Data/Core.hs | 3 ++- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/semantic-core/semantic-core.cabal b/semantic-core/semantic-core.cabal index 49c7ba3fb8..31b5e37b23 100644 --- a/semantic-core/semantic-core.cabal +++ b/semantic-core/semantic-core.cabal @@ -47,6 +47,7 @@ library , prettyprinter-ansi-terminal ^>= 1.1.1 , recursion-schemes ^>= 5.1 , semigroupoids ^>= 5.3 + , text ^>= 1.2.3.1 , transformers ^>= 0.5.6 , trifecta ^>= 2 , unordered-containers ^>= 0.2.10 diff --git a/semantic-core/src/Analysis/Concrete.hs b/semantic-core/src/Analysis/Concrete.hs index cb76d3a69d..6c1134504c 100644 --- a/semantic-core/src/Analysis/Concrete.hs +++ b/semantic-core/src/Analysis/Concrete.hs @@ -29,6 +29,7 @@ import Data.Loc import qualified Data.Map as Map import Data.Monoid (Alt(..)) import Data.Name +import Data.Text (Text) import Prelude hiding (fail) type Precise = Int @@ -41,7 +42,7 @@ data Concrete = Closure Loc Name Core.Core Precise | Unit | Bool Bool - | String String + | String Text | Obj Frame deriving (Eq, Ord, Show) diff --git a/semantic-core/src/Analysis/Eval.hs b/semantic-core/src/Analysis/Eval.hs index 4e296e9a32..676b058c3a 100644 --- a/semantic-core/src/Analysis/Eval.hs +++ b/semantic-core/src/Analysis/Eval.hs @@ -21,6 +21,7 @@ import Data.Functor import Data.Loc import Data.Maybe (fromJust) import Data.Name +import Data.Text (Text, unpack) import GHC.Stack import Prelude hiding (fail) @@ -42,7 +43,7 @@ eval Analysis{..} eval = \case String s -> string s Load p -> do path <- eval p >>= asString - lookupEnv' (Path path) >>= deref' (Path path) + lookupEnv' (Path (unpack path)) >>= deref' (Path (unpack path)) Edge e a -> ref a >>= edge e >> unit Frame -> frame a :. b -> do @@ -207,8 +208,8 @@ data Analysis address value m = Analysis , unit :: m value , bool :: Bool -> m value , asBool :: value -> m Bool - , string :: String -> m value -- FIXME: Text - , asString :: value -> m String + , string :: Text -> m value -- FIXME: Text + , asString :: value -> m Text , frame :: m value , edge :: Edge -> address -> m () , (...) :: forall a . address -> m a -> m a diff --git a/semantic-core/src/Analysis/ImportGraph.hs b/semantic-core/src/Analysis/ImportGraph.hs index 1176f8e904..e66233d5f8 100644 --- a/semantic-core/src/Analysis/ImportGraph.hs +++ b/semantic-core/src/Analysis/ImportGraph.hs @@ -22,6 +22,7 @@ import Data.Loc import qualified Data.Map as Map import Data.Name import qualified Data.Set as Set +import Data.Text (Text) import Prelude hiding (fail) type ImportGraph = Map.Map FilePath (Set.Set FilePath) @@ -41,7 +42,7 @@ instance Monoid Value where data Semi = Closure Loc Name Core.Core Name -- FIXME: Bound String values. - | String String + | String Text | Abstract deriving (Eq, Ord, Show) @@ -98,7 +99,7 @@ importGraphAnalysis = Analysis{..} asBool _ = pure True <|> pure False string s = pure (Value (String s) mempty) asString (Value (String s) _) = pure s - asString _ = pure "" + asString _ = pure mempty frame = pure mempty edge Core.Import (Path to) = do Loc{locPath=from} <- ask diff --git a/semantic-core/src/Analysis/Typecheck.hs b/semantic-core/src/Analysis/Typecheck.hs index 0fd2fe4457..f37338ee69 100644 --- a/semantic-core/src/Analysis/Typecheck.hs +++ b/semantic-core/src/Analysis/Typecheck.hs @@ -160,7 +160,7 @@ typecheckingAnalysis = Analysis{..} bool _ = pure MBool asBool b = unify MBool b >> pure True <|> pure False string _ = pure MString - asString s = unify MString s *> pure "" + asString s = unify MString s *> pure mempty frame = fail "unimplemented" edge _ _ = pure () _ ... m = m diff --git a/semantic-core/src/Data/Core.hs b/semantic-core/src/Data/Core.hs index 6cb92dcd9f..b368705089 100644 --- a/semantic-core/src/Data/Core.hs +++ b/semantic-core/src/Data/Core.hs @@ -20,6 +20,7 @@ import Data.Foldable (foldl') import Data.Loc import Data.Name import Data.Stack +import Data.Text (Text) import GHC.Stack data Edge = Lexical | Import @@ -36,7 +37,7 @@ data Core | Unit | Bool Bool | If Core Core Core - | String String -- FIXME: Text + | String Text -- | Load the specified file (by path). | Load Core | Edge Edge Core From 7583226a556a7d088763112fd236ebaebb625d3c Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 12 Jun 2019 10:43:54 -0400 Subject: [PATCH 48/61] Represent paths as Text. --- semantic-core/src/Analysis/Concrete.hs | 4 ++-- semantic-core/src/Analysis/Eval.hs | 6 +++--- semantic-core/src/Analysis/ImportGraph.hs | 2 +- semantic-core/src/Data/Core/Parser.hs | 4 ++-- semantic-core/src/Data/Loc.hs | 5 +++-- semantic-core/src/Data/Name.hs | 3 ++- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/semantic-core/src/Analysis/Concrete.hs b/semantic-core/src/Analysis/Concrete.hs index 6c1134504c..58a780e159 100644 --- a/semantic-core/src/Analysis/Concrete.hs +++ b/semantic-core/src/Analysis/Concrete.hs @@ -29,7 +29,7 @@ import Data.Loc import qualified Data.Map as Map import Data.Monoid (Alt(..)) import Data.Name -import Data.Text (Text) +import Data.Text (Text, unpack) import Prelude hiding (fail) type Precise = Int @@ -196,7 +196,7 @@ addressStyle heap = (G.defaultStyle vertex) { G.edgeAttributes } Unit -> "()" Bool b -> show b String s -> show s - Closure (Loc p (Span s e)) n _ _ -> "\\\\ " <> fromName n <> " [" <> p <> ":" <> showPos s <> "-" <> showPos e <> "]" + Closure (Loc p (Span s e)) n _ _ -> "\\\\ " <> fromName n <> " [" <> unpack p <> ":" <> showPos s <> "-" <> showPos e <> "]" Obj _ -> "{}" showPos (Pos l c) = show l <> ":" <> show c fromName (User s) = s diff --git a/semantic-core/src/Analysis/Eval.hs b/semantic-core/src/Analysis/Eval.hs index 676b058c3a..7e62c1ed93 100644 --- a/semantic-core/src/Analysis/Eval.hs +++ b/semantic-core/src/Analysis/Eval.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE FlexibleContexts, GeneralizedNewtypeDeriving, LambdaCase, RankNTypes, RecordWildCards #-} +{-# LANGUAGE FlexibleContexts, GeneralizedNewtypeDeriving, LambdaCase, OverloadedStrings, RankNTypes, RecordWildCards #-} module Analysis.Eval ( eval , prog1 @@ -21,7 +21,7 @@ import Data.Functor import Data.Loc import Data.Maybe (fromJust) import Data.Name -import Data.Text (Text, unpack) +import Data.Text (Text) import GHC.Stack import Prelude hiding (fail) @@ -43,7 +43,7 @@ eval Analysis{..} eval = \case String s -> string s Load p -> do path <- eval p >>= asString - lookupEnv' (Path (unpack path)) >>= deref' (Path (unpack path)) + lookupEnv' (Path path) >>= deref' (Path path) Edge e a -> ref a >>= edge e >> unit Frame -> frame a :. b -> do diff --git a/semantic-core/src/Analysis/ImportGraph.hs b/semantic-core/src/Analysis/ImportGraph.hs index e66233d5f8..0610ff2718 100644 --- a/semantic-core/src/Analysis/ImportGraph.hs +++ b/semantic-core/src/Analysis/ImportGraph.hs @@ -25,7 +25,7 @@ import qualified Data.Set as Set import Data.Text (Text) import Prelude hiding (fail) -type ImportGraph = Map.Map FilePath (Set.Set FilePath) +type ImportGraph = Map.Map Text (Set.Set Text) data Value = Value { valueSemi :: Semi diff --git a/semantic-core/src/Data/Core/Parser.hs b/semantic-core/src/Data/Core/Parser.hs index 4e8df75706..368c276055 100644 --- a/semantic-core/src/Data/Core/Parser.hs +++ b/semantic-core/src/Data/Core/Parser.hs @@ -14,6 +14,7 @@ import Data.Core import Data.Name import Data.Semigroup import Data.String +import Data.Text (pack) import qualified Text.Parser.Token as Token import qualified Text.Parser.Token.Highlight as Highlight import Text.Trifecta hiding (ident) @@ -94,7 +95,7 @@ lvalue = choice name :: (TokenParsing m, Monad m) => m Name name = choice [regular, strpath] "name" where regular = User <$> identifier - strpath = Path <$> between (symbolic '"') (symbolic '"') (some $ noneOf "\"") + strpath = Path . pack <$> between (symbolic '"') (symbolic '"') (some $ noneOf "\"") lit :: (TokenParsing m, Monad m) => m Core lit = let x `given` n = x <$ reserved n in choice @@ -112,4 +113,3 @@ lambda = Lam <$ lambduh <*> name <* arrow <*> core "lambda" where ident :: (Monad m, TokenParsing m) => m Core ident = Var <$> name "identifier" - diff --git a/semantic-core/src/Data/Loc.hs b/semantic-core/src/Data/Loc.hs index f9c3b504f1..9999f8a822 100644 --- a/semantic-core/src/Data/Loc.hs +++ b/semantic-core/src/Data/Loc.hs @@ -16,12 +16,13 @@ import Control.Effect.Error import Control.Effect.Fail import Control.Effect.Reader import Control.Effect.Sum +import Data.Text (Text, pack) import Data.Text.Prettyprint.Doc (Pretty (..)) import GHC.Stack import Prelude hiding (fail) data Loc = Loc - { locPath :: !FilePath + { locPath :: !Text , locSpan :: {-# UNPACK #-} !Span } deriving (Eq, Ord, Show) @@ -58,7 +59,7 @@ stackLoc cs = case getCallStack cs of _ -> Nothing fromGHCSrcLoc :: SrcLoc -> Loc -fromGHCSrcLoc SrcLoc{..} = Loc srcLocFile (Span (Pos srcLocStartLine srcLocStartCol) (Pos srcLocEndLine srcLocEndCol)) +fromGHCSrcLoc SrcLoc{..} = Loc (pack srcLocFile) (Span (Pos srcLocStartLine srcLocStartCol) (Pos srcLocEndLine srcLocEndCol)) runFailWithLoc :: FailWithLocC m a -> m (Either (Loc, String) a) diff --git a/semantic-core/src/Data/Name.hs b/semantic-core/src/Data/Name.hs index ccffcb30c9..b9979fc86c 100644 --- a/semantic-core/src/Data/Name.hs +++ b/semantic-core/src/Data/Name.hs @@ -26,6 +26,7 @@ import Control.Monad.IO.Class import qualified Data.Char as Char import Data.HashSet (HashSet) import qualified Data.HashSet as HashSet +import Data.Text (Text) import Data.Text.Prettyprint.Doc (Pretty (..)) import qualified Data.Text.Prettyprint.Doc as Pretty @@ -47,7 +48,7 @@ data Name -- This should be used for names which the user provided and which other code (other functions, other modules, other packages) could call, e.g. declaration names. | User User -- | A variable name represented as the path to a source file. Used for loading modules at a specific name. - | Path FilePath + | Path Text deriving (Eq, Ord, Show) instance Pretty Name where From 1bd25ace27b806913bfc53fd1a63c6bbc213c062 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 12 Jun 2019 10:51:17 -0400 Subject: [PATCH 49/61] Represent user variables as Text. --- semantic-core/src/Analysis/Concrete.hs | 22 +++++++++++----------- semantic-core/src/Data/Name.hs | 8 ++++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/semantic-core/src/Analysis/Concrete.hs b/semantic-core/src/Analysis/Concrete.hs index 58a780e159..633148da50 100644 --- a/semantic-core/src/Analysis/Concrete.hs +++ b/semantic-core/src/Analysis/Concrete.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE FlexibleContexts, FlexibleInstances, GeneralizedNewtypeDeriving, LambdaCase, MultiParamTypeClasses, NamedFieldPuns, RecordWildCards, TypeApplications, TypeOperators, UndecidableInstances #-} +{-# LANGUAGE FlexibleContexts, FlexibleInstances, GeneralizedNewtypeDeriving, LambdaCase, MultiParamTypeClasses, NamedFieldPuns, OverloadedStrings, RecordWildCards, TypeApplications, TypeOperators, UndecidableInstances #-} module Analysis.Concrete ( Concrete(..) , concrete @@ -29,7 +29,7 @@ import Data.Loc import qualified Data.Map as Map import Data.Monoid (Alt(..)) import Data.Name -import Data.Text (Text, unpack) +import Data.Text (Text, pack) import Prelude hiding (fail) type Precise = Int @@ -185,25 +185,25 @@ heapValueGraph h = heapGraph (const id) (const fromAddr) h heapAddressGraph :: Heap -> G.Graph (EdgeType, Precise) heapAddressGraph = heapGraph (\ addr v -> (Value v, addr)) (fmap G.vertex . (,) . either Edge Slot) -addressStyle :: Heap -> G.Style (EdgeType, Precise) String +addressStyle :: Heap -> G.Style (EdgeType, Precise) Text addressStyle heap = (G.defaultStyle vertex) { G.edgeAttributes } - where vertex (_, addr) = maybe (show addr <> " = ?") (((show addr <> " = ") <>) . fromConcrete) (IntMap.lookup addr heap) + where vertex (_, addr) = maybe (pack (show addr) <> " = ?") (((pack (show addr) <> " = ") <>) . fromConcrete) (IntMap.lookup addr heap) edgeAttributes _ (Slot name, _) = ["label" G.:= fromName name] edgeAttributes _ (Edge Core.Import, _) = ["color" G.:= "blue"] edgeAttributes _ (Edge Core.Lexical, _) = ["color" G.:= "green"] edgeAttributes _ _ = [] fromConcrete = \case Unit -> "()" - Bool b -> show b - String s -> show s - Closure (Loc p (Span s e)) n _ _ -> "\\\\ " <> fromName n <> " [" <> unpack p <> ":" <> showPos s <> "-" <> showPos e <> "]" + Bool b -> pack $ show b + String s -> pack $ show s + Closure (Loc p (Span s e)) n _ _ -> "\\\\ " <> fromName n <> " [" <> p <> ":" <> showPos s <> "-" <> showPos e <> "]" Obj _ -> "{}" - showPos (Pos l c) = show l <> ":" <> show c + showPos (Pos l c) = pack (show l) <> ":" <> pack (show c) fromName (User s) = s fromName (Gen sym) = fromGensym sym - fromName (Path p) = show p - fromGensym (Root s) = s - fromGensym (ss :/ (s, i)) = fromGensym ss <> "." <> s <> show i + fromName (Path p) = pack $ show p + fromGensym (Root s) = pack s + fromGensym (ss :/ (s, i)) = fromGensym ss <> "." <> pack s <> pack (show i) data EdgeType = Edge Core.Edge diff --git a/semantic-core/src/Data/Name.hs b/semantic-core/src/Data/Name.hs index b9979fc86c..a9b99464d4 100644 --- a/semantic-core/src/Data/Name.hs +++ b/semantic-core/src/Data/Name.hs @@ -26,12 +26,12 @@ import Control.Monad.IO.Class import qualified Data.Char as Char import Data.HashSet (HashSet) import qualified Data.HashSet as HashSet -import Data.Text (Text) +import Data.Text as Text (Text, any, unpack) import Data.Text.Prettyprint.Doc (Pretty (..)) import qualified Data.Text.Prettyprint.Doc as Pretty -- | User-specified and -relevant names. -type User = String +type User = Text -- | The type of namespaced actions, i.e. actions occurring within some outer name. -- @@ -57,14 +57,14 @@ instance Pretty Name where User n -> pretty n Path p -> pretty (show p) -reservedNames :: HashSet User +reservedNames :: HashSet String reservedNames = [ "#true", "#false", "let", "#frame", "if", "then", "else" , "lexical", "import", "#unit", "load"] -- | Returns true if any character would require quotation or if the -- name conflicts with a Core primitive. needsQuotation :: User -> Bool -needsQuotation u = HashSet.member u reservedNames || any (not . isSimpleCharacter) u +needsQuotation u = HashSet.member (unpack u) reservedNames || Text.any (not . isSimpleCharacter) u -- | A ‘simple’ character is, loosely defined, a character that is compatible -- with identifiers in most ASCII-oriented programming languages. This is defined From 06e3c7f0beb48d40a06f3ca22c45a3da061a03cc Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 12 Jun 2019 10:52:26 -0400 Subject: [PATCH 50/61] Factor the common bits of the string out. --- semantic-core/src/Analysis/Concrete.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semantic-core/src/Analysis/Concrete.hs b/semantic-core/src/Analysis/Concrete.hs index 633148da50..d52fcdf550 100644 --- a/semantic-core/src/Analysis/Concrete.hs +++ b/semantic-core/src/Analysis/Concrete.hs @@ -187,7 +187,7 @@ heapAddressGraph = heapGraph (\ addr v -> (Value v, addr)) (fmap G.vertex . (,) addressStyle :: Heap -> G.Style (EdgeType, Precise) Text addressStyle heap = (G.defaultStyle vertex) { G.edgeAttributes } - where vertex (_, addr) = maybe (pack (show addr) <> " = ?") (((pack (show addr) <> " = ") <>) . fromConcrete) (IntMap.lookup addr heap) + where vertex (_, addr) = pack (show addr) <> " = " <> maybe "?" fromConcrete (IntMap.lookup addr heap) edgeAttributes _ (Slot name, _) = ["label" G.:= fromName name] edgeAttributes _ (Edge Core.Import, _) = ["color" G.:= "blue"] edgeAttributes _ (Edge Core.Lexical, _) = ["color" G.:= "green"] From e9968caa451c5b92c0370a59ef147d7b58e3fbae Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 12 Jun 2019 10:55:04 -0400 Subject: [PATCH 51/61] =?UTF-8?q?Use=20Text=20for=20gensym=E2=80=99d=20nam?= =?UTF-8?q?es.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- semantic-core/src/Analysis/Concrete.hs | 4 ++-- semantic-core/src/Analysis/FlowInsensitive.hs | 2 +- semantic-core/src/Analysis/ImportGraph.hs | 2 +- semantic-core/src/Analysis/Typecheck.hs | 2 +- semantic-core/src/Data/Name.hs | 14 +++++++------- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/semantic-core/src/Analysis/Concrete.hs b/semantic-core/src/Analysis/Concrete.hs index d52fcdf550..e39ceeed36 100644 --- a/semantic-core/src/Analysis/Concrete.hs +++ b/semantic-core/src/Analysis/Concrete.hs @@ -202,8 +202,8 @@ addressStyle heap = (G.defaultStyle vertex) { G.edgeAttributes } fromName (User s) = s fromName (Gen sym) = fromGensym sym fromName (Path p) = pack $ show p - fromGensym (Root s) = pack s - fromGensym (ss :/ (s, i)) = fromGensym ss <> "." <> pack s <> pack (show i) + fromGensym (Root s) = s + fromGensym (ss :/ (s, i)) = fromGensym ss <> "." <> s <> pack (show i) data EdgeType = Edge Core.Edge diff --git a/semantic-core/src/Analysis/FlowInsensitive.hs b/semantic-core/src/Analysis/FlowInsensitive.hs index 05e6faaea8..35a46fa1d0 100644 --- a/semantic-core/src/Analysis/FlowInsensitive.hs +++ b/semantic-core/src/Analysis/FlowInsensitive.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE FlexibleContexts, ScopedTypeVariables #-} +{-# LANGUAGE FlexibleContexts, OverloadedStrings, ScopedTypeVariables #-} module Analysis.FlowInsensitive ( Heap , FrameId(..) diff --git a/semantic-core/src/Analysis/ImportGraph.hs b/semantic-core/src/Analysis/ImportGraph.hs index 0610ff2718..7e71e41a06 100644 --- a/semantic-core/src/Analysis/ImportGraph.hs +++ b/semantic-core/src/Analysis/ImportGraph.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE FlexibleContexts, RecordWildCards #-} +{-# LANGUAGE FlexibleContexts, OverloadedStrings, RecordWildCards #-} module Analysis.ImportGraph ( ImportGraph , importGraph diff --git a/semantic-core/src/Analysis/Typecheck.hs b/semantic-core/src/Analysis/Typecheck.hs index f37338ee69..937165dac4 100644 --- a/semantic-core/src/Analysis/Typecheck.hs +++ b/semantic-core/src/Analysis/Typecheck.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE DeriveFunctor, FlexibleContexts, FlexibleInstances, LambdaCase, RecordWildCards, ScopedTypeVariables, TypeApplications #-} +{-# LANGUAGE DeriveFunctor, FlexibleContexts, FlexibleInstances, LambdaCase, OverloadedStrings, RecordWildCards, ScopedTypeVariables, TypeApplications #-} module Analysis.Typecheck ( Monotype (..) , Meta diff --git a/semantic-core/src/Data/Name.hs b/semantic-core/src/Data/Name.hs index a9b99464d4..a3d1492fe2 100644 --- a/semantic-core/src/Data/Name.hs +++ b/semantic-core/src/Data/Name.hs @@ -77,8 +77,8 @@ isSimpleCharacter = \case c -> Char.isAlphaNum c data Gensym - = Root String - | Gensym :/ (String, Int) + = Root Text + | Gensym :/ (Text, Int) deriving (Eq, Ord, Show) instance Pretty Gensym where @@ -86,21 +86,21 @@ instance Pretty Gensym where Root s -> pretty s p :/ (n, x) -> Pretty.hcat [pretty p, "/", pretty n, "^", pretty x] -(//) :: Gensym -> String -> Gensym +(//) :: Gensym -> Text -> Gensym root // s = root :/ (s, 0) infixl 6 // -gensym :: (Carrier sig m, Member Naming sig) => String -> m Gensym +gensym :: (Carrier sig m, Member Naming sig) => Text -> m Gensym gensym s = send (Gensym s pure) -namespace :: (Carrier sig m, Member Naming sig) => String -> m a -> m a +namespace :: (Carrier sig m, Member Naming sig) => Text -> m a -> m a namespace s m = send (Namespace s m pure) data Naming m k - = Gensym String (Gensym -> k) - | forall a . Namespace String (m a) (a -> k) + = Gensym Text (Gensym -> k) + | forall a . Namespace Text (m a) (a -> k) deriving instance Functor (Naming m) From d64e12d868d0add82e3e98c7557768c70733b236 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 17 Jun 2019 11:18:08 -0400 Subject: [PATCH 52/61] Compile identifiers. Co-Authored-By: Patrick Thomson --- semantic-python/src/Language/Python/Core.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index 14a3d10666..2fe47fe19b 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -5,6 +5,7 @@ module Language.Python.Core import Control.Monad.Fail import Data.Core as Core +import Data.Name as Name import GHC.Generics import Prelude hiding (fail) import qualified TreeSitter.Python.AST as Py @@ -55,7 +56,9 @@ instance Compile Py.FunctionDefinition instance Compile Py.FutureImportStatement instance Compile Py.GeneratorExpression instance Compile Py.GlobalStatement -instance Compile Py.Identifier + +instance Compile Py.Identifier where + compile (Py.Identifier text) = pure (Var (User text)) instance Compile Py.IfStatement where compile Py.IfStatement{..} = If <$> compile condition <*> compile consequence <*> case alternative of From 1164c87b014a2c2002cf5dc08c790f496db06f56 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 17 Jun 2019 12:01:55 -0400 Subject: [PATCH 53/61] Compile function definitions. Co-Authored-By: Patrick Thomson --- semantic-python/src/Language/Python/Core.hs | 24 ++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index 2fe47fe19b..9634eb4464 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -52,7 +52,29 @@ instance Compile Py.False where compile _ = pure (Bool False) instance Compile Py.Float instance Compile Py.ForStatement -instance Compile Py.FunctionDefinition + +instance Compile Py.FunctionDefinition where + compile Py.FunctionDefinition + { name = Py.Identifier name + , parameters = Py.Parameters parameters + , .. + } = do + parameters' <- params + body' <- compile body + pure (Let (User name) := lams parameters' body') + where params = case parameters of + Nothing -> pure [] + Just p -> traverse param [p] -- FIXME: this is wrong in node-types.json, @p@ should already be a list + param (Left Py.AnonymousComma{}) = fail "lol what" + param (Right (Left Py.DefaultParameter{..})) = fail "lol what" + param (Right (Right (Left Py.DictionarySplat{..}))) = fail "lol what" + param (Right (Right (Right (Left (Py.Identifier name))))) = pure (User name) + param (Right (Right (Right (Right (Left Py.KeywordIdentifier{..}))))) = fail "lol what" + param (Right (Right (Right (Right (Right (Left Py.ListSplat{..})))))) = fail "lol what" + param (Right (Right (Right (Right (Right (Right (Left Py.Tuple{..}))))))) = fail "lol what" + param (Right (Right (Right (Right (Right (Right (Right (Left Py.TypedDefaultParameter{..})))))))) = fail "lol what" + param (Right (Right (Right (Right (Right (Right (Right (Right Py.TypedParameter{..})))))))) = fail "lol what" + instance Compile Py.FutureImportStatement instance Compile Py.GeneratorExpression instance Compile Py.GlobalStatement From cf8b344efce6df5f34b4751a1b3515a68b37dcd7 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 19 Jun 2019 10:37:11 -0400 Subject: [PATCH 54/61] Handle all the unimplemented cases with a helper. --- semantic-python/src/Language/Python/Core.hs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/semantic-python/src/Language/Python/Core.hs b/semantic-python/src/Language/Python/Core.hs index 9634eb4464..114198b89b 100644 --- a/semantic-python/src/Language/Python/Core.hs +++ b/semantic-python/src/Language/Python/Core.hs @@ -65,15 +65,9 @@ instance Compile Py.FunctionDefinition where where params = case parameters of Nothing -> pure [] Just p -> traverse param [p] -- FIXME: this is wrong in node-types.json, @p@ should already be a list - param (Left Py.AnonymousComma{}) = fail "lol what" - param (Right (Left Py.DefaultParameter{..})) = fail "lol what" - param (Right (Right (Left Py.DictionarySplat{..}))) = fail "lol what" param (Right (Right (Right (Left (Py.Identifier name))))) = pure (User name) - param (Right (Right (Right (Right (Left Py.KeywordIdentifier{..}))))) = fail "lol what" - param (Right (Right (Right (Right (Right (Left Py.ListSplat{..})))))) = fail "lol what" - param (Right (Right (Right (Right (Right (Right (Left Py.Tuple{..}))))))) = fail "lol what" - param (Right (Right (Right (Right (Right (Right (Right (Left Py.TypedDefaultParameter{..})))))))) = fail "lol what" - param (Right (Right (Right (Right (Right (Right (Right (Right Py.TypedParameter{..})))))))) = fail "lol what" + param x = unimplemented x + unimplemented x = fail $ "unimplemented: " <> show x instance Compile Py.FutureImportStatement instance Compile Py.GeneratorExpression From 6097e4509efd46ee0a7f1eab01f2d2ce71cbaa85 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 25 Jun 2019 13:13:05 -0400 Subject: [PATCH 55/61] :fire: an obsolete FIXME. --- semantic-core/src/Analysis/Eval.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semantic-core/src/Analysis/Eval.hs b/semantic-core/src/Analysis/Eval.hs index 26908ceba8..e3f0c4b53a 100644 --- a/semantic-core/src/Analysis/Eval.hs +++ b/semantic-core/src/Analysis/Eval.hs @@ -208,7 +208,7 @@ data Analysis address value m = Analysis , unit :: m value , bool :: Bool -> m value , asBool :: value -> m Bool - , string :: Text -> m value -- FIXME: Text + , string :: Text -> m value , asString :: value -> m Text , frame :: m value , edge :: Edge -> address -> m () From 2f077365e2f563870ecac1f92daeabe891f05810 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 25 Jun 2019 14:21:36 -0400 Subject: [PATCH 56/61] Generate Text. --- semantic-core/test/Generators.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semantic-core/test/Generators.hs b/semantic-core/test/Generators.hs index 72c6e79447..6201846bdf 100644 --- a/semantic-core/test/Generators.hs +++ b/semantic-core/test/Generators.hs @@ -24,7 +24,7 @@ import Data.Name -- interesting property as they parse regardless. name :: MonadGen m => m Name name = Gen.prune (User <$> names) where - names = Gen.string (Range.linear 1 10) Gen.lower + names = Gen.text (Range.linear 1 10) Gen.lower boolean :: MonadGen m => m Core boolean = Bool <$> Gen.bool From 2009e4ab93a4d66021021bd01bec657f19b552ca Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 25 Jun 2019 14:21:42 -0400 Subject: [PATCH 57/61] Fix the IsString instance. --- semantic-core/test/Spec.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semantic-core/test/Spec.hs b/semantic-core/test/Spec.hs index 678c446ee9..763e1721fc 100644 --- a/semantic-core/test/Spec.hs +++ b/semantic-core/test/Spec.hs @@ -25,7 +25,7 @@ true, false :: Core true = Bool True false = Bool False -instance IsString Name where fromString = User +instance IsString Name where fromString = User . fromString parseEither :: Trifecta.Parser a -> String -> Either String a parseEither p = Trifecta.foldResult (Left . show . Trifecta._errDoc) Right . Trifecta.parseString (p <* Trifecta.eof) mempty From ce1d209b5e4b310c6d2410445c2d2598d6dc694b Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 25 Jun 2019 14:24:49 -0400 Subject: [PATCH 58/61] Correct the doctest runner. --- semantic-core/test/Doctest.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semantic-core/test/Doctest.hs b/semantic-core/test/Doctest.hs index d4f4586570..c25509c81a 100644 --- a/semantic-core/test/Doctest.hs +++ b/semantic-core/test/Doctest.hs @@ -9,4 +9,4 @@ main :: IO () main = do args <- getArgs autogen <- fmap (<> "/build/doctest/autogen") <$> lookupEnv "HASKELL_DIST_DIR" - doctest (maybe id ((:) . ("-i" <>)) autogen ("-isrc" : "--fast" : if null args then ["src"] else args)) + doctest (maybe id ((:) . ("-i" <>)) autogen ("-isemantic-code/src" : "--fast" : if null args then ["semantic-core/src"] else args)) From 58d819f81add2e14acc6d9b39e8260adb47793e6 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 25 Jun 2019 14:26:46 -0400 Subject: [PATCH 59/61] Turn on overloaded strings in the doctests. --- semantic-core/src/Analysis/Concrete.hs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/semantic-core/src/Analysis/Concrete.hs b/semantic-core/src/Analysis/Concrete.hs index 19b878e9c6..68a28f9798 100644 --- a/semantic-core/src/Analysis/Concrete.hs +++ b/semantic-core/src/Analysis/Concrete.hs @@ -210,3 +210,7 @@ data EdgeType | Slot Name | Value Concrete deriving (Eq, Ord, Show) + + +-- $setup +-- >>> :seti -XOverloadedStrings From ffdefb05e9ee55caab6934f082516e54882dc3ec Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 25 Jun 2019 14:27:50 -0400 Subject: [PATCH 60/61] Fix the doctest for concrete. --- semantic-core/src/Analysis/Concrete.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semantic-core/src/Analysis/Concrete.hs b/semantic-core/src/Analysis/Concrete.hs index 68a28f9798..6cb5ef2c7b 100644 --- a/semantic-core/src/Analysis/Concrete.hs +++ b/semantic-core/src/Analysis/Concrete.hs @@ -61,7 +61,7 @@ type Heap = IntMap.IntMap Concrete -- | Concrete evaluation of a term to a value. -- --- >>> snd (concrete [File (Loc "bool" emptySpan) (Core.Bool True)]) +-- >>> map fileBody (snd (concrete [File (Loc "bool" emptySpan) (Core.Bool True)])) -- [Right (Bool True)] concrete :: [File Core.Core] -> (Heap, [File (Either (Loc, String) Concrete)]) concrete From 324e605c3c5c7409c9a857fa760d95d5f647e787 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 25 Jun 2019 14:28:40 -0400 Subject: [PATCH 61/61] Run the doctests in CI. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 50239553ba..ad73246da6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -37,6 +37,7 @@ script: - cabal new-build - cabal new-run semantic:test - cabal new-run semantic-core:spec +- cabal new-run semantic-core:doctest # parse-examples is disabled because it slaughters our CI # - cabal new-run semantic:parse-examples