ifaces: preconditions, proto changes (#11448)

This adds a precondition expression to the protobuf and the
encoders/decoders on the haskell side.

CHANGELOG_BEGIN
CHANGELOG_END
This commit is contained in:
Robin Krom 2021-10-28 15:15:22 +02:00 committed by GitHub
parent 73718a22fa
commit d3b9c84908
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 5 additions and 0 deletions

View File

@ -930,6 +930,7 @@ data DefInterface = DefInterface
, intVirtualChoices :: !(NM.NameMap InterfaceChoice)
, intFixedChoices :: !(NM.NameMap TemplateChoice)
, intMethods :: !(NM.NameMap InterfaceMethod)
, intPrecondition :: !Expr
}
deriving (Eq, Data, Generic, NFData, Show)

View File

@ -241,6 +241,7 @@ decodeDefInterface LF1.DefInterface {..} = do
throwError $ ParseError $ unwords
[ "Interface", T.unpack (T.intercalate "." (unTypeConName intName))
, "has collision between fixed choice and virtual choice." ]
intPrecondition <- mayDecode "defInterfacePrecond" defInterfacePrecond decodeExpr
pure DefInterface {..}
decodeInterfaceChoice :: LF1.InterfaceChoice -> Decode InterfaceChoice

View File

@ -1002,6 +1002,7 @@ encodeDefInterface DefInterface{..} = do
defInterfaceChoices <- encodeNameMap encodeInterfaceChoice intVirtualChoices
defInterfaceFixedChoices <- encodeNameMap encodeTemplateChoice intFixedChoices
defInterfaceMethods <- encodeNameMap encodeInterfaceMethod intMethods
defInterfacePrecond <- encodeExpr intPrecondition
pure $ P.DefInterface{..}
encodeInterfaceChoice :: InterfaceChoice -> Encode P.InterfaceChoice

View File

@ -444,6 +444,7 @@ convertInterfaces env tyThings = interfaceClasses
intVirtualChoices <- NM.fromList <$> mapM convertVirtualChoice
(MS.findWithDefault [] intName (envInterfaceChoiceData env))
intFixedChoices <- convertChoices env intName emptyTemplateBinds
let intPrecondition = EUnit -- TODO (drsk) #11397 Implement interface preconditions
pure DefInterface {..}
convertVirtualChoice :: ChoiceData -> ConvertM InterfaceChoice

View File

@ -1532,6 +1532,7 @@ message DefInterface {
// Binder for interface value ("this") in fixed choices.
int32 param_interned_str = 5;
repeated TemplateChoice fixed_choices = 6;
Expr precond = 7;
}
// Exception definition