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

Add mutablity checks and left hand size assignee checker #182

Merged
merged 1 commit into from
Jan 27, 2021

Conversation

philberty
Copy link
Member

In order to assign to a name we must ensure the LHS is a valid expression
to assign to. This leads onto actually checking if this is a mutable
declaration or not.

Once these checks pass the name resolver we can in GIMPLE create immutable
types for these declarations to help with optimization.

Fixes #77

In order to assign to a name we must ensure the LHS is a valid expression
to assign to. This leads onto actually checking if this is a mutable
declaration or not.

Once these checks pass the name resolver we can in GIMPLE create immutable
types for these declarations to help with optimization.

Fixes #77
@bjorn3
Copy link

bjorn3 commented Jan 26, 2021

This doesn't handle interior mutability, right? If you have multiple immutable references to an UnsafeCell you can derive a mutable reference to the contents of this UnsafeCell from any of these immutable references for as long as only one such mutable reference exists at any point. libcore implements Freeze for all types that don't contain an UnsafeCell to help the compiler with handling interior mutability.

let foo = &UnsafeCell::new(Vec::new());
let bar = &*foo;
unsafe { (*foo.get()).push(1); }
unsafe { (*bar.get()).push(2); }
unsafe { assert_eq!((*foo.get()).len(), 2); }

is not UB.

@philberty
Copy link
Member Author

This doesn't handle interior mutability, right? If you have multiple immutable references to an UnsafeCell you can derive a mutable reference to the contents of this UnsafeCell from any of these immutable references for as long as only one such mutable reference exists at any point. libcore implements Freeze for all types that don't contain an UnsafeCell to help the compiler with handling interior mutability.

let foo = &UnsafeCell::new(Vec::new());
let bar = &*foo;
unsafe { (*foo.get()).push(1); }
unsafe { (*bar.get()).push(2); }
unsafe { assert_eq!((*foo.get()).len(), 2); }

is not UB.

Yes, this PR and issue are about basic mutability rules for builtin types apart from pointers and unsafe etc. I was going to tackle unsafe in the 3rd data structure milestone and start basic pointers in the next one starting next week. Is it ok if I use your comment to raise a new issue for interior mutability?

Thanks again @bjorn3

@bjorn3
Copy link

bjorn3 commented Jan 26, 2021

Is it ok if I use your comment to raise a new issue for interior mutability?

Sure

@philberty philberty mentioned this pull request Jan 26, 2021
@philberty philberty merged commit 8578c61 into master Jan 27, 2021
@philberty philberty deleted the phil/mut-dev branch February 3, 2021 10:26
@CohenArthur CohenArthur mentioned this pull request Jul 22, 2022
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mutability
2 participants