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

Mutable fields, not structs? #37216

Closed
bramtayl opened this issue Aug 26, 2020 · 4 comments
Closed

Mutable fields, not structs? #37216

bramtayl opened this issue Aug 26, 2020 · 4 comments

Comments

@bramtayl
Copy link
Contributor

Apologies if there's already an issue open for this already. I took a quick look but.

Many times when I define a mutable struct, but I know there's only one or two fields in it that will ever change, I feel slightly guilty. I suspect there must be optimizations that could become available if Julia knew which of the fields might change, and which might not. For example, in the following example, perhaps I know that b might change, but a will not.

mutable struct A
    a::Int
    b::Int
end

So I could imagine writing it like this instead:

struct A
    a::Int
    mutable b::Int
end

Of course, it's possible to make b a Ref, but perhaps the solution above seems a bit more general?

@KristofferC
Copy link
Member

Dup of #9448. Also, ref #11430.

@bramtayl
Copy link
Contributor Author

Cool!

@bramtayl
Copy link
Contributor Author

Am I correct in thinking that this can be done in a backwards compatible way, because

struct A
    a::Int
    mutable b::Int
end

is currently a syntax error?

@KristofferC
Copy link
Member

Yeah, see #35795 for some suggestions.

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

2 participants