Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

matthiasgoergens
Copy link
Collaborator

@matthiasgoergens matthiasgoergens commented Dec 14, 2024

We found a neat way to avoid the extra Option wrapper around prog_data.

We only ever needed it, because of some technicalities with the Rust type system.

@@ -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>,
Copy link
Collaborator Author

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;
Copy link
Collaborator Author

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.

@matthiasgoergens matthiasgoergens changed the title refactor: Remove Option wrapper refactor: Remove Option wrapper around prog_data Dec 14, 2024
@@ -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>>,
Copy link
Collaborator Author

@matthiasgoergens matthiasgoergens Dec 14, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant