rust/compiler/rustc_mir/src/transform
bors 016e9b5e33 Auto merge of #84988 - alexcrichton:safe-target-feature-wasm, r=joshtriplett
rustc: Allow safe #[target_feature] on wasm

This commit updates the compiler's handling of the `#[target_feature]`
attribute when applied to functions on WebAssembly-based targets. The
compiler in general requires that any functions with `#[target_feature]`
are marked as `unsafe` as well, but this commit relaxes the restriction
for WebAssembly targets where the attribute can be applied to safe
functions as well.

The reason this is done is that the motivation for this feature of the
compiler is not applicable for WebAssembly targets. In general the
`#[target_feature]` attribute is used to enhance target CPU features
enabled beyond the basic level for the rest of the compilation. If done
improperly this means that your program could execute an instruction
that the CPU you happen to be running on does not understand. This is
considered undefined behavior where it is unknown what will happen (e.g.
it's not a deterministic `SIGILL`).

For WebAssembly, however, the target is different. It is not possible
for a running WebAssembly program to execute an instruction that the
engine does not understand. If this were the case then the program would
not have validated in the first place and would not run at all. Even if
this were allowed in some hypothetical future where engines have some
form of runtime feature detection (which they do not right now) any
implementation of such a feature would generate a trap if a module
attempts to execute an instruction the module does not understand. This
deterministic trap behavior would still not fall into the category of
undefined behavior because the trap is deterministic.

For these reasons the `#[target_feature]` attribute is now allowed on
safe functions, but only for WebAssembly targets. This notably enables
the wasm-SIMD intrinsics proposed for stabilization in #74372 to be
marked as safe generally instead of today where they're all `unsafe` due
to the historical implementation of `#[target_feature]` in the compiler.
2021-06-03 05:12:31 +00:00
..
check_consts stabilize const_fn_unsize 2021-05-22 10:35:49 +02:00
coverage Remove CrateNum::ReservedForIncrCompCache 2021-05-30 14:33:16 +02:00
inline Use small hash set in mir_inliner_callees 2021-02-24 00:00:00 +00:00
add_call_guards.rs Remember the MirSource for each Body 2020-10-04 11:01:38 -07:00
add_moves_for_packed_drops.rs Replace (Body, DefId) with Body where possible 2020-10-04 16:07:03 -07:00
add_retag.rs Retagging: do not retag 'raw reborrows' 2020-10-31 15:31:27 +01:00
check_const_item_mutation.rs Suppress CONST_ITEM_MUTATION lint if a dereference occurs anywhere 2020-12-17 15:25:55 -05:00
check_packed_ref.rs make unaligned_refereces future-incompat lint warn-by-default, and remove the safe_packed_borrows lint that it replaces 2021-03-27 16:59:37 +01:00
check_unsafety.rs rustc: Allow safe #[target_feature] on wasm 2021-05-28 12:57:35 -07:00
cleanup_post_borrowck.rs Remember the MirSource for each Body 2020-10-04 11:01:38 -07:00
const_debuginfo.rs Disable the constant debuginfo promotion pass by default 2020-12-14 19:56:10 -05:00
const_goto.rs Revert "Auto merge of #84797 - richkadel:cover-unreachable-statements, r=tmandry" 2021-05-11 12:47:08 -07:00
const_prop.rs Pass StackPopUnwind to eval_fn_call() and some other functions that are called by eval_fn_call() 2021-05-23 22:10:23 +08:00
deaggregator.rs Remember the MirSource for each Body 2020-10-04 11:01:38 -07:00
deduplicate_blocks.rs Revert "Auto merge of #84797 - richkadel:cover-unreachable-statements, r=tmandry" 2021-05-11 12:47:08 -07:00
dest_prop.rs Use AnonConst for asm! constants 2021-04-06 12:35:41 +01:00
dump_mir.rs Remember the MirSource for each Body 2020-10-04 11:01:38 -07:00
early_otherwise_branch.rs Improve match statements 2021-05-14 08:57:33 +05:30
elaborate_drops.rs Prepare mir::Constant for ty::Const only supporting valtrees 2021-03-12 12:43:54 +00:00
function_item_references.rs Review changes 2021-01-16 18:56:37 -05:00
generator.rs Revert "Auto merge of #84797 - richkadel:cover-unreachable-statements, r=tmandry" 2021-05-11 12:47:08 -07:00
inline.rs Revert "Auto merge of #84797 - richkadel:cover-unreachable-statements, r=tmandry" 2021-05-11 12:47:08 -07:00
instcombine.rs move to separate pass, cache layouts 2021-03-16 21:34:31 -04:00
lower_intrinsics.rs add check that simd_shuffle arguments are constants 2021-05-12 16:15:30 +02:00
match_branches.rs Revert "Auto merge of #84797 - richkadel:cover-unreachable-statements, r=tmandry" 2021-05-11 12:47:08 -07:00
mod.rs Use () for mir_keys. 2021-05-12 13:58:43 +02:00
multiple_return_terminators.rs Revert "Auto merge of #84797 - richkadel:cover-unreachable-statements, r=tmandry" 2021-05-11 12:47:08 -07:00
no_landing_pads.rs Visit only terminators when removing landing pads 2021-01-18 00:00:00 +00:00
nrvo.rs Extract mir_opt_level to a method and use Option to be able to know if the value is provided or not 2021-03-05 17:13:56 -03:00
promote_consts.rs entirely remove rustc_args_required_const attribute 2021-05-12 16:15:27 +02:00
remove_noop_landing_pads.rs Switch to changing cp_non_overlap in tform 2021-03-09 16:54:14 +00:00
remove_storage_markers.rs Remove storage markers if they won't be used during code generation 2021-02-28 20:10:44 +01:00
remove_unneeded_drops.rs Revert "Auto merge of #84797 - richkadel:cover-unreachable-statements, r=tmandry" 2021-05-11 12:47:08 -07:00
remove_zsts.rs RemoveZsts: don't touch unions 2021-03-24 13:00:36 -04:00
required_consts.rs extract ConstKind::Unevaluated into a struct 2021-03-20 17:21:44 +01:00
rustc_peek.rs Prepare mir::Constant for ty::Const only supporting valtrees 2021-03-12 12:43:54 +00:00
simplify_branches.rs Simplify assert terminator only if condition evaluates to expected value 2020-10-21 00:00:00 +00:00
simplify_comparison_integral.rs Prepare mir::Constant for ty::Const only supporting valtrees 2021-03-12 12:43:54 +00:00
simplify_try.rs Improve match statements 2021-05-14 08:57:33 +05:30
simplify.rs Revert "Auto merge of #84797 - richkadel:cover-unreachable-statements, r=tmandry" 2021-05-11 12:47:08 -07:00
uninhabited_enum_branching.rs Refactor how SwitchInt stores jump targets 2020-10-10 17:46:11 +02:00
unreachable_prop.rs Revert "Auto merge of #84797 - richkadel:cover-unreachable-statements, r=tmandry" 2021-05-11 12:47:08 -07:00
validate.rs Clean up todos 2021-03-09 19:31:31 +00:00