question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Regression since 3.0.0-M3: Issue with inlining in transparent macros

See original GitHub issue

Compiler version

3.0.0-RC3

Minimized code

object TransparentMacro:
    transparent inline def apply(inline n: Int): Any = ${applyImpl('n)}
    
    def applyImpl(n: Expr[Int])(using Quotes): Expr[Any] = if n.valueOrError > 0 then n else Expr("negative")

// In other file
object Test extends App:
   inline def x = -5
   println(TransparentMacro(x))

Output

Compilation error:

|Expected a known value. 
[error]    |
[error]    |The value of: com.example.Test.x
[error]    |could not be extracted using scala.quoted.FromExpr$PrimitiveFromExpr@4eae616
[error]    | This location contains code that was inlined from Test.scala:23

Expectation

The above code compiles in 3.0.0-M3. It should also compile in 3.0.0-RC3.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jorge-vasquez-2301commented, May 7, 2021

Ahhh, wasn’t aware of that, and yeah, it works with transparent inline def x = -5. Well, thanks a lot for your help!

0reactions
liufengyuncommented, May 7, 2021

And also, inline def x = -5 works if I define TransparentMacro.apply just as inline def instead of transparent inline def

That explains it: transparent inline are expanded in an earlier phase. Thus at the time when expanding apply, x is not yet inlined. If you add transparent to inline def x = -5, it may work as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Blog - Scala 3 - EPFL
We are happy to announce the release of Scala 3.0.0-M3. ... normal parameters after given parameters, inline givens specialization and more.
Read more >
Inline | Macros in Scala 3
Inlining is a common compile-time metaprogramming technique, typically used to achieve performance optimizations. As we will see, in Scala 3, the concept of ......
Read more >
Using the GNU Compiler Collection
5.36 An Inline Function is As Fast As a Macro . ... is unable to read from a pipe; but the GNU assembler...
Read more >
Using the GNU Compiler Collection (GCC) - Index of
This built-in function returns a pointer to data describing how to perform a call with the same arguments as were passed to the...
Read more >
changes - SWIG.org
SWIG python objects were being freed after the corresponding SWIG module information ... errors in Guile wrappers - regression introduced in swig-3.0.11.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found