-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-codegenArea: Code generationArea: Code generationC-bugCategory: This is a bug.Category: This is a bug.I-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size of generated code.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Description
I tried this code:
pub struct BBox {
top: i32,
left: i32,
height: i32,
width: i32
}
fn fiddle(bbox: BBox) -> Box<BBox> {
Box::new(BBox {
top: bbox.top * 2,
..bbox
})
}
pub fn main() {
let bbox = Box::new(BBox {
top: 551,
left: 100,
height: 200,
width: 180,
});
let bbox = fiddle(*bbox);
let bbox_top = bbox.top;
println!("{}", bbox_top)
}
With rustc 1.60 all Box allocations are totally optimized out.
But starting from 1.61 it doesn't happen.
Possible it is the same issue as #97751
Metadata
Metadata
Assignees
Labels
A-codegenArea: Code generationArea: Code generationC-bugCategory: This is a bug.Category: This is a bug.I-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size of generated code.I-slowIssue: Problems and improvements with respect to performance of generated code.Issue: Problems and improvements with respect to performance of generated code.P-mediumMedium priorityMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
bugadani commentedon Jun 29, 2022
Interestingly, a much simpler case isn't optimized at all with either compiler version (though generated code changed between the versions): https://godbolt.org/z/5G9cP5n88
erikdesjardins commentedon Jun 30, 2022
@bugadani that happens because println takes references to its arguments, which keeps the allocation alive. If you force a move then it is optimized out: https://godbolt.org/z/qz8n7M5jd
erikdesjardins commentedon Jun 30, 2022
Since this starts getting optimized in 1.59 and stops in 1.61, it is likely #92419, which landed in 1.59 and was reverted in 1.61. (see issues linked in #94823 for more info)
apiraino commentedon Jul 7, 2022
WG-prioritization assigning priority (Zulip discussion).
@rustbot label -I-prioritize +P-medium
Jules-Bertholet commentedon Jun 10, 2023
@rustbot label A-codegen I-heavy I-slow -regression-untriaged +regression-from-stable-to-stable
erikdesjardins commentedon Feb 24, 2024
This was fixed in 1.75 by #102099: https://godbolt.org/z/zqcqh3Mch
apiraino commentedon Feb 26, 2024
Given the age of this issue, I'm going to close it and assume it's fixed. @Nekrolm please feel free to open a new issue if it's not the case.
Closed by #102099