Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error checking for array dimensions when using interpreter fix #1682 #2012

Merged
merged 2 commits into from
Aug 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/Language/Futhark/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2028,12 +2028,18 @@ interpretFunction ctx fname vs = do
updateType _ t =
Right t

-- FIXME: we don't check array sizes.
checkInput :: ValueType -> StructType -> Either T.Text ()
checkInput (Scalar (Prim vt)) (Scalar (Prim pt))
| vt /= pt = badPrim vt pt
checkInput (Array _ _ (Prim vt)) (Array _ _ (Prim pt))
| vt /= pt = badPrim vt pt
checkInput vArr@(Array _ (F.Shape vd) _) pArr@(Array _ (F.Shape pd) _)
| length vd /= length pd = badDim vArr pArr
| not . and $ zipWith sameShape vd pd = badDim vArr pArr
where
sameShape :: Int64 -> Size -> Bool
sameShape shape0 (IntLit shape1 _ _) = fromIntegral shape0 == shape1
sameShape _ _ = True
checkInput _ _ =
Right ()

Expand All @@ -2044,3 +2050,11 @@ interpretFunction ctx fname vs = do
<+> align (pretty pt)
</> "Got: "
<+> align (pretty vt)

badDim vd pd =
Left . docText $
"Invalid argument dimensions."
</> "Expected:"
<+> align (pretty pd)
</> "Got: "
<+> align (pretty vd)
Loading