True…and, as you say, if any of those class's properties are themselves reference types, they won't necessarily be immutable (in fact, they probably won't be).
This is an interesting workaround, but again, if the single stored property contains any reference types, you're back to where you started.
Agreed.
Could you be a bit more specific? I'm not sure I follow you here…
I was thinking that you could have two different types of references: one that allows the referenced object to be mutated, and one that does not. Attempts to assign the former to the latter—or vice versa—would result in a compiler error. Put another way, the compiler would guarantee that any given instance of a reference type could either be modified by all references to it or by no references at all.
I'm still trying to parse this—could you provide an example of what you mean?
Yes, @dynamicMemberLookup and key path member lookup make the process of wrapping a type's API less cumbersome, but I wouldn't exactly consider either to be an elegant solution to this particular problem.
How does key path member lookup simulate C++ pointers in Swift? Isn't it essentially a mechanism for synthesizing computed properties without writing them all out by hand?
I can see the distinction, but my understanding was that, once created as a const variable, a C++ object is only allowed to change data members that have been explicitly marked mutable. (Of course, if it turns out that I'm wrong, I agree that my argument has a bit of a hole in it.
)
Theoretically? Yes, in this case I would expect all of a reference type's properties to be immutable unless explicitly marked otherwise (e.g. unless they are modified by a function marked with the mutating keyword).
Yes…it's probably relatively straightforward to guarantee that a particular value (or set of values) in a stack frame will not change during execution, but extending that guarantee to the entire memory graph might be a bit trickier of a proposition. I'm not familiar enough with the LLVM internals to know how feasible it is, though.