Skip to content

Commit fde7c54

Browse files
authored
Fix the downcast in create_mygc_mutator (#399)
1 parent f1655d8 commit fde7c54

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

docs/tutorial/code/mygc_semispace/mutator.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// ANCHOR: imports
22
use super::MyGC; // Add
3+
use crate::Plan;
34
use crate::plan::barriers::NoBarrier;
45
use crate::plan::mutator_context::Mutator;
56
use crate::plan::mutator_context::MutatorConfig;
@@ -59,19 +60,22 @@ lazy_static! {
5960

6061
pub fn create_mygc_mutator<VM: VMBinding>(
6162
mutator_tls: VMMutatorThread,
62-
plan: &'static MyGC<VM>,
63+
plan: &'static dyn Plan<VM = VM>,
6364
) -> Mutator<VM> {
65+
// ANCHOR: plan_downcast
66+
let mygc = plan.downcast_ref::<MyGC<VM>>().unwrap();
67+
// ANCHOR_END: plan_downcast
6468
let config = MutatorConfig {
6569
allocator_mapping: &*ALLOCATOR_MAPPING,
6670
// Modify
6771
// ANCHOR: space_mapping
6872
space_mapping: box vec![
69-
(AllocatorSelector::BumpPointer(0), plan.tospace()),
73+
(AllocatorSelector::BumpPointer(0), mygc.tospace()),
7074
(
7175
AllocatorSelector::BumpPointer(1),
72-
plan.common.get_immortal(),
76+
mygc.common.get_immortal(),
7377
),
74-
(AllocatorSelector::LargeObject(0), plan.common.get_los()),
78+
(AllocatorSelector::LargeObject(0), mygc.common.get_los()),
7579
],
7680
// ANCHOR_END: space_mapping
7781
prepare_func: &mygc_mutator_prepare, // Modify

docs/tutorial/src/mygc/ss/alloc.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,17 @@ space in `space_mapping`. Note that the space allocation is formatted as a list
189189
of tuples. For example, the first bump pointer allocator (`BumpPointer(0)`) is
190190
bound with `tospace`.
191191

192+
Downcast the dynamic `Plan` type to `MyGC` so we can access specific spaces in `MyGC`.
193+
194+
```rust
195+
{{#include ../../../code/mygc_semispace/mutator.rs:plan_downcast}}
196+
```
197+
198+
Then, use `mygc` to access the spaces in `MyGC`.
199+
192200
1. `BumpPointer(0)` should map to the tospace.
193-
2. `BumpPointer(1)` should map to `plan.common.get_immortal()`.
194-
3. `LargeObject(0)` should map to `plan.common.get_los()`.
201+
2. `BumpPointer(1)` should map to `mygc.common.get_immortal()`.
202+
3. `LargeObject(0)` should map to `mygc.common.get_los()`.
195203
4. None of the above should be dereferenced (ie, they should not have
196204
the `&` prefix).
197205

0 commit comments

Comments
 (0)