Skip to content

Question: Is the order of Stmt.getUses() guaranteed to match params? #35

Description

@zlh20040308

Hi,

While working on A4, I have a question regarding transferCallEdge().

I noticed that in transferCallEdge(), the arguments from Stmt.getUses() seem to be in the same order as parameters from getParams(). Is this ordering guaranteed by the API?

I checked the docs but didn't find clarification. If it's intended, maybe we could document it to help future users. If not, perhaps we could provide a utility method like CallEdge.getParameterMapping() to make the mapping explicit.

My implementation of transferCallEdge() is as follows:

protected CPFact transferCallEdge(CallEdge<Stmt> edge, CPFact callSiteOut) {
    List<RValue> uses = edge.getSource().getUses();
    List<Var> params = edge.getCallee().getIR().getParams();
    CPFact newFact = new CPFact();
    for (int i = 0; i < params.size(); i++) {
        if (uses.get(i) instanceof Var var) {
            newFact.update(params.get(i), callSiteOut.get(var));
        }
    }
    return newFact;
}

This code relies on an implicit assumption: the order of arguments returned by uses corresponds exactly to the order of parameters in params. While I verified this through debugging, this guarantee is not documented in Stmt.getUses() or JMethod.getIR().getParams().

A cleaner design might expose a getParameterMapping() method directly on CallEdge, making the argument-parameter correspondence explicit and freeing callers from depending on index ordering.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions