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

ensure binding type is set consistently for consts #44232

Closed
wants to merge 1 commit into from

Conversation

simeonschaub
Copy link
Member

Previously, get_binding_type would usually return Any for constants.
I think always setting it to the type of the actual value is probably
useful.

@simeonschaub simeonschaub added backport 1.8 Change should be backported to release-1.8 modules labels Feb 17, 2022
Previously, `get_binding_type` would usually return `Any` for constants.
I think always setting it to the type of the actual value is probably
useful.
if (b->constp) {
jl_atomic_cmpswap_relaxed(&b->ty, &old_ty, jl_typeof(rhs));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit fussy perhaps, but I think it would make sense to move this inside the if (jl_atomic_cmpswap for the value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure right now we always assume that a non-null value implies that the binding type is also set, while setting a type for an uninitialized binding is perfectly fine. In case of a race we might have set the wrong type, but this should then be caught and error appropriately before we set the value to something inconsistent. Or is there another reason for doing it the other way around?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to add another check of the binding type here though, I can add that. (Although declaring constants isn't really thread-safe right now anyways.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just thinking of making setting the value and type more atomic, but I guess the behavior ends up being the same either way.

@KristofferC KristofferC mentioned this pull request Feb 24, 2022
47 tasks
@KristofferC
Copy link
Member

What's the status here?

@simeonschaub
Copy link
Member Author

It currently doesn't work and I'm not 100% sure anymore we actually want to do this. Regarding the release of 1.8 at least, I don't think this needs to be a blocker

@vtjnash
Copy link
Member

vtjnash commented Mar 8, 2022

@simeonschaub
Copy link
Member Author

Yeah, I'm wondering whether we should just special case constants in get_binding_type instead though

@simeonschaub
Copy link
Member Author

Closing in favor of #44632

@simeonschaub simeonschaub deleted the sds/const_binding_type branch March 15, 2022 20:45
@vtjnash
Copy link
Member

vtjnash commented Mar 15, 2022

I thought @Keno needed this version of it for #44447, but will wait for him to respond. In the meantime, we can merge the other one to get the desired API changes.

@Keno
Copy link
Member

Keno commented Mar 15, 2022

Yes, I'd like it to be Typeof and in particular it needs to be cached for performance.

@simeonschaub
Copy link
Member Author

I assume you're aware of #40985 (comment)? I can try to get this to work instead.

@Keno
Copy link
Member

Keno commented Mar 15, 2022

Well, DataTypes with free typevars aren't really first class. I'm fine if this returns typeof for those instead.

@KristofferC KristofferC removed the backport 1.8 Change should be backported to release-1.8 label Mar 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants