Skip to content

Reworking the Compiler ProtoCompat (big one) #48

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7e2b4e5
Drafted error messages
bladyjoker Feb 13, 2023
aba79e4
Used MonadErro m
bladyjoker Feb 13, 2023
7e2378d
update: KC 1 constructor at a time + add Variable in inference
cstml Feb 13, 2023
097f048
lint: remove redundant import
cstml Feb 13, 2023
e6e7bfd
Saved work, tests almost working
bladyjoker Feb 13, 2023
fc22301
Added tests for empty folds
bladyjoker Feb 13, 2023
e66b833
Purging the mul ty def from KindCheck modules and tests
bladyjoker Feb 13, 2023
3f57029
All errors are in the API now
bladyjoker Feb 14, 2023
e052e32
Reshuffle into ProtoCompat/FromProto
bladyjoker Feb 14, 2023
58065fd
Fixed the Cli
bladyjoker Feb 14, 2023
22c4774
Generators scaffold
bladyjoker Feb 14, 2023
0e2e1aa
Gen Proto tests rework
bladyjoker Feb 14, 2023
21e9f87
Forgot a file
bladyjoker Feb 14, 2023
cc8f0d8
Added warning about `stripSourceInfo`
bladyjoker Feb 14, 2023
ee0ce8b
Merge remote-tracking branch 'origin/bladyjoker/proto-compat-rework' …
cstml Feb 14, 2023
d131862
fix: foldr not foldl
cstml Feb 14, 2023
778ab6a
Merge pull request #47 from mlabs-haskell/compiler/constructor-based-…
bladyjoker Feb 14, 2023
4cc3480
Proto documentation update
bladyjoker Feb 14, 2023
57bee70
Merge remote-tracking branch 'origin/bladyjoker/proto-compat-rework' …
bladyjoker Feb 14, 2023
409ef18
Remove a failing test and added TODOs, cleaned up after merge
bladyjoker Feb 14, 2023
39e0700
Applied review suggestions
bladyjoker Feb 14, 2023
b25c2a9
Merge remote-tracking branch 'origin/main' into bladyjoker/proto-comp…
bladyjoker Feb 15, 2023
d243b4f
fix: add opaque to context
cstml Feb 15, 2023
c1a3f33
Merge pull request #52 from mlabs-haskell/fix/add-opaque-to-context
bladyjoker Feb 15, 2023
54100bd
Applied suggestions
bladyjoker Feb 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions lambda-buffers-compiler/app/LambdaBuffers/Compiler/Cli/Compile.hs
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
module LambdaBuffers.Compiler.Cli.Compile (CompileOpts (..), compile) where

import Control.Lens (makeLenses)
import Control.Lens (makeLenses, (&), (.~))
import Control.Lens.Getter ((^.))
import Data.ByteString qualified as BS
import Data.ProtoLens (Message (defMessage))
import Data.ProtoLens qualified as Pb
import Data.ProtoLens.TextFormat qualified as PbText
import Data.Text.Lazy qualified as Text
import Data.Text.Lazy.IO qualified as Text
import LambdaBuffers.Compiler.KindCheck (check)
import LambdaBuffers.Compiler.ProtoCompat (
FromProtoErr (NamingError, ProtoError),
IsMessage (fromProto, toProto),
)
import LambdaBuffers.Compiler.ProtoCompat.Types qualified as ProtoCompat
import Proto.Compiler as ProtoLib (CompilerInput, CompilerOutput)
import LambdaBuffers.Compiler (runCompiler)
import Proto.Compiler (CompilerError, CompilerInput, CompilerOutput)
import Proto.Compiler_Fields (compilerError, compilerResult)
import System.FilePath.Lens (extension)

data CompileOpts = CompileOpts
Expand All @@ -24,20 +21,19 @@ data CompileOpts = CompileOpts

makeLenses ''CompileOpts

-- NOTE(cstml) - let's use Katip instead of print.
-- NOTE(cstml): Let's use Katip instead of print.

-- | Compile LambdaBuffers modules
compile :: CompileOpts -> IO ()
compile opts = do
compIn <- readCompilerInput (opts ^. input)
case fromProto @CompilerInput @ProtoCompat.CompilerInput compIn of
Left err -> case err of
NamingError ne -> print $ "Encountered a naming error " <> show ne
ProtoError pe -> print $ "Encountered a proto error " <> show pe
Right compIn' -> do
print @String "Successfully processed the CompilerInput"
let result = check compIn'
writeCompilerOutput (opts ^. output) (toProto result)
compInp <- readCompilerInput (opts ^. input)
case runCompiler compInp of
Left compErr -> do
print @String "Encountered errors during Compilation"
writeCompilerError (opts ^. output) compErr
Right compRes -> do
print @String "Compilation succeeded"
writeCompilerOutput (opts ^. output) (defMessage & compilerResult .~ compRes)
return ()

readCompilerInput :: FilePath -> IO CompilerInput
Expand All @@ -52,7 +48,10 @@ readCompilerInput fp = do
return $ PbText.readMessageOrDie content
_ -> error $ "Unknown CompilerInput format " <> ext

writeCompilerOutput :: FilePath -> ProtoLib.CompilerOutput -> IO ()
writeCompilerError :: FilePath -> CompilerError -> IO ()
writeCompilerError fp err = writeCompilerOutput fp (defMessage & compilerError .~ err)

writeCompilerOutput :: FilePath -> CompilerOutput -> IO ()
writeCompilerOutput fp cr = do
let ext = fp ^. extension
case ext of
Expand Down
9 changes: 7 additions & 2 deletions lambda-buffers-compiler/lambda-buffers-compiler.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ library
, text >=1.2

exposed-modules:
LambdaBuffers.Compiler
LambdaBuffers.Compiler.KindCheck
LambdaBuffers.Compiler.KindCheck.Context
LambdaBuffers.Compiler.KindCheck.Derivation
Expand All @@ -117,6 +118,7 @@ library
LambdaBuffers.Compiler.KindCheck.Variable
LambdaBuffers.Compiler.NamingCheck
LambdaBuffers.Compiler.ProtoCompat
LambdaBuffers.Compiler.ProtoCompat.FromProto
LambdaBuffers.Compiler.ProtoCompat.Types
LambdaBuffers.Compiler.TypeClass.Pat
LambdaBuffers.Compiler.TypeClass.Pretty
Expand All @@ -126,7 +128,7 @@ library

hs-source-dirs: src

-- note(cstml): should we name this something shorter? lb-cli?
-- NOTE(cstml): should we name this something shorter? lb-cli?
executable lambda-buffers-compiler-cli
import: common-language
import: common-imports
Expand All @@ -149,8 +151,10 @@ test-suite tests
hs-source-dirs: test
main-is: Test.hs
build-depends:
, containers >=0.6
, lambda-buffers-compiler
, lambda-buffers-compiler-pb >=0.1
, mtl >=2.2
, proto-lens >=0.7
, QuickCheck >=2.14
, tasty >=1.4
Expand All @@ -160,9 +164,10 @@ test-suite tests

other-modules:
Test.KindCheck
Test.LambdaBuffers.Compiler
Test.LambdaBuffers.Compiler.Gen
Test.TypeClassCheck
Test.Utils.CompilerInput
Test.Utils.Constructors
Test.Utils.Module
Test.Utils.SourceInfo
Test.Utils.TyDef
16 changes: 16 additions & 0 deletions lambda-buffers-compiler/src/LambdaBuffers/Compiler.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module LambdaBuffers.Compiler (runCompiler) where

import Data.ProtoLens (Message (defMessage))
import LambdaBuffers.Compiler.KindCheck (check_)
import LambdaBuffers.Compiler.ProtoCompat.FromProto (
runFromProto,
toProto,
)
import Proto.Compiler (CompilerError, CompilerInput, CompilerResult)

runCompiler :: CompilerInput -> Either CompilerError CompilerResult
runCompiler compInp = do
compInp' <- runFromProto compInp
case check_ compInp' of
Left err -> Left $ toProto err
Right _ -> Right defMessage
Loading