-
Notifications
You must be signed in to change notification settings - Fork 237
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
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 like42
for 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 Field
expression 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 fmt
with default settings.