Constructors don't receive `this` as the first argument
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Start by tracing constructor translation and the generated Rust representations for normal, copy, and move constructors; the issue gives no source files or tests to target. Read the related issues #582 and #248 for context, then locate the translation tests covering constructors. Done means constructors receive prebuilt storage through an explicit this argument, and copy/move translation avoids the extra construction and Clone behavior described here.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Normal constructors and copy/move constructors/assignments all receive this as an implicit first argument.
Our constructor translation instead receives no this and returns by value.
This has performance implications as described in #582 but most importantly it has wrong semantics:
- self referential constructors are broken (#248)
- copy/move constructors and assignments introduce calls that C++ does not have:
impl S {
pub fn copy_from(o: Ptr<S>) -> Self {
let __this: Counted = Self {
... // It constructs a fake __this that might have side effects
};
... body of copy ctor ...
__this
}
}
impl Clone for S {
fn clone(&self) -> Self {
// builds a fake argument for copy_from that might have side effects
let __src: Value<S> = Rc::new(RefCell::new(S { ... }));
S::copy_from(__src.as_pointer())
// drops the fake __src and the fields inside it
}
}
For 1, the solution is to build the storage before calling the constructor:
impl S {
pub fn new(this: Ptr<Self>) {
this.a = 1;
this.b = 2;
}
}
let s: Value<S> = Rc::new(RefCell::new(/* uninitialized storage of S */));
S::new(s.as_pointer());
For 2, the solution is to explicitly pass this to the copy ctor and stop using the Clone trait:
impl S for CopyConstructible {
pub fn copy_from(this: Ptr<S>, o: Ptr<S>) {
... body of copy ctor ...
}
}
- Vorherrschende Sprache
- Rust
- Sterne
- 310
- Forks
- 18
- Ø Merge
- 9 Std. 46 Min.
- Gemergte PRs (30 T.)
- 82
Entwicklungsumgebung
Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus Cpp2Rust/cpp2rust
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 79/100
Cpp2Rust/cpp2rust#610 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 15/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 30/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 22/100
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in Cpp2Rust/cpp2rust
Ähnliche Issues
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
kashsuks/Pinel#172 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 69/100
Maintainer antworten meist innerhalb von 1 Tag
-
test_a_503_raises_unavailable_error fails on macOS about one run in sixEvtl. vergeben @naman-modi hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag
-
bug ui
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
userFRM/egui-charts#4168 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
Maintainer antworten meist innerhalb von 1 Tag