about summary refs log tree commit diff
path: root/compiler
AgeCommit message (Collapse)AuthorLines
2023-09-07Use `Freeze` for `SourceFile.lines`John Kåre Alsaker-136/+164
2023-09-07Use `Freeze` for `SourceFile.external_src`John Kåre Alsaker-46/+91
2023-09-07Auto merge of #110050 - saethlin:better-u32-encoding, r=nnethercotebors-45/+399
Use a specialized varint + bitpacking scheme for DepGraph encoding The previous scheme here uses leb128 to encode the edge tables that represent the incr comp dependency graph. The problem with that scheme is that leb128 has overhead for larger values, and generally relies on the distribution of encoded values being heavily skewed towards smaller values. That is definitely not the case for a dep node index, since they are handed out sequentially and the whole range is covered, the distribution is actually biased in the opposite direction: Most dep nodes are large. This PR implements a different varint encoding scheme. Instead of applying varint encoding to individual dep node indices (which is extremely branchy) we now apply it per node. While being built, each node now stores its edges in a `SmallVec` with a bit of extra logic to track the max value of each edge. Then we varint encode the whole batch. This is a gamble: We save on space by only claiming 2 bits per node instead of ~3 bits per edge which is a nice savings but needs to balance out with the space overhead that a single large index in a node with a lot of edges will encode unnecessary bytes in each of that node's edge indices. Then, to keep the runtime overhead of this encoding scheme down we deserialize our indices by loading 4 bytes for each then masking off the bytes that are't ours. This is much less code and branches than leb128, but relies on having some readable bytes past the end of each edge list. We explicitly add such padding to the in-memory data during decoding. And we also do this decoding lazily, turning a dense on-disk encoding into a peak memory reduction. Then we apply a bit-packing scheme; since in https://github.com/rust-lang/rust/pull/115391 we now have unused bits on `DepKind`, we use those unused bits (currently there are 7!) to store the 2 bits that we need for the byte width of the edges in each node, then use the remaining bits to store the length of the edge list, if it fits. r? `@nnethercote`
2023-09-06Add comments with the same level of detail as the PR descriptionBen Kimock-12/+54
2023-09-07Auto merge of #115166 - Urgau:invalid_ref_casting-invalid-unsafecell-usage, ↵bors-5/+40
r=est31 Lint on invalid usage of `UnsafeCell::raw_get` in reference casting This PR proposes to take into account `UnsafeCell::raw_get` method call for non-Freeze types for the `invalid_reference_casting` lint. The goal of this is to catch those kind of invalid reference casting: ```rust fn as_mut<T>(x: &T) -> &mut T { unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) } //~^ ERROR casting `&T` to `&mut T` is undefined behavior } ``` r? `@est31`
2023-09-06Auto merge of #115580 - eduardosm:stdarch-intrinsics, r=davidtwco,bjorn3bors-248/+0
Update stdarch submodule and remove special handling in cranelift codegen for some AVX and SSE2 LLVM intrinsics https://github.com/rust-lang/stdarch/pull/1463 reimplemented some x86 intrinsics to avoid using some x86-specific LLVM intrinsics: * Store unaligned (`_mm*_storeu_*`) use `<*mut _>::write_unaligned` instead of `llvm.x86.*.storeu.*`. * Shift by immediate (`_mm*_s{ll,rl,ra}i_epi*`) use `if` (srl, sll) or `min` (sra) to simulate the behaviour when the RHS is out of range. RHS is constant, so the `if`/`min` will be optimized away. This PR updates the stdarch submodule to pull these changes and removes special handling for those LLVM intrinsics from cranelift codegen. I left gcc codegen untouched because there are some autogenerated lists.
2023-09-06Auto merge of #114946 - anforowicz:generic-fix-for-asan-lto, r=tmiaskobors-0/+7
Preserve ASAN-related symbols during LTO. Fixes https://github.com/rust-lang/rust/issues/113404
2023-09-06Auto merge of #115615 - matthiaskrgr:rollup-49fosdf, r=matthiaskrgrbors-25/+60
Rollup of 9 pull requests Successful merges: - #114511 (Remove the unhelpful let binding diag comes from FormatArguments) - #115473 (Add explanatory note to 'expected item' error) - #115574 (Replace `rustc_data_structures` dependency with `rustc_index` in `rustc_parse_format`) - #115578 (Clarify cryptic comments) - #115587 (fix #115348) - #115596 (A small change) - #115598 (Fix log formatting in bootstrap) - #115605 (Better Debug for `Ty` in smir) - #115614 (Fix minor grammar typo) r? `@ghost` `@rustbot` modify labels: rollup
2023-09-06Rollup merge of #115605 - ouz-a:smir_better_debug, r=oli-obkMatthias Krüger-1/+8
Better Debug for `Ty` in smir Similar to what I did here https://github.com/rust-lang/rust/pull/115534. r? ``@oli-obk``
2023-09-06Rollup merge of #115596 - nnethercote:two-small-changes, r=lqdMatthias Krüger-1/+1
A small change A small change I made while poking around the code. r? `@lqd`
2023-09-06Rollup merge of #115587 - mojave2:issue-115348, r=oli-obkMatthias Krüger-1/+1
fix #115348 fix #115348 It looks that: - In `rustc_mir_build::build`, the body of function will not be built, when the `tcx.check_match(def)` fails due to `non-exhaustive patterns` - In `rustc_mir_transform::check_unsafety`, the `UnsafetyChecker` collects all `used_unsafe_blocks` in the MIR of a function, and the `UnusedUnsafeVisitor` will visit all `UnsafeBlock`s in the HIR and collect `unused_unsafes`, which are not contained in `used_unsafe_blocks`, and report `unnecessary_unsafe`s - So the unsafe block in the issue example code will be reported as `unnecessary_unsafe`.
2023-09-06Rollup merge of #115578 - ouz-a:rustc_clarify, r=oli-obkMatthias Krüger-3/+3
Clarify cryptic comments Clarifies some unclear comments that lurked in the compiler. r? ``@oli-obk``
2023-09-06Rollup merge of #115574 - Veykril:rustc_parse_format-dep, r=NilstriebMatthias Krüger-2/+2
Replace `rustc_data_structures` dependency with `rustc_index` in `rustc_parse_format` `rustc_data_structures` is only used for the `static_assert_size` macro, yet that is defined in `rustc_index` and merely re-exported. `rustc_index` is a lot more lightweight than `rustc_data_structures` which would make this a lot more reusable for rust-analyzer.
2023-09-06Rollup merge of #115473 - gurry:113110-expected-item, r=compiler-errorsMatthias Krüger-4/+8
Add explanatory note to 'expected item' error Fixes #113110 It changes the diagnostic from this: ``` error: expected item, found `5` --> ../test.rs:1:1 | 1 | 5 | ^ expected item ``` to this: ``` error: expected item, found `5` --> ../test.rs:1:1 | 1 | 5 | ^ expected item | = note: items are things that can appear at the root of a module = note: for a full list see https://doc.rust-lang.org/reference/items.html ```
2023-09-06Rollup merge of #114511 - chenyukang:yukang-fix-114374-fmt-args, r=b-naberMatthias Krüger-13/+37
Remove the unhelpful let binding diag comes from FormatArguments Fixes #114374
2023-09-06Auto merge of #115252 - cjgillot:mir-composite, r=davidtwcobors-284/+250
Represent MIR composite debuginfo as projections instead of aggregates Composite debuginfo for MIR is currently represented as ``` debug name => Type { projection1 => place1, projection2 => place2 }; ``` ie. a single `VarDebugInfo` object with that name, and its value a `VarDebugInfoContents::Composite`. This PR proposes to reverse the representation to be ``` debug name.projection1 => place1; debug name.projection2 => place2; ``` ie. multiple `VarDebugInfo` objects with each their projection. This simplifies the handling of composite debuginfo by the compiler by avoiding weird nesting. Based on https://github.com/rust-lang/rust/pull/115139
2023-09-06Ty Debug now prints id and kindouz-a-1/+8
2023-09-06Auto merge of #115401 - Zoxc:freeze, r=oli-obkbors-32/+148
Add `FreezeLock` type and use it to store `Definitions` This adds a `FreezeLock` type which allows mutation using a lock until the value is frozen where it can be accessed lock-free. It's used to store `Definitions` in `Untracked` instead of a `RwLock`. Unlike the current scheme of leaking read guards this doesn't deadlock if definitions is written to after no mutation are expected.
2023-09-06fix #115348mojave2-1/+1
2023-09-06Use a reference to the lock in the guardsJohn Kåre Alsaker-15/+14
2023-09-06make comments less crypticouz-a-3/+3
2023-09-06Implement and test monomorphizationOli Scherer-2/+63
2023-09-06Allow fetching the SMIR body of FnDefsOli Scherer-5/+15
2023-09-06Deopaquify `ParamConst`Oli Scherer-11/+26
2023-09-06Add types to all constantsOli Scherer-8/+9
2023-09-06Also use `Const` in `SMIR` instead of just `ConstantKind`Oli Scherer-15/+19
2023-09-06Add type folder to SMIROli Scherer-6/+255
2023-09-06Adjust `to_attr_token_stream`.Nicholas Nethercote-1/+1
It uses `once` chained with `(0..self.num_calls).map(...)` followed by `.take(self.num_calls`. I found this hard to read. It's simpler to just use `repeat_with`.
2023-09-06Auto merge of #115584 - ezekielathome:docs-pattern-inconsistency, ↵bors-3/+3
r=compiler-errors replace doc occurrences of ItemLikeVisitor Solves #114885 ItemLikeVisitor used to have comments describing visit patterns. After it was removed, it was moved to `rustc_hir::intravisit` but references in `intravisit.rs` weren't updated.
2023-09-06Add explanatory note to 'expected item' errorGurinder Singh-4/+8
2023-09-06Auto merge of #115529 - chenyukang:yukang-fix-115402-overflowsize, ↵bors-0/+19
r=compiler-errors Fix error report for size overflow from transmute Fixes #115402 The span in the error reporting always points to the `dst`, this is an old issue, I may open another PR to fix it.
2023-09-06Auto merge of #115371 - matthewjasper:if-let-guard-parsing, r=cjgillotbors-3/+1
Make if let guard parsing consistent with normal guards - Add tests that struct expressions are not allowed in `if let` and `while let` (no change, consistent with `if` and `while`) - Allow struct expressions in `if let` guards (consistent with `if` guards). r? `@cjgillot` Closes #93817 cc #51114
2023-09-06Fix error report for size overflow from transmuteyukang-0/+19
2023-09-05Auto merge of #115507 - cjgillot:relative-source-file, r=oli-obkbors-349/+244
Use relative positions inside a SourceFile. This allows to remove the normalization of start positions for hashing, and simplify allocation of global address space. cc `@Zoxc`
2023-09-05replace doc occurrences of ItemLikeVisitorezekiel-3/+3
ItemLikeVisitor was removed, and the visit strategy was moved to `rustc_hir::intravisit`
2023-09-05Remove special handling in codegen for some AVX and SSE2 shift by immediate ↵Eduardo Sánchez Muñoz-240/+0
intrinsics Those were removed from stdarch in https://github.com/rust-lang/stdarch/pull/1463 (`simd_shl` and `simd_shr` are used instead)
2023-09-05Rollup merge of #115559 - lcnr:implied-bounds-unconstrained, r=aliemjayMatthias Krüger-9/+5
implied bounds: do not ICE on unconstrained region vars fixes #112832 see tests/ui/implied-bounds/implied-bounds-unconstrained-2.rs for a minimal example showing why this is necessary. r? types cc ``@compiler-errors`` ``@aliemjay`` https://rust-lang.zulipchat.com/#narrow/stream/144729-t-types/topic/assoc.20type.20bound.20in.20super.20trait
2023-09-05Remove special handling in codegen for some SSE2 "storeu" intrinsicsEduardo Sánchez Muñoz-8/+0
Those were removed from stdarch in https://github.com/rust-lang/stdarch/pull/1463 (`<*mut _>::write_unaligned` is used instead)
2023-09-05Refactor how MIR represents composite debuginfo.Camille GILLOT-229/+181
2023-09-05Replace data_structures dependency with index in rustc_parse_formatLukas Wirth-2/+2
2023-09-05Refactor projection debug.Camille GILLOT-55/+69
2023-09-05Add tests and use ControlFlowCelina G. Val-34/+34
2023-09-05SMIR: Allow users to pick if compilation continuesCelina G. Val-8/+20
Currently we stop compilation, but some users might want to keep going. This is needed for us to test against rustc tests. Other tools, such as Kani, also implements parts of their logic as a backend so it is important for compilation to continue.
2023-09-05Diferentiate between ICE and compilation errorCelina G. Val-8/+15
2023-09-05Adjust StableMIR interface to return and not crashCelina G. Val-11/+37
Invoking StableMir::run() on a crate that has any compilation error was crashing the entire process. Instead, return a `CompilerError` so the user knows compilation did not succeed. I believe ICE will also be converted to `CompilerError`. I'm also adding a return value to the callback, because I think it will be handy for users (at least it was for my current task of implementing a tool to validate stable-mir). However, if people disagree, I can remove that.
2023-09-05Rollup merge of #115563 - krasimirgg:llvm-18-bitcodereader, r=nikicMatthias Krüger-0/+4
llvm-wrapper: adapt for LLVM API change No functional changes intended. Adapts the wrapper for https://github.com/llvm/llvm-project/commit/bbe8cd13335300958b04db5318c31ff52714f96f. Found by our experimental rust + llvm @ HEAD CI: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/22055#018a6495-8dd9-41df-9381-5e7b0009ce0a/274-575
2023-09-05Rollup merge of #115540 - cjgillot:custom-debuginfo, r=oli-obkMatthias Krüger-2/+57
Support debuginfo for custom MIR.
2023-09-05Rollup merge of #115536 - RalfJung:interpreter-privacy, r=oli-obkMatthias Krüger-246/+331
interpret: make MemPlace, Place, Operand types private to the interpreter Outside the interpreter, only the typed versions should be used.
2023-09-05Rollup merge of #115523 - mojave2:improve-tokenstream, r=petrochenkovMatthias Krüger-11/+7
improve `AttrTokenStream` Improve the performance of `AttrTokenStream::to_tokenstream` method
2023-09-05llvm-wrapper: adapt for LLVM API changeKrasimir Georgiev-0/+4
No functional changes intended. Adapts the wrapper for https://github.com/llvm/llvm-project/commit/bbe8cd13335300958b04db5318c31ff52714f96f. Found by our experimental rust + llvm @ HEAD CI: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/22055#018a6495-8dd9-41df-9381-5e7b0009ce0a/274-575