Skip to content

Commit

Permalink
Remove need to lie about types.
Browse files Browse the repository at this point in the history
  • Loading branch information
athas committed Jan 18, 2025
1 parent 6df62d8 commit 1cbf1e0
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/Language/Futhark/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,10 @@ resolveTypeParams names orig_t1 orig_t2 =

matchExps bound (Var (QualName _ d1) _ _) e
| d1 `elem` names,
not $ any (`elem` bound) $ fvVars $ freeInExp e =
not $ any problematic $ fvVars $ freeInExp e =
addDim d1 e
where
problematic v = v `elem` bound || v `elem` names
matchExps bound e1 e2
| Just es <- similarExps e1 e2 =
mapM_ (uncurry $ matchExps bound) es
Expand Down Expand Up @@ -2185,30 +2187,28 @@ checkEntryArgs entry args entry_t
-- horribly if these are ill-typed.
interpretFunction :: Ctx -> VName -> [V.Value] -> Either T.Text (F ExtOp Value)
interpretFunction ctx fname vs = do
ft <- case lookupVar (qualName fname) $ ctxEnv ctx of
Just (TermValue (Just (T.BoundV _ t)) _) ->
updateType (map valueType vs) t
Just (TermPoly (Just (T.BoundV _ t)) _) ->
updateType (map valueType vs) t
(ft, mkf) <- case lookupVar (qualName fname) $ ctxEnv ctx of
Just (TermValue (Just (T.BoundV _ t)) v) -> do
ft <- updateType (map valueType vs) t
pure (ft, pure v)
Just (TermPoly (Just (T.BoundV _ t)) v) -> do
ft <- updateType (map valueType vs) t
pure (ft, v ft =<< evalWithExts (ctxEnv ctx))
_ ->
Left $ "Unknown function `" <> nameToText (toName fname) <> "`."

let vs' = map fromDataValue vs

checkEntryArgs fname vs ft

Right $
runEvalM (ctxImports ctx) $ do
-- XXX: We are providing a dummy type here. This is OK as long
-- as the function we invoke is monomorphic, which is what we
-- require of entry points. This is to avoid reimplementing
-- type inference machinery here.
f <- evalTermVar (ctxEnv ctx) (qualName fname) (Scalar (Prim Bool))
foldM (apply noLoc mempty) f vs'
Right $ runEvalM (ctxImports ctx) $ do
f <- mkf
foldM (apply noLoc mempty) f vs'
where
updateType (vt : vts) (Scalar (Arrow als pn d pt (RetType dims rt))) = do
checkInput vt pt
Scalar . Arrow als pn d (valueStructType vt) . RetType dims . toRes Nonunique <$> updateType vts (toStruct rt)
Scalar . Arrow als pn d (valueStructType vt) . RetType dims . toRes Nonunique
<$> updateType vts (toStruct rt)
updateType _ t =
Right t

Expand Down

0 comments on commit 1cbf1e0

Please sign in to comment.