Skip to content

Commit a8e5d72

Browse files
committed
update: internal error
1 parent 942018d commit a8e5d72

File tree

4 files changed

+10
-39
lines changed

4 files changed

+10
-39
lines changed

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
{-# LANGUAGE DuplicateRecordFields #-}
2-
{-# LANGUAGE OverloadedLabels #-}
3-
{-# LANGUAGE RecordWildCards #-}
4-
{-# LANGUAGE TemplateHaskell #-}
5-
61
module LambdaBuffers.Compiler.KindCheck (
72
-- * Kindchecking functions.
83
check,
@@ -59,7 +54,6 @@ import LambdaBuffers.Compiler.ProtoCompat.Types qualified as P (
5954
KindRefType (KType),
6055
KindType (KindArrow, KindRef),
6156
LocalRef,
62-
MiscError (ImpossibleError),
6357
Module,
6458
ModuleName,
6559
Product (..),
@@ -181,7 +175,7 @@ runKindCheck = reinterpret $ \case
181175
InferRecursiveSubstitutionErr _ ->
182176
throwError . P.CompKindCheckError $ P.RecursiveKindError $ tyDef2TyName td
183177
InferImpossibleErr t ->
184-
throwError . P.CompMiscError $ P.ImpossibleError t
178+
throwError . P.InternalError $ t
185179

186180
var2VarName = \case
187181
LocalRef n -> P.VarName n emptySourceInfo

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

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{-# LANGUAGE OverloadedLabels #-}
21
{-# OPTIONS_GHC -Wno-missing-import-lists #-}
32
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
43

@@ -551,25 +550,16 @@ instance IsMessage P.KindCheckError KindCheckError where
551550
& (P.inconsistentTypeError . P.inferredKind) .~ toProto ki
552551
& (P.inconsistentTypeError . P.definedKind) .~ toProto kd
553552

554-
instance IsMessage P.InternalError MiscError where
555-
fromProto kce = case kce ^. P.maybe'internalError of
556-
Just x -> case x of
557-
P.InternalError'ImpossibleError' err -> ImpossibleError <$> fromProto (err ^. P.msg)
558-
Nothing -> throwProtoError EmptyField
559-
560-
toProto = \case
561-
ImpossibleError err -> defMessage & (P.impossibleError . P.msg) .~ toProto err
562-
563553
instance IsMessage P.CompilerError CompilerError where
564-
fromProto err = case err ^. P.maybe'compilerError of
554+
fromProto cErr = case cErr ^. P.maybe'compilerError of
565555
Just x -> case x of
566-
P.CompilerError'CompKindCheckError kcerr -> CompKindCheckError <$> fromProto kcerr
567-
P.CompilerError'CompMiscError miscerr -> CompMiscError <$> fromProto miscerr
556+
P.CompilerError'KindCheckError err -> CompKindCheckError <$> fromProto err
557+
P.CompilerError'InternalError err -> InternalError <$> fromProto (err ^. P.internalError)
568558
Nothing -> throwProtoError EmptyField
569559

570560
toProto = \case
571-
CompKindCheckError kcerr -> defMessage & P.compKindCheckError .~ toProto kcerr
572-
CompMiscError miscerr -> defMessage & P.compMiscError .~ toProto miscerr
561+
CompKindCheckError err -> defMessage & P.kindCheckError .~ toProto err
562+
InternalError err -> defMessage & (P.internalError . P.internalError) .~ toProto err
573563

574564
instance IsMessage P.CompilerResult CompilerResult where
575565
fromProto c =

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
module LambdaBuffers.Compiler.ProtoCompat.Types (
55
ClassDef (..),
6-
MiscError (..),
76
ClassName (..),
87
CompilerError (..),
98
CompilerInput (..),
@@ -219,10 +218,6 @@ newtype CompilerInput = CompilerInput {modules :: [Module]}
219218
deriving stock (Show, Eq, Ord, Generic)
220219
deriving newtype (Monoid, Semigroup)
221220

222-
newtype MiscError = ImpossibleError Text
223-
deriving stock (Show, Eq, Ord, Generic)
224-
instance Exception MiscError
225-
226221
data KindCheckError
227222
= -- | The following term is unbound in the following type definition.
228223
UnboundTermError TyName VarName
@@ -237,7 +232,7 @@ instance Exception KindCheckError
237232

238233
data CompilerError
239234
= CompKindCheckError KindCheckError
240-
| CompMiscError MiscError
235+
| InternalError Text
241236
deriving stock (Show, Eq, Ord, Generic)
242237

243238
data CompilerResult = CompilerResult

lambda-buffers-proto/compiler.proto

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -492,15 +492,7 @@ message CompilerInput {
492492

493493
// Internal errors.
494494
message InternalError {
495-
496-
// This should never happen.
497-
message ImpossibleError {
498-
string msg = 1;
499-
}
500-
501-
oneof internal_error {
502-
ImpossibleError impossible_error = 1;
503-
}
495+
string internal_error = 1;
504496
}
505497

506498
// Kindchecker errors.
@@ -554,8 +546,8 @@ message CompilerError {
554546

555547
// Reason why the compilation failed.
556548
oneof compiler_error {
557-
KindCheckError comp_kind_check_error = 1;
558-
InternalError comp_misc_error = 2;
549+
KindCheckError kind_check_error = 1;
550+
InternalError internal_error = 2;
559551
}
560552
}
561553

0 commit comments

Comments
 (0)