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.

Transparent inline method call doesn't expand inside another inline method

See original GitHub issue

Compiler version

3.0.0

Minimized code

First sample
transparent inline def transform(inline a: Any): Any = inline a match {
  case x: Byte   => x
  case x: Short  => x
  case x: Int    => x
  case x: Long   => x
  case x: Float  => x
  case x: Double => x
  case _         => a
}

@main def test = {
  println(transform(0) < 5)
}
Second sample
transparent inline def transform(inline a: Any): Any = inline a match {
  case x: Byte   => x
  case x: Short  => x
  case x: Int    => x
  case x: Long   => x
  case x: Float  => x
  case x: Double => x
  case _         => a
}

inline def lt(inline a: Any, inline b: Double): Boolean = transform(a) < b

@main def test = {
  println(lt(0, 5))
}

Expectation

The first sample compiles as expected.

The second sample doesn’t compile but should. In lt, the transform call is fully inlined so I assume the compiler should be able to find the right return type.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
nicolasstuckicommented, Jun 9, 2021

We describe the semantics of inlining in more detail in http://biboudis.github.io/papers/inlining-scala20.pdf

1reaction
oderskycommented, Jun 8, 2021

Calls are never inlined in inline methods, so this does not work.

But I agree that the different phases of inlining can be confusing. The question is whether we can and should do all of inlining in typer again to avoid these surprises.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why are there inline function declarations instead of inline ...
A call to a non-inline function can be expanded inline by the compiler if the function is defined in the same translation unit....
Read more >
inline functions
Hello, I have had this problem some time ago and found a workaround. Unfortunatelly this time workaround doesn't work very nice.
Read more >
9: Inline Functions
Any behavior you expect from an ordinary function, you get from an inline function. The only difference is that an inline function is...
Read more >
6.13 — Inline functions - Learn C++
In order to do inline expansion, the compiler needs to be able to see the full definition of an inline function wherever the...
Read more >
Inline (Using the GNU Compiler Collection (GCC))
When an inline function is not static , then the compiler must assume that there may be calls from other source files; since...
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