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

Tracking issue for RFC #2116: fallible collection allocation #48043

Open
aturon opened this Issue Feb 7, 2018 · 15 comments

Comments

Projects
None yet
7 participants
@aturon
Member

aturon commented Feb 7, 2018

This is a tracking issue for the try_reserve part of the RFC "fallible collection allocation" (rust-lang/rfcs#2116).

Steps:

@snf

This comment has been minimized.

Show comment
Hide comment
@snf

snf Feb 22, 2018

Contributor

Hi, this feature will require oom and try_reserve to be implemented. I'm needing try_reserve and I'm willing to work (slowly) on it if noone else does.
I see that the previous commit by @Gankro is here and seems to match the RFC description.
Is there anything else I should consider before rebasing that PR?

Contributor

snf commented Feb 22, 2018

Hi, this feature will require oom and try_reserve to be implemented. I'm needing try_reserve and I'm willing to work (slowly) on it if noone else does.
I see that the previous commit by @Gankro is here and seems to match the RFC description.
Is there anything else I should consider before rebasing that PR?

@snf

This comment has been minimized.

Show comment
Hide comment
@snf

snf Mar 3, 2018

Contributor

I can use some mentorship on what's the best way to implement oom=panic/abort . Should I emit a global variable through rustc depending on this case?

I was taking inspiration from #32900 but there might be an easier way to emit a boolean global variable.

Contributor

snf commented Mar 3, 2018

I can use some mentorship on what's the best way to implement oom=panic/abort . Should I emit a global variable through rustc depending on this case?

I was taking inspiration from #32900 but there might be an easier way to emit a boolean global variable.

@aturon

This comment has been minimized.

Show comment
Hide comment
@aturon

aturon Mar 5, 2018

Member

cc @Gankro, can you help mentor?

Member

aturon commented Mar 5, 2018

cc @Gankro, can you help mentor?

bors added a commit that referenced this issue Mar 9, 2018

Auto merge of #48648 - snf:fallible_allocation, r=Kimundi
Fallible allocation

Implementing RFC#2116 [Fallible Allocation](#48043) .
Work in progress. Initially adding @Gankro's try_reserve for Vec.

bors added a commit that referenced this issue Mar 12, 2018

Auto merge of #48648 - snf:fallible_allocation, r=Kimundi
Fallible allocation

Implementing RFC#2116 [Fallible Allocation](#48043) .
Work in progress. Initially adding @Gankro's try_reserve for Vec.

bors added a commit that referenced this issue Mar 12, 2018

Auto merge of #48648 - snf:fallible_allocation, r=Kimundi
Fallible allocation

Implementing RFC#2116 [Fallible Allocation](#48043) .
Work in progress. Initially adding @Gankro's try_reserve for Vec.

bors added a commit that referenced this issue Mar 13, 2018

Auto merge of #48648 - snf:fallible_allocation, r=Kimundi
Fallible allocation

Implementing RFC#2116 [Fallible Allocation](#48043) .
Work in progress. Initially adding @Gankro's try_reserve for Vec.

bors added a commit that referenced this issue Mar 14, 2018

Auto merge of #48648 - snf:fallible_allocation, r=Kimundi
Fallible allocation

Implementing RFC#2116 [Fallible Allocation](#48043) .
Work in progress. Initially adding @Gankro's try_reserve for Vec.

bors added a commit that referenced this issue Mar 15, 2018

Auto merge of #48648 - snf:fallible_allocation, r=Kimundi
Fallible allocation

Implementing RFC#2116 [Fallible Allocation](#48043) .
Work in progress. Initially adding @Gankro's try_reserve for Vec.

@bluss bluss referenced this issue Mar 25, 2018

Open

Full Consistency With HashMap #19

12 of 20 tasks complete
@SimonSapin

This comment has been minimized.

Show comment
Hide comment
@SimonSapin

SimonSapin Apr 5, 2018

Contributor

try_reserve methods are implemented in Nightly, but the accepted RFC also includes the ability to make allocation failure cause a panic rather than abort and that part is not implemented. Unfortunately the RFC does not discuss how this would be implemented, other than being controlled by a flag in Cargo.toml. It’s not clear to me how this can work.

Contributor

SimonSapin commented Apr 5, 2018

try_reserve methods are implemented in Nightly, but the accepted RFC also includes the ability to make allocation failure cause a panic rather than abort and that part is not implemented. Unfortunately the RFC does not discuss how this would be implemented, other than being controlled by a flag in Cargo.toml. It’s not clear to me how this can work.

@glandium

This comment has been minimized.

Show comment
Hide comment
@glandium

glandium May 4, 2018

Contributor

Unfortunately the RFC does not discuss how this would be implemented, other than being controlled by a flag in Cargo.toml. It’s not clear to me how this can work.

We've been talking about panic::set_hook-like hooking for the new oom lang item in #49668, this could be how this works.

Contributor

glandium commented May 4, 2018

Unfortunately the RFC does not discuss how this would be implemented, other than being controlled by a flag in Cargo.toml. It’s not clear to me how this can work.

We've been talking about panic::set_hook-like hooking for the new oom lang item in #49668, this could be how this works.

@SimonSapin

This comment has been minimized.

Show comment
Hide comment
@SimonSapin

SimonSapin May 29, 2018

Contributor

@alexcrichton, how does #51041 fit with the goal of implementing some way to opt into oom=panic?

Contributor

SimonSapin commented May 29, 2018

@alexcrichton, how does #51041 fit with the goal of implementing some way to opt into oom=panic?

@alexcrichton

This comment has been minimized.

Show comment
Hide comment
@alexcrichton

alexcrichton May 29, 2018

Member

@SimonSapin we'd decide that the regression is acceptable, and we'd revert the change.

Member

alexcrichton commented May 29, 2018

@SimonSapin we'd decide that the regression is acceptable, and we'd revert the change.

@SimonSapin

This comment has been minimized.

Show comment
Hide comment
@SimonSapin

SimonSapin May 29, 2018

Contributor

You use a conditional tense, but oom=panic is already in an accepted RFC (though the implementation strategy is not quite settled).

Contributor

SimonSapin commented May 29, 2018

You use a conditional tense, but oom=panic is already in an accepted RFC (though the implementation strategy is not quite settled).

@alexcrichton

This comment has been minimized.

Show comment
Hide comment
@alexcrichton

alexcrichton May 29, 2018

Member

Ok sure, we can figure it out in the implementation details? AFAIK there's no need to revert the change as it has basically no benefit today. It's a trivial change to revert as well, it's one line in the standard library

Member

alexcrichton commented May 29, 2018

Ok sure, we can figure it out in the implementation details? AFAIK there's no need to revert the change as it has basically no benefit today. It's a trivial change to revert as well, it's one line in the standard library

@3n-mb

This comment has been minimized.

Show comment
Hide comment
@3n-mb

3n-mb Jun 24, 2018

This example in playground asks for 1024*1024*1024*1000 bytes on a server, via v.try_reserve(len)? without giving an error.

Is this RFC implementation is not at the point, at which errors in such cases will start to show up?
Or, is this a gross over-commit by underlying OS, and this state of affairs will stay like this?
Can try_reserve in principle reserve only realistic things?

3n-mb commented Jun 24, 2018

This example in playground asks for 1024*1024*1024*1000 bytes on a server, via v.try_reserve(len)? without giving an error.

Is this RFC implementation is not at the point, at which errors in such cases will start to show up?
Or, is this a gross over-commit by underlying OS, and this state of affairs will stay like this?
Can try_reserve in principle reserve only realistic things?

@SimonSapin

This comment has been minimized.

Show comment
Hide comment
@SimonSapin

SimonSapin Jun 24, 2018

Contributor

When an error is returned is entirely dependent of the underlying allocator. As far as I know Linux usually overcommits, Windows doesn’t.

https://play.rust-lang.org/?gist=aa668f38117983d1951b58307df04880&version=nightly allocates 120 PB but fails at 130 PB, it is exhausting 48 bits of address space.

Even on Linux though, this API can be useful for 32-bit programs when exhausting the address space is much more realistic.

Contributor

SimonSapin commented Jun 24, 2018

When an error is returned is entirely dependent of the underlying allocator. As far as I know Linux usually overcommits, Windows doesn’t.

https://play.rust-lang.org/?gist=aa668f38117983d1951b58307df04880&version=nightly allocates 120 PB but fails at 130 PB, it is exhausting 48 bits of address space.

Even on Linux though, this API can be useful for 32-bit programs when exhausting the address space is much more realistic.

@SimonSapin

This comment has been minimized.

Show comment
Hide comment
@SimonSapin

SimonSapin Jun 27, 2018

Contributor

#43596 was the pre-RFC feature request for oom=panic. I’ve repurposed it as the tracking issue for that feature, since it and try_reserved are likely to be stabilized at different times. This leaves this issue as tracking only try_reserve.

Contributor

SimonSapin commented Jun 27, 2018

#43596 was the pre-RFC feature request for oom=panic. I’ve repurposed it as the tracking issue for that feature, since it and try_reserved are likely to be stabilized at different times. This leaves this issue as tracking only try_reserve.

@snf

This comment has been minimized.

Show comment
Hide comment
@snf

snf Aug 1, 2018

Contributor

#52420 will change CollectionAllocErr to CollectionAllocErr<AllocError>

Contributor

snf commented Aug 1, 2018

#52420 will change CollectionAllocErr to CollectionAllocErr<AllocError>

@SimonSapin

This comment has been minimized.

Show comment
Hide comment
@SimonSapin

SimonSapin Aug 1, 2018

Contributor

Will, or would. I’ve comment there that such a change in public API design merits being discussed separately from a large PR.

Contributor

SimonSapin commented Aug 1, 2018

Will, or would. I’ve comment there that such a change in public API design merits being discussed separately from a large PR.

@Ericson2314

This comment has been minimized.

Show comment
Hide comment
@Ericson2314

Ericson2314 Aug 2, 2018

Contributor

Yeah definitely. Even if it weren't for the 2018 delaying considering these things, I wouldn't expect it to be merged quick. I just make the PR to prove the feasibility and make my ideas clearer to / interactive for others.

Ignoring the benefits of allocator polymorphism itself (that would be #42774), I see 4 big benefits:

  • Self discipline: Applications can prevent themselves statically from forgetting to handled allocations failures.

  • Race freedom: allocation divergence due to try_reserving insufficient space are statically prevented.

  • Expressiveness: Unclear how to do try_reserve-like things for "deep" data structures (those containing indirecation).

  • Library flexibility: Implement functionality just once with a parameteric error type, and you get fallibility polymorphism: downstream can instantiate with ! to get today's divergence, or AllocError to allow them to be explicitly handled.

I thus advocating going with error polymorphism and abandoning try_reverve (I rather reuse try_ for the Result<(), E> copies of every method we'll need for backwards compat). (But, my PR keeps the existing meaning of try_reserve so as to allow a transition period where people can try both approaches.)

Contributor

Ericson2314 commented Aug 2, 2018

Yeah definitely. Even if it weren't for the 2018 delaying considering these things, I wouldn't expect it to be merged quick. I just make the PR to prove the feasibility and make my ideas clearer to / interactive for others.

Ignoring the benefits of allocator polymorphism itself (that would be #42774), I see 4 big benefits:

  • Self discipline: Applications can prevent themselves statically from forgetting to handled allocations failures.

  • Race freedom: allocation divergence due to try_reserving insufficient space are statically prevented.

  • Expressiveness: Unclear how to do try_reserve-like things for "deep" data structures (those containing indirecation).

  • Library flexibility: Implement functionality just once with a parameteric error type, and you get fallibility polymorphism: downstream can instantiate with ! to get today's divergence, or AllocError to allow them to be explicitly handled.

I thus advocating going with error polymorphism and abandoning try_reverve (I rather reuse try_ for the Result<(), E> copies of every method we'll need for backwards compat). (But, my PR keeps the existing meaning of try_reserve so as to allow a transition period where people can try both approaches.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment