-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Fix v0 symbol mangling bug #83767
Fix v0 symbol mangling bug #83767
Conversation
This comment has been minimized.
This comment has been minimized.
It seems @eddyb was suggesting a slightly different approach: #83611 (comment) |
By the way, why do so many |
How do I add a test for this? I wasn't able to find any existing name mangling tests. |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks exactly like what I was expecting. Just needs a test (and comment).
} | ||
Ok(cx) | ||
})?; | ||
ty::ExistentialPredicate::Projection(projection) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, based on @eddyb's comment, we should just do a simple validation here.
When we encounter an ExistentialPredicate::Trait
, we should store that in a local variable last_trait_ref: Binder<'tcx, TraitRef>
then when we see an ExistentialPredicate::Projection
, we want to check that 1) the binders match and 2) the projection's trait is the same as the last trait
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some assertions, are they what you expected? 65c04123f81
The assertions panic on the test case :/
I think the issue is that the projection for the |
So, you should be able to get the trait that defines the associated type by
|
It looks like in order to do that I would need to add a dependency on |
Please add my example as a test - I don't see how |
Sure, I'm happy to add your test case, but I have never written a codegen test before and am new to the symbol mangling code, so I would appreciate extra help :) |
Codegen tests are located in // compile-flags: -Zsymbol-mangling-version=v0 -Cno-prepopulate-passes
pub fn test<T>() {}
fn main() {
// CHECK: ; call a::test::<&dyn for<'a> core::ops::function::FnMut<(&'a u8,), Output = ()>>
test::<&dyn FnMut(&u8)>();
// CHECK: ; call a::test::<for<'a> fn(&'a dyn for<'b> core::ops::function::FnOnce<(&'b u8,), Output = &'b u8> + 'a) -> &'a u8>
test::<for<'a> fn(&'a dyn for<'b> FnOnce(&'b u8) -> &'b u8) -> &'a u8>();
} You can cross verify output with a toolchain before refactoring, e.g., |
That's giving errors:
|
You'll have to convert the |
@camelid @tmiasko We don't use codegen tests for testing symbol names. rust/src/test/ui/symbol-names/impl1.rs Lines 61 to 73 in 5b0ab79
These tests include demangling output, which is important to confirm correct roundtrip. |
What's the state of this PR? Is a test case the only thing that remains to do? |
I think tests and a review from @nikomatsakis |
@jackh726 I don't really understand what I'm meant to review, I think. =) Maybe we can touch on this tomorrow morning? |
@nikomatsakis yeah we can do that |
Hmm, I can't quite get the code working. Here's my current version: ty::ExistentialPredicate::Projection(projection) => {
let assoc_item = self.tcx.associated_item(projection.item_def_id);
let last_trait_ref = last_trait_ref
.expect("trait predicate must come before projection predicate");
assert_eq!(last_trait_ref.bound_vars(), predicate.bound_vars());
// Use a type that can't appear in defaults of type parameters.
let dummy_self = self.tcx.mk_ty_infer(ty::FreshTy(0));
let assoc_item_parent_trait =
traits::supertraits(self.tcx, projection.trait_ref(self.tcx).with_self_ty(self.tcx, dummy_self)).find(|r| {
self.tcx
.associated_items(r.def_id())
.find_by_name_and_kind(
self.tcx,
assoc_item.ident,
assoc_item.kind,
r.def_id(),
)
.is_some()
}).unwrap();
assert_eq!(last_trait_ref.skip_binder(), ty::ExistentialTraitRef::erase_self_ty(self.tcx, assoc_item_parent_trait.skip_binder()));
let name = assoc_item.ident;
self.push("p");
self.push_ident(&name.as_str());
self = projection.ty.print(self)?;
} This code fails to compile:
Then I tried using
What should I do? |
Should be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might have a cleaner way to approach this. @nikomatsakis and I discussed, and would also definitely like to see the example in my comment as a test case too.
@nikomatsakis this is ready :) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Ugh don't remember how to make this reproducible locally |
This comment has been minimized.
This comment has been minimized.
error: demangling-alt(<&dyn core::ops::function::FnMut<(&u8,)>+Output = () as trait_objects::Bar>::method) | ||
--> $DIR/trait-objects.rs:15:5 | ||
error: demangling-alt(<&dyn core::ops::function::FnMut<(&u8,)>+Output = () as trait_objects::Bar>::metSYMBOL_HASH) | ||
--> $DIR/trait-objects.rs:17:5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it expected that this changed from ::method
to ::metSYMBOL_HASH
?
EDIT: This is an outdated diff, but the same change seems to be present in the current diff as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh this file shouldn't be here currently...(mostly because I didn't think hard enough about what regex to use here to make it reproducible and we don't care about legacy here anyways)
@bors r+ |
📌 Commit 8345908 has been approved by |
Fix v0 symbol mangling bug Fixes rust-lang#83611. r? `@jackh726`
Rollup of 8 pull requests Successful merges: - rust-lang#83366 (Stabilize extended_key_value_attributes) - rust-lang#83767 (Fix v0 symbol mangling bug) - rust-lang#84883 (compiletest: "fix" FileCheck with --allow-unused-prefixes) - rust-lang#85274 (Only pass --[no-]gc-sections if linker is GNU ld.) - rust-lang#85297 (bootstrap: build cargo only if requested in tools) - rust-lang#85396 (rustdoc: restore header sizes) - rust-lang#85425 (Fix must_use on `Option::is_none`) - rust-lang#85438 (Fix escape handling) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Fixes #83611.
r? @jackh726