-
Notifications
You must be signed in to change notification settings - Fork 0
review comments #1
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
base: tmp_review_branch
Are you sure you want to change the base?
Conversation
Changed code style for whole solution.
There is circular dependency error.
…n-experiments # Conflicts: # applications/reflection-experiments/src/reflection_parsers/ast_source_parser.cpp # applications/reflection-experiments/src/reflection_parsers/ast_source_parser.h
Still circular issue.
|
|
||
| } | ||
|
|
||
| rsl::dynamic_string reflection_code_generator::get_gen_source_file(rsl::string_view source_location) |
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.
since this function is only used in the reflection_code_generator and static, it might be better to leave this as an implementation detail function, so a global function in an anonymous namespace, or marked static so it gets internal linkage
| { | ||
| rsl::id_type hash = rsl::internal::hash::default_seed; | ||
|
|
||
| this->compile_reflection_container<compile_reflected_class>::sort_container( |
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.
I think we mentioned that if the offset is taken into the hash, then it doesn't need to be sorted right?
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.
yeah, but the hash itself is still an ordered ordeal, so before applying them to hash, we need to put them into correct order. If it was like in AST the hash would be different as AST itself does not guarantee source-like ordering, so we need to always hash in offset order.
| compile_reflected_variable>::get_container_hash(); | ||
| if(hash != 0) { hash = rsl::combine_hash(rsl::internal::hash::default_seed, hash, variable_container_hash); } | ||
|
|
||
| this->compile_reflection_container<compile_reflected_function>::sort_container( |
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.
I don't think the order of the functions matters in the structure hash, arguably functions don't matter at all for the structure hash
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.
yeah, kinda make sense, but strictly from reflection id stand point, if we have a class that is the same in all but functions, id still say its a good idea to make it produce different hash. But for our reflection we still need to know the functions, so the difference is only do we hash functions, which id say we should do.
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.
after giving it another thought, i also want to exclude functions from hashes, would be pretty strange if saves would fail cos you have added a function.
| #include <ostream> | ||
|
|
||
| compile_reflected_element::compile_reflected_element(rsl::dynamic_string&& name) : name(std::move(name)) {} | ||
| compile_reflected_element::compile_reflected_element(rsl::dynamic_string name) |
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.
if you're gonna move, then take it in as a rvalue reference. if you also want to allow copying then also supply a copy constructor using a const lvalue reference. don't take a heavy object like a string in by forced copy value.
|
|
||
| private: | ||
| rsl::dynamic_string source_location; | ||
| const rsl::dynamic_string source_location; |
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.
if you make member variables const, be careful. it's good practice, but it also means that copy or move assignment is deleted. this type becomes construct only
| #include "compile_reflected_variable.h" | ||
|
|
||
| compile_reflected_variable::compile_reflected_variable(CXCursor cursor) | ||
| compile_reflected_variable::compile_reflected_variable(CXCursor& cursor, CXCursor& parent) |
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.
these could be const&, i know the clang library takes them is as a forced value copy.... but i would not take that as a good example. looking at the size of CXCursor, I'd definitely pass it around as a reference. but since it is copied for every clang_ function anyways, we have no need for it to be non-const.
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.
tru, i have probably forgotten to change this to const
|
|
||
| template<typename T> | ||
| T& compile_reflection_container<T>::add_element(const CXCursor& cursor) | ||
| T& compile_reflection_container<T>::add_element(CXCursor& cursor, CXCursor& parent) |
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.
can be const& for the same reason i mentioned earlier
| template<typename T> | ||
| void compile_reflection_container<T>::verify_typename() const | ||
| { | ||
| static_assert(std::is_base_of_v<compile_reflected_element, T>, "T must inherit from compile_reflected_element"); |
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.
static asserts don't need to be called at runtime, so they don't even need to be in a function. they can exist anywhere in the class or other member functions. static_asserts get executed at compile time. the reason why this static assert works, and the concept restriction didn't, is because this function gets instantiated later, after the type T is complete.
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.
Yep, i know that and in this case i wanted to do that from the start (put it in the body of class), but that didnt work, as static assert is called immideately when the class is encountered, so it still tried to use incomplete "compiletime_reflection_class", during the process of compilation. So in this case it seems to me that we had to put here.
| rsl::id_type hash = rsl::internal::hash::default_seed; | ||
|
|
||
| this->compile_reflection_container<compile_reflected_class>::sort_container( | ||
| &compile_reflection_container<compile_reflected_class>::sort_by_offset_comparator); |
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.
arguably, contained classes don't matter for the structure hash either.... although it becomes tricky with anonymous structs and unions, so maybe rather safe than sorry and include them anyways... hmm....
|
|
||
| for(std::size_t i = 0; i < min_length; ++i) | ||
| { | ||
| if(a_string[i] < b_string[i]) { return true; } |
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.
if(a_string[i] != b_string[i]) { return a_string[i] < b_string[i]; }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.
fair enough
|
|
||
| extern "C" | ||
| { | ||
| #include "xxhash.h" |
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.
you can use:
#define XXH_STATIC_LINKING_ONLY /* access advanced declarations */
#define XXH_IMPLEMENTATION /* access definitions */
and then you can add xxhash as a header only library, and then there would be no need for extern "C" either.
| // Vector is not sorted before getting to this function | ||
| rsl::id_type reflection_id::generate_structure_hash(std::vector<std::pair<std::size_t, rsl::id_type>>& members) noexcept | ||
| { | ||
| std::ranges::sort( |
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.
if the structure hash of the members already includes the offset, then sorting is not necessary
No description provided.