Skip to content

transparent modifier breaks beta-reduction #22575

Open
@t9dupuy

Description

Compiler version

3.6.3

Minimized code

Using the transparent modifier seems to break beta-reduction (it doesn't happen) for lambda functions

// Non poly example
transparent inline def apply1[B](inline f: Int => B): B = f(1)
inline def aa: Int => Int = double

def double(i: Int) = i * 2

val a = apply1(aa)
// Got: val a: Int = ((i: Int) => double(i):(Int => Int)).apply(1)
// Expected: val a: Int = double(1):Int

// Poly example
transparent inline def applyInt[B](inline f: [T] => () => B): B = f[Int]()
inline def bb: [T] => () => Int = [T] => () => myIntPoly[T]

def myIntPoly[T]: Int = 1

val b = applyInt(bb)
// Got: val b: Int = ([T >: Nothing <: Any] => () => myIntPoly[T]:([T] => () => Int)).apply[Int]()
// Expected: val b: Int = { type T = Int; myIntPoly[T] }:Int

The code was inspected using -Xprint:type,inlining.
The expected code can reproduced by removing transparent and fits the beta-reduction comment specification given here

/** Rewrite an application
*
* ((x1, ..., xn) => b)(e1, ..., en)
*
* to
*
* val/def x1 = e1; ...; val/def xn = en; b
*
* where `def` is used for call-by-name parameters. However, we shortcut any NoPrefix
* refs among the ei's directly without creating an intermediate binding.
*
* Similarly, rewrites type applications
*
* ([X1, ..., Xm] => (x1, ..., xn) => b).apply[T1, .., Tm](e1, ..., en)
*
* to
*
* type X1 = T1; ...; type Xm = Tm;val/def x1 = e1; ...; val/def xn = en; b
*
* This beta-reduction preserves the integrity of `Inlined` tree nodes.
*/

Output

See comments in minimized code.

Expectation

The beta reduction should be properly applied for transparent methods.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions