Commit 730883f
committed
Fix #14773: Reuse the param slots for the tailrec local mutable vars.
The tailrec phase generates code that looks like
class Bar {
def foo(x1: Int, x2: Int): Int = {
var this$: Bar = this;
var taillocal$x1: Int = x1;
var taillocal$x2: Int = x2;
...
// body where `this`, `x1` and `x2` are replaced by
// `this$`, `taillocal$x1` and `taillocal$x2`
}
}
This generates bytecode where the `this` value and the parameters
never actually change, and are never used. Instead, the synthetic
mutable variables are used instead.
As described in the linked issue, this confuses debuggers, which
only display the never-changing original `this` value and
parameters.
In this commit, we intercept this shape of code in the back-end.
We reliable identify tailrec-generated `ValDef`s from their
semantic names, with an additional safety check that they are
`Synthetic | Mutable`. When we find this shape, we do not allocate
local slots for the `var`s, and instead reuse the slots for `this`
and the parameters. We skip past the `ValDef`s so that code
generation does not re-emit useless assignments.1 parent 5256eb4 commit 730883f
File tree
3 files changed
+84
-55
lines changed- compiler
- src/dotty/tools
- backend/jvm
- dotc/transform
- test/dotty/tools/backend/jvm
3 files changed
+84
-55
lines changedLines changed: 43 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
484 | 486 | | |
485 | 487 | | |
486 | 488 | | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
487 | 497 | | |
488 | 498 | | |
489 | 499 | | |
| |||
753 | 763 | | |
754 | 764 | | |
755 | 765 | | |
756 | | - | |
| 766 | + | |
| 767 | + | |
757 | 768 | | |
758 | 769 | | |
759 | 770 | | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
760 | 799 | | |
761 | 800 | | |
762 | 801 | | |
763 | | - | |
| 802 | + | |
764 | 803 | | |
765 | | - | |
| 804 | + | |
766 | 805 | | |
767 | | - | |
| 806 | + | |
768 | 807 | | |
769 | 808 | | |
770 | 809 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
256 | | - | |
| 256 | + | |
257 | 257 | | |
258 | 258 | | |
259 | 259 | | |
| |||
Lines changed: 40 additions & 50 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
971 | 971 | | |
972 | 972 | | |
973 | 973 | | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
974 | 981 | | |
975 | 982 | | |
976 | | - | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
977 | 986 | | |
| 987 | + | |
978 | 988 | | |
| 989 | + | |
979 | 990 | | |
980 | | - | |
981 | | - | |
982 | | - | |
983 | | - | |
984 | | - | |
985 | | - | |
986 | | - | |
987 | 991 | | |
988 | | - | |
989 | | - | |
990 | | - | |
991 | | - | |
992 | | - | |
| 992 | + | |
993 | 993 | | |
| 994 | + | |
994 | 995 | | |
995 | | - | |
996 | | - | |
997 | | - | |
998 | | - | |
999 | | - | |
1000 | | - | |
1001 | | - | |
1002 | | - | |
1003 | | - | |
1004 | | - | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
1005 | 999 | | |
1006 | | - | |
1007 | | - | |
1008 | | - | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
1009 | 1003 | | |
1010 | 1004 | | |
1011 | 1005 | | |
| |||
1015 | 1009 | | |
1016 | 1010 | | |
1017 | 1011 | | |
| 1012 | + | |
1018 | 1013 | | |
1019 | | - | |
1020 | | - | |
1021 | | - | |
1022 | | - | |
1023 | | - | |
1024 | 1014 | | |
1025 | | - | |
1026 | | - | |
1027 | | - | |
1028 | | - | |
| 1015 | + | |
1029 | 1016 | | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
1030 | 1020 | | |
1031 | 1021 | | |
1032 | | - | |
1033 | | - | |
1034 | | - | |
1035 | | - | |
1036 | | - | |
| 1022 | + | |
| 1023 | + | |
1037 | 1024 | | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
1038 | 1028 | | |
1039 | 1029 | | |
1040 | | - | |
1041 | | - | |
1042 | | - | |
1043 | | - | |
1044 | | - | |
1045 | | - | |
1046 | | - | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
1047 | 1037 | | |
1048 | | - | |
1049 | | - | |
1050 | | - | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
1051 | 1041 | | |
1052 | 1042 | | |
1053 | 1043 | | |
| |||
0 commit comments