SE-0311 (2nd review): Task-local values

Taking off my review-manager hat: @ktoso, did you consider using property wrapper projections here? It seems unfortunate that a reference to the task-local variable ends up producing an Access value instead of, well, the value of the variable.

If the wrapper used a projection for the extended interface, it could expose the value with an effectful property, and the result would be something like this:

@TaskLocal
static var requestID: RequestID?

func readExample() async {
  if let id = await requestID {
    ...
  }
}

func writeExample(id: RequestID) async {
  await $requestID.withValue(id) {
    ...
  }
}

Now, since setting a value is always a scoped operation and can't be expressed as an assignment, you'd always have to use a projection (the $ variable) to do it. We could consider sugaring that eventually if people felt it was a serious problem. Personally, I think the nesting is more objectionable than the $, and that's unavoidable without a new feature for scoped operations.

9 Likes