Skip to content

Commit

Permalink
Bug in code generation for transformers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ryzhyk committed Jun 12, 2019
1 parent a06b94b commit a01721f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/Language/DifferentialDatalog/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Language/DifferentialDatalog/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit a01721f

Please sign in to comment.