Restore in optimization for class types
At first, in parameters were optimized for class types.
Cppfront's optimization of in parameters was faithful to
F.16: For “in” parameters, pass cheaply-copied types by value and others by reference to const.
Then, #270 brought to light that the optimization didn't play well with Cpp2's order independence.
After #317, the net effect is that Cppfront never optimizes in parameters of class type.
I still lament the fact that we lost this optimization to Cpp2 itself.
Similar to #317, here I propose to "improve in parameter passing (restore old behavior, exclude problem cases only)".
#270 (comment) describes the general problem.
However, it generally doesn't apply to Cpp2.
Cpp2 generally requires parameters of complete type.
That's because most functions are initialized and will have a Cpp1 definition emitted.
So we can generally try to optimize in parameters of class types to pass-by-value.
I'd love to have this optimization restored for the general case.
The conditions when applying cpp2::in is wrong are two only (AFAIK).
I propose that we identify these conditions,
and only when at least one of these conditions is true,
do we continue emit a version of cpp2::in that doesn't optimize class types.
Otherwise, we should emit a version of cpp2::in that does try to optimize class types.
Identified problems:
References:
Related links:
Will your feature suggestion eliminate X% of security vulnerabilities of a given kind in current C++ code?
No.
Will your feature suggestion automate or eliminate X% of current C++ guidance literature?
Yes.
F.16: For “in” parameters, pass cheaply-copied types by value and others by reference to const.
Describe alternatives you've considered.
None.
Restore
inoptimization for class typesAt first,
inparameters were optimized for class types.Cppfront's optimization of
inparameters was faithful toF.16: For “in” parameters, pass cheaply-copied types by value and others by reference to
const.Then, #270 brought to light that the optimization didn't play well with Cpp2's order independence.
After #317, the net effect is that Cppfront never optimizes
inparameters of class type.I still lament the fact that we lost this optimization to Cpp2 itself.
Similar to #317, here I propose to "improve
inparameter passing (restore old behavior, exclude problem cases only)".#270 (comment) describes the general problem.
However, it generally doesn't apply to Cpp2.
Cpp2 generally requires parameters of complete type.
That's because most functions are initialized and will have a Cpp1 definition emitted.
So we can generally try to optimize
inparameters of class types to pass-by-value.I'd love to have this optimization restored for the general case.
The conditions when applying
cpp2::inis wrong are two only (AFAIK).inargument passing to function that uses cpp2 user defined type failed with error #270.In the current source order,
it only applies to parameters of type that come later in source order.
An uninitialized
virtual thisfunction can have parameters of incomplete type.When declaring an
override thisorfinal thisfunction in a different TU,we can't know if its
inparameters of class type had opted-into the optimization with the current Cppfront.I propose that we identify these conditions,
and only when at least one of these conditions is true,
do we continue emit a version of
cpp2::inthat doesn't optimize class types.Otherwise, we should emit a version of
cpp2::inthat does try to optimize class types.Identified problems:
This is evident with function types (e.g., see feat: support function types #526 (comment)).
With this suggestion, the effect would, once again, extend to optimized class types.
to determine that a parameter's type indeed names a type that shouldn't be optimized.
References:
inargument passing to function that uses cpp2 user defined type failed with error #270.inargument passing to function that uses cpp2 user defined type failed with error #270 (comment).cpp2::in(restore old behavior, exclude problem cases only) #317.Related links:
Will your feature suggestion eliminate X% of security vulnerabilities of a given kind in current C++ code?
No.
Will your feature suggestion automate or eliminate X% of current C++ guidance literature?
Yes.
F.16: For “in” parameters, pass cheaply-copied types by value and others by reference to
const.Describe alternatives you've considered.
None.