-
Notifications
You must be signed in to change notification settings - Fork 586
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
Parser set defaults improvements #1840
Parser set defaults improvements #1840
Conversation
37c3eec
to
37c8c01
Compare
37c8c01
to
c8e6725
Compare
This is required for this to work:
|
Ensures args_fill() for new cpu_type is called, allowing for patterns in a target file like: parser.set_defaults(cpu_type="vexriscv_smp") parser.set_defaults(cpu_variant="linux") parser.set_defaults(with_fpu=True)
c8e6725
to
0f7ea96
Compare
if len(remaining) > 0: | ||
raise ValueError(f"set_default() for invalid argument(s): {remaining}") |
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.
Having a test and/or a message looks good, but raising an exception may, potentially being a problem for users:
- if in a target I set
cpu_type=vexriscv_smp
anddtlb_size=xxx
- if a user decide to use
--cpu-type=naxriscv
An exception will occur because dtlb_size
is something specific to the vexriscv_smp
.
Maybe it's better here to displays a message (similar to compat_notice) with unused/unknown arguments list with and a delay to warn user about situation. Otherwise user has to modifiy target to remove/comment default and it's not really user friendly.
To complete my previous message (because I have, maybe,seen why you have added the
|
Thanks for the detailed review. From what I've seen, there are many cases where the litex behaviour is to raise an exception of something goes wrong so this pattern is not unusual. However I don't remember my exact thought process on this as I added it a long time ago. I don't mind how the error is reported, I simply wanted it to be clear that the arguments were incorrect instead of being silently ignored as a typo in set_default() is otherwise far harder to find and I lost some time on several occasions due to this, hence I added something to detect the issue and stop. Ultimately this exception is only thrown if there is a bug in the target file. For example I guard set_defauts() for cpu specific arguments based on cpu_type so this exception can be resolved by writing a sane target 😀 |
For example this is how I use set_defaults() for cpu_type to guarantee the defaults are valid while also generating a target that will, by default, build with our required features:
There are a range of other arg parsing refinements I also made a while ago in an PR here: #1759. This small piece was an attempt to break the original larger change set into smaller chunks to be easier to review and merge. |
Yes it's always possible to do something like that, but it adds a bit more complex and break the idea behind
Yes it always better to have a small patches serie (ie multiple PR) with small modifications/fix/new features and a commit message enough to see why this PR (something similar to a primary school's math demonstration) : it's simplify the task for maintainers/reviewers and allows to be merged more quickly. For this PR, first part looks good because it fix a specific issue where cpu-type is not taken into account when it must: with some potential issue for CPU configuration. For the second part I'm a bit mitigated because it make sense to help developer to fix some typos but in the same time it will introduce a potential build failure when user select parameters different than default:
|
I can drop the second patch from this pr if that helps? |
@AndrewD, @trabucayre: I think we can merge as is since already fixing issues with CPU defaults and since mostly experienced developpers will be using the set_defaults for fixed configuration, raising an error when the argument is not supported seems fine. I'm merging and will do a more global review when I'll have a bit more time. |
Thanks @trabucayre and @enjoy-digital ! |
Improvements to LiteXArgumentParser when using set_defaults() in a target to ensure args_fill() for the new cpu_type is called and to report using set_default(arg=default) for an argument that doesn't exist.