@@ -8,7 +8,7 @@ module QueryType (
88 instantiateDataDef , instantiateDepPairTy , instantiatePi , instantiateTabPi ,
99 litType , lamExprTy ,
1010 numNaryPiArgs , naryLamExprType ,
11- oneEffect , projectLength , sourceNameType , typeAsBinderNest
11+ oneEffect , projectLength , sourceNameType , typeAsBinderNest , typeBinOp
1212 ) where
1313
1414import Control.Monad
@@ -203,6 +203,20 @@ typeAsBinderNest ty = do
203203 return $ Abs (Nest (ignored:> ty) Empty ) body
204204{-# INLINE typeAsBinderNest #-}
205205
206+ typeBinOp :: BinOp -> BaseType -> BaseType
207+ typeBinOp binop xTy = case binop of
208+ IAdd -> xTy; ISub -> xTy
209+ IMul -> xTy; IDiv -> xTy
210+ IRem -> xTy;
211+ ICmp _ -> Scalar Word8Type
212+ FAdd -> xTy; FSub -> xTy
213+ FMul -> xTy; FDiv -> xTy;
214+ FPow -> xTy
215+ FCmp _ -> Scalar Word8Type
216+ BAnd -> xTy; BOr -> xTy
217+ BXor -> xTy
218+ BShL -> xTy; BShR -> xTy
219+
206220-- === computing effects ===
207221
208222computeAbsEffects :: (EnvExtender m , SubstE Name e )
@@ -459,19 +473,7 @@ getTypePrimOp op = case op of
459473 TabCon ty _ -> substM ty
460474 ScalarBinOp binop x _ -> do
461475 xTy <- getTypeBaseType x
462- resTy <- return $ case binop of
463- IAdd -> xTy; ISub -> xTy
464- IMul -> xTy; IDiv -> xTy
465- IRem -> xTy;
466- ICmp _ -> Scalar Word8Type
467- FAdd -> xTy; FSub -> xTy
468- FMul -> xTy; FDiv -> xTy;
469- FPow -> xTy
470- FCmp _ -> Scalar Word8Type
471- BAnd -> xTy; BOr -> xTy
472- BXor -> xTy
473- BShL -> xTy; BShR -> xTy
474- return $ TC $ BaseType resTy
476+ return $ TC $ BaseType $ typeBinOp binop xTy
475477 -- All unary ops preserve the type of the input
476478 ScalarUnOp _ x -> getTypeE x
477479 Select _ x _ -> getTypeE x
0 commit comments