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

Can we make expression operations more typesafe #190

Open
phated opened this issue Jul 15, 2023 · 1 comment
Open

Can we make expression operations more typesafe #190

phated opened this issue Jul 15, 2023 · 1 comment

Comments

@phated
Copy link
Member

phated commented Jul 15, 2023

I'm looking at our Expression module and I notice that a lot of naming is to guide the usage of the APIs. Can we use our type system to guard some APIs like BinaryenRefFuncGetFunc to only accept a BinaryenRefFunc instead of any BinaryenExpressionRef? Would that require GADTs?

@ospencer
Copy link
Member

I think it's probably more trouble than it's worth. The problem will always be with APIs like BinaryenLoopGetBody, where you don't know the kind of expression you're going to get back. GADTs don't help here because that function will still return a generic BinaryenExpression type. Of course, you could make a special BinaryenLoopGetBodyRefFunc that gave you back a well-typed BinaryenRefFunc, but it'd have to throw if the body wasn't a ref func. Or return a Result.

Leaning on that, the other solution is to add casts for those situations. Functions that do runtime assertions (or maybe give you a Result) depending on the input expression and give you a well-typed output expression. I suppose you'd gain a little bit nicer of an error message, but that's about it.

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

No branches or pull requests

2 participants