Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Share drop glue too when -Zshare-generics is enabled #84175

Open
bjorn3 opened this issue Apr 13, 2021 · 3 comments
Open

Share drop glue too when -Zshare-generics is enabled #84175

bjorn3 opened this issue Apr 13, 2021 · 3 comments
Labels
-Zshare-generics Unstable options: Share generic instantiations. A-codegen Area: Code generation C-enhancement Category: An issue proposing an enhancement or a PR with one. I-compiletime Issue: Problems and improvements with respect to compile times. I-heavy Issue: Problems and improvements with respect to binary size of generated code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bjorn3
Copy link
Member

bjorn3 commented Apr 13, 2021

cc bevyengine/bevy#1914

@bjorn3 bjorn3 added C-enhancement Category: An issue proposing an enhancement or a PR with one. A-codegen Area: Code generation T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 13, 2021
@jonas-schievink jonas-schievink added I-compiletime Issue: Problems and improvements with respect to compile times. I-heavy Issue: Problems and improvements with respect to binary size of generated code. labels Apr 13, 2021
@jyn514 jyn514 changed the title Share drpp glue too when -Zshare-generics is enabled Share drop glue too when -Zshare-generics is enabled Apr 13, 2021
@jyn514 jyn514 added the -Zpolymorphize Unstable option: Polymorphization. label Apr 13, 2021
@csmoe
Copy link
Member

csmoe commented Jul 16, 2021

#68414 seems already shared there? @bjorn3

@bjorn3
Copy link
Member Author

bjorn3 commented Jul 16, 2021

$ cat > lib.rs
pub struct Foo(pub Vec<u8>);
impl Drop for Foo {
    fn drop(&mut self) {}
}
$ rustc +nightly --crate-type dylib lib.rs -Zshare-generics -Cprefer-dynamic
$ cat > main.rs
fn main() {
    lib::Foo(vec![]);
}
$ rustc +nightly --crate-type bin main.rs -Zshare-generics --extern lib=liblib.so -Cprefer-dynamic
$ objdump -d ./main | grep Foo
00000000000013c0 <_ZN4core3ptr29drop_in_place$LT$lib..Foo$GT$17ha6b7547f0832ce86E>:
    13c8:       48 8b 0d f9 2b 00 00    mov    0x2bf9(%rip),%rcx        # 3fc8 <_ZN50_$LT$lib..Foo$u20$as$u20$core..ops..drop..Drop$GT$4drop17hcc626ef64eb19045E>
    13d1:       eb 00                   jmp    13d3 <_ZN4core3ptr29drop_in_place$LT$lib..Foo$GT$17ha6b7547f0832ce86E+0x13>
    13dc:       eb 27                   jmp    1405 <_ZN4core3ptr29drop_in_place$LT$lib..Foo$GT$17ha6b7547f0832ce86E+0x45>
    13e7:       eb 10                   jmp    13f9 <_ZN4core3ptr29drop_in_place$LT$lib..Foo$GT$17ha6b7547f0832ce86E+0x39>
    13f7:       eb e5                   jmp    13de <_ZN4core3ptr29drop_in_place$LT$lib..Foo$GT$17ha6b7547f0832ce86E+0x1e>
    1531:       e8 8a fe ff ff          callq  13c0 <_ZN4core3ptr29drop_in_place$LT$lib..Foo$GT$17ha6b7547f0832ce86E>

The core::ptr::drop_in_place<lib::Foo> shouldn't be codegened in main, but in liblib.so if -Zshare-generics is used. The <lib::Foo as core::ops::Drop>::drop is codegened in liblib.so as intended though.

@Kobzol
Copy link
Contributor

Kobzol commented Sep 27, 2021

drop_in_place is not codegened in liblib.so, because it's not actually used here. If lib.rs contained something like

fn foo(_: Foo) {}

then the drop_in_place impl would be shared.

Maybe it could be worth it to force codegen of drop_in_place in the crate where the dropped type is defined when -Zshare-generics is used?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
-Zshare-generics Unstable options: Share generic instantiations. A-codegen Area: Code generation C-enhancement Category: An issue proposing an enhancement or a PR with one. I-compiletime Issue: Problems and improvements with respect to compile times. I-heavy Issue: Problems and improvements with respect to binary size of generated code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants