Skip to content

Fallible allocation #48648

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

Merged
merged 3 commits into from
Mar 15, 2018
Merged

Fallible allocation #48648

merged 3 commits into from
Mar 15, 2018

Conversation

snf
Copy link
Contributor

@snf snf commented Mar 1, 2018

Implementing RFC#2116 Fallible Allocation .
Work in progress. Initially adding @gankro's try_reserve for Vec.

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Kimundi (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 1, 2018
@snf
Copy link
Contributor Author

snf commented Mar 3, 2018

I'm thinking if this should be behind a feature gate or not given the RFC was already approved. @Kimundi any idea?

Copy link
Member

@Kimundi Kimundi left a comment

Choose a reason for hiding this comment

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

Looks good!


Got confused by feature gates for new language features there. All new APIs should land as unstable, which automatically gives them the feature gate as written in the unstable attribute. So no extra work is needed, but marking it as a stable directly would be wrong. :)

capacity.checked_mul(size_of_bucket)
.expect("capacity overflow"),
"capacity overflow");
let size_of_bucket = size_of::<HashUint>().checked_add(size_of::<(K, V)>())
Copy link
Member

Choose a reason for hiding this comment

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

You turn a unwrap() into a return with CollectionAllocErr::CapacityOverflow here, which I think technically changes the behaviour (or at least the panic message). Is this just a bugfix because this is also technically a capacity overflow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my understanding, if bucket allocation size cannot be calculated, it's a sign of capacity overflow. I don't think there is a regression risk here because the chances of hitting this case are probably very small. There are 2 things that will change here (1) non try_xxxx methods will have a different panic message (empty vs "capacity overflow") (2) the behaviour might change when oom=panic/abort is introduced.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, makes sense.


fn main() {
let v = Vec::new();
v.try_reserve(10); //~ ERROR: attribute is an experimental feature
Copy link
Member

@Kimundi Kimundi Mar 3, 2018

Choose a reason for hiding this comment

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

This needs to be the error message that the compiler actually outputs. use of unstable library feature "try_reserve" [...] or something like it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, solved!

error[E0658]: the `#[try_reserve]` attribute is an experimental feature
--> $DIR/feature-gate-try_reserve.rs:13:1
|
LL | #[try_reserve] //~ ERROR: attribute is an experimental feature
Copy link
Member

Choose a reason for hiding this comment

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

This should also reflect the error gotten from a unstable library feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, solved!

@snf
Copy link
Contributor Author

snf commented Mar 3, 2018

I think this is all we want to do in this PR, I will create a separate one for oom=panic/abort :)

@Kimundi
Copy link
Member

Kimundi commented Mar 4, 2018

Seems there are still some import issues in the tests.

@snf
Copy link
Contributor Author

snf commented Mar 7, 2018

r? @Kimundi . Thanks and sorry for all the messed up commits!, I will squash them after your review.

@@ -456,6 +456,7 @@ declare_features! (

// Parentheses in patterns
(active, pattern_parentheses, "1.26.0", None),

Copy link
Member

Choose a reason for hiding this comment

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

Spurious whitespace

@Kimundi
Copy link
Member

Kimundi commented Mar 8, 2018

Weird that that failed the tests again... But yeah, feel free to squash :)

@snf
Copy link
Contributor Author

snf commented Mar 8, 2018

Ok, I'm squashing the changes into one

@snf snf force-pushed the fallible_allocation branch from 10a58d5 to 69c67d6 Compare March 8, 2018 14:39
@snf
Copy link
Contributor Author

snf commented Mar 8, 2018

Done :). r? @Kimundi

@Kimundi
Copy link
Member

Kimundi commented Mar 8, 2018

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 8, 2018

📌 Commit 69c67d6 has been approved by Kimundi

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 8, 2018
@bors
Copy link
Collaborator

bors commented Mar 9, 2018

⌛ Testing commit 69c67d637065063979405eb6e9a6d2db11159b8a with merge e1bda06a39850023925b8d72aabdc7a56ae13145...

@bors
Copy link
Collaborator

bors commented Mar 9, 2018

💔 Test failed - status-travis

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 9, 2018
@kennytm
Copy link
Member

kennytm commented Mar 9, 2018

Cannot run x.py tidy on i686 because it segfaults 🤔

[00:04:58] command did not execute successfully: "/checkout/obj/build/i686-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/i686-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor"
[00:04:58] expected success, got: signal: 11

@kennytm kennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 9, 2018
@snf snf force-pushed the fallible_allocation branch from a86536f to f15bd05 Compare March 10, 2018 21:42
@bors bors added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 14, 2018
@kennytm
Copy link
Member

kennytm commented Mar 14, 2018

@bors retry

3 hour timeout

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 14, 2018
@bors
Copy link
Collaborator

bors commented Mar 14, 2018

⌛ Testing commit d4e400407a1c231fcf7f90b020b0e73411a5baec with merge 6319df5ff2bf0c4ef9fb8f95b5c2eae3f237cd90...

@bors
Copy link
Collaborator

bors commented Mar 14, 2018

💔 Test failed - status-travis

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 14, 2018
@kennytm
Copy link
Member

kennytm commented Mar 14, 2018

Recent UI test changes again has broken UI tests 😠. Please rebase and update ui/feature-gate-try_reserve.stderr.

[00:51:10] failures:
[00:51:10] 
[00:51:10] ---- [ui] ui/feature-gate-try_reserve.rs stdout ----
[00:51:10] 	diff of stderr:
[00:51:10] 
[00:51:10] 8	
[00:51:10] 9	error: aborting due to previous error
[00:51:10] 10	
[00:51:10] -	If you want more information on this error, try using "rustc --explain E0658"
[00:51:10] +	For more information about this error, try `rustc --explain E0658`.
[00:51:10] 12	

@kennytm kennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 14, 2018
@snf snf force-pushed the fallible_allocation branch from 4455341 to 06057d9 Compare March 14, 2018 10:49
@snf
Copy link
Contributor Author

snf commented Mar 14, 2018

r? @Kimundi @kennytm . Confirmed the feature-gate error is now ok in my local build.

@kennytm
Copy link
Member

kennytm commented Mar 14, 2018

@bors r=Kimundi

@bors
Copy link
Collaborator

bors commented Mar 14, 2018

📌 Commit 06057d9 has been approved by Kimundi

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 14, 2018
@bors
Copy link
Collaborator

bors commented Mar 15, 2018

⌛ Testing commit 06057d9 with merge a4af6f0...

bors added a commit that referenced this pull request Mar 15, 2018
Fallible allocation

Implementing RFC#2116 [Fallible Allocation](#48043) .
Work in progress. Initially adding @gankro's try_reserve for Vec.
@bors
Copy link
Collaborator

bors commented Mar 15, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: Kimundi
Pushing a4af6f0 to master...

@staktrace
Copy link
Contributor

@snf @Kimundi Is it expected that this PR causes build breakage for some crates? For example mp4parse-rust seems to have stopped building in nightly rust, see https://bugzilla.mozilla.org/show_bug.cgi?id=1446538

@snf
Copy link
Contributor Author

snf commented Mar 16, 2018

@staktrace it's because of the conflicting names. I see that Mike commented that #48552 will fix it (and future breakages).
I'll check how mp4parse-rust is using try_reserve and probably submit a patch to use nightly's try_reserve if that's ok for you.

@staktrace
Copy link
Contributor

@snf I don't have any objections but I'm also not the decision maker on this, I just happened to run into the build failure first. Maybe coordinate with the mp4parse-rust owners?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants