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

Allow mutable slices in statics. #11797

Closed
wants to merge 1 commit into from
Closed

Conversation

xales
Copy link
Contributor

@xales xales commented Jan 25, 2014

No description provided.

},
ExprVstore(_, ExprVstoreUniq) |
ExprVstore(_, ExprVstoreBox) => {
sess.span_err(e.span, "cannot allocate vectors in constant expressions")
sess.span_err(e.span, "cannot allocate vectors in constant expressions")
Copy link
Contributor

Choose a reason for hiding this comment

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

Rust uses 4-spaces indent afaik.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made it consistent with rest of file.

Copy link
Member

Choose a reason for hiding this comment

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

Let's leave this as 4 spaces and hope the rest of the file gets updated soon.

@emberian
Copy link
Member

cc @nikomatsakis this has some interactions with borrowck that need to be resolved, possibly with special cases for static muts. Or, we could just not allow mutable slices, which would make me sad (and probably @Tobba too)

@xales
Copy link
Contributor Author

xales commented Jan 27, 2014

Test currently fails with:
src/test/run-pass/issue-11411.rs:16:9: 16:16 error: cannot assign to an &mut in an aliasable location
src/test/run-pass/issue-11411.rs:16 TEST[0] += 1;

This appears to be due to all statics being considered AliasableOther (librustc/middle/mem_categorization.rs:1176).

llvm::LLVMAddGlobal(cx.llmod, llty.to_ref(), name)
});
llvm::LLVMSetInitializer(gv, cv);
llvm::LLVMSetGlobalConstant(gv, True);
Copy link
Member

Choose a reason for hiding this comment

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

This seems fishy, it's a mutable static but you're setting it as constant!

You may want to test fancier cases as well, you want to make sure that nothing is recursively constant as well. Something like:

struct Foo { a: int };
static mut A: &'static mut [Foo] = &'static mut [Foo { a : 3 }];

fn main() {
    A[0].a += 3;
}

@nikomatsakis
Copy link
Contributor

Is there an issue #? What exactly is being permitted here?

@xales
Copy link
Contributor Author

xales commented Jan 27, 2014

Yes - #11411

@xales
Copy link
Contributor Author

xales commented Jan 27, 2014

Builds and tests cleanly now. Appears to actually work...

fn visit_pat(&mut self, p: &Pat, env: bool) {
check_pat(self, p, env);
}
fn visit_item(&mut self, item: &Item, env: bool) {
check_item(self, self.sess, self.ast_map, self.def_map, self.method_map,
Copy link
Member

Choose a reason for hiding this comment

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

Why do all these need to be passed separately? Can't check_item just retrieve them from self itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's how it was being done previously. Should I change it?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see now... I got distracted by the extra diff. I guess there's no strong need to change it, although it does look kinda silly.

(Maybe you could move this back to being before visit_pat?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure; moved now.

@nikomatsakis
Copy link
Contributor

Please do not merge until I have time to review, thanks.

@alexcrichton
Copy link
Member

ping @nikomatsakis

@nikomatsakis
Copy link
Contributor

Oh yes, sorry...

@alexcrichton
Copy link
Member

ping @nikomatsakis :(

@nikomatsakis
Copy link
Contributor

OK, I do apologize for taking so long. This will need a rebase. I read it over. It seems fine, though I still am not happy about putting an &mut into a static mut. I had to make similar compromises already regarding the aliasability rules and static muts as part of fixing #11913, so I guess this is no worse.

@xales
Copy link
Contributor Author

xales commented Feb 20, 2014

@nikomatsakis I've rebased, but I had to make more changes to borrowck to get it to work. Do these look okay?


static mut TEST: &'static mut [int] = &mut [1];

fn main() {
Copy link
Member

Choose a reason for hiding this comment

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

Just a drive-by-comment, but to pass the check-fast target on windows/bsd this will need to be pub fn main

@flaper87
Copy link
Contributor

flaper87 commented Mar 4, 2014

@xales are you planning you work on this? If not, do you mind if I take over?

@flaper87
Copy link
Contributor

flaper87 commented Mar 6, 2014

superseded by #12742

@flaper87 flaper87 closed this Mar 6, 2014
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

Successfully merging this pull request may close these issues.

7 participants