[Relay] Check match expressions for completeness - #3203
Conversation
|
@slyubomirsky can you make it LOG(WARNING) if a pattern is not exhausted right now? I think we should touch the hd/nth/tl function later. |
|
I agree, I'll make it a warning |
|
@slyubomirsky http://moscova.inria.fr/~maranget/papers/warn/index.html |
| for (size_t i = 0; i < op->patterns.size(); i++) { | ||
| MatchResult submatch = this->Check(op->patterns[i], ctor_cand->patterns[i]); | ||
| if (submatch != MatchResult::kMatch) { | ||
| return submatch; |
There was a problem hiding this comment.
you can be more aggressive here: if any of the child is clash, return clash
There was a problem hiding this comment.
Good point, I'll do that.
|
one small nitpick, otherwise is good. |
…cking, fix prelude functions and broken tests
c590d0f to
b782c03
Compare
|
Pinging @MarisaKirisame and @icemelon9 for final review |
We never defined the semantics of an incomplete match in Relay, so I've written a fairly simple function to check whether a match is complete (there's probably a better algorithm, but this one also concretely finds all cases that are not handled) and added into the type checker.
This did require me to change several functions that relied on having incomplete matches, such ashdandtl. I do not think we should permit partial functions, as that would require us to define semantics for incomplete matches and potentially, down the line, to complicate the language with other kinds of error handling that could be placed higher in the stack (e.g., it would be a problem if some execution settings for Relay had one kind of error for incomplete matches and others reported the error a different way).I suppose, though, that it would be easy to change the match incompleteness to a warning rather than an error if we really do want to keephd,tl, etc.Incomplete matches only generate a warning for now, though we may want to add flags to make this an error later, see @MarisaKirisame's comment below