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

Emit source map information for control flow structures #5524

Merged
merged 1 commit into from
Feb 28, 2023
Merged

Conversation

kripken
Copy link
Member

@kripken kripken commented Feb 24, 2023

With this, the sourcemap testcase outputs the exact same thing as the input.

Followup to #5504

cc @JesseCodeBones

@JesseCodeBones
Copy link
Contributor

JesseCodeBones commented Feb 27, 2023

Hi Alon,
I found if there is duplicate debug location for different instructions, the binaryen will dismiss some of them, here is the lit test, I am still finding the root cause and solution.
I donot know if it is meaningful in real world, and I think for some dynamic language concepts, like closure concept, it could happen, WDYT for such use case?

;; RUN: wasm-opt %s -o %t.wasm -osm %t.map -g -q
;; RUN: wasm-opt %t.wasm -ism %t.map -q -o - -S | filecheck %s
(module
  (func $foo (param $a i32) (param $b i32) (result i32)
    (return
        (i32.add 
            (local.get $a)
            (local.get $b)
        )
    )
  )
  (func $bar (param $a i32)
    ;;@ src.cpp:10:1
    (local.set $a
     (i32.const 1)
    )
    ;;@ src.cpp:10:1
    (drop
        ;;@ src.cpp:10:1
        (call $foo
            ;;@ src.cpp:20:1
            (local.get $a)
            ;;@ src.cpp:30:1
            (i32.const 42)
        )
    )
    (return)
  )
)

;; CHECK:  (module
;; CHECK-NEXT:   (type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
;; CHECK-NEXT:    (type $i32_=>_none (func (param i32)))
;; CHECK-NEXT:    (func $foo (param $a i32) (param $b i32) (result i32)
;; CHECK-NEXT:     (return
;; CHECK-NEXT:      (i32.add
;; CHECK-NEXT:       (local.get $a)
;; CHECK-NEXT:       (local.get $b)
;; CHECK-NEXT:      )
;; CHECK-NEXT:     )
;; CHECK-NEXT:    )
;; CHECK-NEXT:    (func $bar (param $a i32)
;; CHECK-NEXT:     ;;@ src.cpp:10:1
;; CHECK-NEXT:     (local.set $a
;; CHECK-NEXT:      (i32.const 1)
;; CHECK-NEXT:     )
;; CHECK-NEXT:     (drop
;; CHECK-NEXT:      (call $foo
;; CHECK-NEXT:       ;;@ src.cpp:20:1
;; CHECK-NEXT:       (local.get $a)
;; CHECK-NEXT:       ;;@ src.cpp:30:1
;; CHECK-NEXT:       (i32.const 42)
;; CHECK-NEXT:      )
;; CHECK-NEXT:     )
;; CHECK-NEXT:     (return)
;; CHECK-NEXT:    )
;; CHECK-NEXT:   )

Regards

@kripken
Copy link
Member Author

kripken commented Feb 27, 2023

@JesseCodeBones That does look like a real bug. Source maps support referring to the same source line from multiple places. And I agree it can happen in real-world code because sometimes a single source line ends up turned into multiple wasm lines, like you said. If you can find a fix that would be great!

I think that is separate from this PR, though? I see the same results on that testcase with this PR or not. Does this PR look ok to you to land?

@kripken
Copy link
Member Author

kripken commented Feb 27, 2023

cc @aheejin - not sure if you're familiar with this part of the debugging logic (it's source maps and not DWARF) but maybe you're interested in it too.

@JesseCodeBones
Copy link
Contributor

@JesseCodeBones That does look like a real bug. Source maps support referring to the same source line from multiple places. And I agree it can happen in real-world code because sometimes a single source line ends up turned into multiple wasm lines, like you said. If you can find a fix that would be great!

I think that is separate from this PR, though? I see the same results on that testcase with this PR or not. Does this PR look ok to you to land?

yeah, I can handle it after this pr, it may take sometime and I have some personal issue to be handled, I suppose it is not an urgen or blocking issue

@kripken
Copy link
Member Author

kripken commented Feb 27, 2023

Sounds good, thanks, and yes, this is not urgent of course.

@@ -26,8 +26,9 @@
)

;; CHECK: (func $foo (param $x i32) (param $y i32)
;; CHECK-NEXT: ;;@ src.cpp:20:1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very familiar with this part of the code. A few questions:

  • Why didn't we print the debug location for control flow structure before?
  • It looks this src.cpp:20:1 is the debug info for not if but i32.add, given that we didn't print debug info for control flow structures. Then why was it printed before if and not before i32.add?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately I don't think anyone is very familiar with it 😄 It was written a long time ago (and not by me).

I can't see a reason for not printing it for control flow structures before. That might have just been an omission.

I'm not sure about the second question. I know there are some heuristics for how to print and emit stuff, that involve looking at recent instructions or such, so probably related to that?

Overall, my approach here considering this unfamiliar code is to get more tests on it, and improve on them. This PR seems to do that as after it we appear to perfectly roundtrip the input.

@kripken kripken merged commit 62e0b2f into main Feb 28, 2023
@kripken kripken deleted the sourcemap.2 branch February 28, 2023 22:24
radekdoulik pushed a commit to dotnet/binaryen that referenced this pull request Jul 12, 2024
…5524)

With this, the sourcemap testcase outputs the exact same thing as the input.

Followup to WebAssembly#5504
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.

3 participants