Skip to content

Commit

Permalink
Rollup merge of rust-lang#78061 - wesleywiser:opt_zst_const_interning…
Browse files Browse the repository at this point in the history
…, r=oli-obk

Optimize const value interning for ZST types

Interning can skip any inhabited ZST type in general.

Fixes rust-lang#68010

r? @oli-obk
  • Loading branch information
GuillaumeGomez authored Oct 20, 2020
2 parents 8cb4c14 + 1d07d69 commit 765b00e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions compiler/rustc_mir/src/interpret/intern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx>> ValueVisitor<'mir
return walked;
}
}

// ZSTs do not need validation unless they're uninhabited
if mplace.layout.is_zst() && !mplace.layout.abi.is_uninhabited() {
return Ok(());
}

self.walk_aggregate(mplace, fields)
}

Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/issues/issue-68010-large-zst-consts.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// build-pass

fn main() {
println!("{}", [(); std::usize::MAX].len());
}

0 comments on commit 765b00e

Please sign in to comment.