-
Notifications
You must be signed in to change notification settings - Fork 13k
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
CFI: Support calling methods on supertraits #123012
Conversation
r? @davidtwco rustbot has assigned @davidtwco. Use |
r? @ghost (Sorry for the noise, I didn't think a draft PR would auto-assign anyone) |
Failed to set assignee to
|
@maurer It's not possible to unassign people by calling rustbot, sorry! |
@maurer I can't find this commit or a close equivalent in either of your "source" PRs, I assume this was an even-further-deferred followup? |
This is a different approach. My source PR originally shimmed each vtable to be callable at a its vtable type. For example, if you had I was previously thinking of this as a follow-on, but since shims are the most contentious part of my plan, I implemented it early to make it possible to do KCFI trait objects with supertraits, even if concrete function pointers to I do think at this point after breaking things down into pieces that I may be able to avoid |
Aha! If we can avoid CfiShim, that would probably be for the best. |
The one place I'm still iffy about is that Then, over here in the typeid code, if we see We shouldn't need to worry about the original use of Note that this still leaves |
Is this always resolving it to the trait that implements the method (similarly to what I was doing by resolving to the identity of the trait that implements the method), but with args substitution instead? |
Resolving to the trait that implements the method is already done on the declaration with the existing code, and I believe is what your previous implementation did. This adjusts callsites in the same way, so that the type they test against is the one that we put on the declaration, even if they are calling a method on an trait bound of the real dyn object they're working with. I don't think that the previous implementation did this, as until I plumbed |
I didn't know bringing the Instance down to rustc_codegen_llvm would be okay--I did bring fn_attrs, which we should probably remove later, since now we've the Instance--so that is one of the reasons I used the identity of the trait that implemented the method instead both when declaring/defining functions and methods and during code generation at call sites. |
LGTM. |
☔ The latest upstream changes (presumably #123147) made this pull request unmergeable. Please resolve the merge conflicts. |
74448d1
to
42803cb
Compare
For example, if `trait Foo: Bar`, and we try to call a method from `Bar` on `dyn Foo`, encode the callsite as passing a `dyn Bar`, not a `dyn Foo`.
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (50e3d62): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)This benchmark run did not return any relevant results for this metric. CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 669.117s -> 669.053s (-0.01%) |
Automatically adjust
Virtual
calls to supertrait functions to use the supertrait's trait object type as the receiver rather than the child trait.cc @compiler-errors - this is the next usage of
trait_object_ty
I intend to have, so I thought it might be relevant while reviewing the existing one.