rust-lang / rust-lang/rust

Inefficient codegen in builder pattern with existed copyable base value

Open
#130,592 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-LLVM C-bug P-medium regression-untriaged T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

First found in https://github.com/rust-lang/rust/issues/128081#issuecomment-2249215141

In a builder pattern code, when building with existed copyable base value, codegen isn't efficient like partial copy.
This can be reproduced on both argument value and constant value.

Full copy and patial copy:
C version: https://godbolt.org/z/z3fWsKhqE
Rust version: https://godbolt.org/z/MeGf8E5Gd

Existed value and non existed value:
C version: https://godbolt.org/z/9z3x3Kv5c
Rust version: https://godbolt.org/z/vWEaEfd3e

Real use case examaple in rust: https://godbolt.org/z/3q9jn5c1o

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Rust and C Godbolt reproductions and the discussion in rust-lang/rust#128081, comparing generated code for existing versus non-existing and partial-copy builder values. No repository file or test is named; done means the Rust cases produce codegen comparable to the efficient C and partial-copy examples for both argument and constant values.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.