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

muxHandle is wrong #1206

Open
langston-barrett opened this issue Jun 4, 2024 · 0 comments
Open

muxHandle is wrong #1206

langston-barrett opened this issue Jun 4, 2024 · 0 comments

Comments

@langston-barrett
Copy link
Contributor

Crucible doesn't really support muxing function handles, but it does have this muxHandle operation:

muxHandle :: IsExpr (SymExpr sym)
=> sym
-> Pred sym
-> FnVal sym a r
-> FnVal sym a r
-> IO (FnVal sym a r)
muxHandle _ c x y
| Just b <- asConstantPred c = pure $! if b then x else y
| otherwise = return x

This is plainly wrong, as it just returns the first FnVal in the case that the predicate isn't statically known. It should probably panic instead. This code is also reachable via this CanMux instance:

instance IsExprBuilder sym => CanMux sym (FunctionHandleType a r) where
{-# INLINE muxReg #-}
muxReg s = \_ c x y -> do
muxHandle s c x y

Both of these are exported.

I'd advocate for:

  • Making a tryMuxHandle function that returns a Maybe
  • Changing muxHandle to call tryMuxHandle and panic on Nothing
  • Removing the CanMux instance, because it is likely to lead to surprises

However, all of these except the first are breaking changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant