Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate the feedback origin and type recording #1260

Open
fikovnik opened this issue Nov 21, 2023 · 0 comments
Open

Consolidate the feedback origin and type recording #1260

fikovnik opened this issue Nov 21, 2023 · 0 comments

Comments

@fikovnik
Copy link
Collaborator

There are a few places in the code that should likely by consolidated:

  1. Updating feedbackOrigin::function without the corresponding index.

Is it the case that the feedbackOrigin::function is used for something without the index?
It is not clear, should be documented.

In rir/src/compiler/pir/builder.cpp:131 in Builder::Builder(Continuation* cnt, Value* closureEnv):

        mkenv->updateTypeFeedback().feedbackOrigin.function(
            cnt->owner()->rirFunction());

In rir/src/compiler/pir/builder.cpp:180 in Builder::Builder(ClosureVersion* version, Value* closureEnv):

mkenv->updateTypeFeedback().feedbackOrigin.function(rirFun);
  1. The type recording

It feels that all of those are trying to do something similar.
We could pull this into the record_type directly or document why there are differences.

In rir/src/runtime/TypeFeedback.cpp for deopt:

        // FIXME: very similar code is in the recordTypeFeedbackImpl
        // IMHO the one there is more correct. Would it make sense
        // to pull this into the TypeFeedback::record_type()?
        // and get rid of the overload that takes lambda?
        feedback->record_type(origin.idx(), val);
        feedback->record_type(origin.idx(), [&](auto& slot) {
            if (TYPEOF(val) == PROMSXP) {
                if (PRVALUE(val) == R_UnboundValue &&
                    slot.stateBeforeLastForce < ObservedValues::promise)
                    slot.stateBeforeLastForce = ObservedValues::promise;
                else if (slot.stateBeforeLastForce <
                         ObservedValues::evaluatedPromise)
                    slot.stateBeforeLastForce =
                        ObservedValues::evaluatedPromise;
            }
        });

In rir/src/interpreter/interp.cpp in recordForceBehavior:

        c->function()->typeFeedback()->record_type(idx, [&](auto& feedback) {
            if (feedback.stateBeforeLastForce < state) {
                feedback.stateBeforeLastForce = state;
            }
        });

In rir/src/compiler/native/builtins.cpp in recordTypefeedbackImpl:

    feedback->record_type(idx, [&](auto& slot) {
        if (TYPEOF(value) == PROMSXP) {
            if (PRVALUE(value) == R_UnboundValue &&
                slot.stateBeforeLastForce < ObservedValues::promise) {
                slot.stateBeforeLastForce = ObservedValues::promise;
            } else if (slot.stateBeforeLastForce <
                       ObservedValues::evaluatedPromise) {
                slot.stateBeforeLastForce = ObservedValues::evaluatedPromise;
            }
        } else {
            if (slot.stateBeforeLastForce < ObservedValues::value)
                slot.stateBeforeLastForce = ObservedValues::value;
        }
    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant