Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fdefffe
compiler: report error when trait object type param reference self
xtexx Mar 30, 2025
6966416
Update to new rinja version (askama)
GuillaumeGomez Apr 3, 2025
f343b9d
Don't construct preds w escaping bound vars in diagnostic_hir_wf_check
compiler-errors Apr 4, 2025
86a7ee6
create new option `build.compiletest-use-stage0-libtest`
onur-ozkan Apr 4, 2025
17fad21
utilize `compiletest_use_stage0_libtest` option
onur-ozkan Apr 4, 2025
afe3834
add change-entry
onur-ozkan Apr 4, 2025
45afefa
Fix trait upcasting to dyn type with no principal when there are proj…
compiler-errors Apr 5, 2025
a6b7a26
Update rinja version in `generate-copyright`
GuillaumeGomez Apr 4, 2025
d37bd4d
Update proc-macro deps list
GuillaumeGomez Apr 3, 2025
1f06a6a
Tell LLVM about impossible niche tags
scottmcm Mar 29, 2025
51e67e2
LLVM18 compatibility fixes in the tests
scottmcm Mar 29, 2025
c830665
enable in-tree std on some runners
onur-ozkan Apr 5, 2025
cae28b5
implement `check` step for `compiletest` separately
onur-ozkan Apr 7, 2025
e1a69da
unstable-book/intrinsics: wordsmith MIR-lowering intrinsic docs
RalfJung Apr 7, 2025
a7400a8
update intrinsics/mod.rs comment about const intrinsics
RalfJung Apr 7, 2025
250b848
Make error message for missing fields with .. and without .. more con…
compiler-errors Mar 27, 2025
268c56e
Implement overflow for infinite implied lifetime bounds
compiler-errors Apr 7, 2025
502f7f9
Address PR feedback
scottmcm Apr 8, 2025
eb5d892
Allow for missing invisible close delim when reparsing an expression.
nnethercote Apr 3, 2025
e177921
Allow for reparsing failure when reparsing a pasted metavar.
nnethercote Apr 7, 2025
742b378
make hover_feature test less fragile
RalfJung Apr 8, 2025
2b1afcb
Rollup merge of #138676 - compiler-errors:overflow-implied-bounds, r=…
Zalathar Apr 8, 2025
6257825
Rollup merge of #139024 - compiler-errors:tweak-default-value-err, r=…
Zalathar Apr 8, 2025
7ffa56c
Rollup merge of #139098 - scottmcm:assert-impossible-tags, r=WaffleLa…
Zalathar Apr 8, 2025
5913c52
Rollup merge of #139124 - xtexx:gh-139082, r=compiler-errors
Zalathar Apr 8, 2025
dd682f7
Rollup merge of #139321 - GuillaumeGomez:update-rinja, r=notriddle,lo…
Zalathar Apr 8, 2025
133cec7
Rollup merge of #139346 - compiler-errors:non-lifetime-binder-diag-hi…
Zalathar Apr 8, 2025
ab80f57
Rollup merge of #139386 - onur-ozkan:configurable-compiletest-libtest…
Zalathar Apr 8, 2025
056756c
Rollup merge of #139421 - compiler-errors:upcast-no-principal-with-pr…
Zalathar Apr 8, 2025
24369ad
Rollup merge of #139464 - nnethercote:fix-139248-AND-fix-139445, r=pe…
Zalathar Apr 8, 2025
42fdd7d
Rollup merge of #139490 - RalfJung:unstable-intrinsics-docs, r=oli-obk
Zalathar Apr 8, 2025
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
32 changes: 31 additions & 1 deletion compiler/rustc_codegen_ssa/src/mir/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use rustc_middle::mir::{self, ConstValue};
use rustc_middle::ty::Ty;
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
use rustc_middle::{bug, span_bug};
use rustc_session::config::OptLevel;
use tracing::{debug, instrument};

use super::place::{PlaceRef, PlaceValue};
Expand Down Expand Up @@ -496,6 +497,18 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
_ => (tag_imm, bx.cx().immediate_backend_type(tag_op.layout)),
};

// Layout ensures that we only get here for cases where the discriminant
// value and the variant index match, since that's all `Niche` can encode.
// But for emphasis and debugging, let's double-check one anyway.
debug_assert_eq!(
self.layout
.ty
.discriminant_for_variant(bx.tcx(), untagged_variant)
.unwrap()
.val,
u128::from(untagged_variant.as_u32()),
);

let relative_max = niche_variants.end().as_u32() - niche_variants.start().as_u32();

// We have a subrange `niche_start..=niche_end` inside `range`.
Expand Down Expand Up @@ -537,6 +550,21 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
relative_discr,
bx.cx().const_uint(tag_llty, relative_max as u64),
);

// Thanks to parameter attributes and load metadata, LLVM already knows
// the general valid range of the tag. It's possible, though, for there
// to be an impossible value *in the middle*, which those ranges don't
// communicate, so it's worth an `assume` to let the optimizer know.
if niche_variants.contains(&untagged_variant)
&& bx.cx().sess().opts.optimize != OptLevel::No
{
let impossible =
u64::from(untagged_variant.as_u32() - niche_variants.start().as_u32());
let impossible = bx.cx().const_uint(tag_llty, impossible);
let ne = bx.icmp(IntPredicate::IntNE, relative_discr, impossible);
bx.assume(ne);
}

(is_niche, cast_tag, niche_variants.start().as_u32() as u128)
};

Expand All @@ -553,7 +581,9 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
);

// In principle we could insert assumes on the possible range of `discr`, but
// currently in LLVM this seems to be a pessimization.
// currently in LLVM this isn't worth it because the original `tag` will
// have either a `range` parameter attribute or `!range` metadata,
// or come from a `transmute` that already `assume`d it.

discr
}
Expand Down
Loading