Skip to content
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

Preserve local variables names in NIR #3386

Merged

Conversation

WojciechMazur
Copy link
Contributor

@WojciechMazur WojciechMazur commented Jul 12, 2023

Enriches Defn.Define with additional field localNames: Map[Local, String] containing original name of local variables (both val and var) allowing us to emit additional debug informations in the future.

The following snippet now compiles to NIR containing local names:

  def main(args: Array[String]): Unit = {
    val x = 42
    val y = x
    var z = 0
    z = x + y

    val a = "Foo".toLowerCase()
  }
%3(%2 <this> : @"T5Test$", %1 <args> : array[@"T16java.lang.String"]):
  %4 <z> = var[int]
  %5 <x> = copy int 42
  %6 <y> = copy %5 <x> : int
  %7 = varstore %4 <z> : var[int], int 0
  %8 = iadd[int] %5 <x> : int, %6 <y> : int
  %9 = varstore %4 <z> : var[int], %8 : int
  %10 = method "Foo", "D11toLowerCaseL16java.lang.StringEO"
  %11 = call[(@"T16java.lang.String") => @"T16java.lang.String"] %10 : ptr("Foo")
  %12 <a> = copy %11 : @"T16java.lang.String"
  ret unit
}

The literal values are now assigned to local variables (e.g. x, y) to allow for correct mapping of them in debug metadata. The copy operator is effectivelly no-op. It could only affect Val.StructValue and Val.ArrayValue which currently cannot be assigned to variables (low level primitives)

The size of binaries might slightly increase. Scalalib 2.13 now takes 24,104 kB vs 23,910 kB previously (when compared to last NIR encoding changes in #3346)

TODO:

  • Preserve name information in the optimizer transformations
  • Preserve name information in the lowering transformations

@WojciechMazur WojciechMazur marked this pull request as ready for review August 4, 2023 11:02
@WojciechMazur WojciechMazur force-pushed the nir/preserve-local-names-info branch 3 times, most recently from f323475 to 07e09e9 Compare August 10, 2023 16:33
… used to provide better debug informations in the future

Revert "Add optional `name: Option[String]` to Val.{Local, Var} allowing to preserve original name of ValDef. It would be used to provide better debug informations in the future"

This reverts commit 0779259.

Remove backward compat for static calls. No longer needed in 0.5.x

Store name of ValDef in Inst.Let

"Add optional `name: Option[String]` to `Val.Local` allowing to preserve original name of method args.

Ensure that Inst.Let and Val.Local created by Buffer.let have the same name

wip
Revert "Remove backward compat for static calls. No longer needed in 0.5.x"

This reverts commit 04f12eb.

wip
Better names preserving in MergeProcessor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant