Skip to content

Commit

Permalink
interface PoC: protobuf definitions (#10796)
Browse files Browse the repository at this point in the history
* interface PoC: protobuf definitions

The protobuf changes for the Daml interface PoC.

CHANGELOG_BEGIN
CHANGELOG_END

* dummy interface decoder/encoder
  • Loading branch information
Robin Krom authored Sep 7, 2021
1 parent a1da025 commit b8bd5e6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
8 changes: 6 additions & 2 deletions compiler/daml-lf-proto/src/DA/Daml/LF/Proto3/DecodeV1.hs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ decodeScenarioModule minorText protoPkg = do
pure $ head $ NM.toList modules

decodeModule :: LF1.Module -> Decode Module
decodeModule (LF1.Module name flags synonyms dataTypes values templates exceptions) =
decodeModule (LF1.Module name flags synonyms dataTypes values templates exceptions _interfaces) =
Module
<$> decodeDottedName ModuleName name
<*> pure Nothing
Expand All @@ -226,6 +226,10 @@ decodeModule (LF1.Module name flags synonyms dataTypes values templates exceptio
<*> decodeNM DuplicateValue decodeDefValue values
<*> decodeNM EDuplicateTemplate decodeDefTemplate templates
<*> decodeNM DuplicateException decodeDefException exceptions
-- <*> decodeNM decodeDefInterface interfaces -- TODO (drsk) interfaces

-- decodeDefInterface :: LF1.DefInterface -> Decode DefInterface
-- decodeDefInterface = undefined -- TODO (drsk) interfaces

decodeFeatureFlags :: LF1.FeatureFlags -> Decode FeatureFlags
decodeFeatureFlags LF1.FeatureFlags{..} =
Expand Down Expand Up @@ -300,7 +304,7 @@ decodeDefTemplate LF1.DefTemplate{..} = do
<*> mayDecode "defTemplateAgreement" defTemplateAgreement decodeExpr
<*> decodeNM DuplicateChoice decodeChoice defTemplateChoices
<*> mapM (decodeDefTemplateKey tplParam) defTemplateKey

-- <*> pure [] -- TODO (drsk) interfaces

decodeDefTemplateKey :: ExprVarName -> LF1.DefTemplate_DefKey -> Decode TemplateKey
decodeDefTemplateKey templateParam LF1.DefTemplate_DefKey{..} = do
Expand Down
9 changes: 9 additions & 0 deletions compiler/daml-lf-proto/src/DA/Daml/LF/Proto3/EncodeV1.hs
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,10 @@ encodeDefException DefException{..} = do
defExceptionMessage <- encodeExpr exnMessage
pure P.DefException{..}


encodeTemplateImplements :: Qualified TypeConName -> Encode P.TypeConName
encodeTemplateImplements = encodeQualTypeConName'

encodeTemplate :: Template -> Encode P.DefTemplate
encodeTemplate Template{..} = do
defTemplateTycon <- encodeDottedName unTypeConName tplTypeCon
Expand All @@ -891,6 +895,7 @@ encodeTemplate Template{..} = do
defTemplateChoices <- encodeNameMap encodeTemplateChoice tplChoices
defTemplateLocation <- traverse encodeSourceLoc tplLocation
defTemplateKey <- traverse encodeTemplateKey tplKey
defTemplateImplements <- encodeList encodeTemplateImplements [] -- TODO (drsk) interfaces
pure P.DefTemplate{..}

encodeTemplateKey :: TemplateKey -> Encode P.DefTemplate_DefKey
Expand Down Expand Up @@ -938,6 +943,9 @@ encodeScenarioModule version mod =
where
metadata = getPackageMetadata version (PackageName "scenario") Nothing

-- encodeDefInterface :: DefInterface -> Encode P.DefInterface
-- encodeDefInterface = undefined -- TODO (drsk) interfaces

encodeModule :: Module -> Encode P.Module
encodeModule Module{..} = do
moduleName <- encodeDottedName unModuleName moduleName
Expand All @@ -947,6 +955,7 @@ encodeModule Module{..} = do
moduleValues <- encodeNameMap encodeDefValue moduleValues
moduleTemplates <- encodeNameMap encodeTemplate moduleTemplates
moduleExceptions <- encodeNameMap encodeDefException moduleExceptions
let moduleInterfaces = V.empty -- TODO (drsk) interfaces
pure P.Module{..}

encodePackageMetadata :: PackageMetadata -> Encode P.PackageMetadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,15 @@ message TemplateChoice {
Location location = 8;
}

message InterfaceChoice {
Location location = 1;
int32 name_interned_string = 2;
bool consuming = 3;
Type arg_type = 4;
Type ret_type = 5;
}


// we restrict key expressions to records of projections, much like SQL
message KeyExpr {
message Projection {
Expand Down Expand Up @@ -1427,6 +1436,15 @@ message DefTemplate {

// They key definition for the template, if present
DefKey key = 10; // optional

// Interfaces that this template implements.
repeated TypeConName implements = 13; // *Available in versions >= 1.dev*
}

message DefInterface {
Location location = 1;
int32 tycon_interned_dname = 2;
repeated InterfaceChoice choices = 3;
}

// Exception definition
Expand Down Expand Up @@ -1559,6 +1577,7 @@ message Module {
repeated DefValue values = 6;
repeated DefTemplate templates = 7;
repeated DefException exceptions = 10; // *Available in versions >= 1.14*
repeated DefInterface interfaces = 11; // *Available in versions >= 1.dev*
}

message InternedDottedName {
Expand Down

0 comments on commit b8bd5e6

Please sign in to comment.