Conversation
58c0b2d to
6ba1ec9
Compare
|
I've added formatting |
6ba1ec9 to
907f108
Compare
|
I've added handling different types for arms, fixed spawning procs using |
907f108 to
eb5fdd5
Compare
|
@richmckeever is there anything else required to add? |
Co-authored-by: Mateusz Gancarz <[email protected]>
Co-authored-by: Mateusz Gancarz <[email protected]>
eb5fdd5 to
91db648
Compare
|
I've added proper handling of |
| std::vector<TypeAnnotation*> members; | ||
|
|
||
| for (MatchArm* arm : node->arms()) { | ||
| XLS_RETURN_IF_ERROR( |
There was a problem hiding this comment.
I think it would be better to merge this logic into the for loop that is in HandleMatch. i.e. turn the body of that loop into "if (node->IsConst() { ... } else { ... }" perhaps with some common logic at the beginning or end of the loop body. This would be similar to how HandleConditional works.
We generally don't use InferenceTable in such a way that we configure a node the normal way and then reconfigure it if we are in some special case. Even if it happens to work, that is a brittle approach because the normal way could get more complicated later and start doing stuff you don't want for the const case.
|
|
||
| const std::vector<MatchArm*>& arms() const { return arms_; } | ||
| Expr* matched() const { return matched_; } | ||
| Number* arm_idx() const { return arm_idx_; } |
There was a problem hiding this comment.
I think it would be better to model the notion of the chosen arm with dedicated TypeInfo API functions, i.e. add the ability to say
type_info->SetConstActiveArmIndex(match_node, 3)
as opposed to modeling this as a sentinel AST node with a constexpr value. The reason not to use the AST node is that it's is always a bogus zero value, and using that directly would be an easy mistake.
|
|
||
| XLS_ASSIGN_OR_RETURN( | ||
| InterpValue interp_match, | ||
| evaluator_.ConstMatchWhichArm(parametric_context, ti, match)); |
There was a problem hiding this comment.
I think if we move the arm selection to CollectConstants (see other comment), we will be able to just ask TypeInfo for the chosen arm index here, Evaluator will not need a function for it, and we will not need to set anything in TI further down.
| return NotConstantErrorStatus(expr->span(), expr, file_table); | ||
| } | ||
|
|
||
| /* static */ absl::StatusOr<InterpValue> ConstexprEvaluator::ConstMatchWhichArm( |
There was a problem hiding this comment.
It would be more in line with the general data flow in type inference if we could put this logic in CollectConstants() because that function basically runs as soon as it's feasible to decide the constant(s) associated with some node. It relieves ConstexprEvaluator of type inference-related knowledge Ideally ConstexprEvaluator just farms math out to the bytecode interpreter and has minimal inference logic.
Perhaps in CollectConstants, we say after dispatching the node to the visitor: if node->parent() is a Match and node == match->matched(), do this logic and then set the chosen arm index in TypeInfo. It could be a helper function inside that file.
This PR adds support for the constexpr
matchexpression.This is work in progress.
The aim of this PR is to add support for
const matchexpressions, where the arm selection is performed in compilation time.const match, as aMatchnode with a boolean property indicating theconst.const matchconst matchin compilation time