Repository: dotnet/runtime
File: src/coreclr/jit/async.cpp (C++)

Code before:

        CORINFO_CALL_INFO callInfo = {};
        callInfo.hMethod           = captureCall->gtCallMethHnd;
        callInfo.methodFlags       = info.compCompHnd->getMethodAttribs(callInfo.hMethod);
        impMarkInlineCandidate(captureCall, MAKE_METHODCONTEXT(callInfo.hMethod), false, &callInfo, compInlineContext);

        Statement* captureStmt = fgNewStmtFromTree(captureCall);
        fgInsertStmtAtBeg(fgFirstBB, captureStmt);

        JITDUMP("Inserted capture\n");
        DISPSTMT(captureStmt);
    }

    // Insert RestoreContexts call in fault (exceptional case)
    // First argument: started = (continuation == null)
    GenTree* resumed;
    if (compIsForInlining())
    {
        resumed = gtNewFalse();
    }
    else
    {
        GenTree* continuation = gtNewLclvNode(lvaAsyncContinuationArg, TYP_REF);
        GenTree* null         = gtNewNull();
        resumed               = gtNewOperNode(GT_NE, TYP_INT, continuation, null);
    }

    GenTreeCall* restoreCall = gtNewCallNode(CT_USER_FUNC, asyncInfo->restoreContextsMethHnd, TYP_VOID);
    restoreCall->gtArgs.PushFront(this,
                                  NewCallArg::Primitive(gtNewLclVarNode(lvaAsyncSynchronizationContextVar, TYP_REF)));
    restoreCall->gtArgs.PushFront(this, NewCallArg::Primitive(gtNewLclVarNode(lvaAsyncExecutionContextVar, TYP_REF)));
    restoreCall->gtArgs.PushFront(this, NewCallArg::Primitive(resumed));

    Statement* restoreStmt = fgNewStmtFromTree(restoreCall);
    fgInsertStmtAtEnd(faultBB, restoreStmt);

    // Now insert uses of the new contexts to all async calls (modelling the
    // fact that on suspension, we restore the context from those values). Also
    // convert BBJ_RETURNs into an exit to a block outside the region.
    BasicBlock* newReturnBB     = nullptr;
    unsigned    mergedReturnLcl = BAD_VAR_NUM;

    for (BasicBlock* block : Blocks())
    {
        if (!compIsForInlining())
        {
            AddContextArgsToAsyncCalls(block);
        }

        if (!block->KindIs(BBJ_RETURN) || (block == newReturnBB))
        {

Review comment (suggestion):
The comment says the first argument is `started = (continuation == null)`, but the code computes `resumed = (continuation != null)` and passes `resumed`. Either update the comment to match what is actually passed, or rename/adjust the boolean so the code and comment agree (this is especially important now that inlining forces a constant value).

Code after:

        CORINFO_CALL_INFO callInfo = {};
        callInfo.hMethod           = captureCall->gtCallMethHnd;
        callInfo.methodFlags       = info.compCompHnd->getMethodAttribs(callInfo.hMethod);
        impMarkInlineCandidate(captureCall, MAKE_METHODCONTEXT(callInfo.hMethod), false, &callInfo, compInlineContext);

        Statement* captureStmt = fgNewStmtFromTree(captureCall);
        fgInsertStmtAtBeg(fgFirstBB, captureStmt);

        JITDUMP("Inserted capture\n");
        DISPSTMT(captureStmt);
    }

    // Insert RestoreContexts call in fault (exceptional case)
    // First argument: resumed = (continuation != null)
    GenTree* resumed;
    if (compIsForInlining())
    {
        resumed = gtNewFalse();
    }
    else
    {
        GenTree* continuation = gtNewLclvNode(lvaAsyncContinuationArg, TYP_REF);
        GenTree* null         = gtNewNull();
        resumed               = gtNewOperNode(GT_NE, TYP_INT, continuation, null);
    }

    GenTreeCall* restoreCall = gtNewCallNode(CT_USER_FUNC, asyncInfo->restoreContextsMethHnd, TYP_VOID);
    restoreCall->gtArgs.PushFront(this,
                                  NewCallArg::Primitive(gtNewLclVarNode(lvaAsyncSynchronizationContextVar, TYP_REF)));
    restoreCall->gtArgs.PushFront(this, NewCallArg::Primitive(gtNewLclVarNode(lvaAsyncExecutionContextVar, TYP_REF)));
    restoreCall->gtArgs.PushFront(this, NewCallArg::Primitive(resumed));

    Statement* restoreStmt = fgNewStmtFromTree(restoreCall);
    fgInsertStmtAtEnd(faultBB, restoreStmt);

    // Now insert uses of the new contexts to all async calls (modelling the
    // fact that on suspension, we restore the context from those values). Also
    // convert BBJ_RETURNs into an exit to a block outside the region.
    BasicBlock* newReturnBB     = nullptr;
    unsigned    mergedReturnLcl = BAD_VAR_NUM;

    for (BasicBlock* block : Blocks())
    {
        if (!compIsForInlining())
        {
            AddContextArgsToAsyncCalls(block);
        }

        if (!block->KindIs(BBJ_RETURN) || (block == newReturnBB))
        {