Allow more expressions to be used in array sizes#440
Conversation
|
So in the future, ideally, we will need to refactor this code out and move it to the ssa? |
|
If we want to allow for all comptime expressions, yes. Either that or it can be done with terra's scheme of a wrapper language I mentioned before |
|
Alright, if we merge , can you open up another issue to support all comptime expressions, referencing this PR? |
|
Made #445 |
|
SSA is already folding arithmetic expressions so there is not need to add the mini-evaluator to the SSA pass. |
|
Agreed @guipublic. Those difficulties were ultimately why I ended up with this less flexible approach instead. |
guipublic
left a comment
There was a problem hiding this comment.
I think the mini-evaluator is simple enough so that it won't have nor cause any big issue, yet it already brings a lot of flexibility for the user
Related issue(s)
Resolves #415
Description
Summary of changes
Allows use of global variables and simple arithmetic expressions in addition to integer literals within array-size expressions.
Previously an array with repeated-elements like the following:
[0; 42]required an integer literal like42for thecount of repeated elements. This PR expands this a bit such that it may include global integer variables, and simple
operations on them:
+,-,*,/,%,&,|,^, and!.This is done by adding a mini-evaluator during name resolution which is not ideal. Ideally, we could allow any
comptime Fieldexpression by delaying this until ssa and relying on the inlining done in that pass to remove all function calls, comptime variable references, and fold all arithmetic. For now though, this PR brings us most of the way there.Test additions / changes
Adds a quick addition to the globals test.
Checklist
cargo fmtwith default settings.