Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fed2013

Browse files
authoredJul 5, 2020
Rollup merge of #73834 - oli-obk:safe_intrinsics, r=ecstatic-morse
Some refactoring around intrinsic type checking So... This PR went a bit overboard. I wanted to make the `rustc_peek` intrinsic safe (cc @ecstatic-morse ), and remembered a long-standing itch of mine. So I made that huge `&str` match for the intrinsic name a match on `Symbol`s (so basically `u32`s). This is unlikely to have a positive perf effect, even if it likely has better codegen (intrinsics are used rarely, mostly once in their wrapper), so it's mostly a consistency thing since other places actually match on the symbol name of the intrinsics.
2 parents e2ae88d + 394b8cd commit fed2013

15 files changed

+307
-193
lines changed
 

‎src/librustc_span/symbol.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,14 @@ symbols! {
152152
arm_target_feature,
153153
asm,
154154
assert,
155+
assert_inhabited,
156+
assert_uninit_valid,
157+
assert_zero_valid,
155158
associated_consts,
156159
associated_type_bounds,
157160
associated_type_defaults,
158161
associated_types,
162+
assume,
159163
assume_init,
160164
async_await,
161165
async_closure,
@@ -181,11 +185,14 @@ symbols! {
181185
box_patterns,
182186
box_syntax,
183187
braced_empty_structs,
188+
breakpoint,
184189
bswap,
185190
bitreverse,
186191
C,
187192
caller_location,
188193
cdylib,
194+
ceilf32,
195+
ceilf64,
189196
cfg,
190197
cfg_accessible,
191198
cfg_attr,
@@ -239,8 +246,14 @@ symbols! {
239246
convert,
240247
Copy,
241248
copy_closures,
249+
copy,
250+
copy_nonoverlapping,
251+
copysignf32,
252+
copysignf64,
242253
core,
243254
core_intrinsics,
255+
cosf32,
256+
cosf64,
244257
count_code_region,
245258
coverage_counter_add,
246259
coverage_counter_subtract,
@@ -299,6 +312,7 @@ symbols! {
299312
dropck_eyepatch,
300313
dropck_parametricity,
301314
drop_types_in_const,
315+
drop_in_place,
302316
dylib,
303317
dyn_trait,
304318
eh_personality,
@@ -311,11 +325,16 @@ symbols! {
311325
Eq,
312326
Equal,
313327
enclosing_scope,
328+
exact_div,
314329
except,
315330
exclusive_range_pattern,
316331
exhaustive_integer_patterns,
317332
exhaustive_patterns,
318333
existential_type,
334+
expf32,
335+
expf64,
336+
exp2f32,
337+
exp2f64,
319338
expected,
320339
export_name,
321340
expr,
@@ -329,20 +348,32 @@ symbols! {
329348
f16c_target_feature,
330349
f32,
331350
f64,
351+
fadd_fast,
352+
fabsf32,
353+
fabsf64,
354+
fdiv_fast,
332355
feature,
333356
ffi_const,
334357
ffi_pure,
335358
ffi_returns_twice,
336359
field,
337360
field_init_shorthand,
338361
file,
362+
float_to_int_unchecked,
363+
floorf64,
364+
floorf32,
365+
fmaf32,
366+
fmaf64,
339367
fmt,
340368
fmt_internals,
369+
fmul_fast,
341370
fn_must_use,
342371
forbid,
372+
forget,
343373
format_args,
344374
format_args_nl,
345375
format_args_capture,
376+
frem_fast,
346377
from,
347378
From,
348379
from_desugaring,
@@ -352,6 +383,7 @@ symbols! {
352383
from_ok,
353384
from_usize,
354385
from_trait,
386+
fsub_fast,
355387
fundamental,
356388
future,
357389
Future,
@@ -448,6 +480,12 @@ symbols! {
448480
llvm_asm,
449481
local_inner_macros,
450482
log_syntax,
483+
logf32,
484+
logf64,
485+
log10f32,
486+
log10f64,
487+
log2f32,
488+
log2f64,
451489
loop_break_value,
452490
macro_at_most_once_rep,
453491
macro_escape,
@@ -475,10 +513,16 @@ symbols! {
475513
message,
476514
meta,
477515
min_align_of,
516+
min_align_of_val,
478517
min_const_fn,
479518
min_const_unsafe_fn,
480519
min_specialization,
520+
minnumf32,
521+
minnumf64,
522+
maxnumf32,
523+
maxnumf64,
481524
mips_target_feature,
525+
miri_start_panic,
482526
mmx_target_feature,
483527
module,
484528
module_path,
@@ -491,6 +535,8 @@ symbols! {
491535
naked,
492536
naked_functions,
493537
name,
538+
nearbyintf32,
539+
nearbyintf64,
494540
needs_allocator,
495541
needs_drop,
496542
needs_panic_runtime,
@@ -518,6 +564,7 @@ symbols! {
518564
None,
519565
non_exhaustive,
520566
non_modrs_mods,
567+
nontemporal_store,
521568
nontrapping_fptoint: "nontrapping-fptoint",
522569
noreturn,
523570
no_niche,
@@ -577,8 +624,16 @@ symbols! {
577624
poll,
578625
Poll,
579626
powerpc_target_feature,
627+
powf32,
628+
powf64,
629+
powif32,
630+
powif64,
580631
precise_pointer_size_matching,
581632
pref_align_of,
633+
prefetch_read_data,
634+
prefetch_read_instruction,
635+
prefetch_write_data,
636+
prefetch_write_instruction,
582637
prelude,
583638
prelude_import,
584639
preserves_flags,
@@ -640,10 +695,14 @@ symbols! {
640695
Result,
641696
Return,
642697
rhs,
698+
rintf32,
699+
rintf64,
643700
riscv_target_feature,
644701
rlib,
645702
rotate_left,
646703
rotate_right,
704+
roundf32,
705+
roundf64,
647706
rt,
648707
rtm_target_feature,
649708
rust,
@@ -726,14 +785,19 @@ symbols! {
726785
simd_ffi,
727786
simd_insert,
728787
since,
788+
sinf32,
789+
sinf64,
729790
size,
730791
size_of,
792+
size_of_val,
731793
slice_patterns,
732794
slicing_syntax,
733795
soft,
734796
Some,
735797
specialization,
736798
speed,
799+
sqrtf32,
800+
sqrtf64,
737801
sse4a_target_feature,
738802
stable,
739803
staged_api,
@@ -787,6 +851,8 @@ symbols! {
787851
transparent_enums,
788852
transparent_unions,
789853
trivial_bounds,
854+
truncf32,
855+
truncf64,
790856
Try,
791857
try_blocks,
792858
try_trait,
@@ -809,6 +875,8 @@ symbols! {
809875
u32,
810876
u64,
811877
u8,
878+
unaligned_volatile_load,
879+
unaligned_volatile_store,
812880
unboxed_closures,
813881
unchecked_add,
814882
unchecked_div,
@@ -824,6 +892,7 @@ symbols! {
824892
universal_impl_trait,
825893
unlikely,
826894
unmarked_api,
895+
unreachable,
827896
unreachable_code,
828897
unrestricted_attribute_tokens,
829898
unsafe_block_in_unsafe_fn,
@@ -843,12 +912,21 @@ symbols! {
843912
val,
844913
var,
845914
variant_count,
915+
va_arg,
916+
va_copy,
917+
va_end,
918+
va_start,
846919
vec,
847920
Vec,
848921
version,
849922
vis,
850923
visible_private_types,
851924
volatile,
925+
volatile_copy_memory,
926+
volatile_copy_nonoverlapping_memory,
927+
volatile_load,
928+
volatile_set_memory,
929+
volatile_store,
852930
warn,
853931
wasm_import_module,
854932
wasm_target_feature,
@@ -858,6 +936,7 @@ symbols! {
858936
wrapping_add,
859937
wrapping_sub,
860938
wrapping_mul,
939+
write_bytes,
861940
Yield,
862941
}
863942
}

‎src/librustc_typeck/check/intrinsic.rs

Lines changed: 149 additions & 114 deletions
Large diffs are not rendered by default.

‎src/librustc_typeck/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2063,7 +2063,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
20632063
ident: Ident,
20642064
) -> ty::PolyFnSig<'tcx> {
20652065
let unsafety = if abi == abi::Abi::RustIntrinsic {
2066-
intrinsic_operation_unsafety(&tcx.item_name(def_id).as_str())
2066+
intrinsic_operation_unsafety(tcx.item_name(def_id))
20672067
} else {
20682068
hir::Unsafety::Unsafe
20692069
};

‎src/test/ui/mir-dataflow/def-inits-1.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ struct S(i32);
1111
fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
1212
let ret;
1313
// `ret` starts off uninitialized
14-
unsafe { rustc_peek(&ret); } //~ ERROR rustc_peek: bit not set
14+
rustc_peek(&ret); //~ ERROR rustc_peek: bit not set
1515

1616
// All function formal parameters start off initialized.
1717

18-
unsafe { rustc_peek(&x) };
19-
unsafe { rustc_peek(&y) };
20-
unsafe { rustc_peek(&z) };
18+
rustc_peek(&x);
19+
rustc_peek(&y);
20+
rustc_peek(&z);
2121

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

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

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

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

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

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

4343
// `ret` is now definitely initialized (via `if` above).
44-
unsafe { rustc_peek(&ret); }
44+
rustc_peek(&ret);
4545

4646
ret
4747
}

‎src/test/ui/mir-dataflow/def-inits-1.stderr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
error: rustc_peek: bit not set
2-
--> $DIR/def-inits-1.rs:14:14
2+
--> $DIR/def-inits-1.rs:14:5
33
|
4-
LL | unsafe { rustc_peek(&ret); }
5-
| ^^^^^^^^^^^^^^^^
4+
LL | rustc_peek(&ret);
5+
| ^^^^^^^^^^^^^^^^
66

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

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

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

2525
error: stop_after_dataflow ended compilation
2626

‎src/test/ui/mir-dataflow/indirect-mutation-offset.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const BOO: i32 = {
3838

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

4343
val
4444
};

‎src/test/ui/mir-dataflow/indirect-mutation-offset.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: rustc_peek: bit not set
2-
--> $DIR/indirect-mutation-offset.rs:41:14
2+
--> $DIR/indirect-mutation-offset.rs:41:5
33
|
4-
LL | unsafe { rustc_peek(x) };
5-
| ^^^^^^^^^^^^^
4+
LL | rustc_peek(x);
5+
| ^^^^^^^^^^^^^
66

77
error: stop_after_dataflow ended compilation
88

‎src/test/ui/mir-dataflow/inits-1.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ struct S(i32);
1111
fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
1212
let ret;
1313
// `ret` starts off uninitialized, so we get an error report here.
14-
unsafe { rustc_peek(&ret); } //~ ERROR rustc_peek: bit not set
14+
rustc_peek(&ret); //~ ERROR rustc_peek: bit not set
1515

1616
// All function formal parameters start off initialized.
1717

18-
unsafe { rustc_peek(&x) };
19-
unsafe { rustc_peek(&y) };
20-
unsafe { rustc_peek(&z) };
18+
rustc_peek(&x);
19+
rustc_peek(&y);
20+
rustc_peek(&z);
2121

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

2929

3030
// `z` may be initialized here.
31-
unsafe { rustc_peek(&z); }
31+
rustc_peek(&z);
3232

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

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

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

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

4444
// `ret` is now definitely initialized (via `if` above).
45-
unsafe { rustc_peek(&ret); }
45+
rustc_peek(&ret);
4646

4747
ret
4848
}

‎src/test/ui/mir-dataflow/inits-1.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
error: rustc_peek: bit not set
2-
--> $DIR/inits-1.rs:14:14
2+
--> $DIR/inits-1.rs:14:5
33
|
4-
LL | unsafe { rustc_peek(&ret); }
5-
| ^^^^^^^^^^^^^^^^
4+
LL | rustc_peek(&ret);
5+
| ^^^^^^^^^^^^^^^^
66

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

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

1919
error: stop_after_dataflow ended compilation
2020

‎src/test/ui/mir-dataflow/liveness-ptr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ fn foo() -> i32 {
1010
x = 0;
1111

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

1515
p = &x;
1616

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

2121
x = tmp + 1;
2222

23-
unsafe { rustc_peek(x); }
23+
rustc_peek(x);
2424

2525
x
2626
}

‎src/test/ui/mir-dataflow/liveness-ptr.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: rustc_peek: bit not set
2-
--> $DIR/liveness-ptr.rs:18:14
2+
--> $DIR/liveness-ptr.rs:18:5
33
|
4-
LL | unsafe { rustc_peek(x); }
5-
| ^^^^^^^^^^^^^
4+
LL | rustc_peek(x);
5+
| ^^^^^^^^^^^^^
66

77
error: stop_after_dataflow ended compilation
88

‎src/test/ui/mir-dataflow/uninits-1.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ struct S(i32);
1111
fn foo(test: bool, x: &mut S, y: S, mut z: S) -> S {
1212
let ret;
1313
// `ret` starts off uninitialized
14-
unsafe { rustc_peek(&ret); }
14+
rustc_peek(&ret);
1515

1616
// All function formal parameters start off initialized.
1717

18-
unsafe { rustc_peek(&x) }; //~ ERROR rustc_peek: bit not set
19-
unsafe { rustc_peek(&y) }; //~ ERROR rustc_peek: bit not set
20-
unsafe { rustc_peek(&z) }; //~ ERROR rustc_peek: bit not set
18+
rustc_peek(&x); //~ ERROR rustc_peek: bit not set
19+
rustc_peek(&y); //~ ERROR rustc_peek: bit not set
20+
rustc_peek(&z); //~ ERROR rustc_peek: bit not set
2121

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

2929
// `z` may be uninitialized here.
30-
unsafe { rustc_peek(&z); }
30+
rustc_peek(&z);
3131

3232
// `y` is definitely uninitialized here.
33-
unsafe { rustc_peek(&y); }
33+
rustc_peek(&y);
3434

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

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

4040
// `x` is *definitely* uninitialized here
41-
unsafe { rustc_peek(&x); }
41+
rustc_peek(&x);
4242

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

4646
ret
4747
}

‎src/test/ui/mir-dataflow/uninits-1.stderr

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
error: rustc_peek: bit not set
2-
--> $DIR/uninits-1.rs:18:14
2+
--> $DIR/uninits-1.rs:18:5
33
|
4-
LL | unsafe { rustc_peek(&x) };
5-
| ^^^^^^^^^^^^^^
4+
LL | rustc_peek(&x);
5+
| ^^^^^^^^^^^^^^
66

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

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

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

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

3131
error: stop_after_dataflow ended compilation
3232

‎src/test/ui/mir-dataflow/uninits-2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ struct S(i32);
1111
fn foo(x: &mut S) {
1212
// `x` is initialized here, so maybe-uninit bit is 0.
1313

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

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

1818
// `x` definitely uninitialized here, so maybe-uninit bit is 1.
19-
unsafe { rustc_peek(&x) };
19+
rustc_peek(&x);
2020
}
2121
fn main() {
2222
foo(&mut S(13));

‎src/test/ui/mir-dataflow/uninits-2.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: rustc_peek: bit not set
2-
--> $DIR/uninits-2.rs:14:14
2+
--> $DIR/uninits-2.rs:14:5
33
|
4-
LL | unsafe { rustc_peek(&x) };
5-
| ^^^^^^^^^^^^^^
4+
LL | rustc_peek(&x);
5+
| ^^^^^^^^^^^^^^
66

77
error: stop_after_dataflow ended compilation
88

0 commit comments

Comments
 (0)
Please sign in to comment.