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

Q: "non-literal range" explanation? #14

Closed
jpsacha opened this issue Apr 26, 2021 · 2 comments
Closed

Q: "non-literal range" explanation? #14

jpsacha opened this issue Apr 26, 2021 · 2 comments

Comments

@jpsacha
Copy link
Contributor

jpsacha commented Apr 26, 2021

For a line of code:

cfor(myRange) { i =>

I am getting "[Info]" printed during compilation, with message "non-literal range". I assume that it is generated by cfor.
How to interpret that message? Does it have performance implications?

Note, myRange is passed as an argument to the function that is using cfor.

@shuttie
Copy link
Contributor

shuttie commented Apr 27, 2021

I guess the reason is that non-literal ranges (so ranges, defined outside of the cfor context) cannot be effectively rewritten in a simple while loop. So two examples:

// range is within macro context
cfor(0 until 100 step 5) { i => ???}
// so we expand it into this loop
var i = 0
while (i < 100) {
   ???
   i += 5
}
// here the range itself is outside of the cfor macro context, so it cannot know the shape of the range
val range = 0 until 100 step 5
cfor(range) { i => ???}
// so we expand it into a foreach over range, which is also a nice and fast method to use
range.foreach { i => ???}

I guess I need to clarify this warning a bit:

  • add benchmarks on literal and non-literal ranges (I bet they will be almost the same)
  • maybe expand non-literal ranges into another shape of while loop?
  • more clear warning message in this macro (if my attempt on non-literal expansion fails)

@jpsacha
Copy link
Contributor Author

jpsacha commented May 1, 2021

thanks for the explanation

@jpsacha jpsacha closed this as completed May 1, 2021
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