Skip to content

Commit 33f1700

Browse files
authored
Merge pull request rust-lang#4425 from RalfJung/rustup
Rustup
2 parents 651d2f8 + 9c22372 commit 33f1700

File tree

173 files changed

+2454
-2023
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+2454
-2023
lines changed

compiler/rustc_abi/src/lib.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,24 +1592,33 @@ pub enum TagEncoding<VariantIdx: Idx> {
15921592
/// (so converting the tag to the discriminant can require sign extension).
15931593
Direct,
15941594

1595-
/// Niche (values invalid for a type) encoding the discriminant:
1596-
/// Discriminant and variant index coincide.
1595+
/// Niche (values invalid for a type) encoding the discriminant.
1596+
/// Note that for this encoding, the discriminant and variant index of each variant coincide!
1597+
/// This invariant is codified as part of [`layout_sanity_check`](../rustc_ty_utils/layout/invariant/fn.layout_sanity_check.html).
1598+
///
15971599
/// The variant `untagged_variant` contains a niche at an arbitrary
1598-
/// offset (field `tag_field` of the enum), which for a variant with
1599-
/// discriminant `d` is set to
1600-
/// `(d - niche_variants.start).wrapping_add(niche_start)`
1601-
/// (this is wrapping arithmetic using the type of the niche field).
1600+
/// offset (field [`Variants::Multiple::tag_field`] of the enum).
1601+
/// For a variant with variant index `i`, such that `i != untagged_variant`,
1602+
/// the tag is set to `(i - niche_variants.start).wrapping_add(niche_start)`
1603+
/// (this is wrapping arithmetic using the type of the niche field, cf. the
1604+
/// [`tag_for_variant`](../rustc_const_eval/interpret/struct.InterpCx.html#method.tag_for_variant)
1605+
/// query implementation).
1606+
/// To recover the variant index `i` from a `tag`, the above formula has to be reversed,
1607+
/// i.e. `i = tag.wrapping_sub(niche_start) + niche_variants.start`. If `i` ends up outside
1608+
/// `niche_variants`, the tag must have encoded the `untagged_variant`.
16021609
///
1603-
/// For example, `Option<(usize, &T)>` is represented such that
1604-
/// `None` has a null pointer for the second tuple field, and
1605-
/// `Some` is the identity function (with a non-null reference).
1610+
/// For example, `Option<(usize, &T)>` is represented such that the tag for
1611+
/// `None` is the null pointer in the second tuple field, and
1612+
/// `Some` is the identity function (with a non-null reference)
1613+
/// and has no additional tag, i.e. the reference being non-null uniquely identifies this variant.
16061614
///
16071615
/// Other variants that are not `untagged_variant` and that are outside the `niche_variants`
16081616
/// range cannot be represented; they must be uninhabited.
1617+
/// Nonetheless, uninhabited variants can also fall into the range of `niche_variants`.
16091618
Niche {
16101619
untagged_variant: VariantIdx,
1611-
/// This range *may* contain `untagged_variant`; that is then just a "dead value" and
1612-
/// not used to encode anything.
1620+
/// This range *may* contain `untagged_variant` or uninhabited variants;
1621+
/// these are then just "dead values" and not used to encode anything.
16131622
niche_variants: RangeInclusive<VariantIdx>,
16141623
/// This is inbounds of the type of the niche field
16151624
/// (not sign-extended, i.e., all bits beyond the niche field size are 0).

compiler/rustc_ast/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
#![feature(box_patterns)]
1717
#![feature(if_let_guard)]
1818
#![feature(macro_metavar_expr)]
19-
#![feature(negative_impls)]
20-
#![feature(never_type)]
2119
#![feature(rustdoc_internals)]
22-
#![feature(stmt_expr_attributes)]
2320
#![recursion_limit = "256"]
2421
// tidy-alphabetical-end
2522

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
469469
"`if let` guards are experimental",
470470
"you can write `if matches!(<expr>, <pattern>)` instead of `if let <pattern> = <expr>`"
471471
);
472-
gate_all!(let_chains, "`let` expressions in this position are unstable");
473472
gate_all!(
474473
async_trait_bounds,
475474
"`async` trait bounds are unstable",

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ pub enum AttributeKind {
253253
/// Represents `#[inline]` and `#[rustc_force_inline]`.
254254
Inline(InlineAttr, Span),
255255

256+
/// Represents `#[link_name]`.
257+
LinkName { name: Symbol, span: Span },
258+
256259
/// Represents `#[loop_match]`.
257260
LoopMatch(Span),
258261

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ impl AttributeKind {
2929
Stability { .. } => Yes,
3030
Cold(..) => No,
3131
ConstContinue(..) => No,
32+
LinkName { .. } => Yes,
3233
LoopMatch(..) => No,
3334
MayDangle(..) => No,
3435
MustUse { .. } => Yes,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use rustc_attr_data_structures::AttributeKind;
2+
use rustc_attr_data_structures::AttributeKind::LinkName;
3+
use rustc_feature::{AttributeTemplate, template};
4+
use rustc_span::{Symbol, sym};
5+
6+
use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser};
7+
use crate::context::{AcceptContext, Stage};
8+
use crate::parser::ArgParser;
9+
10+
pub(crate) struct LinkNameParser;
11+
12+
impl<S: Stage> SingleAttributeParser<S> for LinkNameParser {
13+
const PATH: &[Symbol] = &[sym::link_name];
14+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst;
15+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
16+
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
17+
18+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
19+
let Some(nv) = args.name_value() else {
20+
cx.expected_name_value(cx.attr_span, None);
21+
return None;
22+
};
23+
let Some(name) = nv.value_as_str() else {
24+
cx.expected_string_literal(nv.value_span, Some(nv.value_as_lit()));
25+
return None;
26+
};
27+
28+
Some(LinkName { name, span: cx.attr_span })
29+
}
30+
}

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub(crate) mod codegen_attrs;
3131
pub(crate) mod confusables;
3232
pub(crate) mod deprecation;
3333
pub(crate) mod inline;
34+
pub(crate) mod link_attrs;
3435
pub(crate) mod lint_helpers;
3536
pub(crate) mod loop_match;
3637
pub(crate) mod must_use;

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::attributes::codegen_attrs::{
2222
use crate::attributes::confusables::ConfusablesParser;
2323
use crate::attributes::deprecation::DeprecationParser;
2424
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
25+
use crate::attributes::link_attrs::LinkNameParser;
2526
use crate::attributes::lint_helpers::{AsPtrParser, PubTransparentParser};
2627
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
2728
use crate::attributes::must_use::MustUseParser;
@@ -121,6 +122,7 @@ attribute_parsers!(
121122
Single<DeprecationParser>,
122123
Single<ExportNameParser>,
123124
Single<InlineParser>,
125+
Single<LinkNameParser>,
124126
Single<LoopMatchParser>,
125127
Single<MayDangleParser>,
126128
Single<MustUseParser>,

compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
496496
| sym::simd_flog
497497
| sym::simd_flog10
498498
| sym::simd_flog2
499-
| sym::simd_round => {
499+
| sym::simd_round
500+
| sym::simd_round_ties_even => {
500501
intrinsic_args!(fx, args => (a); intrinsic);
501502

502503
if !a.layout().ty.is_simd() {
@@ -527,6 +528,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
527528
(sym::simd_flog2, types::F64) => "log2",
528529
(sym::simd_round, types::F32) => "roundf",
529530
(sym::simd_round, types::F64) => "round",
531+
(sym::simd_round_ties_even, types::F32) => "rintf",
532+
(sym::simd_round_ties_even, types::F64) => "rint",
530533
_ => unreachable!("{:?}", intrinsic),
531534
};
532535
fx.lib_call(
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
use std::ffi::OsStr;
2+
use std::path::Path;
3+
4+
use crate::utils::run_command_with_output;
5+
6+
fn show_usage() {
7+
println!(
8+
r#"
9+
`abi-test` command help:
10+
--help : Show this help"#
11+
);
12+
}
13+
14+
pub fn run() -> Result<(), String> {
15+
let mut args = std::env::args().skip(2);
16+
// FractalFir: In the future, I'd like to add some more subcommands / options.
17+
// So, this loop ought to stay for that purpose. It should also stay as a while loop(to parse args)
18+
#[allow(clippy::never_loop, clippy::while_let_on_iterator)]
19+
while let Some(arg) = args.next() {
20+
match arg.as_str() {
21+
"--help" => {
22+
show_usage();
23+
return Ok(());
24+
}
25+
_ => return Err(format!("Unknown option {arg:?}")),
26+
}
27+
}
28+
// Ensure that we have a cloned version of abi-cafe on hand.
29+
crate::utils::git_clone(
30+
"https://github.com/Gankra/abi-cafe.git",
31+
Some("clones/abi-cafe".as_ref()),
32+
true,
33+
)
34+
.map_err(|err| (format!("Git clone failed with message: {err:?}!")))?;
35+
// Configure abi-cafe to use the exact same rustc version we use - this is crucial.
36+
// Otherwise, the concept of ABI compatibility becomes meanignless.
37+
std::fs::copy("rust-toolchain", "clones/abi-cafe/rust-toolchain")
38+
.expect("Could not copy toolchain configs!");
39+
// Get the backend path.
40+
// We will use the *debug* build of the backend - it has more checks enabled.
41+
let backend_path = std::path::absolute("target/debug/librustc_codegen_gcc.so").unwrap();
42+
let backend_arg = format!("--add-rustc-codegen-backend=cg_gcc:{}", backend_path.display());
43+
// Run ABI cafe using cargo.
44+
let cmd: &[&dyn AsRef<OsStr>] = &[
45+
&"cargo",
46+
&"run",
47+
&"--release",
48+
&"--",
49+
&backend_arg,
50+
// Test rust-LLVM to Rust-GCC calls
51+
&"--pairs",
52+
&"rustc_calls_cg_gcc",
53+
&"--pairs",
54+
&"cg_gcc_calls_rustc",
55+
// Test Rust-GCC to C calls
56+
&"--pairs",
57+
&"cg_gcc_calls_c",
58+
&"--pairs",
59+
&"c_calls_cg_gcc",
60+
];
61+
// Run ABI cafe.
62+
run_command_with_output(cmd, Some(Path::new("clones/abi-cafe")))?;
63+
64+
Ok(())
65+
}

0 commit comments

Comments
 (0)