Skip to content

Is realloc required for spilled results on lower, or not? #669

Description

@bvisness

I am having a hard time squaring two different parts of the component spec. In the prose for canon lower, it says:

if len(flatten_types(ft.result_type())) > max_flat_results, realloc is required.

However, the definition of flattening also says:

When lowering into linear memory, this requires the Canonical ABI to call realloc (in lower below) to allocate space to put the tuple. As an optimization, when lowering the return value of an imported function (via canon lower), the caller can have already allocated space for the return value (e.g., efficiently on the stack), passing in an i32 pointer as an parameter instead of returning an i32 as a return value.

And the definition of flatten_functype makes this explicit by appending a pointer parameter and settings results to [].

These two paragraphs seem to contradict each other. The point of the out parameter is explicitly to avoid a realloc for results on lower. Is the prose in canon lower just wrong, or is realloc still conservatively required even if it won't necessarily be called?

(This is separate from the question of string or list results; I realize realloc is always required in that case. I am only asking about whether realloc is required when results are spilled on lower.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions