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

Replace {Alloc,GlobalAlloc}::oom with a lang item. #50144

Merged
merged 3 commits into from Apr 22, 2018

Conversation

Projects
None yet
6 participants
@sfackler
Copy link
Member

sfackler commented Apr 21, 2018

The decision of what to do after an allocation fails is orthogonal to the decision of how to allocate the memory, so this PR splits them apart. Alloc::oom and GlobalAlloc::oom have been removed, and a lang item has been added:

#[lang = "oom"]
fn oom() -> !;

It is specifically a weak lang item, like panic_fmt, except that it is required when you depend on liballoc rather than libcore. libstd provides an implementation that aborts with the message fatal runtime error: memory allocation failed, matching the current behavior.

The new implementation is also significantly simpler - it's "just another weak lang item". RFC 2070 specifies a path towards stabilizing panic_fmt, so any complexities around stable weak lang item definition are already being solved.

To bootstrap, oom silently aborts in stage0. alloc_system no longer has a bunch of code to print to stderr, and alloc_jemalloc no longer depends on alloc_system to pull in that code.

One fun note: System's GlobalAlloc implementation didn't override the default implementation of oom, so it currently aborts silently!

r? @alexcrichton

name: "oom",
inputs: &[],
output: AllocatorTy::Bang,
},

This comment has been minimized.

@mattico

mattico Apr 21, 2018

Contributor

Nit: don't need AllocatorTy::Bang anymore

This comment has been minimized.

@sfackler

sfackler Apr 21, 2018

Author Member

Fixed, thanks

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Apr 21, 2018

@bors: r+

That was easier than I thought it would be!

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Apr 21, 2018

📌 Commit b301d05 has been approved by alexcrichton

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Apr 22, 2018

🔒 Merge conflict

@sfackler sfackler force-pushed the sfackler:oom-lang-item branch from b301d05 to 5969712 Apr 22, 2018

@sfackler

This comment has been minimized.

Copy link
Member Author

sfackler commented Apr 22, 2018

@bors r=alexcrichton

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Apr 22, 2018

📌 Commit 5969712 has been approved by alexcrichton

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Apr 22, 2018

⌛️ Testing commit 5969712 with merge e028687...

bors added a commit that referenced this pull request Apr 22, 2018

Auto merge of #50144 - sfackler:oom-lang-item, r=alexcrichton
Replace {Alloc,GlobalAlloc}::oom with a lang item.

The decision of what to do after an allocation fails is orthogonal to the decision of how to allocate the memory, so this PR splits them apart. `Alloc::oom` and `GlobalAlloc::oom` have been removed, and a lang item has been added:

```rust
#[lang = "oom"]
fn oom() -> !;
```

It is specifically a weak lang item, like panic_fmt, except that it is required when you depend on liballoc rather than libcore. libstd provides an implementation that aborts with the message `fatal runtime error: memory allocation failed`, matching the current behavior.

The new implementation is also significantly simpler - it's "just another weak lang item". [RFC 2070](https://github.com/rust-lang/rfcs/blob/master/text/2070-panic-implementation.md) specifies a path towards stabilizing panic_fmt, so any complexities around stable weak lang item definition are already being solved.

To bootstrap, oom silently aborts in stage0. alloc_system no longer has a bunch of code to print to stderr, and alloc_jemalloc no longer depends on alloc_system to pull in that code.

One fun note: System's GlobalAlloc implementation didn't override the default implementation of oom, so it currently aborts silently!

r? @alexcrichton
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Apr 22, 2018

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

@bors bors merged commit 5969712 into rust-lang:master Apr 22, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@@ -59,7 +59,7 @@ unsafe impl<T> Alloc for T where T: CoreAlloc {
}

fn oom(&mut self, _: AllocErr) -> ! {
CoreAlloc::oom(self)
unsafe { ::core::intrinsics::abort() }

This comment has been minimized.

@eddyb

eddyb Apr 25, 2018

Member

Why doesn't this use the weak lang item?

This comment has been minimized.

@sfackler

sfackler Apr 25, 2018

Author Member

This is only used for stage0 I believe.

@@ -303,7 +303,8 @@ language_item_table! {

ExchangeMallocFnLangItem, "exchange_malloc", exchange_malloc_fn;
BoxFreeFnLangItem, "box_free", box_free_fn;
DropInPlaceFnLangItem, "drop_in_place", drop_in_place_fn;
DropInPlaceFnLangItem, "drop_in_place", drop_in_place_fn;
OomLangItem, "oom", oom;

This comment has been minimized.

@eddyb

eddyb Apr 25, 2018

Member

Are weak lang items not grouped in here?

@sfackler sfackler deleted the sfackler:oom-lang-item branch Apr 25, 2018

@ekmartin ekmartin referenced this pull request Apr 27, 2018

Merged

Use oom lang item #3

phil-opp added a commit to phil-opp/linked-list-allocator that referenced this pull request Apr 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.