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

Part of debug info missed for template function #2686

Closed
JesseCodeBones opened this issue Apr 18, 2023 · 2 comments
Closed

Part of debug info missed for template function #2686

JesseCodeBones opened this issue Apr 18, 2023 · 2 comments
Labels

Comments

@JesseCodeBones
Copy link
Contributor

JesseCodeBones commented Apr 18, 2023

Bug description

After compilation, some debug info (sourcemap) missed for $assembly/index/testFoo<assembly/index/AA|null> funciton.

I prepared a reproduce repo: https://github.com/JesseCodeBones/miss_debug_info
for this function, this part of debug info will be missed:

  if(v.length > 10) {
    return 2;
  } else {
    return 3;
  }

below is the output for function $assembly/index/testFoo<assembly/index/AA|null> and $assembly/index/testFoo<assembly/index/AA>

(func $assembly/index/testFoo<assembly/index/AA|null> (param $v i32) (result i32)
  (local $1 i32)
  (global.set $~lib/memory/__stack_pointer
   (i32.sub
    (global.get $~lib/memory/__stack_pointer)
    (i32.const 4)
   )
  )
  (call $~stack_check)
  (i32.store
   (global.get $~lib/memory/__stack_pointer)
   (i32.const 0)
  )
  ;;@ assembly/index.ts:6:28
  (if
   (i32.eq
    ;;@ assembly/index.ts:6:23
    (local.get $v)
    ;;@ assembly/index.ts:6:28
    (i32.const 0)
   )
   (block
    ;;@ assembly/index.ts:7:11
    (local.set $1
     (i32.const 1)
    )
    (global.set $~lib/memory/__stack_pointer
     (i32.add
      (global.get $~lib/memory/__stack_pointer)
      (i32.const 4)
     )
    )
    ;;@ assembly/index.ts:7:4
    (return
     (local.get $1)
    )
   )
  )
  (local.set $1
   (local.get $v)
  )
  (i32.store
   (global.get $~lib/memory/__stack_pointer)
   (local.get $1)
  )
  (if
   (i32.gt_s
    (call $assembly/index/AA#get:length <--------------------**from here the debug info missed ** 
     (local.get $1)
    )
    (i32.const 10)
   )
   (block
    (local.set $1
     (i32.const 2)
    )
    (global.set $~lib/memory/__stack_pointer
     (i32.add
      (global.get $~lib/memory/__stack_pointer)
      (i32.const 4)
     )
    )
    (return
     (local.get $1)
    )
   )
   (block
    (local.set $1
     (i32.const 3)
    )
    (global.set $~lib/memory/__stack_pointer
     (i32.add
      (global.get $~lib/memory/__stack_pointer)
      (i32.const 4)
     )
    )
    (return
     (local.get $1)
    )
   )
  )
 )

but debug info for $assembly/index/testFoo<assembly/index/AA> is good:

(func $assembly/index/testFoo<assembly/index/AA> (param $v i32) (result i32)
  (local $1 i32)
  (global.set $~lib/memory/__stack_pointer
   (i32.sub
    (global.get $~lib/memory/__stack_pointer)
    (i32.const 4)
   )
  )
  (call $~stack_check)
  (i32.store
   (global.get $~lib/memory/__stack_pointer)
   (i32.const 0)
  )
  ;;@ assembly/index.ts:6:6
  (drop
   (i32.const 0)
  )
  ;;@ assembly/index.ts:9:6
  (local.set $1
   (local.get $v)
  )
  (i32.store
   (global.get $~lib/memory/__stack_pointer)
   (local.get $1)
  )
  ;;@ assembly/index.ts:9:17
  (if
   (i32.gt_s
    ;;@ assembly/index.ts:9:6
    (call $assembly/index/AA#get:length
     (local.get $1)
    )
    ;;@ assembly/index.ts:9:17
    (i32.const 10)
   )
   (block
    ;;@ assembly/index.ts:10:11
    (local.set $1
     (i32.const 2)
    )
    (global.set $~lib/memory/__stack_pointer
     (i32.add
      (global.get $~lib/memory/__stack_pointer)
      (i32.const 4)
     )
    )
    ;;@ assembly/index.ts:10:4
    (return
     (local.get $1)
    )
   )
   (block
    ;;@ assembly/index.ts:12:11
    (local.set $1
     (i32.const 3)
    )
    (global.set $~lib/memory/__stack_pointer
     (i32.add
      (global.get $~lib/memory/__stack_pointer)
      (i32.const 4)
     )
    )
    ;;@ assembly/index.ts:12:4
    (return
     (local.get $1)
    )
   )
  )
 )

Steps to reproduce

  1. create AS file with below code:
 class AA {
  length: i32 = 1
}

function testFoo<T>(v: T): i32 {
  if (isNullable(v) && v == null) {
    return 1;
  }
  if (v.length > 10) {
    return 2;
  } else {
    return 3;
  }
}
export function testExport(): void {
  testFoo<AA | null>(null);
  const a = new AA();
  testFoo(a);
}

  1. run compile command: asc assembly/index.ts --debug --disable bulk-memory --sourceMap --textFile --outFile dist/test.wasm
  2. run [wasm-opt executable] dist/test.wasm -ism dist/test.wasm.map --print

AssemblyScript version

v0.27.2

@JesseCodeBones JesseCodeBones changed the title part of debug info missed for template function Part of debug info missed for template function Apr 18, 2023
@JesseCodeBones
Copy link
Contributor Author

For quick check, please refer the output of action:
https://github.com/JesseCodeBones/miss_debug_info/actions/runs/4729454293/jobs/8391987558

@JesseCodeBones JesseCodeBones mentioned this issue Apr 20, 2023
2 tasks
@JesseCodeBones
Copy link
Contributor Author

try to fix in binaryen:
WebAssembly/binaryen#5547
close this issue

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

Successfully merging a pull request may close this issue.

1 participant