-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Remove Option
wrapper around prog_data
#757
base: master
Are you sure you want to change the base?
Conversation
@@ -10,8 +10,7 @@ use crate::addr::{Addr, RegIdx}; | |||
#[derive(Clone, Debug)] | |||
pub struct Platform { | |||
pub rom: Range<Addr>, | |||
// This is an `Option` to allow `const` here. | |||
pub prog_data: Option<HashSet<Addr>>, | |||
pub prog_data: BTreeSet<Addr>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HashSet
doesn't have const
in pub fn new() -> HashSet<T, RandomState>
.
But BTreeSet
has pub const fn new() -> BTreeSet<T>
.
@@ -38,7 +38,10 @@ use strum::IntoEnumIterator; | |||
|
|||
const MAX_CONSTRAINT_DEGREE: usize = 2; | |||
const MOCK_PROGRAM_SIZE: usize = 32; | |||
pub const MOCK_PC_START: ByteAddr = ByteAddr(CENO_PLATFORM.pc_base()); | |||
pub static MOCK_PC_START: ByteAddr = ByteAddr({ | |||
static CENO_PLATFORM: Platform = ceno_emul::CENO_PLATFORM; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of the way const
and static
interact, we are statically leaking a single copy of CENO_PLATFORM
here. But that's only a few bytes, and the compiler optimises it away on anything higher than -O0
.
Option
wrapperOption
wrapper around prog_data
@@ -10,8 +10,7 @@ use crate::addr::{Addr, RegIdx}; | |||
#[derive(Clone, Debug)] | |||
pub struct Platform { | |||
pub rom: Range<Addr>, | |||
// This is an `Option` to allow `const` here. | |||
pub prog_data: Option<HashSet<Addr>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The minor problem here was that None
and Some(empty_hash_set)
are two different ways to express the same thing.
Now the types are cleaner, and quite a bit of the rest of the code becomes slightly simpler, too. See for example fn is_prog_data
.
We found a neat way to avoid the extra
Option
wrapper aroundprog_data
.We only ever needed it, because of some technicalities with the Rust type system.