about summary refs log tree commit diff
path: root/src/librustc_trait_selection
AgeCommit message (Collapse)AuthorLines
2020-05-22Remove dead ScopeTree codeMatthew Jasper-5/+0
2020-05-22Remove ReScopeMatthew Jasper-2/+2
2020-05-22Stabilize str_strip featureLzu Tao-1/+0
2020-05-22Rollup merge of #71829 - kper:issue71136, r=matthewjasperRalf Jung-6/+19
Fix suggestion to borrow in struct The corresponding issue is #71136. The compiler suggests that borrowing `the_foos` might solve the problem. This is obviously incorrect. ``` struct Foo(u8); #[derive(Clone)] struct FooHolster { the_foos: Vec<Foo>, } ``` I propose as fix to check if there is any colon in the span. However, there might a case where `my_method(B { a: 1, b : foo })` would be appropriate to show a suggestion for `&B ...`. To fix that too, we can simply check if there is a bracket in the span. This is only possible because both spans are different. Issue's span: `the_foos: Vec<Foo>` other's span: `B { a : 1, b : foo }`
2020-05-22Using `!span.from_expansion()` instead of snippetsKevin Per-25/+1
2020-05-22only try to suggest for try trait_refcsmoe-1/+5
2020-05-21Rollup merge of #72055 - lcnr:predicate-kind, r=nikomatsakisRalf Jung-191/+222
Intern predicates Implements the first step of https://github.com/rust-lang/compiler-team/issues/285 Renames `ty::Predicate` to `ty::PredicateKind`, which is now interned. To ease the transition, `ty::Predicate` is now a struct containing a reference to `ty::PredicateKind`. r? @ghost
2020-05-21Auto merge of #70705 - lcnr:generic_discriminant, r=nikomatsakisbors-20/+102
Use `T`'s discriminant type in `mem::Discriminant<T>` instead of `u64`. fixes #70509 Adds the lang-item `discriminant_kind`. Updates the function signature of `intrinsics::discriminant_value`. Adds the *probably permanently unstable* trait `DiscriminantKind`. `mem::Discriminant` should now be smaller in some cases. r? @ghost
2020-05-20change `Predicate::kind` to return a referenceBastian Kauschke-29/+27
2020-05-20intern `PredicateKind`Bastian Kauschke-1/+1
2020-05-20introduce newtype'd `Predicate<'tcx>`Bastian Kauschke-55/+73
2020-05-20make `to_predicate` take a `tcx` argumentNiko Matsakis-61/+68
2020-05-20rename `Predicate` to `PredicateKind`, introduce aliasBastian Kauschke-100/+108
2020-05-20Auto merge of #71923 - csmoe:issue-70818, r=tmandrybors-108/+135
Check non-Send/Sync upvars captured by generator Closes #70818 r? @tmandry
2020-05-20comment return sitesBastian Kauschke-7/+14
2020-05-20Be more conservative concerning `structural_match`Bastian Kauschke-21/+19
2020-05-20note for `ty::Error`.Bastian Kauschke-7/+14
2020-05-20exhaustively match during structural match checkingBastian Kauschke-2/+33
2020-05-19Auto merge of #69171 - Amanieu:new-asm, r=nagisa,nikomatsakisbors-3/+6
Implement new asm! syntax from RFC 2850 This PR implements the new `asm!` syntax proposed in https://github.com/rust-lang/rfcs/pull/2850. # Design A large part of this PR revolves around taking an `asm!` macro invocation and plumbing it through all of the compiler layers down to LLVM codegen. Throughout the various stages, an `InlineAsm` generally consists of 3 components: - The template string, which is stored as an array of `InlineAsmTemplatePiece`. Each piece represents either a literal or a placeholder for an operand (just like format strings). ```rust pub enum InlineAsmTemplatePiece { String(String), Placeholder { operand_idx: usize, modifier: Option<char>, span: Span }, } ``` - The list of operands to the `asm!` (`in`, `[late]out`, `in[late]out`, `sym`, `const`). These are represented differently at each stage of lowering, but follow a common pattern: - `in`, `out` and `inout` all have an associated register class (`reg`) or explicit register (`"eax"`). - `inout` has 2 forms: one with a single expression that is both read from and written to, and one with two separate expressions for the input and output parts. - `out` and `inout` have a `late` flag (`lateout` / `inlateout`) to indicate that the register allocator is allowed to reuse an input register for this output. - `out` and the split variant of `inout` allow `_` to be specified for an output, which means that the output is discarded. This is used to allocate scratch registers for assembly code. - `sym` is a bit special since it only accepts a path expression, which must point to a `static` or a `fn`. - The options set at the end of the `asm!` macro. The only one that is particularly of interest to rustc is `NORETURN` which makes `asm!` return `!` instead of `()`. ```rust bitflags::bitflags! { pub struct InlineAsmOptions: u8 { const PURE = 1 << 0; const NOMEM = 1 << 1; const READONLY = 1 << 2; const PRESERVES_FLAGS = 1 << 3; const NORETURN = 1 << 4; const NOSTACK = 1 << 5; } } ``` ## AST `InlineAsm` is represented as an expression in the AST: ```rust pub struct InlineAsm { pub template: Vec<InlineAsmTemplatePiece>, pub operands: Vec<(InlineAsmOperand, Span)>, pub options: InlineAsmOptions, } pub enum InlineAsmRegOrRegClass { Reg(Symbol), RegClass(Symbol), } pub enum InlineAsmOperand { In { reg: InlineAsmRegOrRegClass, expr: P<Expr>, }, Out { reg: InlineAsmRegOrRegClass, late: bool, expr: Option<P<Expr>>, }, InOut { reg: InlineAsmRegOrRegClass, late: bool, expr: P<Expr>, }, SplitInOut { reg: InlineAsmRegOrRegClass, late: bool, in_expr: P<Expr>, out_expr: Option<P<Expr>>, }, Const { expr: P<Expr>, }, Sym { expr: P<Expr>, }, } ``` The `asm!` macro is implemented in librustc_builtin_macros and outputs an `InlineAsm` AST node. The template string is parsed using libfmt_macros, positional and named operands are resolved to explicit operand indicies. Since target information is not available to macro invocations, validation of the registers and register classes is deferred to AST lowering. ## HIR `InlineAsm` is represented as an expression in the HIR: ```rust pub struct InlineAsm<'hir> { pub template: &'hir [InlineAsmTemplatePiece], pub operands: &'hir [InlineAsmOperand<'hir>], pub options: InlineAsmOptions, } pub enum InlineAsmRegOrRegClass { Reg(InlineAsmReg), RegClass(InlineAsmRegClass), } pub enum InlineAsmOperand<'hir> { In { reg: InlineAsmRegOrRegClass, expr: Expr<'hir>, }, Out { reg: InlineAsmRegOrRegClass, late: bool, expr: Option<Expr<'hir>>, }, InOut { reg: InlineAsmRegOrRegClass, late: bool, expr: Expr<'hir>, }, SplitInOut { reg: InlineAsmRegOrRegClass, late: bool, in_expr: Expr<'hir>, out_expr: Option<Expr<'hir>>, }, Const { expr: Expr<'hir>, }, Sym { expr: Expr<'hir>, }, } ``` AST lowering is where `InlineAsmRegOrRegClass` is converted from `Symbol`s to an actual register or register class. If any modifiers are specified for a template string placeholder, these are validated against the set allowed for that operand type. Finally, explicit registers for inputs and outputs are checked for conflicts (same register used for different operands). ## Type checking Each register class has a whitelist of types that it may be used with. After the types of all operands have been determined, the `intrinsicck` pass will check that these types are in the whitelist. It also checks that split `inout` operands have compatible types and that `const` operands are integers or floats. Suggestions are emitted where needed if a template modifier should be used for an operand based on the type that was passed into it. ## HAIR `InlineAsm` is represented as an expression in the HAIR: ```rust crate enum ExprKind<'tcx> { // [..] InlineAsm { template: &'tcx [InlineAsmTemplatePiece], operands: Vec<InlineAsmOperand<'tcx>>, options: InlineAsmOptions, }, } crate enum InlineAsmOperand<'tcx> { In { reg: InlineAsmRegOrRegClass, expr: ExprRef<'tcx>, }, Out { reg: InlineAsmRegOrRegClass, late: bool, expr: Option<ExprRef<'tcx>>, }, InOut { reg: InlineAsmRegOrRegClass, late: bool, expr: ExprRef<'tcx>, }, SplitInOut { reg: InlineAsmRegOrRegClass, late: bool, in_expr: ExprRef<'tcx>, out_expr: Option<ExprRef<'tcx>>, }, Const { expr: ExprRef<'tcx>, }, SymFn { expr: ExprRef<'tcx>, }, SymStatic { expr: ExprRef<'tcx>, }, } ``` The only significant change compared to HIR is that `Sym` has been lowered to either a `SymFn` whose `expr` is a `Literal` ZST of the `fn`, or a `SymStatic` whose `expr` is a `StaticRef`. ## MIR `InlineAsm` is represented as a `Terminator` in the MIR: ```rust pub enum TerminatorKind<'tcx> { // [..] /// Block ends with an inline assembly block. This is a terminator since /// inline assembly is allowed to diverge. InlineAsm { /// The template for the inline assembly, with placeholders. template: &'tcx [InlineAsmTemplatePiece], /// The operands for the inline assembly, as `Operand`s or `Place`s. operands: Vec<InlineAsmOperand<'tcx>>, /// Miscellaneous options for the inline assembly. options: InlineAsmOptions, /// Destination block after the inline assembly returns, unless it is /// diverging (InlineAsmOptions::NORETURN). destination: Option<BasicBlock>, }, } pub enum InlineAsmOperand<'tcx> { In { reg: InlineAsmRegOrRegClass, value: Operand<'tcx>, }, Out { reg: InlineAsmRegOrRegClass, late: bool, place: Option<Place<'tcx>>, }, InOut { reg: InlineAsmRegOrRegClass, late: bool, in_value: Operand<'tcx>, out_place: Option<Place<'tcx>>, }, Const { value: Operand<'tcx>, }, SymFn { value: Box<Constant<'tcx>>, }, SymStatic { value: Box<Constant<'tcx>>, }, } ``` As part of HAIR lowering, `InOut` and `SplitInOut` operands are lowered to a split form with a separate `in_value` and `out_place`. Semantically, the `InlineAsm` terminator is similar to the `Call` terminator except that it has multiple output places where a `Call` only has a single return place output. The constant promotion pass is used to ensure that `const` operands are actually constants (using the same logic as `#[rustc_args_required_const]`). ## Codegen Operands are lowered one more time before being passed to LLVM codegen: ```rust pub enum InlineAsmOperandRef<'tcx, B: BackendTypes + ?Sized> { In { reg: InlineAsmRegOrRegClass, value: OperandRef<'tcx, B::Value>, }, Out { reg: InlineAsmRegOrRegClass, late: bool, place: Option<PlaceRef<'tcx, B::Value>>, }, InOut { reg: InlineAsmRegOrRegClass, late: bool, in_value: OperandRef<'tcx, B::Value>, out_place: Option<PlaceRef<'tcx, B::Value>>, }, Const { string: String, }, SymFn { instance: Instance<'tcx>, }, SymStatic { def_id: DefId, }, } ``` The operands are lowered to LLVM operands and constraint codes as follow: - `out` and the output part of `inout` operands are added first, as required by LLVM. Late output operands have a `=` prefix added to their constraint code, non-late output operands have a `=&` prefix added to their constraint code. - `in` operands are added normally. - `inout` operands are tied to the matching output operand. - `sym` operands are passed as function pointers or pointers, using the `"s"` constraint. - `const` operands are formatted to a string and directly inserted in the template string. The template string is converted to LLVM form: - `$` characters are escaped as `$$`. - `const` operands are converted to strings and inserted directly. - Placeholders are formatted as `${X:M}` where `X` is the operand index and `M` is the modifier character. Modifiers are converted from the Rust form to the LLVM form. The various options are converted to clobber constraints or LLVM attributes, refer to the [RFC](https://github.com/Amanieu/rfcs/blob/inline-asm/text/0000-inline-asm.md#mapping-to-llvm-ir) for more details. Note that LLVM is sometimes rather picky about what types it accepts for certain constraint codes so we sometimes need to insert conversions to/from a supported type. See the target-specific ISelLowering.cpp files in LLVM for details. # Adding support for new architectures Adding inline assembly support to an architecture is mostly a matter of defining the registers and register classes for that architecture. All the definitions for register classes are located in `src/librustc_target/asm/`. Additionally you will need to implement lowering of these register classes to LLVM constraint codes in `src/librustc_codegen_llvm/asm.rs`.
2020-05-19auto impl`DiscriminantKind` for every typeBastian Kauschke-20/+102
2020-05-18HIR passes for asm!Amanieu d'Antras-0/+3
2020-05-18Implement asm! in librustc_builtin_macrosAmanieu d'Antras-3/+3
2020-05-17Logically seperate lazy norm from `const_generics`Bastian Kauschke-1/+1
2020-05-17add docsBastian Kauschke-1/+1
2020-05-17merge lazy_normalization_consts into const_genericsBastian Kauschke-1/+1
2020-05-17explicitly handle errors in `select`Bastian Kauschke-13/+19
2020-05-17explicitly handle errors in fulfillBastian Kauschke-11/+12
2020-05-17initial cleanupBastian Kauschke-3/+6
2020-05-17Put lazy normalization behind a feature gateBen Lewis-0/+14
2020-05-17Assume unevaluated consts are equal to the other consts and add ConstEquate ↵Ben Lewis-53/+180
obligation. This delays the need to evaluate consts eagerly and therefore gets around const eval query cycles.
2020-05-17Rollup merge of #72282 - jonas-schievink:issue-typo, r=Dylan-DPCDylan DPC-1/+1
Fix issue number typo in note
2020-05-17Rollup merge of #72281 - estebank:fix-ws-sugg, r=Dylan-DPCDylan DPC-1/+1
Fix whitespace in `?Sized` structured suggestion
2020-05-16Fix issue number typo in noteJonas Schievink-1/+1
2020-05-16Fix whitespace in `?Sized` structured suggestionEsteban Küber-1/+1
2020-05-16Rollup merge of #72216 - doctorn:require-lang-item, r=lcnrDylan DPC-2/+3
Remove `lang_items\(\).*\.unwrap\(\)` Follows up #72170 to remove the remaining uses of `lang_items\(\).*\.unwrap\(\)` (avoids a bunch of potential ICEs when working in `#![no_core]`). Resolves #72195
2020-05-16Rollup merge of #71948 - csmoe:issue-61076, r=oli-obkDylan DPC-1/+143
Suggest to await future before ? operator Closes https://github.com/rust-lang/rust/issues/71811 cc #61076
2020-05-15Remove lang_items\(\).*\.unwrap\(\)Nathan Corbyn-2/+3
2020-05-15implement type_implments_trait querycsmoe-19/+60
2020-05-14Rollup merge of #72194 - doctorn:dispatch-from-dyn-ice, r=estebankDylan DPC-6/+23
Don't ICE on missing `Unsize` impl Previously code of the form ```rust #![feature(unsize, dispatch_from_dyn)] use std::marker::Unsize; use std::ops::DispatchFromDyn; pub struct Foo<'a, T: ?Sized> { _inner: &'a &'a T, } impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Foo<'a, U>> for Foo<'a, T> {} ``` would generate an ICE due to the missing `Unsize` impl being run through the `suggest_change_mut` suggestion. This PR adds an early exit and a pointer to the appropriate docs regarding `Unsize` instead: ``` error[E0277]: the trait bound `&'a T: std::marker::Unsize<&'a U>` is not satisfied --> src/test/ui/issues/issue-71036.rs:11:1 | 11 | impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Foo<'a, U>> for Foo<'a, T> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Unsize<&'a U>` is not implemented for `&'a T` | = note: all implementations of `Unsize` are provided automatically by the compiler, see <https://doc.rust-lang.org/stable/std/marker/trait.Unsize.html> for more information = note: required because of the requirements on the impl of `std::ops::DispatchFromDyn<&'a &'a U>` for `&'a &'a T` error: aborting due to previous error For more information about this error, try `rustc --explain E0277`. ``` r? @estebank Resolves #71036
2020-05-14Rollup merge of #72170 - lcnr:lang_item, r=oli-obkDylan DPC-2/+3
use `require_lang_item` over `unwrap`. Does not yet replace all uses of `lang_items\(\)\.*\.unwrap\(\)`, as there are more than I expected :sweat_smile: Fixes #72099 r? @RalfJung *edit: The goal of this this PR is to change ICE from missing lang items to a fatal error.*
2020-05-14Don't ICE on missing `Unsize` implNathan Corbyn-6/+23
2020-05-14Rollup merge of #72150 - jackh726:unnorm_projection, r=nikomatsakisRalf Jung-15/+6
Remove UnnormalizedProjection This was only used for the old chalk integration with chalk-engine r? @nikomatsakis
2020-05-13use `require_lang_item` over `unwrap`.Bastian Kauschke-2/+3
2020-05-12review commentsEsteban Küber-2/+9
2020-05-12Increase verbosity of bound restriction suggestionsEsteban Küber-4/+8
- Make the bound restriction suggestion `span_suggestion_verbose`. - Fix whitespace typo.
2020-05-12Suggest adding super trait constraintsEsteban Küber-4/+41
2020-05-12Remove ty::UnnormalizedProjectionJack Huey-15/+6
2020-05-11Rollup merge of #72109 - matthiaskrgr:cl8ppy, r=Dylan-DPCDylan DPC-5/+5
Fix clippy warnings Fixes clippy::{cone_on_copy, filter_next, redundant_closure, single_char_pattern, len_zero,redundant_field_names, useless_format, identity_conversion, map_clone, into_iter_on_ref, needless_return, option_as_ref_deref, unused_unit, unnecessary_mut_passed} r? @Dylan-DPC
2020-05-11Rollup merge of #72019 - matthewjasper:dont-skip-binder, r=davidtwcoDylan DPC-0/+9
Fix debug assertion in error code Closes #70813
2020-05-11Fix clippy warningsMatthias Krüger-5/+5
Fixes clippy::{cone_on_copy, filter_next, redundant_closure, single_char_pattern, len_zero,redundant_field_names, useless_format, identity_conversion, map_clone, into_iter_on_ref, needless_return, option_as_ref_deref, unused_unit, unnecessary_mut_passed}