Skip to content

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

Merged
merged 14 commits into from
Jan 18, 2020
Merged

Add attempt for better module configuration #161

merged 14 commits into from
Jan 18, 2020

Conversation

axic
Copy link
Member

@axic axic commented Sep 19, 2019

Closes #135.

@axic axic mentioned this pull request Sep 19, 2019
Err(ModuleError::NotSupported)
}

fn with_config(config: &HashMap<String, String>) -> Result<Self, ModuleError> {
Copy link
Member Author

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"

Copy link
Collaborator

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.

Copy link
Member Author

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.

Copy link
Collaborator

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?

Copy link
Member Author

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?

Copy link
Collaborator

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.

@axic axic force-pushed the module-config branch 3 times, most recently from 93544f2 to 7bf94eb Compare September 25, 2019 17:42
@axic axic force-pushed the module-config branch 3 times, most recently from 1d88cfd to 6719d0c Compare September 25, 2019 18:54
@@ -29,6 +32,34 @@ impl<'a> ChiselModule<'a> for DropSection {
}
}

impl From<std::num::ParseIntError> for ModuleError {
Copy link
Collaborator

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())
    }
}

Copy link
Member Author

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.

Copy link
Member Author

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

Copy link
Collaborator

@jakelang jakelang Sep 25, 2019

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

Ok(DropSection::CustomSectionByIndex(str::parse::<usize>(val)?))
}
"unknown_by_index" => Ok(DropSection::UnknownSectionByIndex(str::parse::<usize>(
val,
Copy link
Member Author

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

}

fn with_config(config: &HashMap<String, String>) -> Result<Self, ModuleError> {
for (key, val) in config.iter() {
Copy link
Collaborator

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?

Copy link
Member Author

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.

Copy link
Collaborator

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.

Copy link
Member Author

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.

@@ -80,6 +81,17 @@ pub trait ModulePreset {
Self: std::marker::Sized;
}

// TODO: move this to be part of ChiselModule
Copy link
Collaborator

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.

@axic axic force-pushed the module-config branch 3 times, most recently from 861aaf5 to 106fbc1 Compare September 25, 2019 19:31
@axic axic force-pushed the module-config branch 5 times, most recently from ae356d5 to 85840af Compare January 15, 2020 00:37
@axic axic marked this pull request as ready for review January 15, 2020 00:37
@axic axic force-pushed the module-config branch 2 times, most recently from 7fbba65 to b1cdd54 Compare January 15, 2020 00:55
Copy link
Collaborator

@jakelang jakelang left a 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.

@axic axic merged commit 35bbe00 into master Jan 18, 2020
@axic axic deleted the module-config branch January 18, 2020 10:51
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.

Key-value configuration for modules
2 participants