-
Notifications
You must be signed in to change notification settings - Fork 10
Add attempt for better module configuration #161
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
Conversation
Err(ModuleError::NotSupported) | ||
} | ||
|
||
fn with_config(config: &HashMap<String, String>) -> Result<Self, ModuleError> { |
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.
Could also split this into two (and that would remove the need for default):
- "with config string"
- "with complex config"
e.g.
fn with_config_string(config: &str)
fn with_config_map(config: &HashMap<String, String>)
and then with_config_string(&"")
would mean "defaults"
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.
I think key-val configuration should be fine for now. No need to further complicate things with the config string, and we can definitely just implement the config string as a specified key config
or something in the hashmap.
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.
True, but the downside is the terrible syntax needed for creating a hashmap and passing it. So for simple modules a string is much more simple.
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.
Perhaps the config string method could just wrap that logic?
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.
What do you mean by wrap? Define a way to encode hashmaps?
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.
with_config_string
would just call with_config
where a dedicated key such as config_string
is set to the value provided.
93544f2
to
7bf94eb
Compare
1d88cfd
to
6719d0c
Compare
@@ -29,6 +32,34 @@ impl<'a> ChiselModule<'a> for DropSection { | |||
} | |||
} | |||
|
|||
impl From<std::num::ParseIntError> for ModuleError { |
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.
Could make this more generic, and support all kinds of errors:
impl From<E: Error> for ModuleError {
fn from(error: E) -> Self {
ModuleError::Custom(error.description().to_string())
}
}
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.
True, though I was considering here to wrap it with some text or use NotSupported
.
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.
Apparently this is unstable: rust-lang/rust#52662
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.
You could have this blanket impl and then have specialized impls for specific errors
libchisel/src/dropsection.rs
Outdated
Ok(DropSection::CustomSectionByIndex(str::parse::<usize>(val)?)) | ||
} | ||
"unknown_by_index" => Ok(DropSection::UnknownSectionByIndex(str::parse::<usize>( | ||
val, |
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.
rustfmt is rather weird sometimes
libchisel/src/dropsection.rs
Outdated
} | ||
|
||
fn with_config(config: &HashMap<String, String>) -> Result<Self, ModuleError> { | ||
for (key, val) in config.iter() { |
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.
Why do we need the loop here if it will always return on first iteration?
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.
Legacy. I guess it could pick a random key/val and do it from there.
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.
That would result in some strange behavior, I feel.
Perhaps enforcing mutual exclusion of dropsection modes here would make the best sense.
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.
Yeah I'm torn on that one. Enforcing that will add a ton of complexity – that's how I started first.
libchisel/src/lib.rs
Outdated
@@ -80,6 +81,17 @@ pub trait ModulePreset { | |||
Self: std::marker::Sized; | |||
} | |||
|
|||
// TODO: move this to be part of ChiselModule |
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.
I'm undecided as to whether that is a good idea.
861aaf5
to
106fbc1
Compare
ae356d5
to
85840af
Compare
7fbba65
to
b1cdd54
Compare
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.
Looks good. We should also introduce a PR to remove the ChiselModule trait in the future.
Co-authored-by: Jake Lang <[email protected]>
Closes #135.