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

Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cac1768
First cut of `std::lazy` module
matklad Jan 12, 2020
237a977
integrate Lazy into std layout
KodrAus Jan 14, 2020
d1263f5
use set() in SyncOnceCell::from
KodrAus Jun 30, 2020
d101794
remove inlined lazy::Waiter in favor of sync::Once
KodrAus Jun 30, 2020
1f1cda6
appease tidy
KodrAus Jun 30, 2020
ab23a2a
ci: Set `shell: bash` as a default, remove duplicates
rye Jul 16, 2020
b26ecd2
Test codegen of compare_exchange operations
tmiasko Jul 17, 2020
48844fe
include changes to Cargo.lock
KodrAus Jul 17, 2020
d866160
bootstrap.py: guard against GC in NixOS patching support.
eddyb Jul 17, 2020
b5076fb
bootstrap.py: patch RPATH on NixOS to handle the new zlib dependency.
eddyb Jul 17, 2020
49f5078
ci: Stop setting CI_OVERRIDE_SHELL environment variable
rye Jul 17, 2020
586629c
ci: Replace exec-with-shell wrapper with "plain bash"
rye Jul 17, 2020
f7979d3
Add regression test for #69414
Alexendoo Jul 17, 2020
b0a7fbd
[experiment] ty/layout: compute both niche-filling and tagged layouts…
eddyb Apr 11, 2020
2e431c6
compare tagged/niche-filling layout and pick the best one
erikdesjardins Jul 5, 2020
3924672
document test changes
erikdesjardins Jul 16, 2020
95df802
improper_ctypes_definitions: allow `Box`
davidtwco Jul 17, 2020
4127ed1
Fix `Safety` docs for `from_raw_parts_mut`
aticu Jul 17, 2020
4adb13c
rustbuild: drop tool::should_install
Keruspe Jul 17, 2020
91314e2
Use intra-doc links in BTreeSet docs
Manishearth Jul 17, 2020
748634e
Use intra doc links in std::str
Manishearth Jul 17, 2020
4b6a027
fixes #67108 by using the external crate
Jul 17, 2020
5702ce8
Allows pathdiff package
Jul 17, 2020
fe63905
link once_cell feature to #74465
KodrAus Jul 18, 2020
caa3478
Rollup merge of #72414 - KodrAus:feat/stdlazy, r=Mark-Simulacrum
Manishearth Jul 18, 2020
5aae126
Rollup merge of #74069 - erikdesjardins:bad-niche, r=nikomatsakis
Manishearth Jul 18, 2020
e5009f7
Rollup merge of #74418 - rye:gha-dedup-shell-setting, r=pietroalbini
Manishearth Jul 18, 2020
9ad1d26
Rollup merge of #74441 - eddyb:zlib-on-nixos, r=nagisa
Manishearth Jul 18, 2020
0e8b901
Rollup merge of #74444 - Alexendoo:test-69414, r=nikomatsakis
Manishearth Jul 18, 2020
baea76b
Rollup merge of #74448 - davidtwco:improper-ctypes-definitions-boxes,…
Manishearth Jul 18, 2020
77e5d3c
Rollup merge of #74449 - tmiasko:cmpxchg-test, r=nikomatsakis
Manishearth Jul 18, 2020
eca3465
Rollup merge of #74450 - aticu:master, r=jonas-schievink
Manishearth Jul 18, 2020
c881a4a
Rollup merge of #74453 - Manishearth:intra-doc-std, r=jyn514
Manishearth Jul 18, 2020
9580d5e
Rollup merge of #74457 - Keruspe:install, r=Mark-Simulacrum
Manishearth Jul 18, 2020
fcfdbc5
Rollup merge of #74464 - FedericoPonzi:fix-#67108, r=Manishearth
Manishearth Jul 18, 2020
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
1 change: 1 addition & 0 deletions src/librustc_middle/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#![feature(bool_to_option)]
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(cmp_min_max_by)]
#![feature(const_fn)]
#![feature(const_panic)]
#![feature(const_fn_transmute)]
Expand Down
26 changes: 22 additions & 4 deletions src/librustc_middle/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
.iter_enumerated()
.all(|(i, v)| v.discr == ty::VariantDiscr::Relative(i.as_u32()));

let mut niche_filling_layout = None;

// Niche-filling enum optimization.
if !def.repr.inhibit_enum_layout_opt() && no_explicit_discriminants {
let mut dataful_variant = None;
Expand Down Expand Up @@ -972,7 +974,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
let largest_niche =
Niche::from_scalar(dl, offset, niche_scalar.clone());

return Ok(tcx.intern_layout(Layout {
niche_filling_layout = Some(Layout {
variants: Variants::Multiple {
tag: niche_scalar,
tag_encoding: TagEncoding::Niche {
Expand All @@ -991,7 +993,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
largest_niche,
size,
align,
}));
});
}
}
}
Expand Down Expand Up @@ -1214,7 +1216,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {

let largest_niche = Niche::from_scalar(dl, Size::ZERO, tag.clone());

tcx.intern_layout(Layout {
let tagged_layout = Layout {
variants: Variants::Multiple {
tag,
tag_encoding: TagEncoding::Direct,
Expand All @@ -1229,7 +1231,23 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
abi,
align,
size,
})
};

let best_layout = match (tagged_layout, niche_filling_layout) {
(tagged_layout, Some(niche_filling_layout)) => {
// Pick the smaller layout; otherwise,
// pick the layout with the larger niche; otherwise,
// pick tagged as it has simpler codegen.
cmp::min_by_key(tagged_layout, niche_filling_layout, |layout| {
let niche_size =
layout.largest_niche.as_ref().map_or(0, |n| n.available(dl));
(layout.size, cmp::Reverse(niche_size))
})
}
(tagged_layout, None) => tagged_layout,
};

tcx.intern_layout(best_layout)
}

// Types with no meaningful known layout.
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/print_type_sizes/niche-filling.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ print-type-size variant `Some`: 12 bytes
print-type-size field `.0`: 12 bytes
print-type-size variant `None`: 0 bytes
print-type-size type: `EmbeddedDiscr`: 8 bytes, alignment: 4 bytes
print-type-size discriminant: 1 bytes
print-type-size variant `Record`: 7 bytes
print-type-size field `.val`: 4 bytes
print-type-size field `.post`: 2 bytes
print-type-size field `.pre`: 1 bytes
print-type-size field `.post`: 2 bytes
print-type-size field `.val`: 4 bytes
print-type-size variant `None`: 0 bytes
print-type-size end padding: 1 bytes
print-type-size type: `MyOption<Union1<std::num::NonZeroU32>>`: 8 bytes, alignment: 4 bytes
print-type-size discriminant: 4 bytes
print-type-size variant `Some`: 4 bytes
Expand Down
25 changes: 25 additions & 0 deletions src/test/ui/type-sizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![feature(never_type)]

use std::mem::size_of;
use std::num::NonZeroU8;

struct t {a: u8, b: i8}
struct u {a: u8, b: i8, c: u8}
Expand Down Expand Up @@ -102,6 +103,23 @@ enum Option2<A, B> {
None
}

// Two layouts are considered for `CanBeNicheFilledButShouldnt`:
// Niche-filling:
// { u32 (4 bytes), NonZeroU8 + tag in niche (1 byte), padding (3 bytes) }
// Tagged:
// { tag (1 byte), NonZeroU8 (1 byte), padding (2 bytes), u32 (4 bytes) }
// Both are the same size (due to padding),
// but the tagged layout is better as the tag creates a niche with 254 invalid values,
// allowing types like `Option<Option<CanBeNicheFilledButShouldnt>>` to fit into 8 bytes.
pub enum CanBeNicheFilledButShouldnt {
A(NonZeroU8, u32),
B
}
pub enum AlwaysTaggedBecauseItHasNoNiche {
A(u8, u32),
B
}

pub fn main() {
assert_eq!(size_of::<u8>(), 1 as usize);
assert_eq!(size_of::<u32>(), 4 as usize);
Expand Down Expand Up @@ -145,4 +163,11 @@ pub fn main() {
assert_eq!(size_of::<Option<Option<(&(), bool)>>>(), size_of::<(bool, &())>());
assert_eq!(size_of::<Option<Option2<bool, &()>>>(), size_of::<(bool, &())>());
assert_eq!(size_of::<Option<Option2<&(), bool>>>(), size_of::<(bool, &())>());

assert_eq!(size_of::<CanBeNicheFilledButShouldnt>(), 8);
assert_eq!(size_of::<Option<CanBeNicheFilledButShouldnt>>(), 8);
assert_eq!(size_of::<Option<Option<CanBeNicheFilledButShouldnt>>>(), 8);
assert_eq!(size_of::<AlwaysTaggedBecauseItHasNoNiche>(), 8);
assert_eq!(size_of::<Option<AlwaysTaggedBecauseItHasNoNiche>>(), 8);
assert_eq!(size_of::<Option<Option<AlwaysTaggedBecauseItHasNoNiche>>>(), 8);
}