-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add support for global allocation in smir #118012
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod alloc; | ||
mod body; | ||
pub mod mono; | ||
pub mod pretty; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
//! This module provides methods to retrieve allocation information, such as static variables. | ||
use crate::mir::mono::{Instance, StaticDef}; | ||
use crate::ty::{Allocation, Binder, ExistentialTraitRef, IndexedVal, Ty}; | ||
use crate::with; | ||
|
||
/// An allocation in the SMIR global memory can be either a function pointer, | ||
/// a static, or a "real" allocation with some data in it. | ||
#[derive(Debug, Clone, Eq, PartialEq)] | ||
pub enum GlobalAlloc { | ||
/// The alloc ID is used as a function pointer. | ||
Function(Instance), | ||
/// This alloc ID points to a symbolic (not-reified) vtable. | ||
/// The `None` trait ref is used to represent auto traits. | ||
VTable(Ty, Option<Binder<ExistentialTraitRef>>), | ||
/// The alloc ID points to a "lazy" static variable that did not get computed (yet). | ||
/// This is also used to break the cycle in recursive statics. | ||
Static(StaticDef), | ||
/// The alloc ID points to memory. | ||
Memory(Allocation), | ||
} | ||
|
||
impl From<AllocId> for GlobalAlloc { | ||
fn from(value: AllocId) -> Self { | ||
with(|cx| cx.global_alloc(value)) | ||
} | ||
} | ||
|
||
impl GlobalAlloc { | ||
/// Retrieve the allocation id for a global allocation if it exists. | ||
/// | ||
/// For `[GlobalAlloc::VTable]`, this will return the allocation for the VTable of the given | ||
/// type for the optional trait if the type implements the trait. | ||
/// | ||
/// This method will always return `None` for allocations other than `[GlobalAlloc::VTable]`. | ||
pub fn vtable_allocation(&self) -> Option<AllocId> { | ||
with(|cx| cx.vtable_allocation(self)) | ||
} | ||
} | ||
|
||
/// A unique identification number for each provenance | ||
#[derive(Clone, Copy, PartialEq, Eq, Debug)] | ||
pub struct AllocId(usize); | ||
|
||
impl IndexedVal for AllocId { | ||
fn to_val(index: usize) -> Self { | ||
AllocId(index) | ||
} | ||
fn to_index(&self) -> usize { | ||
self.0 | ||
} | ||
} |
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.