{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/48779","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/48779/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/48779/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/48779/events","html_url":"https://github.com/rust-lang/rust/pull/48779","id":302708016,"number":48779,"title":"Allow for re-using monomorphizations in upstream crates.","user":{"login":"michaelwoerister","id":1825894,"avatar_url":"https://avatars2.githubusercontent.com/u/1825894?v=4","gravatar_id":"","url":"https://api.github.com/users/michaelwoerister","html_url":"https://github.com/michaelwoerister","followers_url":"https://api.github.com/users/michaelwoerister/followers","following_url":"https://api.github.com/users/michaelwoerister/following{/other_user}","gists_url":"https://api.github.com/users/michaelwoerister/gists{/gist_id}","starred_url":"https://api.github.com/users/michaelwoerister/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaelwoerister/subscriptions","organizations_url":"https://api.github.com/users/michaelwoerister/orgs","repos_url":"https://api.github.com/users/michaelwoerister/repos","events_url":"https://api.github.com/users/michaelwoerister/events{/privacy}","received_events_url":"https://api.github.com/users/michaelwoerister/received_events","type":"User","site_admin":false},"labels":[{"id":583436937,"url":"https://api.github.com/repos/rust-lang/rust/labels/S-waiting-on-author","name":"S-waiting-on-author","color":"d3dddd","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":66,"created_at":"2018-03-06T13:49:46Z","updated_at":"2018-04-03T13:28:59Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/rust-lang/rust/pulls/48779","html_url":"https://github.com/rust-lang/rust/pull/48779","diff_url":"https://github.com/rust-lang/rust/pull/48779.diff","patch_url":"https://github.com/rust-lang/rust/pull/48779.patch"},"body":"Followup to #48611. This implementation is pretty much finished modulo failing tests if there are any. Not quite ready for review yet though.\r\n\r\n### DESCRIPTION\r\n\r\nThis PR introduces a `share-generics` mode for RLIBs and Rust dylibs. When a crate is compiled in this mode, two things will happen:\r\n- before instantiating a monomorphization in the current crate, the compiler will look for that monomorphization in all upstream crates and link to it, if possible.\r\n- monomorphizations are not internalized during partitioning. Instead they are added to the list of symbols exported from the crate. \r\n\r\nThis results in less code being translated and LLVMed. However, there are also downsides:\r\n- it will impede optimization somewhat, since fewer functions can be internalized, and\r\n- Rust dylibs will have bigger symbol tables since they'll also export monomorphizations.\r\n\r\nConsequently, this PR only enables the `shared-generics` mode for opt-levels `No`, `Less`, `Size`, and `MinSize`, and for when incremental compilation is activated. `-O2` and `-O3` will still generate generic functions per-crate.\r\n\r\nAnother thing to note is that this has a somewhat similar effect as MIR-only RLIBs, in that monomorphizations are shared, but it is less effective because it cannot share monomorphizations between sibling crates:\r\n\r\n```\r\n         A        <--- defines `fn foo<T>() { .. }`\r\n       /   \\\r\n      /     \\\r\n     B       C    <--- both call `foo<u32>()`\r\n      \\     /\r\n       \\   /\r\n         D        <--- calls `foo<u32>()` too\r\n```\r\n\r\nWith `share-generics`, both `B` and `C` have to instantiate `foo<u32>` and only `D` can re-use it (from either `B` or `C`). With MIR-only RLIBs, `B` and `C` would not instantiate anything, and in `D` we would then only instantiate `foo<u32>` once. \r\nOn the other hand, when there are many leaf crates in the graph (e.g. when compiling many individual test binaries) then the `share-generics` approach will often be more effective.  \r\n\r\n### TODO\r\n - [x] Add codegen test that makes sure monomorphizations can be internalized in non-Rust binaries.\r\n - [x] Add codegen-units test that makes sure we share generics.\r\n - [x] Add run-make test that makes sure we don't export any monomorphizations from non-Rust binaries.\r\n - [x] Review for reproducible-builds implications."},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/378250055","html_url":"https://github.com/rust-lang/rust/pull/48779#issuecomment-378250055","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/48779","id":378250055,"user":{"login":"michaelwoerister","id":1825894,"avatar_url":"https://avatars2.githubusercontent.com/u/1825894?v=4","gravatar_id":"","url":"https://api.github.com/users/michaelwoerister","html_url":"https://github.com/michaelwoerister","followers_url":"https://api.github.com/users/michaelwoerister/followers","following_url":"https://api.github.com/users/michaelwoerister/following{/other_user}","gists_url":"https://api.github.com/users/michaelwoerister/gists{/gist_id}","starred_url":"https://api.github.com/users/michaelwoerister/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaelwoerister/subscriptions","organizations_url":"https://api.github.com/users/michaelwoerister/orgs","repos_url":"https://api.github.com/users/michaelwoerister/repos","events_url":"https://api.github.com/users/michaelwoerister/events{/privacy}","received_events_url":"https://api.github.com/users/michaelwoerister/received_events","type":"User","site_admin":false},"created_at":"2018-04-03T13:28:59Z","updated_at":"2018-04-03T13:28:59Z","author_association":"CONTRIBUTOR","body":"OK, let's give it another go.\r\n\r\n@bors r=alexcrichton"}}
{"actor":{"display_login":"michaelwoerister"}}