Skip to content

Commit af39137

Browse files
committed
update: add the errors to the .proto
1 parent 32feea0 commit af39137

File tree

5 files changed

+52
-15
lines changed

5 files changed

+52
-15
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,15 +550,29 @@ instance IsMessage P.KindCheckError KindCheckError where
550550
& (P.inconsistentTypeError . P.inferredKind) .~ toProto ki
551551
& (P.inconsistentTypeError . P.definedKind) .~ toProto kd
552552

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 ->
561+
defMessage
562+
& (P.multipleDeclarationError . P.declaration1) .~ toProto d1
563+
& (P.multipleDeclarationError . P.declaration2) .~ toProto d2
564+
553565
instance IsMessage P.CompilerError CompilerError where
554566
fromProto cErr = case cErr ^. P.maybe'compilerError of
555567
Just x -> case x of
556568
P.CompilerError'KindCheckError err -> CompKindCheckError <$> fromProto err
557569
P.CompilerError'InternalError err -> InternalError <$> fromProto (err ^. P.internalError)
570+
P.CompilerError'ReaderError err -> CompReaderError <$> fromProto err
558571
Nothing -> throwProtoError EmptyField
559572

560573
toProto = \case
561574
CompKindCheckError err -> defMessage & P.kindCheckError .~ toProto err
575+
CompReaderError err -> defMessage & P.readerError .~ toProto err
562576
InternalError err -> defMessage & (P.internalError . P.internalError) .~ toProto err
563577

564578
instance IsMessage P.CompilerResult CompilerResult where

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ instance Exception KindCheckError
294294
checking.
295295
-}
296296
data ReaderError
297-
= -- | The following type@(TyName) was declared here@(SourceInfo) and here@(SourceInfo).
297+
= -- | The following type@(TyName) was redeclared here@(TyName).
298298
MultipleDeclaration TyName TyName
299299
deriving stock (Show, Eq, Ord, Generic)
300300
deriving (Arbitrary) via GenericArbitrary ReaderError

lambda-buffers-compiler/test/Test/Samples/Proto/CompilerInput.hs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
module Test.Samples.Proto.CompilerInput (compilerInput'incoherent, compilerInput'maybe, compilerInput'doubleDeclaration, compilerInput'doubleDeclarationDiffMod) where
1+
module Test.Samples.Proto.CompilerInput (
2+
compilerInput'incoherent,
3+
compilerInput'maybe,
4+
compilerInput'doubleDeclaration,
5+
compilerInput'doubleDeclarationDiffMod,
6+
) where
27

38
import Control.Lens ((%~), (&), (.~))
49
import LambdaBuffers.Compiler.ProtoCompat qualified as P
510
import Test.Samples.Proto.Module (module'incoherent, module'maybe)
6-
import Test.Samples.Proto.SourceInfo
11+
import Test.Samples.Proto.SourceInfo (sourceInfo'empty)
712

13+
_CompilerInput :: [P.Module] -> P.CompilerInput
814
_CompilerInput x = P.CompilerInput {P.modules = x}
915

1016
-- | Compiler Input containing 1 module with 1 definition - Maybe.

lambda-buffers-compiler/test/Test/Samples/Proto/Module.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
module Test.Samples.Proto.Module (module'maybe, module'incoherent) where
1+
module Test.Samples.Proto.Module (module'maybe, module'incoherent, _Module) where
22

33
import Control.Lens ((%~), (&))
44
import LambdaBuffers.Compiler.ProtoCompat qualified as P
55
import Test.Samples.Proto.SourceInfo (sourceInfo'empty)
66
import Test.Samples.Proto.TyDef (tyDef'incoherent, tyDef'maybe)
77

8+
_Module :: P.ModuleName -> [P.TyDef] -> [P.ClassDef] -> [P.InstanceClause] -> P.Module
89
_Module mn tds cds ins =
910
P.Module
1011
{ P.moduleName = mn

lambda-buffers-proto/compiler.proto

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -505,26 +505,26 @@ message KindCheckError {
505505
VarName var_name = 2;
506506
}
507507

508-
// Unification has failed - type is incorrectly defined. Error reads as
508+
// Unification has failed - type is incorrectly defined. Error reads as
509509
// follows:
510-
// > In ty_name definition an error has occurred when trying to unify kind
511-
// > ty_kind_1 with ty_kind_2.
510+
// > In ty_name definition an error has occurred when trying to unify kind
511+
// > ty_kind_1 with ty_kind_2.
512512
//
513-
// FIXME(cstml): add source of constraint to the error such that user can see
514-
// where the constraint was generated - therefore where the error precisely
515-
// is.
513+
// FIXME(cstml): add source of constraint to the error such that user can see
514+
// where the constraint was generated - therefore where the error precisely
515+
// is.
516516
message ImpossibleUnificationError {
517517
TyName ty_name = 1;
518518
Kind ty_kind_1 = 2;
519519
Kind ty_kind_2 = 3;
520520
}
521521

522522
// Error reads:
523-
// Inifinitely recursive term detected in definition ty_name.
523+
// Inifinitely recursive term detected in definition ty_name.
524524
message RecursiveKindError {
525525
TyName ty_name = 1;
526526
}
527-
527+
528528
// The inferred type differs from the type as defined.
529529
message InconsistentTypeError {
530530
TyName ty_name = 1;
@@ -536,18 +536,34 @@ message KindCheckError {
536536
oneof kind_check_error {
537537
UnboundTermError unbound_term_error = 1;
538538
ImpossibleUnificationError unification_error = 2;
539-
RecursiveKindError recursive_subs_error = 3;
539+
RecursiveKindError recursive_subs_error = 3;
540540
InconsistentTypeError inconsistent_type_error = 4;
541541
}
542542
}
543543

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;
555+
}
556+
}
557+
544558
// Compiler Error can be extended with other classes of errors.
545559
message CompilerError {
546-
560+
547561
// Reason why the compilation failed.
548562
oneof compiler_error {
549563
KindCheckError kind_check_error = 1;
550-
InternalError internal_error = 2;
564+
ReaderError reader_error = 2;
565+
InternalError internal_error = 3;
566+
551567
}
552568
}
553569

0 commit comments

Comments
 (0)