fn grant(
        &mut self,
        derived_from: SbTag,
        new: Item,
        (alloc_id, alloc_range, offset): (AllocId, AllocRange, Size), // just for debug printing and error messages
        global: &GlobalState,
    ) -> InterpResult<'tcx> {
        // Figure out which access `perm` corresponds to.
        let access =
            if new.perm.grants(AccessKind::Write) { AccessKind::Write } else { AccessKind::Read };
        // Now we figure out which item grants our parent (`derived_from`) this kind of access.
        // We use that to determine where to put the new item.
        let granting_idx = self
            .find_granting(access, derived_from)
            .ok_or_else(|| self.grant_error(derived_from, new, alloc_id, alloc_range, offset))?;

        // Compute where to put the new item.
        // Either way, we ensure that we insert the new item in a way such that between
        // `derived_from` and the new one, there are only items *compatible with* `derived_from`.
        let new_idx = if new.perm == Permission::SharedReadWrite {
            assert!(
                access == AccessKind::Write,
                "this case only makes sense for stack-like accesses"
            );
            // SharedReadWrite can coexist with "existing loans", meaning they don't act like a write
            // access.  Instead of popping the stack, we insert the item at the place the stack would
            // be popped to (i.e., we insert it above all the write-compatible items).
            // This ensures F2b by adding the new item below any potentially existing `SharedReadOnly`.
            self.find_first_write_incompatible(granting_idx)
        } else {
            // A "safe" reborrow for a pointer that actually expects some aliasing guarantees.
            // Here, creating a reference actually counts as an access.
            // This ensures F2b for `Unique`, by removing offending `SharedReadOnly`.
            self.access(access, derived_from, (alloc_id, alloc_range, offset), global)?;

            // We insert "as far up as possible": We know only compatible items are remaining
            // on top of `derived_from`, and we want the new item at the top so that we
            // get the strongest possible guarantees.
            // This ensures U1 and F1.
            self.borrows.len()
        };

        // Put the new item there. As an optimization, deduplicate if it is equal to one of its new neighbors.
        if self.borrows[new_idx - 1] == new || self.borrows.get(new_idx) == Some(&new) {
            // Optimization applies, done.
            trace!("reborrow: avoiding adding redundant item {:?}", new);
        } else {
            trace!("reborrow: adding item {:?}", new);
            self.borrows.insert(new_idx, new);
        }

        Ok(())
    }
/// Derive a new pointer from one with the given tag.
/// `weak` controls whether this operation is weak or strong: weak granting does not act as
/// an access, and they add the new item directly on top of the one it is derived
/// from instead of all the way at the top of the stack.
/// `range` refers the entire operation, and `offset` refers to the specific location in
/// `range` that we are currently checking.
Derive a new pointer from one with the given tag.
`weak` controls whether this operation is weak or strong: weak granting does not act as
an access, and they add the new item directly on top of the one it is derived
from instead of all the way at the top of the stack.
Derive a new pointer from one with the given tag . ` weak ` controls whether this operation is weak or strong : weak granting does not act as an access and they add the new item directly on top of the one it is derived from instead of all the way at the top of the stack .
fn grant(
        &mut self,
        derived_from: SbTag,
        new: Item,
        (alloc_id, alloc_range, offset): (AllocId, AllocRange, Size), // just for debug printing and error messages
        global: &GlobalState,
    ) -> InterpResult<'tcx> {
        // Figure out which access `perm` corresponds to.
        let access =
            if new.perm.grants(AccessKind::Write) { AccessKind::Write } else { AccessKind::Read };
        // Now we figure out which item grants our parent (`derived_from`) this kind of access.
        // We use that to determine where to put the new item.
        let granting_idx = self
            .find_granting(access, derived_from)
            .ok_or_else(|| self.grant_error(derived_from, new, alloc_id, alloc_range, offset))?;
        // Compute where to put the new item.
        // Either way, we ensure that we insert the new item in a way such that between
        // `derived_from` and the new one, there are only items *compatible with* `derived_from`.
        let new_idx = if new.perm == Permission::SharedReadWrite {
            assert!(
                access == AccessKind::Write,
                "this case only makes sense for stack-like accesses"
            );
            // SharedReadWrite can coexist with "existing loans", meaning they don't act like a write
            // access.  Instead of popping the stack, we insert the item at the place the stack would
            // be popped to (i.e., we insert it above all the write-compatible items).
            // This ensures F2b by adding the new item below any potentially existing `SharedReadOnly`.
            self.find_first_write_incompatible(granting_idx)
        } else {
            // A "safe" reborrow for a pointer that actually expects some aliasing guarantees.
            // Here, creating a reference actually counts as an access.
            // This ensures F2b for `Unique`, by removing offending `SharedReadOnly`.
            self.access(access, derived_from, (alloc_id, alloc_range, offset), global)?;
            // We insert "as far up as possible": We know only compatible items are remaining
            // on top of `derived_from`, and we want the new item at the top so that we
            // get the strongest possible guarantees.
            // This ensures U1 and F1.
            self.borrows.len()
        };
        // Put the new item there. As an optimization, deduplicate if it is equal to one of its new neighbors.
        if self.borrows[new_idx - 1] == new || self.borrows.get(new_idx) == Some(&new) {
            // Optimization applies, done.
            trace!("reborrow: avoiding adding redundant item {:?}", new);
        } else {
            trace!("reborrow: adding item {:?}", new);
            self.borrows.insert(new_idx, new);
        }
        Ok(())
    }
fn grant ( & mut self , derived_from : SbTag , new : Item , ( alloc_id , alloc_range , offset ) : ( AllocId , AllocRange , Size ) , // just for debug printing and error messages global : & GlobalState , ) -> InterpResult < ' tcx > { // Figure out which access `perm` corresponds to. let access = if new . perm . grants ( AccessKind :: Write ) { AccessKind :: Write } else { AccessKind :: Read } ; // Now we figure out which item grants our parent (`derived_from`) this kind of access. // We use that to determine where to put the new item. let granting_idx = self . find_granting ( access , derived_from ) . ok_or_else ( | | self . grant_error ( derived_from , new , alloc_id , alloc_range , offset ) ) ? ; // Compute where to put the new item. // Either way, we ensure that we insert the new item in a way such that between // `derived_from` and the new one, there are only items *compatible with* `derived_from`. let new_idx = if new . perm == Permission :: SharedReadWrite { assert ! ( access AccessKind Write " " ) ; // SharedReadWrite can coexist with "existing loans", meaning they don't act like a write // access.  Instead of popping the stack, we insert the item at the place the stack would // be popped to (i.e., we insert it above all the write-compatible items). // This ensures F2b by adding the new item below any potentially existing `SharedReadOnly`. self . find_first_write_incompatible ( granting_idx ) } else { // A "safe" reborrow for a pointer that actually expects some aliasing guarantees. // Here, creating a reference actually counts as an access. // This ensures F2b for `Unique`, by removing offending `SharedReadOnly`. self . access ( access , derived_from , ( alloc_id , alloc_range , offset ) , global ) ? ; // We insert "as far up as possible": We know only compatible items are remaining // on top of `derived_from`, and we want the new item at the top so that we // get the strongest possible guarantees. // This ensures U1 and F1. self . borrows . len ( ) } ; // Put the new item there. As an optimization, deduplicate if it is equal to one of its new neighbors. if self . borrows [ new_idx - 1 ] == new || self . borrows . get ( new_idx ) == Some ( & new ) { // Optimization applies, done. trace ! ( " " new ) ; } else { trace ! ( " " new ) ; self . borrows . insert ( new_idx , new ) ; } Ok ( ( ) ) }
Derive a new pointer from one with the given tag.
Derive a new pointer from one with the given tag .
&mut self
derived_from
SbTag
new
(AllocId, AllocRange, Size)
global
&GlobalState