ensure fastForInline does not make closures - #1111
Conversation
|
Brilliant, thank you! I remember asking about this in #1067 (comment) but seems I forgot to create an issue to track it 😅 We're not fussed about bincompat at the moment, but for my own education: what are the bincompat implications of a change like this? If you feel so motivated, feel free to run the |
|
Hmm, this seems to have broken the semantics somehow 🤔 I only looked quickly, but it's also possible you managed to restore the spire/tests/shared/src/test/scala/spire/syntax/FastForSuite.scala Lines 102 to 113 in a667a99 If that's the case, then maybe we can implement |
|
This seems great, I wonder why the tests broke |
make the parameters of fastForInline `inline`, which will beta reduce them when applied update FastForSuite
|
I have updated the tests to reflect the fact that any of the arguments to This does mean that the semantics of the scala 2 versions does not match, so the test will probably fail again. |
armanbilge
left a comment
There was a problem hiding this comment.
🎉 hooray, all tests passing! Thank you so much 😁
I have a question below.
0584c18 to
1dd5586
Compare
|
@armanbilge I have optimised the implementation for both |
|
Wow! I see you were able to fix the semantics so that they match I think this means we can rename Right now the Scala 2 I'll take a closer look later today. Thanks again for your efforts here :) |
|
@armanbilge I have made the FastForSuite scala 3 only :) |
There was a problem hiding this comment.
LGTM and not too hard to wrap my head around, although letFunc went a bit over my head 😅 Regarding the Long implementation, I think it we should definitely include it 👍
I hope @cquiroz can take a look as well :)
| ${ Expr.betaReduce(body) }(index) | ||
| index += $stride | ||
| } | ||
| private def letFunc[A, B, C](using Quotes)(name: String, rhs: Expr[A => B])(in: Expr[A => B] => Expr[C]): Expr[C] = |
There was a problem hiding this comment.
Would you mind writing a comment(s) to explain a little of the macro magic here? For curious users and future contributors/maintainers alike :)
There was a problem hiding this comment.
I have added some doc comments, and also found a pattern extractor I can use to simplify function literal detection
cquiroz
left a comment
There was a problem hiding this comment.
Looks great, thanks a lot for this fix
|
|
||
| import quoted._ | ||
| import collection.immutable.NumericRange | ||
| import scala.quoted.* |
There was a problem hiding this comment.
I wonder why the scala part wasn't needed earlier
There was a problem hiding this comment.
It's still not needed, I thought it just made it more clear where quoted comes from
| ValDef.let(Symbol.spliceOwner, name, f.asTerm)(ref => in(ref.unsafeAsExpr[A]).asTerm).unsafeAsExpr[B] | ||
|
|
||
| end fastForRangeMacro | ||
| if isFunctionLiteral(rhs) then in(Expr.betaReduce(rhs)) |
There was a problem hiding this comment.
Nice, in the old scala2 code there was a differentiation for literals as well that I didn't manage to port to scala 3
|
@armanbilge @cquiroz I have pushed another commit to simplify a bit and document |
armanbilge
left a comment
There was a problem hiding this comment.
Thanks, looks great! I hope that as you find time, you may continue to contribute—I think spire has an interesting journey ahead as we figure out how to work in a language without specialization :)
make the parameters of fastForInline
inline, which will beta reduce them when applied.Currently examining produced bytecode, closures are created for
test,nextandbody