Skip to content

Commit

Permalink
Auto merge of rust-lang#113166 - moulins:ref-niches-initial, r=oli-obk
Browse files Browse the repository at this point in the history
Prototype: Add unstable `-Z reference-niches` option

MCP: rust-lang/compiler-team#641
Relevant RFC: rust-lang/rfcs#3204

This prototype adds a new `-Z reference-niches` option, controlling the range of valid bit-patterns for reference types (`&T` and `&mut T`), thereby enabling new enum niching opportunities. Like `-Z randomize-layout`, this setting is crate-local; as such, references to built-in types (primitives, tuples, ...) are not affected.

The possible settings are (here, `MAX` denotes the all-1 bit-pattern):
| `-Z reference-niches=` | Valid range |
|:---:|:---:|
| `null` (the default) | `1..=MAX` |
| `size` | `1..=(MAX- size)` |
| `align` | `align..=MAX.align_down_to(align)` |
| `size,align` | `align..=(MAX-size).align_down_to(align)` |

------

This is very WIP, and I'm not sure the approach I've taken here is the best one, but stage 1 tests pass locally; I believe this is in a good enough state to unleash this upon unsuspecting 3rd-party code, and see what breaks.
  • Loading branch information
bors committed Jul 21, 2023
2 parents c022c81 + 1984e20 commit e865542
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
return pointee;
}

let result = Ty::ty_and_layout_pointee_info_at(*self, cx, offset);
let assume_valid_ptr = true;
let result = Ty::ty_and_layout_pointee_info_at(*self, cx, offset, assume_valid_ptr);

cx.pointee_infos.borrow_mut().insert((self.ty, offset), result);
result
Expand Down

0 comments on commit e865542

Please sign in to comment.