-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Objects that are modified should be passed as in out parameters #10
Comments
The unusual (shallow) design of a
would help a bit. But, why? and how to know when altering variable A also alters variable B? Isn't there an AQ&S recommendation against it?!! |
Hello @simonjwright Sorry for the very late answer! I don’t think this design is that unusual: the As to why: I find dealing with references in an imperative language much easier for recursive data structures than when primitives operate with by-value semantics. For instance, imagine an array A.Item (1).Set (Key, Value);
Unless there are easy ways to prevent this from happening (and I think that’s not the case when using by-value APIs with the kind of serious consequence I’ve described above), I think it’s hard to provide such guarantees without Rust-like borrow checkers… It seems that you already found the bug that made you open this ticket, but I just wanted to add: IIUC the only case when an Ada compiler is allowed to remove such procedure calls (i.e. when the compiler does not have visibility over the procedure implementation while it is compiling the call) is when the procedure is pure, which is not the case here. |
Looking at this in
toml.ads
we haveIn other words, the intent is to modify
Value
.Now,
TOML_Value
is a tagged type and therefore passed by reference, so sinceSet
only touches the internals it appears to work.However, here in
alire-user_pins.adb
we haveand the compiler is entitled to ignore the two
Table.Set
calls -- which claim not to alterTable
- and return the unmodifiedTable
(it beingconstant
).I have a strong suspicion that this is exactly what is happening with alire built on Apple M1 (aarch64).
There are several other similar subprograms.
The text was updated successfully, but these errors were encountered: