6 ms·
This is one advantage of Ada, where parameters are abstractly declared as "in" or "in out" or "out". The compiler can then decide how to best implement it for t
by dwheeler 4y ago
This is one advantage of Ada, where parameters are abstractly declared as "in" or "in out" or "out". The compiler can then decide how to best implement it for that specific size and architecture.
- bvrmn 4y agoAlways curious how Ada solves ABI issue with such optimizations in place.
- rightbyte 4y agoAs long as the calling convention is deterministic from the declaration of the function it should be fine right?
- usrnm 4y agoIf it's deterministic, the compiler cannot actually choose the best way to optimise it.
- rightbyte 4y agoIt just have to come up with the same best way each time?
- deleted 4y ago[deleted]
- int_19h 4y agoAt the minimum, the compiler can look at the size of the type to decide whether copying or indirection makes more sense. The size is stable for a given parameter signature and architecture, so the ABI is stable. But also, the ABI only matters between two pieces that are separately compiled. A static binary optimized at link-time doesn't have to care.
- sampo 4y ago> This is one advantage of Ada, where parameters are abstractly declared as "in" or "in out" or "out". Also Fortran has "in", "inout" and "out".
- pletnes 4y agoFortran also has «default» / no intent. This is somehow different from inout.
- trifurcate 4y agoAlso, MSVC has similar annotations for various static analyses: https://learn.microsoft.com/en-us/cpp/code-quality/understanding-sal?view=msvc-170 https://learn.microsoft.com/en-us/cpp/code-quality/understan...
- jb1991 4y agoAnd Swift also has "inout" parameters.
- stephencanon 4y agoBut not “out” params, sadly. It can return multiple values, so this doesn’t matter much for value types, but it would be nice to be able to specify that a pointer arg is an out-param sometimes and enforce that it is not read from while handling allocation in the caller.
- wiz21c 4y agoand GL/SL IIRC ...
- FpUser 4y agoSo does Delphi / FreePascal
- Congeec 4y agoC++23 is not too late to the party https://en.cppreference.com/w/cpp/memory/out_ptr_t/out_ptr https://en.cppreference.com/w/cpp/memory/out_ptr_t/out_ptr
- chromatin 4y agoDlang can also qualify parameters as in, out, and inout; although I don't know to what degree the compiler is able to use that for optimization purposes (it is used for safety checks IIRC)
- ardel95 4y agoHow is that semantically different from Rust? in - regular function arguments inout - mut function arguments out - function return Is there any additional information that a compiler can infer from Ada’s parameter syntax?
- layer8 4y agoThe difference between passing by reference vs. by value is observable when comparing pointers to the original vs. to the argument. This difference may be unobservable in Ada though (not sure), so Ada would have more freedom choosing between the two.
- deleted 4y ago[deleted]
- deleted 4y ago[deleted]
- rwaksmunski 4y agoA question to the Rust experts, would lifetime annotations 'a in Rust have similar benefit as "in" or "in out" or "out" in Ada and other languages? With the additional benefit in Rust where the compiler can deduce those automatically for most cases?
- chc 4y agoAs a sibling comment points out, "in" is effectively equivalent to "&T", and "inout" is effectively equivalent to "&mut T". Rust is missing purely "out" parameters, but that isn't a very common case, and I'm not sure how much value there is in saying "this reference can't be read" since references are always guaranteed to be valid in Rust.
- db48x 4y agoA Rust program can trivially return a tuple of values, so it doesn't need out params.
- zozbot234 4y agoOut params are needed to ensure zero-copy in-place initialization of large objects, i.e. what C++ does with placement new. You can sort of fake it with MaybeUninit<> https://doc.rust-lang.org/std/mem/union.MaybeUninit.html https://doc.rust-lang.org/std/mem/union.MaybeUninit.html but it's quite fiddly, requires unsafe code, and has undesirable effects on the layout of containing objects.
- db48x 4y agoIn–place initialization is nice to have, but not strictly required.
- deleted 4y ago[deleted]