Skip to content

Some refactoring around intrinsic type checking #73834

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions src/librustc_span/symbol.rs
Original file line number Diff line number Diff line change
@@ -152,10 +152,14 @@ symbols! {
arm_target_feature,
asm,
assert,
assert_inhabited,
assert_uninit_valid,
assert_zero_valid,
associated_consts,
associated_type_bounds,
associated_type_defaults,
associated_types,
assume,
assume_init,
async_await,
async_closure,
@@ -181,11 +185,14 @@ symbols! {
box_patterns,
box_syntax,
braced_empty_structs,
breakpoint,
bswap,
bitreverse,
C,
caller_location,
cdylib,
ceilf32,
ceilf64,
cfg,
cfg_accessible,
cfg_attr,
@@ -239,8 +246,14 @@ symbols! {
convert,
Copy,
copy_closures,
copy,
copy_nonoverlapping,
copysignf32,
copysignf64,
core,
core_intrinsics,
cosf32,
cosf64,
count_code_region,
coverage_counter_add,
coverage_counter_subtract,
@@ -299,6 +312,7 @@ symbols! {
dropck_eyepatch,
dropck_parametricity,
drop_types_in_const,
drop_in_place,
dylib,
dyn_trait,
eh_personality,
@@ -311,11 +325,16 @@ symbols! {
Eq,
Equal,
enclosing_scope,
exact_div,
except,
exclusive_range_pattern,
exhaustive_integer_patterns,
exhaustive_patterns,
existential_type,
expf32,
expf64,
exp2f32,
exp2f64,
expected,
export_name,
expr,
@@ -329,20 +348,32 @@ symbols! {
f16c_target_feature,
f32,
f64,
fadd_fast,
fabsf32,
fabsf64,
fdiv_fast,
feature,
ffi_const,
ffi_pure,
ffi_returns_twice,
field,
field_init_shorthand,
file,
float_to_int_unchecked,
floorf64,
floorf32,
fmaf32,
fmaf64,
fmt,
fmt_internals,
fmul_fast,
fn_must_use,
forbid,
forget,
format_args,
format_args_nl,
format_args_capture,
frem_fast,
from,
From,
from_desugaring,
@@ -352,6 +383,7 @@ symbols! {
from_ok,
from_usize,
from_trait,
fsub_fast,
fundamental,
future,
Future,
@@ -448,6 +480,12 @@ symbols! {
llvm_asm,
local_inner_macros,
log_syntax,
logf32,
logf64,
log10f32,
log10f64,
log2f32,
log2f64,
loop_break_value,
macro_at_most_once_rep,
macro_escape,
@@ -475,10 +513,16 @@ symbols! {
message,
meta,
min_align_of,
min_align_of_val,
min_const_fn,
min_const_unsafe_fn,
min_specialization,
minnumf32,
minnumf64,
maxnumf32,
maxnumf64,
mips_target_feature,
miri_start_panic,
mmx_target_feature,
module,
module_path,
@@ -491,6 +535,8 @@ symbols! {
naked,
naked_functions,
name,
nearbyintf32,
nearbyintf64,
needs_allocator,
needs_drop,
needs_panic_runtime,
@@ -518,6 +564,7 @@ symbols! {
None,
non_exhaustive,
non_modrs_mods,
nontemporal_store,
nontrapping_fptoint: "nontrapping-fptoint",
noreturn,
no_niche,
@@ -577,8 +624,16 @@ symbols! {
poll,
Poll,
powerpc_target_feature,
powf32,
powf64,
powif32,
powif64,
precise_pointer_size_matching,
pref_align_of,
prefetch_read_data,
prefetch_read_instruction,
prefetch_write_data,
prefetch_write_instruction,
prelude,
prelude_import,
preserves_flags,
@@ -640,10 +695,14 @@ symbols! {
Result,
Return,
rhs,
rintf32,
rintf64,
riscv_target_feature,
rlib,
rotate_left,
rotate_right,
roundf32,
roundf64,
rt,
rtm_target_feature,
rust,
@@ -726,14 +785,19 @@ symbols! {
simd_ffi,
simd_insert,
since,
sinf32,
sinf64,
size,
size_of,
size_of_val,
slice_patterns,
slicing_syntax,
soft,
Some,
specialization,
speed,
sqrtf32,
sqrtf64,
sse4a_target_feature,
stable,
staged_api,
@@ -787,6 +851,8 @@ symbols! {
transparent_enums,
transparent_unions,
trivial_bounds,
truncf32,
truncf64,
Try,
try_blocks,
try_trait,
@@ -809,6 +875,8 @@ symbols! {
u32,
u64,
u8,
unaligned_volatile_load,
unaligned_volatile_store,
unboxed_closures,
unchecked_add,
unchecked_div,
@@ -824,6 +892,7 @@ symbols! {
universal_impl_trait,
unlikely,
unmarked_api,
unreachable,
unreachable_code,
unrestricted_attribute_tokens,
unsafe_block_in_unsafe_fn,
@@ -843,12 +912,21 @@ symbols! {
val,
var,
variant_count,
va_arg,
va_copy,
va_end,
va_start,
vec,
Vec,
version,
vis,
visible_private_types,
volatile,
volatile_copy_memory,
volatile_copy_nonoverlapping_memory,
volatile_load,
volatile_set_memory,
volatile_store,
warn,
wasm_import_module,
wasm_target_feature,
@@ -858,6 +936,7 @@ symbols! {
wrapping_add,
wrapping_sub,
wrapping_mul,
write_bytes,
Yield,
}
}
263 changes: 149 additions & 114 deletions src/librustc_typeck/check/intrinsic.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
@@ -2063,7 +2063,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
ident: Ident,
) -> ty::PolyFnSig<'tcx> {
let unsafety = if abi == abi::Abi::RustIntrinsic {
intrinsic_operation_unsafety(&tcx.item_name(def_id).as_str())
intrinsic_operation_unsafety(tcx.item_name(def_id))
} else {
hir::Unsafety::Unsafe
};
18 changes: 9 additions & 9 deletions src/test/ui/mir-dataflow/def-inits-1.rs
Original file line number Diff line number Diff line change
@@ -11,13 +11,13 @@ struct S(i32);
fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
let ret;
// `ret` starts off uninitialized
unsafe { rustc_peek(&ret); } //~ ERROR rustc_peek: bit not set
rustc_peek(&ret); //~ ERROR rustc_peek: bit not set

// All function formal parameters start off initialized.

unsafe { rustc_peek(&x) };
unsafe { rustc_peek(&y) };
unsafe { rustc_peek(&z) };
rustc_peek(&x);
rustc_peek(&y);
rustc_peek(&z);

ret = if test {
::std::mem::replace(x, y)
@@ -27,21 +27,21 @@ fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
};

// `z` may be uninitialized here.
unsafe { rustc_peek(&z); } //~ ERROR rustc_peek: bit not set
rustc_peek(&z); //~ ERROR rustc_peek: bit not set

// `y` is definitely uninitialized here.
unsafe { rustc_peek(&y); } //~ ERROR rustc_peek: bit not set
rustc_peek(&y); //~ ERROR rustc_peek: bit not set

// `x` is still (definitely) initialized (replace above is a reborrow).
unsafe { rustc_peek(&x); }
rustc_peek(&x);

::std::mem::drop(x);

// `x` is *definitely* uninitialized here
unsafe { rustc_peek(&x); } //~ ERROR rustc_peek: bit not set
rustc_peek(&x); //~ ERROR rustc_peek: bit not set

// `ret` is now definitely initialized (via `if` above).
unsafe { rustc_peek(&ret); }
rustc_peek(&ret);

ret
}
24 changes: 12 additions & 12 deletions src/test/ui/mir-dataflow/def-inits-1.stderr
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
error: rustc_peek: bit not set
--> $DIR/def-inits-1.rs:14:14
--> $DIR/def-inits-1.rs:14:5
|
LL | unsafe { rustc_peek(&ret); }
| ^^^^^^^^^^^^^^^^
LL | rustc_peek(&ret);
| ^^^^^^^^^^^^^^^^

error: rustc_peek: bit not set
--> $DIR/def-inits-1.rs:30:14
--> $DIR/def-inits-1.rs:30:5
|
LL | unsafe { rustc_peek(&z); }
| ^^^^^^^^^^^^^^
LL | rustc_peek(&z);
| ^^^^^^^^^^^^^^

error: rustc_peek: bit not set
--> $DIR/def-inits-1.rs:33:14
--> $DIR/def-inits-1.rs:33:5
|
LL | unsafe { rustc_peek(&y); }
| ^^^^^^^^^^^^^^
LL | rustc_peek(&y);
| ^^^^^^^^^^^^^^

error: rustc_peek: bit not set
--> $DIR/def-inits-1.rs:41:14
--> $DIR/def-inits-1.rs:41:5
|
LL | unsafe { rustc_peek(&x); }
| ^^^^^^^^^^^^^^
LL | rustc_peek(&x);
| ^^^^^^^^^^^^^^

error: stop_after_dataflow ended compilation

2 changes: 1 addition & 1 deletion src/test/ui/mir-dataflow/indirect-mutation-offset.rs
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ const BOO: i32 = {

*rmut_cell = 42; // Mutates `x` indirectly even though `x` is not marked indirectly mutable!!!
let val = *rmut_cell;
unsafe { rustc_peek(x) }; //~ ERROR rustc_peek: bit not set
rustc_peek(x); //~ ERROR rustc_peek: bit not set

val
};
6 changes: 3 additions & 3 deletions src/test/ui/mir-dataflow/indirect-mutation-offset.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: rustc_peek: bit not set
--> $DIR/indirect-mutation-offset.rs:41:14
--> $DIR/indirect-mutation-offset.rs:41:5
|
LL | unsafe { rustc_peek(x) };
| ^^^^^^^^^^^^^
LL | rustc_peek(x);
| ^^^^^^^^^^^^^

error: stop_after_dataflow ended compilation

18 changes: 9 additions & 9 deletions src/test/ui/mir-dataflow/inits-1.rs
Original file line number Diff line number Diff line change
@@ -11,13 +11,13 @@ struct S(i32);
fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
let ret;
// `ret` starts off uninitialized, so we get an error report here.
unsafe { rustc_peek(&ret); } //~ ERROR rustc_peek: bit not set
rustc_peek(&ret); //~ ERROR rustc_peek: bit not set

// All function formal parameters start off initialized.

unsafe { rustc_peek(&x) };
unsafe { rustc_peek(&y) };
unsafe { rustc_peek(&z) };
rustc_peek(&x);
rustc_peek(&y);
rustc_peek(&z);

ret = if test {
::std::mem::replace(x, y)
@@ -28,21 +28,21 @@ fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {


// `z` may be initialized here.
unsafe { rustc_peek(&z); }
rustc_peek(&z);

// `y` is definitely uninitialized here.
unsafe { rustc_peek(&y); } //~ ERROR rustc_peek: bit not set
rustc_peek(&y); //~ ERROR rustc_peek: bit not set

// `x` is still (definitely) initialized (replace above is a reborrow).
unsafe { rustc_peek(&x); }
rustc_peek(&x);

::std::mem::drop(x);

// `x` is *definitely* uninitialized here
unsafe { rustc_peek(&x); } //~ ERROR rustc_peek: bit not set
rustc_peek(&x); //~ ERROR rustc_peek: bit not set

// `ret` is now definitely initialized (via `if` above).
unsafe { rustc_peek(&ret); }
rustc_peek(&ret);

ret
}
18 changes: 9 additions & 9 deletions src/test/ui/mir-dataflow/inits-1.stderr
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
error: rustc_peek: bit not set
--> $DIR/inits-1.rs:14:14
--> $DIR/inits-1.rs:14:5
|
LL | unsafe { rustc_peek(&ret); }
| ^^^^^^^^^^^^^^^^
LL | rustc_peek(&ret);
| ^^^^^^^^^^^^^^^^

error: rustc_peek: bit not set
--> $DIR/inits-1.rs:34:14
--> $DIR/inits-1.rs:34:5
|
LL | unsafe { rustc_peek(&y); }
| ^^^^^^^^^^^^^^
LL | rustc_peek(&y);
| ^^^^^^^^^^^^^^

error: rustc_peek: bit not set
--> $DIR/inits-1.rs:42:14
--> $DIR/inits-1.rs:42:5
|
LL | unsafe { rustc_peek(&x); }
| ^^^^^^^^^^^^^^
LL | rustc_peek(&x);
| ^^^^^^^^^^^^^^

error: stop_after_dataflow ended compilation

6 changes: 3 additions & 3 deletions src/test/ui/mir-dataflow/liveness-ptr.rs
Original file line number Diff line number Diff line change
@@ -10,17 +10,17 @@ fn foo() -> i32 {
x = 0;

// `x` is live here since it is used in the next statement...
unsafe { rustc_peek(x); }
rustc_peek(x);

p = &x;

// ... but not here, even while it can be accessed through `p`.
unsafe { rustc_peek(x); } //~ ERROR rustc_peek: bit not set
rustc_peek(x); //~ ERROR rustc_peek: bit not set
let tmp = unsafe { *p };

x = tmp + 1;

unsafe { rustc_peek(x); }
rustc_peek(x);

x
}
6 changes: 3 additions & 3 deletions src/test/ui/mir-dataflow/liveness-ptr.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: rustc_peek: bit not set
--> $DIR/liveness-ptr.rs:18:14
--> $DIR/liveness-ptr.rs:18:5
|
LL | unsafe { rustc_peek(x); }
| ^^^^^^^^^^^^^
LL | rustc_peek(x);
| ^^^^^^^^^^^^^

error: stop_after_dataflow ended compilation

18 changes: 9 additions & 9 deletions src/test/ui/mir-dataflow/uninits-1.rs
Original file line number Diff line number Diff line change
@@ -11,13 +11,13 @@ struct S(i32);
fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
let ret;
// `ret` starts off uninitialized
unsafe { rustc_peek(&ret); }
rustc_peek(&ret);

// All function formal parameters start off initialized.

unsafe { rustc_peek(&x) }; //~ ERROR rustc_peek: bit not set
unsafe { rustc_peek(&y) }; //~ ERROR rustc_peek: bit not set
unsafe { rustc_peek(&z) }; //~ ERROR rustc_peek: bit not set
rustc_peek(&x); //~ ERROR rustc_peek: bit not set
rustc_peek(&y); //~ ERROR rustc_peek: bit not set
rustc_peek(&z); //~ ERROR rustc_peek: bit not set

ret = if test {
::std::mem::replace(x, y)
@@ -27,21 +27,21 @@ fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
};

// `z` may be uninitialized here.
unsafe { rustc_peek(&z); }
rustc_peek(&z);

// `y` is definitely uninitialized here.
unsafe { rustc_peek(&y); }
rustc_peek(&y);

// `x` is still (definitely) initialized (replace above is a reborrow).
unsafe { rustc_peek(&x); } //~ ERROR rustc_peek: bit not set
rustc_peek(&x); //~ ERROR rustc_peek: bit not set

::std::mem::drop(x);

// `x` is *definitely* uninitialized here
unsafe { rustc_peek(&x); }
rustc_peek(&x);

// `ret` is now definitely initialized (via `if` above).
unsafe { rustc_peek(&ret); } //~ ERROR rustc_peek: bit not set
rustc_peek(&ret); //~ ERROR rustc_peek: bit not set

ret
}
30 changes: 15 additions & 15 deletions src/test/ui/mir-dataflow/uninits-1.stderr
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
error: rustc_peek: bit not set
--> $DIR/uninits-1.rs:18:14
--> $DIR/uninits-1.rs:18:5
|
LL | unsafe { rustc_peek(&x) };
| ^^^^^^^^^^^^^^
LL | rustc_peek(&x);
| ^^^^^^^^^^^^^^

error: rustc_peek: bit not set
--> $DIR/uninits-1.rs:19:14
--> $DIR/uninits-1.rs:19:5
|
LL | unsafe { rustc_peek(&y) };
| ^^^^^^^^^^^^^^
LL | rustc_peek(&y);
| ^^^^^^^^^^^^^^

error: rustc_peek: bit not set
--> $DIR/uninits-1.rs:20:14
--> $DIR/uninits-1.rs:20:5
|
LL | unsafe { rustc_peek(&z) };
| ^^^^^^^^^^^^^^
LL | rustc_peek(&z);
| ^^^^^^^^^^^^^^

error: rustc_peek: bit not set
--> $DIR/uninits-1.rs:36:14
--> $DIR/uninits-1.rs:36:5
|
LL | unsafe { rustc_peek(&x); }
| ^^^^^^^^^^^^^^
LL | rustc_peek(&x);
| ^^^^^^^^^^^^^^

error: rustc_peek: bit not set
--> $DIR/uninits-1.rs:44:14
--> $DIR/uninits-1.rs:44:5
|
LL | unsafe { rustc_peek(&ret); }
| ^^^^^^^^^^^^^^^^
LL | rustc_peek(&ret);
| ^^^^^^^^^^^^^^^^

error: stop_after_dataflow ended compilation

4 changes: 2 additions & 2 deletions src/test/ui/mir-dataflow/uninits-2.rs
Original file line number Diff line number Diff line change
@@ -11,12 +11,12 @@ struct S(i32);
fn foo(x: &mut S) {
// `x` is initialized here, so maybe-uninit bit is 0.

unsafe { rustc_peek(&x) }; //~ ERROR rustc_peek: bit not set
rustc_peek(&x); //~ ERROR rustc_peek: bit not set

::std::mem::drop(x);

// `x` definitely uninitialized here, so maybe-uninit bit is 1.
unsafe { rustc_peek(&x) };
rustc_peek(&x);
}
fn main() {
foo(&mut S(13));
6 changes: 3 additions & 3 deletions src/test/ui/mir-dataflow/uninits-2.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: rustc_peek: bit not set
--> $DIR/uninits-2.rs:14:14
--> $DIR/uninits-2.rs:14:5
|
LL | unsafe { rustc_peek(&x) };
| ^^^^^^^^^^^^^^
LL | rustc_peek(&x);
| ^^^^^^^^^^^^^^

error: stop_after_dataflow ended compilation