Closed
Description
I have:
- A struct
CodePoint
with aconst fn from(...) -> Self
constructor - A large number of
CodePoint
constants (42.000+) using the constructor
#[repr(transparent)]
pub struct CodePoint {
raw: u32
}
impl CodePoint {
pub const fn from(raw: u32) -> Self {
// debug_assert!(raw <= 0x10FFFF);
CodePoint { raw }
}
}
// include!(...)
// 42508 constants, 3.28MB file
impl CodePoint {
pub const SPACE : CodePoint = CodePoint::from(32u32);
...
}
Building this leads to:
- Compiler busy for 2min+
- Compiler error trying to allocate 1.2GB:
memory allocation of 1207959552 bytes failed
even though I have 12GB of unused RAM
Using struct expressions instead of a const fn
constructor:
impl CodePoint {
pub const SPACE : CodePoint = CodePoint { raw: 32u32 };
...
}
- Compiler finishes within 5s.
Tested on nightly
and stable
, with include!(...)
and copy-pasting: no differences.
Source file to reproduce: reproduce.zip