From 59985157d3931861a709ff610b22114442aac9ba Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 30 Apr 2019 13:48:16 +0200 Subject: [PATCH 1/2] SharedReadOnly reborrows are never weak --- src/stacked_borrows.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/stacked_borrows.rs b/src/stacked_borrows.rs index bac35796ed13..c2e4c72fb73d 100644 --- a/src/stacked_borrows.rs +++ b/src/stacked_borrows.rs @@ -400,6 +400,9 @@ impl<'tcx> Stack { // Either way, we ensure that we insert the new item in a way that between // `derived_from` and the new one, there are only items *compatible with* `derived_from`. let new_idx = if weak { + // A weak ShareadReadOnly reborrow might be added below other items, violating the + // invariant that only SharedReadOnly can sit on top of SharedReadOnly. + assert!(new.perm != Permission::SharedReadOnly, "Weak ShareadReadOnly reborrows don't work"); // A very liberal reborrow because the new pointer does not expect any kind of aliasing guarantee. // Just insert new permission as child of old permission, and maintain everything else. // This inserts "as far down as possible", which is good because it makes this pointer as @@ -581,8 +584,8 @@ trait EvalContextPrivExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a, // We need a frozen-sensitive reborrow. return this.visit_freeze_sensitive(place, size, |cur_ptr, size, frozen| { // We are only ever `SharedReadOnly` inside the frozen bits. - let weak = !frozen || kind != RefKind::Shared; // `RefKind::Raw` is always weak, as is `SharedReadWrite`. let perm = if frozen { Permission::SharedReadOnly } else { Permission::SharedReadWrite }; + let weak = perm == Permission::SharedReadWrite; let item = Item { perm, tag: new_tag, protector }; alloc.extra.for_each(cur_ptr, size, |stack, global| { stack.reborrow(cur_ptr.tag, force_weak || weak, item, global) From 17643af868c0310ec23c64d729e2f75ff19f21c7 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 30 Apr 2019 15:31:53 +0200 Subject: [PATCH 2/2] Apply suggestions from code review Co-Authored-By: RalfJung --- src/stacked_borrows.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stacked_borrows.rs b/src/stacked_borrows.rs index c2e4c72fb73d..2b4034d73137 100644 --- a/src/stacked_borrows.rs +++ b/src/stacked_borrows.rs @@ -400,9 +400,9 @@ impl<'tcx> Stack { // Either way, we ensure that we insert the new item in a way that between // `derived_from` and the new one, there are only items *compatible with* `derived_from`. let new_idx = if weak { - // A weak ShareadReadOnly reborrow might be added below other items, violating the + // A weak SharedReadOnly reborrow might be added below other items, violating the // invariant that only SharedReadOnly can sit on top of SharedReadOnly. - assert!(new.perm != Permission::SharedReadOnly, "Weak ShareadReadOnly reborrows don't work"); + assert!(new.perm != Permission::SharedReadOnly, "Weak SharedReadOnly reborrows don't work"); // A very liberal reborrow because the new pointer does not expect any kind of aliasing guarantee. // Just insert new permission as child of old permission, and maintain everything else. // This inserts "as far down as possible", which is good because it makes this pointer as