Commit 59c8081
committed
[dart2wasm] Use shared closure argument dispatchers for dynamic call entries
This removes 4591 functions from ACX gallery main module
which translates to -43 KB / -1.6% (-3.5% code section)
We have already today a callsite guarantee that the closure call
(type, positional, named) arguments are valid arguments to the
target closure (they also have the right type).
That means the `closure.vtable.dynamicCall` entry's only purpose
is to unpack the (type, positional, named) argument arrays and call
the target.
Instead of calling the target directly (as we did so far) we now
unpack argument arrays and call the right vtable entry. This logic
can be shared amongst all closures of the same representation and
therefore leads to big reduction in wasm functions.
=> We do that in this CL.
There's two exceptions to this:
* In dynamic module scenario we don't have closed-world knowledge
of closure definitions & closure call site. There's no specific
vtable entries for positional+name combinations we could forward
to.
* In closed world scenario where there's a usage of `Function.apply`
with named arguments: We don't generate vtable entries for all
possible name combinations a closure can be called with.
So we change the closure layouter algorithm to find out if there's
a usage of `Function.apply` with named arguments.
A few tangential changes:
* Fix a bug revealed by this change: The static tearoff
instantiation constant's dynamic call entry must pass the generic
closure object when calling the generic closure.
=> The shared dynamic call entry dispatchers will now verify
(in assertion) mode the assumptions, which revealed this issue
* The closure layouter algorithm will now consider `obj.foo(a: ...)`
as a potential dynamic call site (due to call-via-field) and
therefore record the name combinations used there
=> Tested via `web/wasm/closures/dynamic_call_via_field_test`
We test the optimization by checking in 3 tests that show what
ends up in the vtables:
* `pkg/dart2wasm/test/ir_tests/dyn_closure.dart`
=> uses dynamic calls
=> dynamic call entries are "closure arguments dispatcher"
* `pkg/dart2wasm/test/ir_tests/dyn_closure_function_apply.dart`
=> uses Function.apply without names
=> dynamic call entries are "closure arguments dispatcher"
* `pkg/dart2wasm/test/ir_tests/dyn_closure_function_apply_named.dart`
=> uses Function.apply with named arguments
=> dynamic call entries are closure specific
Issue #60458
Change-Id: I099984b542b05920b02596410a1bf6a08d2a0302
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/460080
Reviewed-by: Ömer Ağacan <[email protected]>1 parent 43dd090 commit 59c8081
File tree
18 files changed
+812
-67
lines changed- pkg/dart2wasm
- lib
- test/ir_tests
- sdk/lib/_internal/wasm/lib
- tests/web/wasm/closures
18 files changed
+812
-67
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
63 | | - | |
| 62 | + | |
64 | 63 | | |
65 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
66 | 68 | | |
67 | 69 | | |
68 | 70 | | |
| |||
129 | 131 | | |
130 | 132 | | |
131 | 133 | | |
| 134 | + | |
132 | 135 | | |
133 | 136 | | |
134 | 137 | | |
135 | 138 | | |
136 | 139 | | |
137 | 140 | | |
138 | 141 | | |
| 142 | + | |
| 143 | + | |
139 | 144 | | |
140 | 145 | | |
141 | 146 | | |
| |||
216 | 221 | | |
217 | 222 | | |
218 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
219 | 228 | | |
220 | 229 | | |
221 | 230 | | |
| |||
400 | 409 | | |
401 | 410 | | |
402 | 411 | | |
403 | | - | |
404 | 412 | | |
| 413 | + | |
| 414 | + | |
405 | 415 | | |
406 | 416 | | |
407 | 417 | | |
| |||
478 | 488 | | |
479 | 489 | | |
480 | 490 | | |
481 | | - | |
| 491 | + | |
482 | 492 | | |
483 | 493 | | |
484 | 494 | | |
485 | 495 | | |
486 | | - | |
| 496 | + | |
487 | 497 | | |
488 | 498 | | |
489 | 499 | | |
| |||
508 | 518 | | |
509 | 519 | | |
510 | 520 | | |
511 | | - | |
| 521 | + | |
512 | 522 | | |
513 | 523 | | |
514 | 524 | | |
| |||
564 | 574 | | |
565 | 575 | | |
566 | 576 | | |
| 577 | + | |
567 | 578 | | |
568 | 579 | | |
569 | 580 | | |
| |||
618 | 629 | | |
619 | 630 | | |
620 | 631 | | |
621 | | - | |
| 632 | + | |
622 | 633 | | |
623 | 634 | | |
624 | 635 | | |
| |||
1008 | 1019 | | |
1009 | 1020 | | |
1010 | 1021 | | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
1011 | 1038 | | |
1012 | 1039 | | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
1013 | 1043 | | |
1014 | 1044 | | |
1015 | 1045 | | |
| |||
1028 | 1058 | | |
1029 | 1059 | | |
1030 | 1060 | | |
1031 | | - | |
1032 | | - | |
1033 | | - | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
1034 | 1078 | | |
1035 | 1079 | | |
1036 | 1080 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1180 | 1180 | | |
1181 | 1181 | | |
1182 | 1182 | | |
1183 | | - | |
1184 | 1183 | | |
1185 | 1184 | | |
1186 | 1185 | | |
1187 | 1186 | | |
1188 | | - | |
| 1187 | + | |
| 1188 | + | |
1189 | 1189 | | |
1190 | 1190 | | |
1191 | 1191 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2021 | 2021 | | |
2022 | 2022 | | |
2023 | 2023 | | |
2024 | | - | |
| 2024 | + | |
2025 | 2025 | | |
2026 | 2026 | | |
2027 | 2027 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
| 279 | + | |
| 280 | + | |
279 | 281 | | |
280 | 282 | | |
281 | 283 | | |
| |||
0 commit comments