Skip to content

inline def with inline function parameter not inlining the function #9456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rcano opened this issue Jul 29, 2020 · 2 comments · Fixed by #11113
Closed

inline def with inline function parameter not inlining the function #9456

rcano opened this issue Jul 29, 2020 · 2 comments · Fixed by #11113

Comments

@rcano
Copy link

rcano commented Jul 29, 2020

Minimized code

object inlinetest:
  def test: Int =
    inline2(inline1(2.+))

  inline def inline1(inline f: Int => Int): Int => Int =
    i => f(1)

  inline def inline2(inline f: Int => Int): Int =
    f(2) + 3

Output

Disassemblied (via CFR) output of test

    public int test() {
        return BoxesRunTime.unboxToInt((Object)((JFunction1.mcII.sp & Serializable)(JFunction1.mcII.sp & Serializable)i -> {
            int x = 1;
            return 2 + x;
        }).apply((Object)BoxesRunTime.boxToInteger((int)2))) + 3;
    }

Expectation

The result should not contain any lambda.

Notes

Manually inlining inline1 produces the intended result

 def test: Int =
    inline2(i => 2 + 1)

it gets properly inlined

    public int test() {
        return 6;
    }
@nicolasstucki
Copy link
Contributor

I noticed this as well. We only inline TermRefs but not constants.

https://github.com/lampepfl/dotty/blob/master/compiler/src/dotty/tools/dotc/transform/BetaReduce.scala#L63-L70

@nicolasstucki nicolasstucki self-assigned this Jul 30, 2020
@nicolasstucki
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants