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

Storage types fixed #32

Merged
merged 24 commits into from
May 28, 2022
Merged

Storage types fixed #32

merged 24 commits into from
May 28, 2022

Conversation

pfeatherstone
Copy link
Contributor

Problem:

  • Local storage didn't work
  • Move constructors of erased type were being called in copy constructors of poly

Solution:

  • Storage types handle memory manually. So longer need void_ptr
  • Deleted copy semantics are converted to exceptions in polys
  • Deleted move semantics are converted to exceptions in polys

Issue: #31

Reviewers:
@krzysztof-jusiak

pf added 5 commits May 1, 2022 12:35
…manually. This deals with local storage (future SBO and other) properly

- All storages define copy semantics AND move semantics. If the underlying (erased) type is not copy constructible, then an exception is thrown at runtime if a copy is attempted. Similar thing for move semantics.
- defined custom exchange() as std::exchange() is not constexpr in C++17
…ype is nothrow constructible with forwarding reference

- added small buffer optimization (SBO) storage
@pfeatherstone
Copy link
Contributor Author

@krzysztof-jusiak I've also added sbo_storage and shared_storage

@kris-jusiak
Copy link
Contributor

nice, can we add some more tests please to ensure that functionality won't get removed in the future

@pfeatherstone
Copy link
Contributor Author

Yep no problem

…e want te::poly to be default constructible in the future. No reason why not.

- bug: If a copy assign or move assign throws, the pointer won't be reset so you could get a double free.
  fix: null pointers after deletion
- added tests for sbo_storage and shared_storage
@pfeatherstone
Copy link
Contributor Author

I added some tests. I don't think the tests are as complete as they should be. But we could add more in future PRs

pf added 2 commits May 1, 2022 17:55
- enhancing should_support_dynamic_storage()
- testing value semantics more thoroughly based on storage type
@pfeatherstone
Copy link
Contributor Author

@krzysztof-jusiak OK, i've added a few more tests, specifically that test value semantics more closely depending on the storage type. If everything passes, I would be keen for you to review. Thanks

@kris-jusiak
Copy link
Contributor

Fantastic, thanks

@pfeatherstone
Copy link
Contributor Author

I've added bug fixes and tests for self-assignment :)

@pfeatherstone
Copy link
Contributor Author

Hmm, with the fixes and noexcept-correctness, the library generates a lot more assembly. So the whole "better inlining" argument goes out the window. Maybe there are some optimizations possible

@pfeatherstone
Copy link
Contributor Author

Hmm, with the fixes and noexcept-correctness, the library generates a lot more assembly. So the whole "better inlining" argument goes out the window. Maybe there are some optimizations possible

Compiler explorer experiments hint that's because I've removed loads of noexcept specifiers. I think we should, otherwise it's a lie. The underlying types may well throw during construction or assignment.

@pfeatherstone
Copy link
Contributor Author

Like, te::call shouldn't have a noexcept either. Otherwise a program will terminate even if the culprit is in a try-catch statement.

@pfeatherstone
Copy link
Contributor Author

I don't understand what Codacy is chatting about

@pfeatherstone
Copy link
Contributor Author

I've tried so many different compilers, and it always works fine. So I really don't know what Codacy is talking about. It doesn't make sense to have an explicit templated constructor with a universal reference. I'm not even sure that would be valid C++. @krzysztof-jusiak any ideas?

@pfeatherstone
Copy link
Contributor Author

I give up fighting Codacy. I would love it if someone showed me what I'm doing wrong. The code builds everywhere (everywhere i've been bothered to try)

pfeatherstone added 2 commits May 12, 2022 10:27
…happy

- function pointers for copy, move etc need to have arguments with correct names, i.e. whether the pointers refer to 'self' or 'other' objects
@hgkjshegfskef
Copy link

@pfeatherstone Perhaps I don't understand the problem, but is there any reason you don't want to make the poly constructor explicit, as the tool suggests? From a cold view, right now the tool complains that poly constructor takes a single argument but the constructor is not marked explicit.

pf added 2 commits May 15, 2022 21:10
- removed default constructors. I re-added them at some point because I thought that would somehow trigger some C++ rule that would make Codacy happy
- added // cppcheck-suppress noExplicitConstructor to one of the poly constructors
@pfeatherstone
Copy link
Contributor Author

I have a few more ideas for another PR. For example, the storage policies should have additional policies that dictate whether or not they should be copyable, moveable, noexcept copyable or noexcept moveable. At the moment, all of them are copyable and moveable. If the underlying erased type is not copyable say, then the copy constructor or copy assign operator of the poly throws. Which means we can't mark the copy constructor or copy assignment operators as noexcept. Similar thing for move semantics. Or depending on the policy, we may want to delete copy or move semantics. these types of things will chip away lines of assembly. The default behavior before was to mark everything as noexcept which I think is incorrect because your program will always terminate. i don't think that's desirable.

@pfeatherstone
Copy link
Contributor Author

@krzysztof-jusiak Do you mind reviewing when you get the chance?

@kris-jusiak
Copy link
Contributor

@pfeatherstone very nice, thank you 👏 I think it just need rebasing and it's good to go 👍

@pfeatherstone
Copy link
Contributor Author

@krzysztof-jusiak Sorry, I'm not a git expert. Do you mind giving some instructions? This branch is ahead of boost-ext/te anyway so not sure what rebasing would do. Do you mean squashing commits?

@hgkjshegfskef
Copy link

@pfeatherstone see #19 regarding compilation errors with GCC

@pfeatherstone
Copy link
Contributor Author

@hgkjshegfskef Thanks. Now i know what name to put to that mappings_size() thing. I was calling it ADL hacking magic. So don't know what to do then. Surely we want this to work with gcc, it is after all the most popular compiler. I guess reflection in C++23 (or whenever it comes) will solve all of this.

@hgkjshegfskef
Copy link

@pfeatherstone if you understand how that "ADL magic" works (I unfortunately do not), perhaps you can borrow the implementation from Anton Polukhin's Boost.PFR, which works under c++17 and even c++14, which, as far as I understand, needs to do something similar. That issue is 4 years old, and nobody suggested a patch yet, so good luck :)

@pfeatherstone
Copy link
Contributor Author

I think Boost.PFR uses something different. It has to do with aggregate initialization.

@pfeatherstone
Copy link
Contributor Author

I think we need @krzysztof-jusiak to lay out his opinion on this. Making this work on gcc without changing the API would be nice. I'm not a fan of the Dyno interface which requires you to define several things. This is super clean. But if it can't be done with gcc then it can't be done. Sy Brand did something really great using the old metaclasses proposal. I'm sure something equivalent with reflection will be possible soon and all problems will go away. In the mean time, we make this a Clang only library.

@kris-jusiak
Copy link
Contributor

hmm, it seems that the soution has been broken for g++8+ borefe these changes either way. I think we can proceeed with the PR as it's a great improvement and figure out whether there is a valuable wknd or g++8+. I do remember seeing a workable solution somewhere at some point. Will try to dig it in.

@kris-jusiak
Copy link
Contributor

Regardin the MR conficts

Merging via command line
If you do not want to use the merge button or an automatic merge cannot be performed, you can perform a manual merge on the command line. However, the following steps are not applicable if the base branch is protected.

https://github.com/pfeatherstone/te.git
Step 1: From your project repository, check out a new branch and test the changes.

git checkout -b pfeatherstone-master master
git pull https://github.com/pfeatherstone/te.git master
Step 2: Merge the changes and update on GitHub.

git checkout master
git merge --no-ff pfeatherstone-master
git push origin master

@pfeatherstone
Copy link
Contributor Author

I don't quite understand what you want me to do with the rebase. Can't we just do a squash and merge? I made my changes on master. When I run your commands I just get messages like "Already up-to-date". I'm really sorry if I'm being dumb.

@pfeatherstone
Copy link
Contributor Author

pfeatherstone commented May 24, 2022

hmm, it seems that the soution has been broken for g++8+ borefe these changes either way. I think we can proceeed with the PR as it's a great improvement and figure out whether there is a valuable wknd or g++8+. I do remember seeing a workable solution somewhere at some point. Will try to dig it in.

It also doesn't work for certain versions of Clang, for example 11.0.0, 10.0.1, 9.0.1, 8.0.1. https://godbolt.org/z/TdTKaah18
Basically, some of the compilers really don't like templated type erasure.

@kris-jusiak kris-jusiak merged commit 2746584 into boost-ext:master May 28, 2022
@kris-jusiak
Copy link
Contributor

merged, thanks @pfeatherstone, @hgkjshegfskef

@pfeatherstone
Copy link
Contributor Author

Awesome. Now we just need it to work on gcc and other versions of clang.

@pfeatherstone
Copy link
Contributor Author

hmm, it seems that the soution has been broken for g++8+ borefe these changes either way. I think we can proceeed with the PR as it's a great improvement and figure out whether there is a valuable wknd or g++8+. I do remember seeing a workable solution somewhere at some point. Will try to dig it in.

@krzysztof-jusiak Is this relevant to fixing the implementation such that it works with g++ and some version of clang?

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.

3 participants