From a01721f35c830f02cdc9ca7008058de4c0fddade Mon Sep 17 00:00:00 2001 From: Leonid Ryzhyk Date: Wed, 12 Jun 2019 10:23:07 -0700 Subject: [PATCH] Bug in code generation for transformers There was a completely unnecessary hack in `Compiler.compileApplyNode` that used name case to distinguish relation from function arguments to transformer. This broke when combined with module name flattening. The fix uses proper HO type information instead. --- src/Language/DifferentialDatalog/Compile.hs | 7 ++++--- src/Language/DifferentialDatalog/Syntax.hs | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Language/DifferentialDatalog/Compile.hs b/src/Language/DifferentialDatalog/Compile.hs index f7ebbef81..f6b252db0 100644 --- a/src/Language/DifferentialDatalog/Compile.hs +++ b/src/Language/DifferentialDatalog/Compile.hs @@ -958,11 +958,12 @@ compileApplyNode d Apply{..} = ApplyNode $ " })" $$ "}; transformer}" where - inputs = concatMap (\i -> - if isLower $ head i + Transformer{..} = getTransformer d applyTransformer + inputs = concatMap (\(i, ti) -> + if hotypeIsFunction (hofType ti) then [rname i] else ["collections.get(&(" <> relId i <> ")).unwrap()", extractValue d (relType $ getRelation d i)]) - applyInputs + (zip applyInputs transInputs) ++ map (\o -> parens $ "|v|" <> mkValue' d "v" (relType $ getRelation d o)) applyOutputs outputs = map rname applyOutputs diff --git a/src/Language/DifferentialDatalog/Syntax.hs b/src/Language/DifferentialDatalog/Syntax.hs index 50e20ab86..f9e1087a3 100644 --- a/src/Language/DifferentialDatalog/Syntax.hs +++ b/src/Language/DifferentialDatalog/Syntax.hs @@ -794,11 +794,11 @@ instance Show HOType where hotypeIsRelation :: HOType -> Bool hotypeIsRelation HOTypeRelation{} = True -hotypeIsRelation _ = True +hotypeIsRelation _ = False hotypeIsFunction :: HOType -> Bool hotypeIsFunction HOTypeFunction{} = True -hotypeIsFunction _ = True +hotypeIsFunction _ = False -- | Type variables used in transformer declaration in the order they appear in the declaration hotypeTypeVars :: HOType -> [String]