You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
structS{intP=>0;// not readonlyint this[strings]=>0;// not readonlyreadonlyvoidM(){_=P;// warning CS8656: Call to non-readonly member 'S.P.get' from a 'readonly' member results in an implicit copy of 'this'._=this[""];// warning CS8656: Call to non-readonly member 'S.this[string].get' from a 'readonly' member results in an implicit copy of 'this'.
N();// warning CS8656: Call to non-readonly member 'S.N()' from a 'readonly' member results in an implicit copy of 'this'.}voidN(){}}
@KalleOlaviNiemitalo is making a point about the warnings Roslyn issues, not about the three copies of this the Standard mandates as “defensive copies” as being redundant.
Surely a different compiler might choose to analyze P, this[] & N; figure out they do not modify the struct; skip the defensive copies; produce the intended semantics; and yet be non-compliant for doing so…
Are not defensive copies a compiler strategy for achieving a particular semantics; is the Standard mandating the strategy rather than the semantics; and in doing so limiting compilers (and performance in this case)?
Should not the strategy be left to the compilers, and the semantics to the Standard?
Or is it argued that the strategy here is the intended semantics?
[Ducking ;-)] Maybe someone should look into this…
The text was updated successfully, but these errors were encountered:
Nigel-Ecma
changed the title
“Defensive” copies – standardising a compiler or language semantics?
“Defensive” copies – standardising a compiler strategy or language semantics?
Mar 4, 2024
@KalleOlaviNiemitalo uses the following code in a comment on PR #673:
@KalleOlaviNiemitalo is making a point about the warnings Roslyn issues, not about the three copies of
this
the Standard mandates as “defensive copies” as being redundant.Surely a different compiler might choose to analyze
P
,this[]
&N
; figure out they do not modify the struct; skip the defensive copies; produce the intended semantics; and yet be non-compliant for doing so…Are not defensive copies a compiler strategy for achieving a particular semantics; is the Standard mandating the strategy rather than the semantics; and in doing so limiting compilers (and performance in this case)?
Should not the strategy be left to the compilers, and the semantics to the Standard?
Or is it argued that the strategy here is the intended semantics?
[Ducking ;-)] Maybe someone should look into this…
The text was updated successfully, but these errors were encountered: