Skip to content

Commit cf654b9

Browse files
committed
update: respond to comments:
1. merge error 2. change error name
1 parent af39137 commit cf654b9

File tree

4 files changed

+21
-41
lines changed

4 files changed

+21
-41
lines changed

lambda-buffers-compiler/src/LambdaBuffers/Compiler/KindCheck.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ tyDef2Context curModName tyDef@(P.TyDef tyName _ _) = do
217217
associateName v t = do
218218
maps <- get @(M.Map Variable P.TyName)
219219
case maps M.!? v of
220-
Just otherTyName -> throwError . PT.CompReaderError $ PT.MultipleDeclaration otherTyName t
220+
Just otherTyName -> throwError . PT.CompKindCheckError $ PT.MultipleTyDefError otherTyName t
221221
Nothing -> modify (M.insert v t)
222222

223223
{- | Converts the Proto Module name to a local modname - dropping the

lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat.hs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,10 @@ instance IsMessage P.KindCheckError KindCheckError where
529529
<$> fromProto (err ^. P.tyName)
530530
<*> fromProto (err ^. P.inferredKind)
531531
<*> fromProto (err ^. P.definedKind)
532+
P.KindCheckError'MultipleTyDefError' err ->
533+
MultipleTyDefError
534+
<$> fromProto (err ^. P.declaration1)
535+
<*> fromProto (err ^. P.declaration2)
532536
Nothing -> throwProtoError EmptyField
533537

534538
toProto = \case
@@ -549,30 +553,20 @@ instance IsMessage P.KindCheckError KindCheckError where
549553
& (P.inconsistentTypeError . P.tyName) .~ toProto name
550554
& (P.inconsistentTypeError . P.inferredKind) .~ toProto ki
551555
& (P.inconsistentTypeError . P.definedKind) .~ toProto kd
552-
553-
instance IsMessage P.ReaderError ReaderError where
554-
fromProto rErr = case rErr ^. P.maybe'readerError of
555-
Just x -> case x of
556-
P.ReaderError'MultipleDeclarationError' err -> MultipleDeclaration <$> fromProto (err ^. P.declaration1) <*> fromProto (err ^. P.declaration2)
557-
Nothing -> throwProtoError EmptyField
558-
559-
toProto = \case
560-
MultipleDeclaration d1 d2 ->
556+
MultipleTyDefError d1 d2 ->
561557
defMessage
562-
& (P.multipleDeclarationError . P.declaration1) .~ toProto d1
563-
& (P.multipleDeclarationError . P.declaration2) .~ toProto d2
558+
& (P.multipleTyDefError . P.declaration1) .~ toProto d1
559+
& (P.multipleTyDefError . P.declaration2) .~ toProto d2
564560

565561
instance IsMessage P.CompilerError CompilerError where
566562
fromProto cErr = case cErr ^. P.maybe'compilerError of
567563
Just x -> case x of
568564
P.CompilerError'KindCheckError err -> CompKindCheckError <$> fromProto err
569565
P.CompilerError'InternalError err -> InternalError <$> fromProto (err ^. P.internalError)
570-
P.CompilerError'ReaderError err -> CompReaderError <$> fromProto err
571566
Nothing -> throwProtoError EmptyField
572567

573568
toProto = \case
574569
CompKindCheckError err -> defMessage & P.kindCheckError .~ toProto err
575-
CompReaderError err -> defMessage & P.readerError .~ toProto err
576570
InternalError err -> defMessage & (P.internalError . P.internalError) .~ toProto err
577571

578572
instance IsMessage P.CompilerResult CompilerResult where

lambda-buffers-compiler/src/LambdaBuffers/Compiler/ProtoCompat/Types.hs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{-# LANGUAGE DuplicateRecordFields #-}
22
{-# OPTIONS_GHC -Wno-orphans #-}
33
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
4+
{-# OPTIONS_GHC -fconstraint-solver-iterations=0 #-}
45

6+
{- | this is needed so the deriving via can generate Arbitrary instances for
7+
data definitions with more than 4 constructors
8+
-}
59
module LambdaBuffers.Compiler.ProtoCompat.Types (
610
ClassDef (..),
711
ClassName (..),
@@ -41,7 +45,6 @@ module LambdaBuffers.Compiler.ProtoCompat.Types (
4145
TyRef (..),
4246
TyVar (..),
4347
VarName (..),
44-
ReaderError (..),
4548
module VARS,
4649
) where
4750

@@ -286,23 +289,15 @@ data KindCheckError
286289
RecursiveKindError TyName
287290
| -- | The following type has the wrong.
288291
InconsistentTypeError TyName Kind Kind
292+
| -- | The following type@(TyName) was redeclared here@(TyName).
293+
MultipleTyDefError TyName TyName
289294
deriving stock (Show, Eq, Ord, Generic)
290295
deriving (Arbitrary) via GenericArbitrary KindCheckError
291296
instance Exception KindCheckError
292297

293-
{- | Reader errors are validation errors which are not directly tied to the kind
294-
checking.
295-
-}
296-
data ReaderError
297-
= -- | The following type@(TyName) was redeclared here@(TyName).
298-
MultipleDeclaration TyName TyName
299-
deriving stock (Show, Eq, Ord, Generic)
300-
deriving (Arbitrary) via GenericArbitrary ReaderError
301-
302298
-- | All the compiler errors.
303299
data CompilerError
304300
= CompKindCheckError KindCheckError
305-
| CompReaderError ReaderError
306301
| InternalError Text
307302
deriving stock (Show, Eq, Ord, Generic)
308303
deriving (Arbitrary) via GenericArbitrary CompilerError

lambda-buffers-proto/compiler.proto

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -532,26 +532,19 @@ message KindCheckError {
532532
Kind defined_kind = 3;
533533
}
534534

535+
// A tydef was defined multiple times.
536+
message MultipleTyDefError {
537+
TyName declaration_1 = 1;
538+
TyName declaration_2 = 2;
539+
}
540+
535541
// The types of inference errors.
536542
oneof kind_check_error {
537543
UnboundTermError unbound_term_error = 1;
538544
ImpossibleUnificationError unification_error = 2;
539545
RecursiveKindError recursive_subs_error = 3;
540546
InconsistentTypeError inconsistent_type_error = 4;
541-
}
542-
}
543-
544-
// Error relating to the content read by the compiler.
545-
message ReaderError {
546-
547-
// A tydef was defined multiple times.
548-
message MultipleDeclarationError {
549-
TyName declaration_1 = 1;
550-
TyName declaration_2 = 2;
551-
}
552-
553-
oneof reader_error {
554-
MultipleDeclarationError multiple_declaration_error = 1;
547+
MultipleTyDefError multiple_tydef_error = 5;
555548
}
556549
}
557550

@@ -561,9 +554,7 @@ message CompilerError {
561554
// Reason why the compilation failed.
562555
oneof compiler_error {
563556
KindCheckError kind_check_error = 1;
564-
ReaderError reader_error = 2;
565557
InternalError internal_error = 3;
566-
567558
}
568559
}
569560

0 commit comments

Comments
 (0)