[Pitch] Task Cancellation Shields

Normally speaking, “cancellation propagation” refers to propagating the cancellation to child tasks. But in your way of framing things, simply calling a function would have to be called propagation, because cleanup code that needs to be shielded from the cancellation generally sits at the same level as the code doing the cancellable work.

To effectively reverse things in a way that guaranties cleanup code is being shielded by default, you’d need to make all function calls shielded by default. Then the burden is on annotating the calls you need to be unshielded. It could be done at the expression level like this:

// this call is cancellable
let result = try cancellable longCall()

// this call is NOT cancellable (implicitly shielded)
let result = try longCall()

This would make code that is cancellable stand out, and your cleanup code would become obviously incorrect if labeled cancellable. But it’d be quite a departure from the current model.

2 Likes