| Age | Commit message (Collapse) | Author | Lines | |
|---|---|---|---|---|
| 2020-05-25 | Rollup merge of #72544 - sexxi-goose:upvars_mentioned, r=matthewjasper | Ralf Jung | -4/+9 | |
| librustc_middle: Rename upvars query to upvars_mentioned As part of supporting RFC 2229, we will be capturing all the Places that were mentioned in the closure. This commit modifies the name of the upvars query to upvars_mentioned. r? @nikomatsakis @blitzerr @matthewjasper | ||||
| 2020-05-25 | Rollup merge of #72525 - RalfJung:miri-cast-checks, r=eddyb | Ralf Jung | -94/+101 | |
| Miri casts: do not blindly rely on dest type Make sure that we notice when the MIR is bad and the casted-to and destination type are e.g. of different size, as suggested by @eddyb. | ||||
| 2020-05-25 | add a lint against references to packed fields | Ralf Jung | -1/+71 | |
| 2020-05-25 | Auto merge of #72520 - jonas-schievink:cleanup-userty, r=matthewjasper | bors | -0/+4 | |
| Clear MIR local type annotations after borrowck | ||||
| 2020-05-24 | librustc_middle: Rename upvars query to upvars_mentioned | Aman Arora | -4/+9 | |
| As part of supporting RFC 2229, we will be capturing all the Places that were mentioned in the closure. This commit modifies the name of the upvars query to upvars_mentioned. Co-authored-by: Aman Arora <me@aman-arora.com> Co-authored-by: Chris Pardy <chrispardy36@gmail.com> | ||||
| 2020-05-24 | comment nit | Ralf Jung | -1/+1 | |
| 2020-05-24 | use helper method for determining size of int type | Ralf Jung | -15/+11 | |
| 2020-05-24 | Removed all instances of const_field. | Rakshith Ravi | -32/+1 | |
| 2020-05-24 | Fix unsizing casts | Ralf Jung | -20/+18 | |
| 2020-05-24 | Miri casts: do not blindly rely on dest type | Ralf Jung | -51/+76 | |
| 2020-05-24 | Auto merge of #72362 - matthewjasper:remove-rescope, r=nikomatsakis | bors | -5/+0 | |
| Remove ReScope `ReScope` is unnecessary now that AST borrowck is gone and we're erasing the results of region inference in function bodies. This removes about as much of the old regionck code as possible without having to enable NLL fully. cc #68261 r? @nikomatsakis | ||||
| 2020-05-24 | Clear MIR local type annotations after borrowck | Jonas Schievink | -0/+4 | |
| 2020-05-24 | Properly handle InlineAsmOperand::SymFn when collecting monomorphized items | Amanieu d'Antras | -2/+9 | |
| Fixes #72484 | ||||
| 2020-05-24 | make some cast helpers infallible | Ralf Jung | -29/+17 | |
| 2020-05-23 | fix discriminant type in generator transform | Ralf Jung | -1/+1 | |
| 2020-05-23 | take mir::PlaceElem by value | Bastian Kauschke | -38/+38 | |
| 2020-05-23 | iterate List by value | Bastian Kauschke | -15/+15 | |
| 2020-05-22 | Use `OnceCell` instead of `Once` | Dylan MacKenzie | -6/+5 | |
| 2020-05-22 | Remove dead ScopeTree code | Matthew Jasper | -4/+0 | |
| 2020-05-22 | Remove ReScope | Matthew Jasper | -1/+0 | |
| 2020-05-22 | Rollup merge of #71610 - divergentdave:InvalidUndefBytes-range, r=RalfJung | Ralf Jung | -6/+8 | |
| InvalidUndefBytes: Track size of undef region used This PR adds a size to `UndefinedBehaviorInfo::InvalidUndefBytes`, to keep track of how many undefined bytes in a row were accessed, and changes a few methods to pass this information through. This additional information will eventually be used in Miri to improve diagnostics for this UB error. See also rust-lang/miri#1354 for prior discussion. I expect Miri will break the next time its submodule is updated, due to this change to the `InvalidUndefBytes`. (The current commit for src/tools/miri predates rust-lang/miri#1354, and thus does not try to destructure the `InvalidUndefBytes` variant) I have a corresponding change prepared for that repository. r? @RalfJung | ||||
| 2020-05-21 | Perform MIR NRVO even if types don't match | Dylan MacKenzie | -12/+6 | |
| 2020-05-22 | Auto merge of #71956 - ecstatic-morse:remove-requires-storage-analysis, ↵ | bors | -370/+252 | |
| r=tmandry Clean up logic around live locals in generator analysis Resolves #69902. Requires #71893. I've found it difficult to make changes in the logic around live locals in `generator/transform.rs`. It uses a custom dataflow analysis, `MaybeRequiresStorage`, that AFAICT computes whether a local is either initialized or borrowed. That analysis is using `before` effects, which we should try to avoid if possible because they are harder to reason about than ones only using the unprefixed effects. @pnkfelix has suggested removing "before" effects entirely to simplify the dataflow framework, which I might pursue someday. This PR replaces `MaybeRequiresStorage` with a combination of the existing `MaybeBorrowedLocals` and a new `MaybeInitializedLocals`. `MaybeInitializedLocals` is just `MaybeInitializedPlaces` with a coarser resolution: it works on whole locals instead of move paths. As a result, I was able to simplify the logic in `compute_storage_conflicts` and `locals_live_across_suspend_points`. This is not exactly equivalent to the old logic; some generators are now smaller than before. I believe this was because the old logic was too conservative, but I'm not as familiar with the constraints as the original implementers were, so I could be wrong. For example, I don't see a reason the size of the `mixed_sizes` future couldn't be 5K. It went from 7K to 6K in this PR. r? @jonas-schievink @tmandry | ||||
| 2020-05-21 | Rollup merge of #72425 - RalfJung:discr-sign-ext, r=nikomatsakis | Ralf Jung | -1/+4 | |
| fix discriminant_value sign extension Fixes a regression introduced in https://github.com/rust-lang/rust/pull/70705 r? @nikomatsakis Cc @lcnr @oli-obk | ||||
| 2020-05-21 | Rollup merge of #72055 - lcnr:predicate-kind, r=nikomatsakis | Ralf Jung | -23/+27 | |
| 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-21 | fix discriminant sign extension | Ralf Jung | -1/+4 | |
| 2020-05-21 | Auto merge of #72205 - ecstatic-morse:nrvo, r=oli-obk | bors | -0/+240 | |
| Dumb NRVO This is a very simple version of an NRVO pass, which scans backwards from the `return` terminator to see if there is an an assignment like `_0 = _1`. If a basic block with two or more predecessors is encountered during this scan without first seeing an assignment to the return place, we bail out. This avoids running a full "reaching definitions" dataflow analysis. I wanted to see how much `rustc` would benefit from even a very limited version of this optimization. We should be able to use this as a point of comparison for more advanced versions that are based on live ranges. r? @ghost | ||||
| 2020-05-20 | Bail out if new return place has different type than old | Dylan MacKenzie | -1/+12 | |
| 2020-05-21 | Auto merge of #70705 - lcnr:generic_discriminant, r=nikomatsakis | bors | -3/+6 | |
| 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-20 | Use `is_const_fn_raw` when unsafety checking | Dylan MacKenzie | -2/+2 | |
| 2020-05-20 | change `Predicate::kind` to return a reference | Bastian Kauschke | -1/+1 | |
| 2020-05-20 | introduce newtype'd `Predicate<'tcx>` | Bastian Kauschke | -9/+11 | |
| 2020-05-20 | rename `Predicate` to `PredicateKind`, introduce alias | Bastian Kauschke | -17/+19 | |
| 2020-05-20 | fix is_const_context | Bastian Kauschke | -1/+1 | |
| 2020-05-19 | Document why we don't look at storage liveness | Dylan MacKenzie | -0/+9 | |
| ...when determining what locals are live. A local cannot be borrowed before it is `storage_live` and `MaybeBorrowedLocals` already invalidates borrows on `StorageDead`. Likewise, a local cannot be initialized before it is marked StorageLive and is marked as uninitialized after `StorageDead`. | ||||
| 2020-05-19 | Document assumptions made in generator transform for analyses | Dylan MacKenzie | -0/+6 | |
| The generator transform needs to inspect all possible dataflow states. This can be done with half the number of bitset union operations if we can assume that the relevant analyses do not use "before" effects. | ||||
| 2020-05-19 | Look for storage conflicts before terminator effect | Dylan MacKenzie | -5/+6 | |
| 2020-05-19 | Add comment for strange conditional | Dylan MacKenzie | -0/+1 | |
| 2020-05-19 | Add comment explaining the extra `record_conflicts` | Dylan MacKenzie | -0/+4 | |
| 2020-05-19 | Remove `MaybeRequiresStorage` | Dylan MacKenzie | -234/+2 | |
| 2020-05-19 | Clean up generator live locals analysis | Dylan MacKenzie | -137/+113 | |
| Instead of using a bespoke dataflow analysis, `MaybeRequiresStorage`, for computing locals that need to be stored across yield points and that have conflicting storage, use a combination of simple, generally applicable dataflow analyses. In this case, the formula for locals that are live at a yield point is: live_across_yield := (live & init) | (!movable & borrowed) and the formula for locals that require storage (and thus may conflict with others) at a given point is: requires_storage := init | borrowed `init` is `MaybeInitializedLocals`, a direct equivalent of `MaybeInitializedPlaces` that works only on whole `Local`s. `borrowed` and `live` are the pre-existing `MaybeBorrowedLocals` and `MaybeLiveLocals` analyses respectively. | ||||
| 2020-05-19 | Add `MaybeInitializedLocals` dataflow analysis | Dylan MacKenzie | -0/+117 | |
| 2020-05-19 | Auto merge of #69171 - Amanieu:new-asm, r=nagisa,nikomatsakis | bors | -27/+227 | |
| 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-19 | update codegen of `discriminant_value` | Bastian Kauschke | -3/+6 | |
| 2020-05-18 | Rollup merge of #72283 - jonas-schievink:elaborate-drop-elaboration, r=cramertj | Dylan DPC | -9/+99 | |
| Drop Elaboration Elaboration As in, adding more documentation to it. | ||||
| 2020-05-18 | Rollup merge of #71973 - lcnr:lazy-norm, r=nikomatsakis | Dylan DPC | -2/+7 | |
| Lazy normalization of constants (Reprise) Continuation of #67890 by @skinny121. Initial implementation of #60471 for constants. Perform normalization/evaluation of constants lazily, which is known as lazy normalization. Lazy normalization is only enabled when using `#![feature(lazy_normalization_consts)]`, by default constants are still evaluated eagerly as there are currently. Lazy normalization of constants is achieved with a new ConstEquate predicate which type inferences uses to delay checking whether constants are equal to each other until later, avoiding cycle errors. Note this doesn't allow the use of generics within repeat count expressions as that is still evaluated during conversion to mir. There are also quite a few other known problems with lazy normalization which will be fixed in future PRs. r? @nikomatsakis fixes #71922, fixes #71986 | ||||
| 2020-05-18 | Rollup merge of #71599 - ldm0:fnclo, r=nikomatsakis | Dylan DPC | -1/+1 | |
| Support coercion between (FnDef | Closure) and (FnDef | Closure) Fixes #46742, fixes #48109 Inject `Closure` into the `FnDef x FnDef` coercion special case, which makes coercion of `(FnDef | Closure) x (FnDef | Closure)` possible, where closures should be **non-capturing**. | ||||
| 2020-05-18 | Check that asm const operands are actually constants | Amanieu d'Antras | -16/+65 | |
| 2020-05-18 | Add asm! to MIR | Amanieu d'Antras | -11/+162 | |
| 2020-05-18 | Auto merge of #72269 - RalfJung:unsafe-borrow-of-packed, r=Mark-Simulacrum | bors | -19/+19 | |
| move borrow-of-packed-field unsafety check out of loop Looks like during the place refactoring, this code somehow got into this loop even though it does not actually depend on the loop variables. | ||||
