@@ -15,6 +15,7 @@ import ProjectM36.DataTypes.Primitive
15import ProjectM36.AtomFunction
15import ProjectM36.AtomFunction
16import ProjectM36.DatabaseContextFunction
16import ProjectM36.DatabaseContextFunction
17import ProjectM36.Arbitrary
17import ProjectM36.Arbitrary
18+import ProjectM36.GraphRefRelationalExpr
18import ProjectM36.Transaction
19import ProjectM36.Transaction
19import qualified ProjectM36.Attribute as A
20import qualified ProjectM36.Attribute as A
20import qualified Data.Map as M
21import qualified Data.Map as M
@@ -111,7 +112,7 @@ mergeTuplesIntoGraphRefRelationalExprEnv tupIn e =
111 new_elems = Just (Left newTuple)
112 new_elems = Just (Left newTuple)
112 mergedTupMap = M.union (tupleToMap tupIn) (tupleToMap (envTuple e))
113 mergedTupMap = M.union (tupleToMap tupIn) (tupleToMap (envTuple e))
113 newTuple = mkRelationTupleFromMap mergedTupMap
114 newTuple = mkRelationTupleFromMap mergedTupMap
115mergeAttributesIntoGraphRefRelationalExprEnv :: Attributes -> GraphRefRelationalExprEnv -> GraphRefRelationalExprEnv
116mergeAttributesIntoGraphRefRelationalExprEnv :: Attributes -> GraphRefRelationalExprEnv -> GraphRefRelationalExprEnv
116mergeAttributesIntoGraphRefRelationalExprEnv attrsIn e = e { gre_extra = newattrs }
117mergeAttributesIntoGraphRefRelationalExprEnv attrsIn e = e { gre_extra = newattrs }
@@ -185,7 +186,7 @@ gfDatabaseContextForMarker (TransactionMarker transId) = concreteDatabaseContext
185gfDatabaseContextForMarker UncommittedContextMarker = do
186gfDatabaseContextForMarker UncommittedContextMarker = do
186 mctx <- gre_context <$> askEnv
187 mctx <- gre_context <$> askEnv
187 case mctx of
188 case mctx of
188− Nothing -> throwError NoUncommittedContextInEvalError
189+ Nothing -> throwError (traceStack "relexpr" NoUncommittedContextInEvalError)
189 Just ctx -> pure ctx
190 Just ctx -> pure ctx
191runGraphRefRelationalExprM :: GraphRefRelationalExprEnv -> GraphRefRelationalExprM a -> Either RelationalError a
192runGraphRefRelationalExprM :: GraphRefRelationalExprEnv -> GraphRefRelationalExprM a -> Either RelationalError a
@@ -1131,6 +1132,7 @@ evalGraphRefAttrExpr (NakedAttributeExpr attr) = pure attr
1132-- for tuple type concrete resolution (Nothing ==> Maybe Int) when the attributes hint is Nothing, we need to first process all the tuples, then extract the concrete types on a per-attribute basis, then reprocess the tuples to include the concrete types
1133-- for tuple type concrete resolution (Nothing ==> Maybe Int) when the attributes hint is Nothing, we need to first process all the tuples, then extract the concrete types on a per-attribute basis, then reprocess the tuples to include the concrete types
1133evalGraphRefTupleExprs :: Maybe Attributes -> [GraphRefTupleExpr] -> GraphRefRelationalExprM [RelationTuple]
1134evalGraphRefTupleExprs :: Maybe Attributes -> [GraphRefTupleExpr] -> GraphRefRelationalExprM [RelationTuple]
1135+evalGraphRefTupleExprs _ [] = pure []
1134evalGraphRefTupleExprs mAttrs tupleExprs = do
1136evalGraphRefTupleExprs mAttrs tupleExprs = do
1135 tuples <- mapM (evalGraphRefTupleExpr mAttrs) tupleExprs
1137 tuples <- mapM (evalGraphRefTupleExpr mAttrs) tupleExprs
1136 finalAttrs <- case mAttrs of
1138 finalAttrs <- case mAttrs of
@@ -1150,8 +1152,13 @@ evalGraphRefTupleExprs mAttrs tupleExprs = do
1150 Left _ -> accAttr
1152 Left _ -> accAttr
1151 Right val -> val) (zip (V.toList $ tupleAttributes tup) acc)) (V.toList $ tupleAttributes headTuple) tailTuples
1153 Right val -> val) (zip (V.toList $ tupleAttributes tup) acc)) (V.toList $ tupleAttributes headTuple) tailTuples
1152 pure (A.attributesFromList mostResolvedTypes)
1154 pure (A.attributesFromList mostResolvedTypes)
1153− --is it OK to get the tConsMap like this and use it uniformly across the tuples- couldn't the tuple expressions use types from other parts of the graph? Maybe it's OK because this is only used
1155+ --strategy: if all the tuple expr transaction markers refer to one location, then we can pass the type constructor mapping from that location, otherwise, we cannot assume that the types are the same
1156+ tConsMap <- case singularTransactions tupleExprs of
1157+ SingularTransactionRef commonTransId -> do
1154− tConsMap <- typeConstructorMapping <$> gfDatabaseContextForMarker UncommittedContextMarker
1158+ typeConstructorMapping <$> gfDatabaseContextForMarker commonTransId
1159+ NoTransactionsRef -> pure [] --no custom type constructors are referenced, so no tConsMap is needed
1160+ -- if there are multiple transaction markers in the TupleExprs, then we can't assume a single type constructor mapping- this could be improved in the future, but if all the tuples are fully resolved, then we don't need further resolution
1161+ _ -> throwError TupleExprsReferenceMultipleMarkersError
1155 lift $ except $ validateAttributes tConsMap finalAttrs
1162 lift $ except $ validateAttributes tConsMap finalAttrs
1156 mapM (\tup -> lift $ except $ resolveTypesInTuple finalAttrs tConsMap tup) tuples
1163 mapM (\tup -> lift $ except $ resolveTypesInTuple finalAttrs tConsMap tup) tuples
@@ -1386,7 +1393,7 @@ typeForGraphRefRelationalExpr expr@(With withs _) = do
1386 case M.lookup macroName rvs of
1393 case M.lookup macroName rvs of
1387 Just _ -> lift $ except $ Left (RelVarAlreadyDefinedError macroName) --this error does not include the transaction marker, but should be good enough to identify the cause
1394 Just _ -> lift $ except $ Left (RelVarAlreadyDefinedError macroName) --this error does not include the transaction marker, but should be good enough to identify the cause
1388 Nothing -> pure ()
1395 Nothing -> pure ()
1389− mapM checkMacroName (map fst withs)
1396+ mapM_ checkMacroName (map fst withs)
1390 typeForGraphRefRelationalExpr expr'
1397 typeForGraphRefRelationalExpr expr'
1392evalGraphRefAttributeNames :: GraphRefAttributeNames -> GraphRefRelationalExpr -> GraphRefRelationalExprM (S.Set AttributeName)
1399evalGraphRefAttributeNames :: GraphRefAttributeNames -> GraphRefRelationalExpr -> GraphRefRelationalExprM (S.Set AttributeName)