Skip to content

Rollup of 12 pull requests #81625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 90 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
77f74ed
Merge commit 'dbee13661efa269cb4cd57bb4c6b99a19732b484' into sync_cg_…
bjorn3 Dec 27, 2020
50a6a84
Merge branch 'sync_from_rust'
bjorn3 Dec 27, 2020
2c41a69
Rustup to rustc 1.51.0-nightly (44e3daf5e 2020-12-31)
bjorn3 Jan 1, 2021
1a1cdac
Remove code that was moved from the backend to rustc_incremental
bjorn3 Jan 2, 2021
3ea8915
Disable timings by default for cargo.sh
bjorn3 Jan 6, 2021
ea73caa
codegen_cranelift: Fix redundant semicolon warn
osa1 Jan 16, 2021
c34e165
Update Cranelift
bjorn3 Jan 16, 2021
1952b1f
Update dependencies
bjorn3 Jan 16, 2021
cfedad1
Clear domtree after cg_clif optimizations
bjorn3 Jan 16, 2021
c3d7dc9
Use ty::{IntTy,UintTy,FloatTy} in rustc
LeSeulArtichaut Dec 12, 2020
c0aefeb
Rustup to rustc 1.51.0-nightly (a4cbb44ae 2021-01-20)
bjorn3 Jan 21, 2021
7f60301
Disable new failing libcore tests
bjorn3 Jan 21, 2021
9bf5cb4
Fix indirectly linking to libstd.so with the JIT
bjorn3 Jan 21, 2021
a19ef67
Update Cranelift
bjorn3 Jan 18, 2021
173ec34
Add a feature flag to switch between oldbe and newbe
bjorn3 Jan 18, 2021
da4aa92
Test both oldbe and newbe on CI
bjorn3 Jan 21, 2021
500faf2
Merge pull request #1127 from bjorn3/newbe
bjorn3 Jan 21, 2021
2ced8c0
Fix rust-analyzer pref name
bjorn3 Jan 21, 2021
ae6daf7
Default to Cranelift newBE
bjorn3 Jan 22, 2021
d6eb4f5
clean up some const error reporting around promoteds
RalfJung Jan 24, 2021
496836a
Improve `rustc_mir_build::matches` docs
camelid Jan 25, 2021
d39b441
Start using ArgAbi
bjorn3 Jan 25, 2021
6170fc6
Split abi adjustments out
bjorn3 Jan 25, 2021
ff33042
Rustup to rustc 1.51.0-nightly (1d0d76f8d 2021-01-24)
bjorn3 Jan 25, 2021
de713a8
Replace all uses of PassMode with ArgAbi
bjorn3 Jan 25, 2021
2b58d8c
Misc cleanups
bjorn3 Jan 25, 2021
4555737
Split symbol name and signature calculation
bjorn3 Jan 26, 2021
fc595f1
[WIP] Use FnAbi everywhere instead of our own abi calculations
bjorn3 Jan 26, 2021
d263447
Replace EmptySinglePair with SmallVec
bjorn3 Jan 27, 2021
aa23f86
Remove vararg support check
bjorn3 Jan 27, 2021
e564a0a
Rustfmt
bjorn3 Jan 27, 2021
268d7bc
Remove fn_sig_for_fn_abi
bjorn3 Jan 27, 2021
f8e0e78
Rename NLL* to Nll* accordingly to C-CASE
hkmatsumoto Jan 28, 2021
9e4ed33
Suggest accessing field when code compiles with it
hkmatsumoto Jan 28, 2021
e67b72d
Rollup merge of #81333 - RalfJung:const-err-simplify, r=oli-obk
JohnTitor Jan 29, 2021
a9abf6f
Add test for match expression
hkmatsumoto Jan 29, 2021
f641f51
Add rust-fix test
hkmatsumoto Jan 29, 2021
d10ee0d
Fix invalid camel case suggestion involving unicode idents
estebank Jan 29, 2021
849dc1a
Indicate both start and end of pass RSS in time-passes output
tgnottingham Jan 25, 2021
e8f48e4
[WIP] Implement PassMode::Cast
bjorn3 Jan 29, 2021
ad9f707
Fix test to check help message as well
hkmatsumoto Jan 30, 2021
08d31e0
Remove logging iterator
hkmatsumoto Jan 30, 2021
2ce2d14
Account for union
hkmatsumoto Jan 30, 2021
6bc9634
Rename function to `suggest_accessing_field_where_appropriate`
hkmatsumoto Jan 30, 2021
139a6d1
Fix 128bit checked math intrinsic calls
bjorn3 Jan 30, 2021
b5ddb76
Force stack slot size to be a multiple of 16
bjorn3 Jan 30, 2021
2d69817
Handle argument extension mode
bjorn3 Jan 30, 2021
7fcf59f
Add print on panic for predefining of a function
bjorn3 Jan 30, 2021
3eb649c
dont set rustflags when no specific linker needed
Uriopass Jan 30, 2021
6a739b3
Merge pull request #1132 from Uriopass/master
bjorn3 Jan 30, 2021
18de1b1
Merge pull request #1131 from bjorn3/abi_compat
bjorn3 Jan 30, 2021
f344768
Handle PassMode::Cast in combination with #[repr(align)]
bjorn3 Jan 30, 2021
8faae29
Add missing dir to .gitignore
bjorn3 Jan 30, 2021
d34b5e2
Rustup to rustc 1.51.0-nightly (b12290861 2021-01-29)
bjorn3 Jan 30, 2021
356d749
Update Readme.md for the fixed abi compatibility
bjorn3 Jan 30, 2021
7657ebc
Fix macOS build
bjorn3 Jan 30, 2021
84f24e5
Re-enable mir inlining for the sysroot
bjorn3 Jan 30, 2021
fa9a99f
review comments
estebank Jan 31, 2021
a292ac7
Fix prefix of debug log
hkmatsumoto Jan 31, 2021
f45a993
Rustfmt
hkmatsumoto Jan 31, 2021
1548411
Add missing directory to clean_all.sh
bjorn3 Jan 31, 2021
9c943bf
Fix sysroot dir for cg_clif_build_sysroot
bjorn3 Jan 31, 2021
9384af4
Link examples to the correct libc when targeting Windows
bjorn3 Jan 31, 2021
0a93cb3
Remove unneeded explicit width from search results
GuillaumeGomez Jan 31, 2021
07f5ca7
Prevent search section to go over search input
GuillaumeGomez Jan 31, 2021
be9b112
Improve resize handling
GuillaumeGomez Jan 31, 2021
9164653
Split config.sh and add support for copying the mingw runtime objects
bjorn3 Jan 31, 2021
8c7ae41
Remove code comment
bjorn3 Jan 31, 2021
0929e37
Fix a small error in the readme
bjorn3 Jan 31, 2021
17cffc1
Move some env var definitions around to fix cross-compilation
bjorn3 Jan 31, 2021
4105506
specialize io::copy to use the memory of the writer if it is a BufWriter
the8472 Nov 1, 2020
1fe1fa9
Avoid building LLVM just for llvm-dwp
bjorn3 Jan 31, 2021
3acd1a4
Fix calling convention for CRT startup
sivadeilra Jan 31, 2021
d556c56
Add option to build using the sysroot of rustc
bjorn3 Jan 31, 2021
6a03f03
Add error message for private fn
JulianKnodt Nov 22, 2020
2bb4a69
Move some tests to more reasonable directories
c410-f3r Jan 31, 2021
8b52cdc
Update outdated comment
camelid Jan 31, 2021
2785533
Merge commit 'd556c56f792756dd7cfec742b9f2e07612dc10f4' into sync_cg_…
bjorn3 Feb 1, 2021
a7a6f01
Rollup merge of #78641 - the8472:buffered-copy, r=sfackler
jonas-schievink Feb 1, 2021
21d0e9b
Rollup merge of #79291 - JulianKnodt:ce_priv, r=petrochenkov
jonas-schievink Feb 1, 2021
ab74346
Rollup merge of #81364 - camelid:improve-build-matches-docs, r=varkor
jonas-schievink Feb 1, 2021
c99ec7f
Rollup merge of #81387 - c410-f3r:tests-tests-tests, r=petrochenkov
jonas-schievink Feb 1, 2021
9e8753e
Rollup merge of #81463 - matsujika:nll-ensure-c-case, r=varkor
jonas-schievink Feb 1, 2021
853cfd4
Rollup merge of #81504 - matsujika:suggestion-field-access, r=estebank
jonas-schievink Feb 1, 2021
39ea347
Rollup merge of #81529 - estebank:case_lints, r=davidtwco
jonas-schievink Feb 1, 2021
82b00ec
Rollup merge of #81536 - tgnottingham:time-passes-rss, r=oli-obk
jonas-schievink Feb 1, 2021
ccc5a85
Rollup merge of #81592 - GuillaumeGomez:rustdoc-ui-fixes, r=Nemo157
jonas-schievink Feb 1, 2021
52907cc
Rollup merge of #81594 - bjorn3:avoid_building_llvm_for_dwp, r=sanxiyn
jonas-schievink Feb 1, 2021
2622227
Rollup merge of #81598 - sivadeilra:windows_dll_imports_fix_x86, r=m-…
jonas-schievink Feb 1, 2021
b3339ab
Rollup merge of #81618 - bjorn3:sync_cg_clif-2021-02-01, r=bjorn3
jonas-schievink Feb 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 73 additions & 54 deletions compiler/rustc_mir_build/src/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// visible through borrow checking. False edges ensure that the CFG as
/// seen by borrow checking doesn't encode this. False edges are added:
///
/// * From each prebinding block to the next prebinding block.
/// * From each otherwise block to the next prebinding block.
/// * From each pre-binding block to the next pre-binding block.
/// * From each otherwise block to the next pre-binding block.
crate fn match_expr(
&mut self,
destination: Place<'tcx>,
Expand Down Expand Up @@ -630,10 +630,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

#[derive(Debug)]
pub(super) struct Candidate<'pat, 'tcx> {
/// `Span` of the original pattern that gave rise to this candidate
/// [`Span`] of the original pattern that gave rise to this candidate.
span: Span,

/// This `Candidate` has a guard.
/// Whether this `Candidate` has a guard.
has_guard: bool,

/// All of these must be satisfied...
Expand All @@ -645,14 +645,15 @@ pub(super) struct Candidate<'pat, 'tcx> {
/// ...and these types asserted...
ascriptions: Vec<Ascription<'tcx>>,

/// ... and if this is non-empty, one of these subcandidates also has to match ...
/// ...and if this is non-empty, one of these subcandidates also has to match...
subcandidates: Vec<Candidate<'pat, 'tcx>>,

/// ...and the guard must be evaluated, if false branch to Block...
/// ...and the guard must be evaluated; if it's `false` then branch to `otherwise_block`.
otherwise_block: Option<BasicBlock>,

/// ...and the blocks for add false edges between candidates
/// The block before the `bindings` have been established.
pre_binding_block: Option<BasicBlock>,
/// The pre-binding block of the next candidate.
next_candidate_pre_binding_block: Option<BasicBlock>,
}

Expand Down Expand Up @@ -737,26 +738,27 @@ crate struct MatchPair<'pat, 'tcx> {
pattern: &'pat Pat<'tcx>,
}

/// See [`Test`] for more.
#[derive(Clone, Debug, PartialEq)]
enum TestKind<'tcx> {
/// Test the branches of enum.
/// Test what enum variant a value is.
Switch {
/// The enum being tested
/// The enum type being tested.
adt_def: &'tcx ty::AdtDef,
/// The set of variants that we should create a branch for. We also
/// create an additional "otherwise" case.
variants: BitSet<VariantIdx>,
},

/// Test what value an `integer`, `bool` or `char` has.
/// Test what value an integer, `bool`, or `char` has.
SwitchInt {
/// The type of the value that we're testing.
switch_ty: Ty<'tcx>,
/// The (ordered) set of values that we test for.
///
/// For integers and `char`s we create a branch to each of the values in
/// `options`, as well as an "otherwise" branch for all other values, even
/// in the (rare) case that options is exhaustive.
/// in the (rare) case that `options` is exhaustive.
///
/// For `bool` we always generate two edges, one for `true` and one for
/// `false`.
Expand All @@ -776,17 +778,21 @@ enum TestKind<'tcx> {
/// Test whether the value falls within an inclusive or exclusive range
Range(PatRange<'tcx>),

/// Test length of the slice is equal to len
/// Test that the length of the slice is equal to `len`.
Len { len: u64, op: BinOp },
}

/// A test to perform to determine which [`Candidate`] matches a value.
///
/// [`Test`] is just the test to perform; it does not include the value
/// to be tested.
#[derive(Debug)]
crate struct Test<'tcx> {
span: Span,
kind: TestKind<'tcx>,
}

/// ArmHasGuard is isomorphic to a boolean flag. It indicates whether
/// `ArmHasGuard` is a wrapper around a boolean flag. It indicates whether
/// a match arm has a guard expression attached to it.
#[derive(Copy, Clone, Debug)]
crate struct ArmHasGuard(crate bool);
Expand All @@ -801,27 +807,27 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// candidates are sorted such that the first item in the list
/// has the highest priority. When a candidate is found to match
/// the value, we will set and generate a branch to the appropriate
/// prebinding block.
/// pre-binding block.
///
/// If we find that *NONE* of the candidates apply, we branch to the
/// `otherwise_block`, setting it to `Some` if required. In principle, this
/// means that the input list was not exhaustive, though at present we
/// sometimes are not smart enough to recognize all exhaustive inputs.
///
/// It might be surprising that the input can be inexhaustive.
/// It might be surprising that the input can be non-exhaustive.
/// Indeed, initially, it is not, because all matches are
/// exhaustive in Rust. But during processing we sometimes divide
/// up the list of candidates and recurse with a non-exhaustive
/// list. This is important to keep the size of the generated code
/// under control. See `test_candidates` for more details.
/// under control. See [`Builder::test_candidates`] for more details.
///
/// If `fake_borrows` is Some, then places which need fake borrows
/// If `fake_borrows` is `Some`, then places which need fake borrows
/// will be added to it.
///
/// For an example of a case where we set `otherwise_block`, even for an
/// exhaustive match consider:
/// exhaustive match, consider:
///
/// ```rust
/// ```
/// match x {
/// (true, true) => (),
/// (_, false) => (),
Expand All @@ -830,8 +836,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// ```
///
/// For this match, we check if `x.0` matches `true` (for the first
/// arm). If that's false, we check `x.1`. If it's `true` we check if
/// `x.0` matches `false` (for the third arm). In the (impossible at
/// arm). If it doesn't match, we check `x.1`. If `x.1` is `true` we check
/// if `x.0` matches `false` (for the third arm). In the (impossible at
/// runtime) case when `x.0` is now `true`, we branch to
/// `otherwise_block`.
fn match_candidates<'pat>(
Expand Down Expand Up @@ -938,26 +944,31 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
);
}

/// Link up matched candidates. For example, if we have something like
/// this:
/// Link up matched candidates.
///
/// For example, if we have something like this:
///
/// ```rust
/// ...
/// Some(x) if cond => ...
/// Some(x) if cond1 => ...
/// Some(x) => ...
/// Some(x) if cond => ...
/// Some(x) if cond2 => ...
/// ...
/// ```
///
/// We generate real edges from:
/// * `start_block` to the `prebinding_block` of the first pattern,
/// * the otherwise block of the first pattern to the second pattern,
/// * the otherwise block of the third pattern to the a block with an
/// Unreachable terminator.
///
/// As well as that we add fake edges from the otherwise blocks to the
/// prebinding block of the next candidate in the original set of
/// * `start_block` to the [pre-binding block] of the first pattern,
/// * the [otherwise block] of the first pattern to the second pattern,
/// * the [otherwise block] of the third pattern to a block with an
/// [`Unreachable` terminator](TerminatorKind::Unreachable).
///
/// In addition, we add fake edges from the otherwise blocks to the
/// pre-binding block of the next candidate in the original set of
/// candidates.
///
/// [pre-binding block]: Candidate::pre_binding_block
/// [otherwise block]: Candidate::otherwise_block
fn select_matched_candidates(
&mut self,
matched_candidates: &mut [&mut Candidate<'_, 'tcx>],
Expand Down Expand Up @@ -1044,7 +1055,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// forwards to [Builder::test_candidates].
///
/// Given a pattern `(P | Q, R | S)` we (in principle) generate a CFG like
/// so
/// so:
///
/// ```text
/// [ start ]
Expand Down Expand Up @@ -1214,31 +1225,35 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// This is the most subtle part of the matching algorithm. At
/// this point, the input candidates have been fully simplified,
/// and so we know that all remaining match-pairs require some
/// sort of test. To decide what test to do, we take the highest
/// priority candidate (last one in the list) and extract the
/// first match-pair from the list. From this we decide what kind
/// of test is needed using `test`, defined in the `test` module.
/// sort of test. To decide what test to perform, we take the highest
/// priority candidate (the first one in the list, as of January 2021)
/// and extract the first match-pair from the list. From this we decide
/// what kind of test is needed using [`Builder::test`], defined in the
/// [`test` module](mod@test).
///
/// *Note:* taking the first match pair is somewhat arbitrary, and
/// we might do better here by choosing more carefully what to
/// test.
///
/// For example, consider the following possible match-pairs:
///
/// 1. `x @ Some(P)` -- we will do a `Switch` to decide what variant `x` has
/// 2. `x @ 22` -- we will do a `SwitchInt`
/// 3. `x @ 3..5` -- we will do a range test
/// 1. `x @ Some(P)` -- we will do a [`Switch`] to decide what variant `x` has
/// 2. `x @ 22` -- we will do a [`SwitchInt`] to decide what value `x` has
/// 3. `x @ 3..5` -- we will do a [`Range`] test to decide what range `x` falls in
/// 4. etc.
///
/// [`Switch`]: TestKind::Switch
/// [`SwitchInt`]: TestKind::SwitchInt
/// [`Range`]: TestKind::Range
///
/// Once we know what sort of test we are going to perform, this
/// Tests may also help us with other candidates. So we walk over
/// test may also help us winnow down our candidates. So we walk over
/// the candidates (from high to low priority) and check. This
/// gives us, for each outcome of the test, a transformed list of
/// candidates. For example, if we are testing the current
/// variant of `x.0`, and we have a candidate `{x.0 @ Some(v), x.1
/// @ 22}`, then we would have a resulting candidate of `{(x.0 as
/// Some).0 @ v, x.1 @ 22}`. Note that the first match-pair is now
/// simpler (and, in fact, irrefutable).
/// candidates. For example, if we are testing `x.0`'s variant,
/// and we have a candidate `(x.0 @ Some(v), x.1 @ 22)`,
/// then we would have a resulting candidate of `((x.0 as Some).0 @ v, x.1 @ 22)`.
/// Note that the first match-pair is now simpler (and, in fact, irrefutable).
///
/// But there may also be candidates that the test just doesn't
/// apply to. The classical example involves wildcards:
Expand Down Expand Up @@ -1268,7 +1283,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// is trivially NP-complete:
///
/// ```rust
/// match (var0, var1, var2, var3, ..) {
/// match (var0, var1, var2, var3, ...) {
/// (true, _, _, false, true, ...) => false,
/// (_, true, true, false, _, ...) => false,
/// (false, _, false, false, _, ...) => false,
Expand All @@ -1283,7 +1298,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
///
/// That kind of exponential worst-case might not occur in practice, but
/// our simplistic treatment of constants and guards would make it occur
/// in very common situations - for example #29740:
/// in very common situations - for example [#29740]:
///
/// ```rust
/// match x {
Expand All @@ -1294,13 +1309,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// }
/// ```
///
/// Here we first test the match-pair `x @ "foo"`, which is an `Eq` test.
/// [#29740]: https://github.com/rust-lang/rust/issues/29740
///
/// Here we first test the match-pair `x @ "foo"`, which is an [`Eq` test].
///
/// [`Eq` test]: TestKind::Eq
///
/// It might seem that we would end up with 2 disjoint candidate
/// sets, consisting of the first candidate or the other 3, but our
/// algorithm doesn't reason about "foo" being distinct from the other
/// sets, consisting of the first candidate or the other two, but our
/// algorithm doesn't reason about `"foo"` being distinct from the other
/// constants; it considers the latter arms to potentially match after
/// both outcomes, which obviously leads to an exponential amount
/// both outcomes, which obviously leads to an exponential number
/// of tests.
///
/// To avoid these kinds of problems, our algorithm tries to ensure
Expand All @@ -1312,16 +1331,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
///
/// After we perform our test, we branch into the appropriate candidate
/// set and recurse with `match_candidates`. These sub-matches are
/// obviously inexhaustive - as we discarded our otherwise set - so
/// obviously non-exhaustive - as we discarded our otherwise set - so
/// we set their continuation to do `match_candidates` on the
/// "unmatched" set (which is again inexhaustive).
/// "unmatched" set (which is again non-exhaustive).
///
/// If you apply this to the above test, you basically wind up
/// with an if-else-if chain, testing each candidate in turn,
/// which is precisely what we want.
///
/// In addition to avoiding exponential-time blowups, this algorithm
/// also has nice property that each guard and arm is only generated
/// also has the nice property that each guard and arm is only generated
/// once.
fn test_candidates<'pat, 'b, 'c>(
&mut self,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/matches/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use std::cmp::Ordering;
impl<'a, 'tcx> Builder<'a, 'tcx> {
/// Identifies what test is needed to decide if `match_pair` is applicable.
///
/// It is a bug to call this with a simplifiable pattern.
/// It is a bug to call this with a not-fully-simplified pattern.
pub(super) fn test<'pat>(&mut self, match_pair: &MatchPair<'pat, 'tcx>) -> Test<'tcx> {
match *match_pair.pattern.kind {
PatKind::Variant { ref adt_def, substs: _, variant_index: _, subpatterns: _ } => Test {
Expand Down