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

to panic or not to panic, that is the question #170

Open
gaissmai opened this issue Aug 29, 2024 · 7 comments
Open

to panic or not to panic, that is the question #170

gaissmai opened this issue Aug 29, 2024 · 7 comments

Comments

@gaissmai
Copy link

New() intercepts a panic in defer() of makeslice and at least for this reason New() is not inlineable and therefore the slice always escapes to the heap. Currently I work around this with From(buffer) but would it also be possible that a MustNew(int) is possibly inlineable if it just propagates the panic.

@lemire
Copy link
Member

lemire commented Aug 29, 2024

Sure, pull request invited.

@gaissmai
Copy link
Author

maybe you will rethink if you really catch the panic in New() and change the length to 0 under the hood. Perhaps it's generally better to propagate the runtime panics unaltered. You can save some cpu cycles in the hot path and you panic anyway e.g. in extendSet and ShiftLeft .

@gaissmai gaissmai changed the title proposal: add an inlineable MustNew() to panic or not to panic, that is the question Aug 30, 2024
@lemire
Copy link
Member

lemire commented Aug 30, 2024

@gaissmai Yes, although that would have to be a major release and we should carefully document that the constructor may panic. Pull request invited.

@gaissmai
Copy link
Author

gaissmai commented Aug 30, 2024

hmm, I'm not sure whether this requires a major release.

The public interface does not change, only the internal behavior:

  • the possibility that New() is now panicking (nobody is happy with a suppressed panic)
  • some other panic strings change from self crafted to runtime (the string is no public interface)

I would also leave out the test on panicIfNull, I would rather prefer the runtime panic. The bitset library is used for speed optimization and it is not a high level library, the users of this library prefer to see the runtime panic than a trapped and rewritten panic text.

request for comment

@bbrodriges
Copy link

the possibility that New() is now panicking (nobody is happy with a suppressed panic)

This is a big deal. For now there is no way function can panic from user perspective, but changing this behaviour without major version bump can lead to potential unexpected panics in runtime for users.

@gaissmai
Copy link
Author

gaissmai commented Sep 2, 2024

But there are other functions that trigger a panic for the same reason, i.e. if you have specified a tooBig start value for New(tooBig), then New does not panic (and unfortunately also returns no error) but possibly a Set(tooBig) later in the middle of the code.

@gaissmai
Copy link
Author

gaissmai commented Sep 2, 2024

and by the way, the current docstring for New() does not exclude any panic

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

No branches or pull requests

3 participants