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

Use box syntax in vec! macro #31797

Merged
merged 1 commit into from
Mar 3, 2016
Merged

Use box syntax in vec! macro #31797

merged 1 commit into from
Mar 3, 2016

Conversation

apasel422
Copy link
Contributor

Closes #28950.

r? @eddyb

@eddyb
Copy link
Member

eddyb commented Feb 20, 2016

r? @alexcrichton There might be a reason this wasn't done yet.

@rust-highfive rust-highfive assigned alexcrichton and unassigned eddyb Feb 20, 2016
@alexcrichton
Copy link
Member

Hm, I think that there's no reason to not do this. I don't think there's anything visible that can be relied upon by using box instead of Box::new. That being said this is a super common macro, so we may wish to tread carefully.

cc @rust-lang/libs

@alexcrichton alexcrichton added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Feb 21, 2016
@sfackler
Copy link
Member

I'm on board - this seems like exactly the kind of thing we added #[allow_internal_unstable] for.

@eddyb
Copy link
Member

eddyb commented Feb 21, 2016

Mind adding a test that would overflow the default stack with the old implementation, and force it to be compiled with no optimizations?

@apasel422
Copy link
Contributor Author

@eddyb Would something like this suffice?

#![feature(box_syntax)]

const LEN: usize = 1 << 15;

use std::thread::Builder;

fn main() {
    assert!(Builder::new().stack_size(LEN / 2).spawn(|| {
        let vec = <[_]>::into_vec(box ([0; LEN]);
        assert_eq!(vec.len(), LEN);
    }).unwrap().join().is_ok());
}

@eddyb
Copy link
Member

eddyb commented Feb 21, 2016

@apasel422 the point is to use vec![...] so that the test will pass as long as box [...] is being used in vec!.
(But yes, that test looks good otherwise)

EDIT: Oops, I forgot we don't use the array for for repeats, so it would be hard to trigger without passing a lot of things to vec![] or using a large type - vec![[0; LEN]] might just work (check on playpen or on older build that it overflows the stack).

@apasel422
Copy link
Contributor Author

@eddyb Right. Do you have an example of how I could use the vec![a, b, c] syntax with enough elements to overflow the stack?

@eddyb
Copy link
Member

eddyb commented Feb 21, 2016

This crashes on playpen:

fn main() {
    let _v = vec![[0; 1 << 23]];
}

@apasel422
Copy link
Contributor Author

Is there a way to specify the optimization level in a run-pass test, or do I have to use a run-make test?

Edit: Never mind; found compile-flags.

Edit 2: Actually, because -O is already specified, using // compile-flags: -C opt-level=0 conflicts with it. I think a run-make test is necessary.

@apasel422
Copy link
Contributor Author

Updated with test.

-include ../tools.mk

all:
$(RUSTC) -C opt-level=0 big_vec.rs
Copy link
Member

Choose a reason for hiding this comment

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

Could this be added as a run-pass test instead? We've got builders for unoptimized tests which should cover this I believe.

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. I guess I don't have to do anything special to configure the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@alexcrichton
Copy link
Member

To be extra super sure, I'm gonna run crater on this.

@alexcrichton alexcrichton added the S-waiting-on-crater Status: Waiting on a crater run to be completed. label Feb 22, 2016
@alexcrichton
Copy link
Member

Crater reports zero regressions (as expected)

@alexcrichton alexcrichton removed the S-waiting-on-crater Status: Waiting on a crater run to be completed. label Feb 23, 2016
@apasel422
Copy link
Contributor Author

@alexcrichton Does this need anything else?

@alexcrichton
Copy link
Member

Ah I was just hoping to discuss this with the libs team briefly, but I suspect we'll just merge

@bors
Copy link
Contributor

bors commented Feb 26, 2016

☔ The latest upstream changes (presumably #31749) made this pull request unmergeable. Please resolve the merge conflicts.

@alexcrichton
Copy link
Member

We talked about this in triage yesterday and everything seemed all good, thanks again @apasel422!

@bors: r+ 34aed8f

@bors
Copy link
Contributor

bors commented Mar 3, 2016

⌛ Testing commit 34aed8f with merge 809b14a...

bors added a commit that referenced this pull request Mar 3, 2016
@bors bors merged commit 34aed8f into rust-lang:master Mar 3, 2016
@apasel422 apasel422 deleted the issue-28950 branch March 3, 2016 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants