Skip to content

Investigate Fishy Record Names in Optimizer Core #4947

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
gzm0 opened this issue Feb 18, 2024 · 4 comments
Closed

Investigate Fishy Record Names in Optimizer Core #4947

gzm0 opened this issue Feb 18, 2024 · 4 comments
Assignees
Labels
bug Confirmed bug. Needs to be fixed.
Milestone

Comments

@gzm0
Copy link
Contributor

gzm0 commented Feb 18, 2024

Follow-up form here:

/* FIXME How come this lookup requires only the `simpleName`?
* The `recordType` is created at `InlineableClassStructure.recordType`,
* where it uses an allocator. Something fishy is going on here.
* (And no, this is not dead code.)
*/

@gzm0
Copy link
Contributor Author

gzm0 commented Feb 18, 2024

I've been playing around with this and so far, I have not actually managed for the optimizer to produce a Record.

Either, the local def system already resolved everything before even creating a record (this is what happened here: #4946 (comment)) or the optimizer cancelled the inlining.

@sjrd how did you determine the piece of code in question is not dead code? I'm starting to suspect that it only triggers for RuntimeLong (where we have more aggressive class inlining policies).

@sjrd
Copy link
Member

sjrd commented Feb 18, 2024

@sjrd how did you determine the piece of code in question is not dead code? I'm starting to suspect that it only triggers for RuntimeLong (where we have more aggressive class inlining policies).

Replace it by ??? and try testSuite2_12/Test/fastLinkJS. It blows up.

In order for a record to be reified, I believe we need at least an if/else where both branches return an instance of the inline class. Or any other merge point. So that's maybe what we need to add to #4946 (comment)

@gzm0
Copy link
Contributor Author

gzm0 commented Nov 17, 2024

I managed to find a problematic program:

class A {
  private val x: Int = 1
  def foo = x
}

@inline
class B extends A {
  private val x: String = "f"
  def bar = x
}

object HelloWorld {
  @noinline
  def p(x: Any) = println(x)

  @noinline
  def test: Boolean = false

  def main(args: Array[String]): Unit = {
    val b =
      if (test) new B()
      else new B()

    p(b.foo)
    p(b.bar)
  }
}

The main method links to:

$c_Lhelloworld_HelloWorld$.prototype.main__AT__V = (function(args) {
  if (this.test__Z()) {
    var b__x = 1;
    var b__x$1 = "f";
  } else {
    var b__x = 1;
    var b__x$1 = "f";
  }
  this.p__O__V(b__x);
  this.p__O__V(b__x); // should be b__x$1
});

@gzm0 gzm0 added the bug Confirmed bug. Needs to be fixed. label Nov 17, 2024
@sjrd
Copy link
Member

sjrd commented Nov 17, 2024

Nice catch!

@sjrd sjrd added this to the v1.18.0 milestone Nov 17, 2024
@sjrd sjrd self-assigned this Dec 9, 2024
sjrd added a commit to sjrd/scala-js that referenced this issue Dec 18, 2024
Instead of only retaining the `RecordType`.

The `structure` contains the complete information required to map
`FieldName`s to the record's `SimpleFieldName`s.
sjrd added a commit to sjrd/scala-js that referenced this issue Dec 22, 2024
Instead of only retaining the `RecordType`.

The `structure` contains the complete information required to map
`FieldName`s to the record's `SimpleFieldName`s.
@sjrd sjrd closed this as completed in 24c79c2 Dec 27, 2024
sjrd added a commit that referenced this issue Dec 27, 2024
Fix #4947: Retain the `structure` of `PreTransRecordTree`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug. Needs to be fixed.
Projects
None yet
Development

No branches or pull requests

2 participants