isKnownUniquelyReferenced thread safety

The semantic difference between "+0 pass-by-value" and "pass-by-reference" is that the following code prints "5" vs. "6":

func f(sh: __shared Int, f: () -> ()) {
  f()
  print(sh)
}

var x = 5
let f = { x += 1 }
f(sh: x, f: f)

I don't know what "pass-by-reference" means to you, but I think almost everyone would consider it equivalent to C++ 'const &' in this context.

You can't claim that it's really "pass-by-reference-with-implicit-copy" because that's the same thing as saying "pass-by-value".

I think most of the posts above would be avoided if people would realize that our misnamed __shared keyword does not mean that the argument is "shared", nor does it mean that it is "borrowed".

It is still passed-by-value using an "unowned" or "nonconsuming" calling convention which makes it ABI compatible with an argument that happens to be a "borrowed" variable, when such a thing exists:

1 Like