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

Treat code following calls to functions returning Never as unreachable. #59941

Open
mkustermann opened this issue Jan 20, 2025 · 1 comment
Open
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends.

Comments

@mkustermann
Copy link
Member

See e.g.

main() {
  foo();
}

@pragma('vm:never-inline')
void foo() {
  int i = 1;
  if (int.parse('1') == 1) {
    i = 2;
    bar(); // <-- Return type `Never`, so it always throws and can never fall through.
  }
  print(i);
}

@pragma('vm:never-inline')
Never bar() {
  throw 'baz';
}

Here the print(i) could be turned into a print(1) but it doesn't seem the VM does that atm:

*** BEGIN CFG
After AllocateRegisters
==== file:///.../foo (RegularFunction)
  0: B0[graph]:0 {
      v0 <- Constant(#null) T{Null?}
      v15 <- UnboxedConstant(#1) [1, 1] int64
      v16 <- UnboxedConstant(#2) [2, 2] int64
}
  2: B1[function entry]:2
  4:     CheckStackOverflow:8(stack=0, loop=0)
  5:     ParallelMove rdi <- C
  6:     v4 <- StaticCall:14( parse<0> v3, result_type = T{int}) [-9223372036854775808, 9223372036854775807] int64
  8:     Branch if EqualityCompare(v4 == v15 T{_Smi}) T{bool} goto (3, 4)
 10: B3[target]:22
 12:     StaticCall:26( bar<0> )
 14:     ParallelMove rax <- C goto:32 B5
 16: B4[target]:28
 18:     ParallelMove rax <- C goto:34 B5
 20: B5[join]:30 pred(B3, B4) {
      v7 <- phi(v16 T{_Smi}, v15 T{_Smi}) alive [1, 2] int64 T{_Smi}
}
 22:     v14 <- BoxInt64(v7) [1, 2] T{_Smi}
 24:     StaticCall:36( print<0> v14 T{_Smi})
 25:     ParallelMove rax <- C
 26:     DartReturn:40(v0)
*** END CFG

@mkustermann mkustermann added the area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. label Jan 20, 2025
@a-siva
Copy link
Contributor

a-siva commented Jan 21, 2025

//cc @alexmarkov

@alexmarkov alexmarkov self-assigned this Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends.
Projects
None yet
Development

No branches or pull requests

3 participants