Transparent inline method call doesn't expand inside another inline method
See original GitHub issueCompiler 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:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We describe the semantics of inlining in more detail in http://biboudis.github.io/papers/inlining-scala20.pdf
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.