-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
add --lean
compiler flag; improve error message when strutils.%
or addf throws by showing all useful context
#14282
Conversation
If you are planning to commit this, I will close #14486. |
ya I am planning to, will get to it |
bb3593e
to
1183ab5
Compare
strutils.%
or addf throws by showing all useful context
IMHO |
nim r --stacktrace:off --excessivestacktrace:off main import strutils
proc main()=
echo "abc1 $foo1 " % ["goo", "bar0"]
echo "abc $foo2 " % ["foo", "bar"]
main() before PR: nim --eval:'echo (41-14)/(325 + 14)' an overall 27 LOC increase (8% increase in There are plenty of things that will have much bigger impact on reducing code size that should be tried first, but if somehow that 8% increase is a problem, I can introduce and document a [1] but |
I am not talking about "LOC" (lines of code), I'm talking about the resulting binary sizes. And while it's hardly significant for this "one little thing", these little things do add up. And on an embedded chip, I'm not willing to pay the price for debug conveniences in the final build, eventually I stop debugging my code and then I'm left with the bloat. So arguably, this should all be done for debug mode only.
We already have debug vs release vs danger, adding more doesn't seem wise. |
fine but then let's do it properly and without conflating features (which always bites you back), via a proper dedicated flag
It's easy enough for a user on scarce resource to combine however they wish, eg
|
When I want to optimize for size, it means I care about the size. Why shouldn't the stdlib adapt to my wish? How is |
1183ab5
to
ad87c3a
Compare
PTAL, added
because users would not expect
done but we may need to revisit this decision soon; i'm not sure it's a good idea, because (I also made it imply Keeping flags orthogonal is always the simplest/less buggy / most flexible; documentation is always there to help picking which flags for size/speed/debug. |
ad87c3a
to
e05d926
Compare
e7e03b2
to
aad4aa5
Compare
strutils.%
or addf throws by showing all useful context--lean
compiler flag; improve error message when strutils.%
or addf throws by showing all useful context
aad4aa5
to
d61bfb4
Compare
Is this really so important that it needs an entirely new compiler flag? How often are library writers actually going to check for this flag? And if it affects semantics, why would users use it? Affecting semantics means libraries depending on "regular" semantics may break, sometimes in unexpected ways. |
This pull request has been automatically marked as stale because it has not had recent activity. If you think it is still a valid PR, please rebase it on the latest devel; otherwise it will be closed. Thank you for your contributions. |
%
now shows a more helpful error msg:before PR:
Error: unhandled exception: invalid format string [ValueError]
after PR:
Error: unhandled exception: invalid char '$' at index: '2' for input: 'a $key2 b' [ValueError]
I found it quite useful while working on #14278; without this, you got cryptic errors when format string was wrong (eg
doc/advopt.txt
)after this you get all useful context which should help you spot the error faster.
The error formatting is not set in stone so shouldn't be relied on in hardcoded tests.
future work
This can be moved to lib/std/private/miscdollars.nim to be usable in other modules that need to report parsing error with useful context:
tests/stdlib/tstrutil.nim
withtests/stdlib/tstrutils.nim
links