Commit 643d1ba
[dart2wasm] Check const-ness of instructions added to const exprs
A constant expression in Wasm is an instruction sequence that consists
of only the constant instructions.
Currently if I generate a non-constant instruction in a constant
expression I get an error during Wasm compilation. I then have to find
where and how I generate the instruction, possibly by using `--watch
<instruction offset>` passed to dart2wasm.
With this change we check in an assertion that an instruction added to
an instruction sequence for a constant expression can only be a constant
expression.
This helps with debugging as I notice the error earlier, and get a stack
trace of the compiler function that generates the invalid instruction.
Changes:
- Add `bool get isConstant => false` member to `Instruction`.
A method instead of field to avoid adding one more word to
`Instruction` objects.
- Override the member in constant instructions.
- When creating an instructions builder, mark the builder as "constant",
with an optional named constructor argument that defaults to `false`.
- When adding an instruction to an instructions builder, check that if
the instruction block is for a constant expression, the instruction is
constant.
Spec:
https://webassembly.github.io/gc/core/valid/instructions.html#constant-expressions
Change-Id: I59454f0634ab419a62f9455c84aa9ce631db8b63
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391440
Commit-Queue: Ömer Ağacan <[email protected]>
Reviewed-by: Slava Egorov <[email protected]>1 parent 2b899ad commit 643d1ba
File tree
3 files changed
+63
-3
lines changed- pkg/wasm_builder/lib/src
- builder
- ir
3 files changed
+63
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
149 | 152 | | |
150 | 153 | | |
151 | | - | |
| 154 | + | |
| 155 | + | |
152 | 156 | | |
153 | | - | |
| 157 | + | |
| 158 | + | |
154 | 159 | | |
155 | 160 | | |
156 | 161 | | |
| |||
184 | 189 | | |
185 | 190 | | |
186 | 191 | | |
| 192 | + | |
| 193 | + | |
187 | 194 | | |
188 | 195 | | |
189 | 196 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
19 | 26 | | |
20 | 27 | | |
21 | 28 | | |
| |||
226 | 233 | | |
227 | 234 | | |
228 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
229 | 239 | | |
230 | 240 | | |
231 | 241 | | |
| |||
382 | 392 | | |
383 | 393 | | |
384 | 394 | | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
385 | 398 | | |
386 | 399 | | |
387 | 400 | | |
| |||
597 | 610 | | |
598 | 611 | | |
599 | 612 | | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
600 | 616 | | |
601 | 617 | | |
602 | 618 | | |
| |||
613 | 629 | | |
614 | 630 | | |
615 | 631 | | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
616 | 635 | | |
617 | 636 | | |
618 | 637 | | |
| |||
728 | 747 | | |
729 | 748 | | |
730 | 749 | | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
731 | 753 | | |
732 | 754 | | |
733 | 755 | | |
| |||
743 | 765 | | |
744 | 766 | | |
745 | 767 | | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
746 | 771 | | |
747 | 772 | | |
748 | 773 | | |
| |||
823 | 848 | | |
824 | 849 | | |
825 | 850 | | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
826 | 854 | | |
827 | 855 | | |
828 | 856 | | |
| |||
839 | 867 | | |
840 | 868 | | |
841 | 869 | | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
842 | 873 | | |
843 | 874 | | |
844 | 875 | | |
| |||
854 | 885 | | |
855 | 886 | | |
856 | 887 | | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
857 | 891 | | |
858 | 892 | | |
859 | 893 | | |
| |||
995 | 1029 | | |
996 | 1030 | | |
997 | 1031 | | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
998 | 1035 | | |
999 | 1036 | | |
1000 | 1037 | | |
1001 | 1038 | | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
1002 | 1042 | | |
1003 | 1043 | | |
1004 | 1044 | | |
1005 | 1045 | | |
1006 | 1046 | | |
1007 | 1047 | | |
1008 | 1048 | | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
1009 | 1052 | | |
1010 | 1053 | | |
1011 | 1054 | | |
| |||
1018 | 1061 | | |
1019 | 1062 | | |
1020 | 1063 | | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
1021 | 1067 | | |
1022 | 1068 | | |
1023 | 1069 | | |
| |||
1030 | 1076 | | |
1031 | 1077 | | |
1032 | 1078 | | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
1033 | 1082 | | |
1034 | 1083 | | |
1035 | 1084 | | |
| |||
1042 | 1091 | | |
1043 | 1092 | | |
1044 | 1093 | | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
1045 | 1097 | | |
1046 | 1098 | | |
1047 | 1099 | | |
| |||
0 commit comments