Skip to content

Should we have freeze and thaw #256

Open
@Tokazama

Description

@Tokazama

I've seen freeze(x) and thaw(x) thrown around for making x immutable and mutable, respectively. I'm not sure if we should wait for base to formalize the ImmutableArray approach, or if it's worth have some common syntax for that right now. I'm not sure if we're ever going to get much petter than this pattern:

function foo(x)
    y = similar(x)
    foo!(y, x)
    if ismutable(x)
        return y
    else
        return freeze(y)
    end
end
# change values of `y`
foo!(y, x) = ...

Which might be fine if we can ensure that freeze(y) and similar(x) are close so that the compiler can easily figure out what to allocate to the stack and elide unnecessary allocations.

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