Skip to content

[SUGGESTION] Improve in parameter passing (restore old behavior, exclude problem cases only) #666

Open
@JohelEGP

Description

@JohelEGP

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions