Skip to content

Commit 3d5a516

Browse files
committed
Auto merge of rust-lang#2878 - RalfJung:rustup, r=RalfJung
Rustup
2 parents dd9df18 + e476f7a commit 3d5a516

File tree

436 files changed

+6509
-3037
lines changed

Some content is hidden

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

436 files changed

+6509
-3037
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,20 @@ jobs:
4242
TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate"
4343
CACHE_DOMAIN: ci-caches.rust-lang.org
4444
if: "github.event_name == 'pull_request'"
45-
continue-on-error: "${{ matrix.tidy }}"
45+
continue-on-error: "${{ matrix.name == 'mingw-check-tidy' }}"
4646
strategy:
4747
matrix:
4848
include:
4949
- name: mingw-check
50-
tidy: false
5150
os: ubuntu-20.04-16core-64gb
5251
env: {}
5352
- name: mingw-check-tidy
54-
tidy: true
5553
os: ubuntu-20.04-16core-64gb
5654
env: {}
5755
- name: x86_64-gnu-llvm-14
58-
tidy: false
5956
os: ubuntu-20.04-16core-64gb
6057
env: {}
6158
- name: x86_64-gnu-tools
62-
tidy: false
6359
os: ubuntu-20.04-16core-64gb
6460
env: {}
6561
timeout-minutes: 600
@@ -98,9 +94,6 @@ jobs:
9894
- name: show the current environment
9995
run: src/ci/scripts/dump-environment.sh
10096
if: success() && !env.SKIP_JOB
101-
- name: install awscli
102-
run: src/ci/scripts/install-awscli.sh
103-
if: success() && !env.SKIP_JOB
10497
- name: install sccache
10598
run: src/ci/scripts/install-sccache.sh
10699
if: success() && !env.SKIP_JOB
@@ -170,6 +163,7 @@ jobs:
170163
TOOLSTATE_PUBLISH: 1
171164
CACHES_AWS_ACCESS_KEY_ID: AKIA46X5W6CZI5DHEBFL
172165
ARTIFACTS_AWS_ACCESS_KEY_ID: AKIA46X5W6CZN24CBO55
166+
AWS_REGION: us-west-1
173167
CACHE_DOMAIN: ci-caches.rust-lang.org
174168
if: "github.event_name == 'push' && github.ref == 'refs/heads/auto' && github.repository == 'rust-lang-ci/rust'"
175169
strategy:
@@ -521,9 +515,6 @@ jobs:
521515
- name: show the current environment
522516
run: src/ci/scripts/dump-environment.sh
523517
if: success() && !env.SKIP_JOB
524-
- name: install awscli
525-
run: src/ci/scripts/install-awscli.sh
526-
if: success() && !env.SKIP_JOB
527518
- name: install sccache
528519
run: src/ci/scripts/install-sccache.sh
529520
if: success() && !env.SKIP_JOB
@@ -593,6 +584,7 @@ jobs:
593584
TOOLSTATE_PUBLISH: 1
594585
CACHES_AWS_ACCESS_KEY_ID: AKIA46X5W6CZI5DHEBFL
595586
ARTIFACTS_AWS_ACCESS_KEY_ID: AKIA46X5W6CZN24CBO55
587+
AWS_REGION: us-west-1
596588
CACHE_DOMAIN: ci-caches.rust-lang.org
597589
if: "github.event_name == 'push' && (github.ref == 'refs/heads/try' || github.ref == 'refs/heads/try-perf') && github.repository == 'rust-lang-ci/rust'"
598590
strategy:
@@ -637,9 +629,6 @@ jobs:
637629
- name: show the current environment
638630
run: src/ci/scripts/dump-environment.sh
639631
if: success() && !env.SKIP_JOB
640-
- name: install awscli
641-
run: src/ci/scripts/install-awscli.sh
642-
if: success() && !env.SKIP_JOB
643632
- name: install sccache
644633
run: src/ci/scripts/install-sccache.sh
645634
if: success() && !env.SKIP_JOB
@@ -706,6 +695,7 @@ jobs:
706695
TOOLSTATE_PUBLISH: 1
707696
CACHES_AWS_ACCESS_KEY_ID: AKIA46X5W6CZI5DHEBFL
708697
ARTIFACTS_AWS_ACCESS_KEY_ID: AKIA46X5W6CZN24CBO55
698+
AWS_REGION: us-west-1
709699
CACHE_DOMAIN: ci-caches.rust-lang.org
710700
if: "github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'rust-lang-ci/rust'"
711701
steps:

Cargo.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1"
577577

578578
[[package]]
579579
name = "clippy"
580-
version = "0.1.70"
580+
version = "0.1.71"
581581
dependencies = [
582582
"clap 4.2.1",
583583
"clippy_lints",
@@ -619,7 +619,7 @@ dependencies = [
619619

620620
[[package]]
621621
name = "clippy_lints"
622-
version = "0.1.70"
622+
version = "0.1.71"
623623
dependencies = [
624624
"arrayvec",
625625
"cargo_metadata 0.15.3",
@@ -643,7 +643,7 @@ dependencies = [
643643

644644
[[package]]
645645
name = "clippy_utils"
646-
version = "0.1.70"
646+
version = "0.1.71"
647647
dependencies = [
648648
"arrayvec",
649649
"if_chain",
@@ -969,7 +969,7 @@ checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69"
969969

970970
[[package]]
971971
name = "declare_clippy_lint"
972-
version = "0.1.70"
972+
version = "0.1.71"
973973
dependencies = [
974974
"itertools",
975975
"quote",

compiler/rustc_abi/src/layout.rs

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -729,42 +729,73 @@ pub trait LayoutCalculator {
729729
align = align.max(AbiAndPrefAlign::new(repr_align));
730730
}
731731

732-
let optimize = !repr.inhibit_union_abi_opt();
732+
// If all the non-ZST fields have the same ABI and union ABI optimizations aren't
733+
// disabled, we can use that common ABI for the union as a whole.
734+
struct AbiMismatch;
735+
let mut common_non_zst_abi_and_align = if repr.inhibit_union_abi_opt() {
736+
// Can't optimize
737+
Err(AbiMismatch)
738+
} else {
739+
Ok(None)
740+
};
741+
733742
let mut size = Size::ZERO;
734-
let mut abi = Abi::Aggregate { sized: true };
735743
let only_variant = &variants[FIRST_VARIANT];
736744
for field in only_variant {
737745
assert!(field.0.is_sized());
746+
738747
align = align.max(field.align());
748+
size = cmp::max(size, field.size());
739749

740-
// If all non-ZST fields have the same ABI, forward this ABI
741-
if optimize && !field.0.is_zst() {
750+
if field.0.is_zst() {
751+
// Nothing more to do for ZST fields
752+
continue;
753+
}
754+
755+
if let Ok(common) = common_non_zst_abi_and_align {
742756
// Discard valid range information and allow undef
743-
let field_abi = match field.abi() {
744-
Abi::Scalar(x) => Abi::Scalar(x.to_union()),
745-
Abi::ScalarPair(x, y) => Abi::ScalarPair(x.to_union(), y.to_union()),
746-
Abi::Vector { element: x, count } => {
747-
Abi::Vector { element: x.to_union(), count }
748-
}
749-
Abi::Uninhabited | Abi::Aggregate { .. } => Abi::Aggregate { sized: true },
750-
};
757+
let field_abi = field.abi().to_union();
751758

752-
if size == Size::ZERO {
753-
// first non ZST: initialize 'abi'
754-
abi = field_abi;
755-
} else if abi != field_abi {
756-
// different fields have different ABI: reset to Aggregate
757-
abi = Abi::Aggregate { sized: true };
759+
if let Some((common_abi, common_align)) = common {
760+
if common_abi != field_abi {
761+
// Different fields have different ABI: disable opt
762+
common_non_zst_abi_and_align = Err(AbiMismatch);
763+
} else {
764+
// Fields with the same non-Aggregate ABI should also
765+
// have the same alignment
766+
if !matches!(common_abi, Abi::Aggregate { .. }) {
767+
assert_eq!(
768+
common_align,
769+
field.align().abi,
770+
"non-Aggregate field with matching ABI but differing alignment"
771+
);
772+
}
773+
}
774+
} else {
775+
// First non-ZST field: record its ABI and alignment
776+
common_non_zst_abi_and_align = Ok(Some((field_abi, field.align().abi)));
758777
}
759778
}
760-
761-
size = cmp::max(size, field.size());
762779
}
763780

764781
if let Some(pack) = repr.pack {
765782
align = align.min(AbiAndPrefAlign::new(pack));
766783
}
767784

785+
// If all non-ZST fields have the same ABI, we may forward that ABI
786+
// for the union as a whole, unless otherwise inhibited.
787+
let abi = match common_non_zst_abi_and_align {
788+
Err(AbiMismatch) | Ok(None) => Abi::Aggregate { sized: true },
789+
Ok(Some((abi, _))) => {
790+
if abi.inherent_align(dl).map(|a| a.abi) != Some(align.abi) {
791+
// Mismatched alignment (e.g. union is #[repr(packed)]): disable opt
792+
Abi::Aggregate { sized: true }
793+
} else {
794+
abi
795+
}
796+
}
797+
};
798+
768799
Some(LayoutS {
769800
variants: Variants::Single { index: FIRST_VARIANT },
770801
fields: FieldsShape::Union(NonZeroUsize::new(only_variant.len())?),

compiler/rustc_abi/src/lib.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,50 @@ impl Abi {
12721272
pub fn is_scalar(&self) -> bool {
12731273
matches!(*self, Abi::Scalar(_))
12741274
}
1275+
1276+
/// Returns the fixed alignment of this ABI, if any is mandated.
1277+
pub fn inherent_align<C: HasDataLayout>(&self, cx: &C) -> Option<AbiAndPrefAlign> {
1278+
Some(match *self {
1279+
Abi::Scalar(s) => s.align(cx),
1280+
Abi::ScalarPair(s1, s2) => s1.align(cx).max(s2.align(cx)),
1281+
Abi::Vector { element, count } => {
1282+
cx.data_layout().vector_align(element.size(cx) * count)
1283+
}
1284+
Abi::Uninhabited | Abi::Aggregate { .. } => return None,
1285+
})
1286+
}
1287+
1288+
/// Returns the fixed size of this ABI, if any is mandated.
1289+
pub fn inherent_size<C: HasDataLayout>(&self, cx: &C) -> Option<Size> {
1290+
Some(match *self {
1291+
Abi::Scalar(s) => {
1292+
// No padding in scalars.
1293+
s.size(cx)
1294+
}
1295+
Abi::ScalarPair(s1, s2) => {
1296+
// May have some padding between the pair.
1297+
let field2_offset = s1.size(cx).align_to(s2.align(cx).abi);
1298+
(field2_offset + s2.size(cx)).align_to(self.inherent_align(cx)?.abi)
1299+
}
1300+
Abi::Vector { element, count } => {
1301+
// No padding in vectors, except possibly for trailing padding
1302+
// to make the size a multiple of align (e.g. for vectors of size 3).
1303+
(element.size(cx) * count).align_to(self.inherent_align(cx)?.abi)
1304+
}
1305+
Abi::Uninhabited | Abi::Aggregate { .. } => return None,
1306+
})
1307+
}
1308+
1309+
/// Discard validity range information and allow undef.
1310+
pub fn to_union(&self) -> Self {
1311+
assert!(self.is_sized());
1312+
match *self {
1313+
Abi::Scalar(s) => Abi::Scalar(s.to_union()),
1314+
Abi::ScalarPair(s1, s2) => Abi::ScalarPair(s1.to_union(), s2.to_union()),
1315+
Abi::Vector { element, count } => Abi::Vector { element: element.to_union(), count },
1316+
Abi::Uninhabited | Abi::Aggregate { .. } => Abi::Aggregate { sized: true },
1317+
}
1318+
}
12751319
}
12761320

12771321
#[derive(PartialEq, Eq, Hash, Clone, Debug)]

compiler/rustc_ast/src/ast.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,6 +1821,8 @@ pub enum LitKind {
18211821
/// A byte string (`b"foo"`). Not stored as a symbol because it might be
18221822
/// non-utf8, and symbols only allow utf8 strings.
18231823
ByteStr(Lrc<[u8]>, StrStyle),
1824+
/// A C String (`c"foo"`). Guaranteed to only have `\0` at the end.
1825+
CStr(Lrc<[u8]>, StrStyle),
18241826
/// A byte char (`b'f'`).
18251827
Byte(u8),
18261828
/// A character literal (`'a'`).
@@ -1875,6 +1877,7 @@ impl LitKind {
18751877
// unsuffixed variants
18761878
LitKind::Str(..)
18771879
| LitKind::ByteStr(..)
1880+
| LitKind::CStr(..)
18781881
| LitKind::Byte(..)
18791882
| LitKind::Char(..)
18801883
| LitKind::Int(_, LitIntType::Unsuffixed)

compiler/rustc_ast/src/token.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ pub enum LitKind {
7474
StrRaw(u8), // raw string delimited by `n` hash symbols
7575
ByteStr,
7676
ByteStrRaw(u8), // raw byte string delimited by `n` hash symbols
77+
CStr,
78+
CStrRaw(u8),
7779
Err,
7880
}
7981

@@ -141,6 +143,10 @@ impl fmt::Display for Lit {
141143
delim = "#".repeat(n as usize),
142144
string = symbol
143145
)?,
146+
CStr => write!(f, "c\"{symbol}\"")?,
147+
CStrRaw(n) => {
148+
write!(f, "cr{delim}\"{symbol}\"{delim}", delim = "#".repeat(n as usize))?
149+
}
144150
Integer | Float | Bool | Err => write!(f, "{symbol}")?,
145151
}
146152

@@ -170,6 +176,7 @@ impl LitKind {
170176
Float => "float",
171177
Str | StrRaw(..) => "string",
172178
ByteStr | ByteStrRaw(..) => "byte string",
179+
CStr | CStrRaw(..) => "C string",
173180
Err => "error",
174181
}
175182
}

0 commit comments

Comments
 (0)