hsutter / cppfront

A personal experimental C++ Syntax 2 -> Syntax 1 compiler
Other
5.46k stars 239 forks source link

[QUESTION] will Cpp2 in/inout/out parameters honor the law of exclusivity? (Related to C++ safe subsets) #1289

Open germandiagogomez opened 4 days ago

germandiagogomez commented 4 days ago

Hello there.

I am a person inclined towards value semantics in my programs when possible.

I would like to ask (current Cpp2 implementation apart) if the parameter passing in Cpp has a vocation for implementing the law of exclusivity meaning that many in parameters can access the same data but no inout/out can or writing the variable is allowed.

I have been following with interest some talks and I am referring to the fact of being able to avoid problems like this: https://youtu.be/QthAU-t3PQ4?t=535

Namely, there would be analysis for exclusivity: when an in parameter is there, several of them are possible. When an out or inout parameter is then access should be exclusive. If there is an inout/out parameter, then in parameters are not possible.

I think it would be worth an analysis if that could be implemented.

dutkalex commented 3 days ago

A similar discussion was brought up in #1273

I think it would be worth an analysis if that could be implemented.

If I recall correctly, whether it is implementable is a tricky question because cpp2 is not all-in on value semantics as is val/hylo, and there is no consensus right now on the subject

germandiagogomez commented 3 days ago

If I recall correctly, whether it is implementable is a tricky question because cpp2 is not all-in on value semantics as is val/hylo, and there is no consensus right now on the subject

I think it is not implementable in C++ (right now) but it should be as an "overlay analysis" on Cpp2 as long as you guarantee that your code is not mixed back with regular C++.

Namely, if you translate it to references that have been verified by the upper Cpp2 layer and not mix it then it is ok, otherwise you are on your own.