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

Autodetect the type of allocator crate used #44133

Merged
merged 1 commit into from
Sep 12, 2017
Merged

Autodetect the type of allocator crate used #44133

merged 1 commit into from
Sep 12, 2017

Conversation

vorner
Copy link
Contributor

@vorner vorner commented Aug 28, 2017

Annotate the allocator crates (allocator_system, allocator_jemalloc) by the type of allocator they are. If one is requested as an exe allocator, detect its type by the flags.

This has the effect that using this (de jure wrong) configuration in the target spec works instead of producing a really unhelpful and arcane linker error:

"exe-allocation-crate": "alloc_system"

Fixes #43524.

There are two yet unsolved FIXME's, I'll be glad for some advice on what to do with them.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @arielb1 (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.

@arielb1
Copy link
Contributor

arielb1 commented Aug 29, 2017

r? @alexcrichton

@arielb1 arielb1 added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 29, 2017
@alexcrichton
Copy link
Member

Thanks for the PR! I wonder if we might reorganize this a little slightly though? I'd imagine that we'd select an crate to be an allocator in which case we'd have a CrateNum, and then depending on the attributes in that we'd set the session's allocator flavor. Right now this fixes one half of the bug but not the other (setting the lib default allocator to somethign tagged as an exe allocator).

@vorner
Copy link
Contributor Author

vorner commented Aug 30, 2017

Thank you for the answer. I guess that makes sense and I'll look into it. Some small questions, though:

  • What is the purpose of the flavor in the first place? Why not have the prefixes all the same?
  • Fixup commits that'd get squashed before merging are fine? Who squashes them (is it bors' job, or should I, once they are reviewed)?

@alexcrichton
Copy link
Member

These may be ok with the same prefix, I forget at this point :(. If the tests pass then should be good!

And yeah sure squashing commits and whatnot is fine

@vorner
Copy link
Contributor Author

vorner commented Sep 1, 2017

The prefixes are needed. It seems sometimes both kinds are linked in sometimes :-|. I don't feel like changing that.

Anyway, I made some more changes here, tried to reorder the code a bit. There's still a small bit I'm not sure about how to do ‒ can I get CrateMetadata for the crate passed to the function? (I guess it's the currently compiled crate)

#![cfg_attr(any(unix, target_os = "redox"), feature(libc))]
#![alloc_kind = "lib"]
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 perhaps be called "rustc_alloc_kind" to clearly deliniate that it's rustc-specific?

}

None => {
// TODO: Is there a way to get the metadata for krate and unify this with the
Copy link
Member

Choose a reason for hiding this comment

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

AFAIK this can't be done, but this probably isn't that important to solve regardless?

@alexcrichton
Copy link
Member

Looks like some tests may be failing?

@vorner
Copy link
Contributor Author

vorner commented Sep 9, 2017

Hmm. But they passed locally. I'll have to experiment a bit to see what's wrong :-|.

Maybe, can the rustc_* attributes act a bit differently? Because I got an error message about them and it talked about rustc diagnostics ‒ and I don't think this is really a diagnostic.

@vorner
Copy link
Contributor Author

vorner commented Sep 9, 2017

Hm. Apparently not caused by the name of the flag.

@alexcrichton
Copy link
Member

CI's still failing?

@vorner
Copy link
Contributor Author

vorner commented Sep 9, 2017

Yes, there must be some bug. I didn't find the time to look into it properly yet, I didn't even manage to reproduce it locally (does ./x.py test run all tests?)

Anyway, I'll have a look once I get some time.

@alexcrichton
Copy link
Member

Yes ./x.py test should run those tests.

@bors
Copy link
Contributor

bors commented Sep 10, 2017

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

Annotate the allocator crates (allocator_system, allocator_jemalloc) by
the type of allocator they are. If one is requested as an exe allocator,
detect its type by the flags.

This has the effect that using this (de jure wrong) configuration in the
target spec works instead of producing a really unhelpful and arcane
linker error:

"exe-allocation-crate": "alloc_system"

Fixes #43524.
@vorner
Copy link
Contributor Author

vorner commented Sep 11, 2017

I'm trying something, if the checks pass. No need to review yet, I have a theory I want to confirm first.

@vorner
Copy link
Contributor Author

vorner commented Sep 12, 2017

Good, the tests passed, so I think it is ready for another round of review.

I apologize for rewriting the whole branch, so the latest changes aren't easily seen, but it kind of happened during solving the conflicts. The important change is in src/librustc_metadata/creader.rs:1004. Now I default to AllocatorKind::DefaultLib when the allocator crate doesn't contain the attribute.

I'm not sure why that happens on the build bot and why it doesn't happen to me locally, but it seems the build bot sometimes links with the libraries before modification. Is that possible? Anyway, the fact that switching it around would explain why it failed previously with the error it did and why it doesn't fail now.

@alexcrichton
Copy link
Member

@bors: r+

Looks good to me, thanks!

@bors
Copy link
Contributor

bors commented Sep 12, 2017

📌 Commit 94297c6 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Sep 12, 2017

⌛ Testing commit 94297c6 with merge dd08c30...

bors added a commit that referenced this pull request Sep 12, 2017
Autodetect the type of allocator crate used

Annotate the allocator crates (allocator_system, allocator_jemalloc) by the type of allocator they are. If one is requested as an exe allocator, detect its type by the flags.

This has the effect that using this (de jure wrong) configuration in the target spec works instead of producing a really unhelpful and arcane linker error:

"exe-allocation-crate": "alloc_system"

Fixes #43524.

There are two yet unsolved FIXME's, I'll be glad for some advice on what to do with them.
@bors
Copy link
Contributor

bors commented Sep 12, 2017

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

@bors bors merged commit 94297c6 into rust-lang:master Sep 12, 2017
@vorner vorner deleted the allocator-kind-autodetect branch December 3, 2017 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants