This repository was archived by the owner on May 28, 2025. It is now read-only.
Commit d1414c5
authored
Rollup merge of rust-lang#126242 - yaahc:simplify-provider, r=jhpratt
Simplify provider api to improve llvm ir
This PR seeks to resolve the last concern in rust-lang#99301 (comment)
We resolve the issue by moving the type_id to be stored in the `Request` itself rather than being accessed through the `Erased` trait, letting the compiler infer that the value of the type id will not change between lookups.
### LLVM Codegen
**Before**
```
; <provider_test::MyError as core::error::Error>::provide
; Function Attrs: nonlazybind uwtable
define void `@"_ZN61_$LT$provider_test..MyError$u20$as$u20$core..error..Error$GT$7provide17hd9c9de412063aa73E"(ptr` noalias nocapture noundef nonnull readonly align 1 %self, ptr noundef nonnull align 1 %request.0, ptr noalias nocapture noundef readonly align 8 dereferenceable(32) %request.1) unnamed_addr #0 personality ptr `@rust_eh_personality` {
start:
%0 = getelementptr inbounds i8, ptr %request.1, i64 24
%self.1.val.i = load ptr, ptr %0, align 8
%1 = tail call { i64, i64 } %self.1.val.i(ptr noundef nonnull align 1 %request.0), !noalias !15
%2 = extractvalue { i64, i64 } %1, 0
%3 = extractvalue { i64, i64 } %1, 1
%_18.i.i = icmp ne i64 %2, 1101338453689927725
%_2.i.i = icmp ne i64 %3, 472224167662714873
%or.cond.i.not.i = select i1 %_18.i.i, i1 true, i1 %_2.i.i
br i1 %or.cond.i.not.i, label %_ZN4core5error7Request7provide17h8f8125d2543333e0E.exit, label %bb2.i
```
**After**
```
; <provider_test::MyError as provider_test::Error>::provide
; Function Attrs: mustprogress nofree norecurse nosync nounwind nonlazybind willreturn memory(argmem: readwrite) uwtable
define void `@"_ZN63_$LT$provider_test..MyError$u20$as$u20$provider_test..Error$GT$7provide17h5bbf091795a6d359E"(ptr` noalias nocapture noundef nonnull readonly align 1 %self, ptr nocapture noundef nonnull align 8 %request.0, ptr noalias nocapture noundef readonly align 8 dereferenceable(24) %request.1) unnamed_addr #2 personality ptr `@rust_eh_personality` {
start:
%_19.i = load i64, ptr %request.0, align 8, !noalias !3, !noundef !3
switch i64 %_19.i, label %_ZN13provider_test7Request7provide17heb3ee140962e3b2fE.exit [
i64 7665305208997882008, label %bb12.i
i64 7050211241160863540, label %bb12.i3
i64 9112786072622981063, label %bb12.i11
]
```1 file changed
+23
-26
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
407 | | - | |
| 407 | + | |
408 | 408 | | |
409 | | - | |
| 409 | + | |
410 | 410 | | |
411 | 411 | | |
412 | 412 | | |
| |||
507 | 507 | | |
508 | 508 | | |
509 | 509 | | |
510 | | - | |
| 510 | + | |
511 | 511 | | |
512 | 512 | | |
513 | | - | |
514 | | - | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | 513 | | |
521 | 514 | | |
522 | 515 | | |
| |||
940 | 933 | | |
941 | 934 | | |
942 | 935 | | |
943 | | - | |
| 936 | + | |
944 | 937 | | |
945 | | - | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
946 | 942 | | |
947 | 943 | | |
948 | 944 | | |
949 | 945 | | |
950 | 946 | | |
951 | 947 | | |
952 | | - | |
953 | | - | |
954 | | - | |
955 | | - | |
| 948 | + | |
956 | 949 | | |
957 | | - | |
958 | | - | |
959 | | - | |
960 | | - | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
961 | 955 | | |
962 | 956 | | |
963 | | - | |
| 957 | + | |
964 | 958 | | |
965 | 959 | | |
966 | 960 | | |
967 | 961 | | |
968 | 962 | | |
969 | 963 | | |
970 | 964 | | |
971 | | - | |
| 965 | + | |
972 | 966 | | |
973 | | - | |
| 967 | + | |
974 | 968 | | |
975 | 969 | | |
976 | 970 | | |
| |||
983 | 977 | | |
984 | 978 | | |
985 | 979 | | |
986 | | - | |
987 | | - | |
988 | | - | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
989 | 986 | | |
990 | 987 | | |
991 | 988 | | |
| |||
0 commit comments