Commit Graph

219 Commits

Author SHA1 Message Date
bors d77014a608 Auto merge of #111697 - rcvalle:rust-cfi-fix-111510, r=bjorn3
CFI: Fix encode_ty: unexpected Param(B/#1)

Fixes #111510 and complements #106547 by adding support for encoding type parameters and also by transforming trait objects' traits into their identities before emitting type checks.
2023-05-21 06:42:05 +00:00
Ramon de C Valle f067935ab2 CFI: Fix encode_ty: unexpected Param(B/#1)
Fixes #111510 and complements #106547 by adding support for encoding
type parameters and also by transforming trait objects' traits into
their identities before emitting type checks.
2023-05-17 22:12:13 +00:00
John Kåre Alsaker fff20a703d Move expansion of query macros in rustc_middle to rustc_middle::query 2023-05-15 08:49:13 +02:00
Ramon de C Valle 7c7b22e62c CFI: Fix SIGILL reached via trait objects
Fix #106547 by transforming the concrete self into a reference to a
trait object before emitting type metadata identifiers for trait
methods.
2023-05-09 20:04:19 +00:00
Manish Goregaokar 38bbc39895
Rollup merge of #105452 - rcvalle:rust-cfi-3, r=bjorn3
Add cross-language LLVM CFI support to the Rust compiler

This PR adds cross-language LLVM Control Flow Integrity (CFI) support to the Rust compiler by adding the `-Zsanitizer-cfi-normalize-integers` option to be used with Clang `-fsanitize-cfi-icall-normalize-integers` for normalizing integer types (see https://reviews.llvm.org/D139395).

It provides forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space). For more information about LLVM CFI and cross-language LLVM CFI support for the Rust compiler, see design document in the tracking issue #89653.

Cross-language LLVM CFI can be enabled with -Zsanitizer=cfi and -Zsanitizer-cfi-normalize-integers, and requires proper (i.e., non-rustc) LTO (i.e., -Clinker-plugin-lto).

Thank you again, ``@bjorn3,`` ``@nikic,`` ``@samitolvanen,`` and the Rust community for all the help!
2023-05-03 16:42:48 -07:00
Ramon de C Valle 004aa15b47 Add cross-language LLVM CFI support to the Rust compiler
This commit adds cross-language LLVM Control Flow Integrity (CFI)
support to the Rust compiler by adding the
`-Zsanitizer-cfi-normalize-integers` option to be used with Clang
`-fsanitize-cfi-icall-normalize-integers` for normalizing integer types
(see https://reviews.llvm.org/D139395).

It provides forward-edge control flow protection for C or C++ and Rust
-compiled code "mixed binaries" (i.e., for when C or C++ and Rust
-compiled code share the same virtual address space). For more
information about LLVM CFI and cross-language LLVM CFI support for the
Rust compiler, see design document in the tracking issue #89653.

Cross-language LLVM CFI can be enabled with -Zsanitizer=cfi and
-Zsanitizer-cfi-normalize-integers, and requires proper (i.e.,
non-rustc) LTO (i.e., -Clinker-plugin-lto).
2023-05-03 22:41:29 +00:00
Boxy 842419712a rename `needs_subst` to `has_param` 2023-04-27 08:35:19 +01:00
Oli Scherer 1ce80e210d Allow `LocalDefId` as the argument to `def_path_str` 2023-04-21 22:27:20 +00:00
Maybe Waffle 3f15521396 Add `GenericArgKind::as_{type,const,region}` 2023-04-19 14:54:31 +00:00
bors d7f9e81650 Auto merge of #110407 - Nilstrieb:fluent-macro, r=davidtwco
Add `rustc_fluent_macro` to decouple fluent from `rustc_macros`

Fluent, with all the icu4x it brings in, takes quite some time to compile. `fluent_messages!` is only needed in further downstream rustc crates, but is blocking more upstream crates like `rustc_index`. By splitting it out, we allow `rustc_macros` to be compiled earlier, which speeds up `x check compiler` by about 5 seconds (and even more after the needless dependency on `serde_json` is removed from `rustc_data_structures`).
2023-04-19 08:26:47 +00:00
Nilstrieb b5d3d970fa Add `rustc_fluent_macro` to decouple fluent from `rustc_macros`
Fluent, with all the icu4x it brings in, takes quite some time to
compile. `fluent_messages!` is only needed in further downstream rustc
crates, but is blocking more upstream crates like `rustc_index`. By
splitting it out, we allow `rustc_macros` to be compiled earlier, which
speeds up `x check compiler` by about 5 seconds (and even more after the
needless dependency on `serde_json` is removed from
`rustc_data_structures`).
2023-04-18 18:56:22 +00:00
Ben Kimock 0445fbdd83 Store hashes in special types so they aren't accidentally encoded as numbers 2023-04-18 10:52:47 -04:00
Jack Huey f0edcc8a6f Remove index from BrAnon 2023-04-06 23:01:40 -04:00
John Kåre Alsaker 0d89c6a2d4 Support TLS access into dylibs on Windows 2023-03-29 08:55:21 +02:00
Michael Goulet 2eb1c08e43 Use local key in providers 2023-03-21 15:38:51 +00:00
est31 7e2ecb3cd8 Simplify message paths
This makes it easier to open the messages file while developing on features.

The commit was the result of automatted changes:

for p in compiler/rustc_*; do mv $p/locales/en-US.ftl $p/messages.ftl; rmdir $p/locales; done

for p in compiler/rustc_*; do sed -i "s#\.\./locales/en-US.ftl#../messages.ftl#" $p/src/lib.rs; done
2023-03-11 22:51:57 +01:00
Nicholas Nethercote 2200911616 Rename many interner functions.
(This is a large commit. The changes to
`compiler/rustc_middle/src/ty/context.rs` are the most important ones.)

The current naming scheme is a mess, with a mix of `_intern_`, `intern_`
and `mk_` prefixes, with little consistency. In particular, in many
cases it's easy to use an iterator interner when a (preferable) slice
interner is available.

The guiding principles of the new naming system:
- No `_intern_` prefixes.
- The `intern_` prefix is for internal operations.
- The `mk_` prefix is for external operations.
- For cases where there is a slice interner and an iterator interner,
  the former is `mk_foo` and the latter is `mk_foo_from_iter`.

Also, `slice_interners!` and `direct_interners!` can now be `pub` or
non-`pub`, which helps enforce the internal/external operations
division.

It's not perfect, but I think it's a clear improvement.

The following lists show everything that was renamed.

slice_interners
- const_list
  - mk_const_list -> mk_const_list_from_iter
  - intern_const_list -> mk_const_list
- substs
  - mk_substs -> mk_substs_from_iter
  - intern_substs -> mk_substs
  - check_substs -> check_and_mk_substs (this is a weird one)
- canonical_var_infos
  - intern_canonical_var_infos -> mk_canonical_var_infos
- poly_existential_predicates
  - mk_poly_existential_predicates -> mk_poly_existential_predicates_from_iter
  - intern_poly_existential_predicates -> mk_poly_existential_predicates
  - _intern_poly_existential_predicates -> intern_poly_existential_predicates
- predicates
  - mk_predicates -> mk_predicates_from_iter
  - intern_predicates -> mk_predicates
  - _intern_predicates -> intern_predicates
- projs
  - intern_projs -> mk_projs
- place_elems
  - mk_place_elems -> mk_place_elems_from_iter
  - intern_place_elems -> mk_place_elems
- bound_variable_kinds
  - mk_bound_variable_kinds -> mk_bound_variable_kinds_from_iter
  - intern_bound_variable_kinds -> mk_bound_variable_kinds

direct_interners
- region
  - intern_region (unchanged)
- const
  - mk_const_internal -> intern_const
- const_allocation
  - intern_const_alloc -> mk_const_alloc
- layout
  - intern_layout -> mk_layout
- adt_def
  - intern_adt_def -> mk_adt_def_from_data (unusual case, hard to avoid)
  - alloc_adt_def(!) -> mk_adt_def
- external_constraints
  - intern_external_constraints -> mk_external_constraints

Other
- type_list
  - mk_type_list -> mk_type_list_from_iter
  - intern_type_list -> mk_type_list
- tup
  - mk_tup -> mk_tup_from_iter
  - intern_tup -> mk_tup
2023-02-24 07:32:24 +11:00
bors fdbc4329cb Auto merge of #108340 - eggyal:remove_traversal_trait_aliases, r=oli-obk
Remove type-traversal trait aliases

#107924 moved the type traversal (folding and visiting) traits into the type library, but created trait aliases in `rustc_middle` to minimise both the API churn for trait consumers and the arising boilerplate.  As mentioned in that PR, an alternative approach of defining subtraits with blanket implementations of the respective supertraits was also considered at that time but was ruled out as not adding much value.

Unfortunately, it has since emerged that rust-analyzer has difficulty with these trait aliases at present, resulting in a degraded contributor experience (see the recent [r-a has become useless](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/r-a.20has.20become.20useless) topic on the #t-compiler/help Zulip stream).

This PR removes the trait aliases, and accordingly the underlying type library traits are now used directly; they are parameterised by `TyCtxt<'tcx>` rather than just the `'tcx` lifetime, and imports have been updated to reflect the fact that the trait aliases' explicitly named traits are no longer automatically brought into scope.  These changes also roll-back the (no-longer required) workarounds to #107747 that were made in b409329c62.

Since this PR is just a find+replace together with the changes necessary for compilation & tidy to pass, it's currently just one mega-commit.  Let me know if you'd like it broken up.

r? `@oli-obk`
2023-02-22 18:26:51 +00:00
Alan Egerton 695072daa6
Remove type-traversal trait aliases 2023-02-22 17:04:58 +00:00
David Wood d1fcf61117 errors: generate typed identifiers in each crate
Instead of loading the Fluent resources for every crate in
`rustc_error_messages`, each crate generates typed identifiers for its
own diagnostics and creates a static which are pulled together in the
`rustc_driver` crate and provided to the diagnostic emitter.

Signed-off-by: David Wood <david.wood@huawei.com>
2023-02-22 09:15:53 +00:00
Dylan DPC 076e627023
Rollup merge of #108141 - spastorino:add_rpitit_queries, r=compiler-errors
Add rpitit queries

This is part of the changes we are making to lower RPITITs as an associated type. The rest of the stuff will follow under a `-Z` flag.

I still need to add comments to the code, explain stuff and also I'd need to avoid encoding in metadata when rpitit queries return `&[]`

r? `@compiler-errors`
2023-02-21 14:19:59 +05:30
Santiago Pastorino 4e703a2772
Add associated_items_for_impl_trait_in_trait query 2023-02-19 11:18:56 -03:00
Nicholas Nethercote 2017aeff88 Use `IntoIterator` for `mk_fn_sig`.
This makes a lot of call sites nicer.
2023-02-17 22:24:34 +11:00
Nicholas Nethercote 9d5cf0f0bf Remove the `InternIteratorElement` impl for `&'a T`.
`InternIteratorElement` is a trait used to intern values produces by
iterators. There are three impls, corresponding to iterators that
produce different types:
- One for `T`, which operates straightforwardly.
- One for `Result<T, E>`, which is fallible, and will fail early with an
  error result if any of the iterator elements are errors.
- One for `&'a T`, which clones the items as it iterates.

That last one is bad: it's extremely easy to use it without realizing
that it clones, which goes against Rust's normal "explicit is better"
approach to cloning.

So this commit just removes it. In practice, there weren't many use
sites. For all but one of them `into_iter()` could be used, which avoids
the need for cloning. And for the one remaining case `copied()` is
used.
2023-02-17 22:24:34 +11:00
Nicholas Nethercote bcf0ec0191 Replace `mk_foo` calls with `infer_foo` where possible.
There are several `mk_foo`/`intern_foo` pairs, where the former takes an
iterator and the latter takes a slice. (This naming convention is bad,
but that's a fix for another PR.)

This commit changes several `mk_foo` occurrences into `intern_foo`,
avoiding the need for some `.iter()`/`.into_iter()` calls. Affected
cases:
- mk_type_list
- mk_tup
- mk_substs
- mk_const_list
2023-02-17 22:24:31 +11:00
Kyle Matsuda c183110cc2 remove bound_type_of query; make type_of return EarlyBinder; change type_of in metadata 2023-02-16 17:05:56 -07:00
Kyle Matsuda d822b97a27 change usages of type_of to bound_type_of 2023-02-16 17:01:52 -07:00
Maybe Waffle 8751fa1a9a `if $c:expr { Some($r:expr) } else { None }` =>> `$c.then(|| $r)` 2023-02-16 15:26:00 +00:00
Nicholas Nethercote 6248bbbf26 Pre-intern some commonly used type variables.
This requires some rearrangement of plumbing, such as adding
`mk_fresh_{,int_,float_}ty` and removing `mk_ty_infer`.
2023-02-13 09:25:36 +11:00
Esteban Küber 861f451235 Change to `ReError(ErrorGuaranteed)` 2023-02-09 10:26:49 +00:00
Esteban Küber 30cf7a3f51 Introduce `ReError`
CC #69314
2023-02-09 10:26:49 +00:00
Camille GILLOT 1974b6b68d Introduce GeneratorWitnessMIR. 2023-01-27 18:58:44 +00:00
Michael Goulet 3c41003873 Add type flags support for Ty and Const late-bound regions 2023-01-08 03:37:20 +00:00
nils fd7a159710 Fix `uninlined_format_args` for some compiler crates
Convert all the crates that have had their diagnostic migration
completed (except save_analysis because that will be deleted soon and
apfloat because of the licensing problem).
2023-01-05 19:01:12 +01:00
Matthew Maurer fb2c27d73f CFI: Monomorphize transparent ADTs before typeid
Monomorphise `#[repr(transparent)]` parameterized ADTs before turning
them into an Itanium mangled String.

`#[repr(transparent)]` ADTs currently use the single field to represent
them in their CFI type ID to ensure that they are compatible. However,
if that type involves a type parameter instantiated at the ADT level, as
in `ManuallyDrop`, this will currently ICE as the `Parameter` type
cannot be mangled. Since this happens at lowering time, it should always
be concrete after substitution.

Fixes #106230
2022-12-29 10:21:07 -08:00
Jeremy Stucki 3dde32ca97
rustc: Remove needless lifetimes 2022-12-20 22:10:40 +01:00
Matthias Krüger 1da4a49912 clippy::complexity fixes
filter_next
needless_question_mark
bind_instead_of_map
manual_find
derivable_impls
map_identity
redundant_slicing
skip_while_next
unnecessary_unwrap
needless_bool
2022-12-19 00:04:28 +01:00
Oli Scherer a5cd3bde95 Ensure no one constructs `AliasTy`s themselves 2022-12-14 15:36:39 +00:00
Michael Goulet 96cb18e864 Combine identical alias arms 2022-12-13 17:48:55 +00:00
Michael Goulet 61adaf8187 Combine projection and opaque into alias 2022-12-13 17:48:55 +00:00
Michael Goulet c13bd83528 squash OpaqueTy and ProjectionTy into AliasTy 2022-12-13 17:40:27 +00:00
Michael Goulet 5c6afb850c ProjectionTy.item_def_id -> ProjectionTy.def_id 2022-12-13 17:34:44 +00:00
Michael Goulet 7f3af72606 Use ty::OpaqueTy everywhere 2022-12-13 17:29:26 +00:00
Matthias Krüger 947fe7e341
Rollup merge of #105109 - rcvalle:rust-kcfi, r=bjorn3
Add LLVM KCFI support to the Rust compiler

This PR adds LLVM Kernel Control Flow Integrity (KCFI) support to the Rust compiler. It initially provides forward-edge control flow protection for operating systems kernels for Rust-compiled code only by aggregating function pointers in groups identified by their return and parameter types. (See llvm/llvm-project@cff5bef.)

Forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space) will be provided in later work as part of this project by identifying C char and integer type uses at the time types are encoded (see Type metadata in the design document in the tracking issue #89653).

LLVM KCFI can be enabled with -Zsanitizer=kcfi.

Thank you again, `@bjorn3,` `@eddyb,` `@nagisa,` and `@ojeda,` for all the help!
2022-12-10 09:24:43 +01:00
Ramon de C Valle 65698ae9f3 Add LLVM KCFI support to the Rust compiler
This commit adds LLVM Kernel Control Flow Integrity (KCFI) support to
the Rust compiler. It initially provides forward-edge control flow
protection for operating systems kernels for Rust-compiled code only by
aggregating function pointers in groups identified by their return and
parameter types. (See llvm/llvm-project@cff5bef.)

Forward-edge control flow protection for C or C++ and Rust -compiled
code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code
share the same virtual address space) will be provided in later work as
part of this project by identifying C char and integer type uses at the
time types are encoded (see Type metadata in the design document in the
tracking issue #89653).

LLVM KCFI can be enabled with -Zsanitizer=kcfi.

Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
2022-12-08 17:24:39 -08:00
Guillaume Gomez a2e485c25c
Rollup merge of #104786 - WaffleLapkin:amp-mut-help, r=compiler-errors
Use the power of adding helper function to simplify code w/ `Mutability`

r? `@compiler-errors`
2022-11-26 17:47:23 +01:00
kadmin f9750c1554 Add empty ConstKind::Abstract
Initial pass at expr/abstract const/s

Address comments

Switch to using a list instead of &[ty::Const], rm `AbstractConst`

Remove try_unify_abstract_consts

Update comments

Add edits

Recurse more

More edits

Prevent equating associated consts

Move failing test to ui

Changes this test from incremental to ui, and mark it as failing and a known bug.
Does not cause the compiler to ICE, so should be ok.
2022-11-25 09:28:43 +00:00
Maybe Waffle da40965300 Add `Mutability::{is_mut,is_not}` 2022-11-23 20:26:31 +00:00
Vadim Petrochenkov 7a5376d23c Unreserve braced enum variants in value namespace 2022-11-21 22:40:06 +03:00
Michael Goulet c36ff28d42 drive-by: PolyExistentialPredicate 2022-11-19 04:04:27 +00:00