|
| 1 | +using System; |
| 2 | +using System.Threading.Tasks; |
| 3 | +using RLibA; |
| 4 | +// H-25 await-wrapped acquire recognition: positive forms and hostile twins, frozen BEFORE any code (h25-prereg-v1.json). |
| 5 | +// FA.FactoryAsync / FA.FactoryValueTaskAsync carry trusted rows (the LOGICAL result is fresh owned); BorrowedAsync, |
| 6 | +// CachedAsync, UnknownAsync carry none. Expected classifications are in the prereg, not here. Census only: no lowering. |
| 7 | +public static class Positive |
| 8 | +{ |
| 9 | + // AW1: Task<R> awaited in an existing-local assignment |
| 10 | + public static async Task AW1_task_assignment() { R x = null; x = await FA.FactoryAsync(); x.Ping(); x.Dispose(); } |
| 11 | + // AW2: the same through ConfigureAwait(false) |
| 12 | + public static async Task AW2_configure_await() { R x = null; x = await FA.FactoryAsync().ConfigureAwait(false); x.Ping(); x.Dispose(); } |
| 13 | + // AW3: ValueTask<R> |
| 14 | + public static async Task AW3_valuetask() { R x = null; x = await FA.FactoryValueTaskAsync(); x.Ping(); x.Dispose(); } |
| 15 | + // AW4: declaration form `var x = await FactoryAsync()` |
| 16 | + public static async Task AW4_declaration() { var x = await FA.FactoryAsync(); x.Ping(); x.Dispose(); } |
| 17 | + // AW5: declaration form through ConfigureAwait |
| 18 | + public static async Task AW5_declaration_configure_await() { var x = await FA.FactoryAsync().ConfigureAwait(false); x.Ping(); } |
| 19 | + // AW6: the try/finally initialisation idiom with an awaited trusted factory (the dominant population shape) |
| 20 | + public static async Task AW6_try_finally() { R x = null; try { x = await FA.FactoryAsync(); x.Ping(); } finally { x?.Dispose(); } } |
| 21 | +} |
| 22 | +public static class Hostile |
| 23 | +{ |
| 24 | + // HW1: the task is stored first and awaited later: the Task<R> local is NOT an R acquire; the obligation belongs to the awaited R |
| 25 | + public static async Task HW1_deferred_await() { var task = FA.FactoryAsync(); var x = await task; x.Ping(); } |
| 26 | + // HW2: awaited result is borrowed (no row): no acquire |
| 27 | + public static async Task HW2_borrowed() { R x = null; x = await FA.BorrowedAsync(); x.Ping(); } |
| 28 | + // HW3: awaited result is cached (no row): no acquire |
| 29 | + public static async Task HW3_cached() { R x = null; x = await FA.CachedAsync(); x.Ping(); } |
| 30 | + // HW4: Task without a resource result: nothing is written |
| 31 | + public static async Task HW4_fire_and_forget() { await FA.FireAndForgetAsync(); } |
| 32 | + // HW5: fresh in fact but NO row: must not be an acquire (the effect comes only from a trusted row) |
| 33 | + public static async Task HW5_unknown() { R x = null; x = await FA.UnknownAsync(); x.Ping(); } |
| 34 | + // HW6: the sync twin name has no row either; a name-based `Async` strip must never mint |
| 35 | + public static async Task HW6_name_twin() { R x = null; x = await FA.BorrowedTwinAsync(); x.Ping(); } |
| 36 | + // HW7: awaited result assigned to a field: an escape, classified only |
| 37 | + static R _f; |
| 38 | + public static async Task HW7_field_store() { _f = await FA.FactoryAsync(); } |
| 39 | + // HW8: `await using` declaration of an awaited factory: a using shape, classified only |
| 40 | + public static async Task HW8_using_declaration() { using var x = await FA.FactoryAsync(); x.Ping(); } |
| 41 | +} |
0 commit comments