Skip to content

Commit

Permalink
Optimize const value interning for ZST types
Browse files Browse the repository at this point in the history
Interning can skip any inhabited ZST type in general.
  • Loading branch information
wesleywiser committed Oct 17, 2020
1 parent ffeeb20 commit 1d07d69
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
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
@@ -0,0 +1,5 @@
// build-pass

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

0 comments on commit 1d07d69

Please sign in to comment.