Skip to content

Commit 09be027

Browse files
committed
WIP PROOF-OF-CONCEPT handle all the fallout in rustc
Why does rustc do oh so many crimes? Oh so many...
1 parent 701aa6c commit 09be027

File tree

11 files changed

+37
-10
lines changed

11 files changed

+37
-10
lines changed

compiler/rustc_arena/src/lib.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#![feature(decl_macro)]
1919
#![feature(rustc_attrs)]
2020
#![cfg_attr(test, feature(test))]
21+
#![feature(strict_provenance)]
2122

2223
use smallvec::SmallVec;
2324

@@ -87,7 +88,7 @@ impl<T> ArenaChunk<T> {
8788
unsafe {
8889
if mem::size_of::<T>() == 0 {
8990
// A pointer as large as possible for zero-sized elements.
90-
!0 as *mut T
91+
ptr::invalid_mut(!0)
9192
} else {
9293
self.start().add(self.storage.len())
9394
}
@@ -199,7 +200,7 @@ impl<T> TypedArena<T> {
199200
unsafe {
200201
if mem::size_of::<T>() == 0 {
201202
self.ptr.set((self.ptr.get() as *mut u8).wrapping_offset(1) as *mut T);
202-
let ptr = mem::align_of::<T>() as *mut T;
203+
let ptr = ptr::NonNull::<T>::dangling().as_ptr();
203204
// Don't drop the object. This `write` is equivalent to `forget`.
204205
ptr::write(ptr, object);
205206
&mut *ptr
@@ -216,7 +217,7 @@ impl<T> TypedArena<T> {
216217

217218
#[inline]
218219
fn can_allocate(&self, additional: usize) -> bool {
219-
let available_bytes = self.end.get() as usize - self.ptr.get() as usize;
220+
let available_bytes = self.end.get().addr() - self.ptr.get().addr();
220221
let additional_bytes = additional.checked_mul(mem::size_of::<T>()).unwrap();
221222
available_bytes >= additional_bytes
222223
}
@@ -262,7 +263,7 @@ impl<T> TypedArena<T> {
262263
// If a type is `!needs_drop`, we don't need to keep track of how many elements
263264
// the chunk stores - the field will be ignored anyway.
264265
if mem::needs_drop::<T>() {
265-
let used_bytes = self.ptr.get() as usize - last_chunk.start() as usize;
266+
let used_bytes = self.ptr.get().addr() - last_chunk.start().addr();
266267
last_chunk.entries = used_bytes / mem::size_of::<T>();
267268
}
268269

@@ -288,9 +289,9 @@ impl<T> TypedArena<T> {
288289
// chunks.
289290
fn clear_last_chunk(&self, last_chunk: &mut ArenaChunk<T>) {
290291
// Determine how much was filled.
291-
let start = last_chunk.start() as usize;
292+
let start = last_chunk.start().addr();
292293
// We obtain the value of the pointer to the first uninitialized element.
293-
let end = self.ptr.get() as usize;
294+
let end = self.ptr.get().addr();
294295
// We then calculate the number of elements to be dropped in the last chunk,
295296
// which is the filled area's length.
296297
let diff = if mem::size_of::<T>() == 0 {
@@ -395,15 +396,16 @@ impl DroplessArena {
395396
/// request.
396397
#[inline]
397398
fn alloc_raw_without_grow(&self, layout: Layout) -> Option<*mut u8> {
398-
let start = self.start.get() as usize;
399-
let end = self.end.get() as usize;
399+
let start = self.start.get().addr();
400+
let old_end = self.end.get();
401+
let end = old_end.addr();
400402

401403
let align = layout.align();
402404
let bytes = layout.size();
403405

404406
let new_end = end.checked_sub(bytes)? & !(align - 1);
405407
if start <= new_end {
406-
let new_end = new_end as *mut u8;
408+
let new_end = old_end.with_addr(new_end);
407409
self.end.set(new_end);
408410
Some(new_end)
409411
} else {

compiler/rustc_codegen_ssa/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(once_cell)]
77
#![feature(nll)]
88
#![feature(associated_type_bounds)]
9+
#![feature(strict_provenance)]
910
#![recursion_limit = "256"]
1011
#![allow(rustc::potential_query_instability)]
1112

compiler/rustc_codegen_ssa/src/mono_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
116116
fn to_raw_string(&self) -> String {
117117
match *self {
118118
MonoItem::Fn(instance) => {
119-
format!("Fn({:?}, {})", instance.def, instance.substs.as_ptr() as usize)
119+
format!("Fn({:?}, {})", instance.def, instance.substs.as_ptr().addr())
120120
}
121121
MonoItem::Static(id) => format!("Static({:?})", id),
122122
MonoItem::GlobalAsm(id) => format!("GlobalAsm({:?})", id),

compiler/rustc_data_structures/src/tagged_ptr.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(strict_provenance_magic): rustc is grounded for pointer crimes.
2+
#![cfg_attr(not(bootstrap), allow(fuzzy_provenance_casts))]
3+
14
//! This module implements tagged pointers.
25
//!
36
//! In order to utilize the pointer packing, you must have two types: a pointer,

compiler/rustc_interface/src/util.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(strict_provenance_magic): rustc is grounded for pointer crimes.
2+
#![cfg_attr(not(bootstrap), allow(fuzzy_provenance_casts))]
3+
14
use libloading::Library;
25
use rustc_ast as ast;
36
use rustc_codegen_ssa::traits::CodegenBackend;

compiler/rustc_middle/src/ty/adt.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(strict_provenance_magic): rustc is grounded for pointer crimes.
2+
#![cfg_attr(not(bootstrap), allow(fuzzy_provenance_casts))]
3+
14
use crate::mir::interpret::ErrorHandled;
25
use crate::ty;
36
use crate::ty::util::{Discr, IntTypeExt};

compiler/rustc_middle/src/ty/context.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//! Type context book-keeping.
22
3+
// FIXME(strict_provenance_magic): rustc is grounded for pointer crimes.
4+
#![cfg_attr(not(bootstrap), allow(fuzzy_provenance_casts))]
5+
36
use crate::arena::Arena;
47
use crate::dep_graph::{DepGraph, DepKind, DepKindStruct};
58
use crate::hir::place::Place as HirPlace;

compiler/rustc_middle/src/ty/impls_ty.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
//! This module contains `HashStable` implementations for various data types
22
//! from `rustc_middle::ty` in no particular order.
33
4+
// FIXME(strict_provenance_magic): rustc is grounded for pointer crimes.
5+
#![cfg_attr(not(bootstrap), allow(fuzzy_provenance_casts))]
6+
47
use crate::middle::region;
58
use crate::mir;
69
use crate::ty;

compiler/rustc_middle/src/ty/list.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(strict_provenance_magic): rustc is grounded for pointer crimes.
2+
#![cfg_attr(not(bootstrap), allow(fuzzy_provenance_casts))]
3+
14
use crate::arena::Arena;
25
use rustc_serialize::{Encodable, Encoder};
36
use std::alloc::Layout;

compiler/rustc_middle/src/ty/subst.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// Type substitutions.
22

3+
// FIXME(strict_provenance_magic): rustc is grounded for pointer crimes.
4+
#![cfg_attr(not(bootstrap), allow(fuzzy_provenance_casts))]
5+
36
use crate::mir;
47
use crate::ty::codec::{TyDecoder, TyEncoder};
58
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeVisitor};

compiler/rustc_parse/src/parser/expr.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(strict_provenance_magic): rustc is grounded for pointer crimes.
2+
#![cfg_attr(not(bootstrap), allow(fuzzy_provenance_casts))]
3+
14
use super::diagnostics::SnapshotParser;
25
use super::pat::{CommaRecoveryMode, RecoverColon, RecoverComma, PARAM_EXPECTED};
36
use super::ty::{AllowPlus, RecoverQPath, RecoverReturnSign};

0 commit comments

Comments
 (0)