Repository navigation
Add some docs to Global
#163332
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
Add some docs to Global
#163332
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the implication that it's OK to
Global.allocateand then std::alloc::deallocate that memory? I would expect that to not be the case. I think it definitely shouldn't be guaranteed that you canGlobal.allocateandSystem.deallocate, even if #[global_allocator] = System.View changes since the review
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That must be the case, since otherwise the guarantees made by
Boxabout this are broken, unless we special case around it by saying "if you go to aBox(orVec) first, then you canalloc::deallocorGlobal.deallocate". But at that point we might as well just guarantee this.In particular, we allow you to create
Box<T, Global>usingalloc::alloc()andfrom_raw. Likewise for its allocator obviously. OTOH, we allow you to deallocate it usinginto_rawandalloc::dealloc, and obviously using its allocator.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note this is specifically for
Global, not for anything that is equivalent toGlobal, like that example. The goal is to deprecate these methods explicitly in favour of methods onGlobal, so, it's useful to say they're identical.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also note that using the allocator you registered as the global allocator (e.g.
System) to deallocate stuff fromGlobal/alloc::alloc(...)is never allowed. Does my text insinuate that? If so, it needs to be fixedThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be worth making sure that these lines from
std::alloc::allocis copied here (or into doc comments on allocate/deallocate):and:
I think that last paragraph at least implies you can't
std::alloc::alloc()and then<Global as GlobalAlloc>::dealloc(...)-- perhaps the right thing is to rephrase it, alongside any coping done?It may be worth expanding the documentation at the top level (
std::alloc):This saying something about the relationship of methods from:
I believe we annotate some of these functions to LLVM -- maybe just the inner functions that we eventually call though? -- and given the proliferation of ways to reach the #[global_allocator] it seems worth documenting some more details.
I'm not sure if the text here insinuates you can interchange with System, but IMO we have a bunch of documentation around this that is not as clear as it used to be (in part due to added indirection and added Allocator stabilization), and probably was never crystal clear.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, we can do that
Globalis not the underlyingGlobalAllocallocator. In factGlobaldoes not implementGlobalAlloc. If it did, it would create an infinite loop when registered as the global allocator.Globalis the allocator that invokes the registered#[global_allocator]through the free standing allocation functions inalloc, and is therefore equivalent to them. In particular, as contradictory as that might sound,Globalis never a global allocator.