Skip to content

make detect encoding functions constexpr - #920

Open
shikharish wants to merge 6 commits into
simdutf:masterfrom
shikharish:encoding-constexpr
Open

shikharish wants to merge 6 commits into
simdutf:masterfrom
shikharish:encoding-constexpr

Conversation

@shikharish

Copy link
Copy Markdown
Contributor

Closes #891

Signed-off-by: Shikhar <shikharish05@gmail.com>
Signed-off-by: Shikhar <shikharish05@gmail.com>
@shikharish

Copy link
Copy Markdown
Contributor Author

cc: @lemire @pauldreik

@lemire

lemire commented Jan 13, 2026

Copy link
Copy Markdown
Member

@shikharish thanks. This will nicely close our gap. Let us include this in our next release.

@pauldreik pauldreik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I am in a hurry so sorry for not doing a thorough review.
I think it is mostly fine but I have some questions.

Comment thread include/simdutf/common_defs.h Outdated
Comment thread include/simdutf/compiler_check.h Outdated
Comment thread include/simdutf/encoding_types.h Outdated
simdutf_warn_unused encoding_type check_bom(const uint8_t *byte, size_t length);
simdutf_warn_unused encoding_type check_bom(const char *byte, size_t length);
template <typename BytePtr>
simdutf_warn_unused inline simdutf_constexpr14 encoding_type

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use a macro guarded c++20 concept here to restrict the bytepr.

Comment thread include/simdutf/encoding_types.h Outdated
return encoding_type::unspecified;
}

simdutf_warn_unused inline encoding_type check_bom(const char *byte,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be really_inline

Comment thread include/simdutf/implementation.h Outdated
#include <simdutf/scalar/utf32_to_utf8/utf32_to_utf8.h>
#include <simdutf/scalar/utf32_to_utf8/valid_utf32_to_utf8.h>
#include <simdutf/scalar/utf8.h>
#include <simdutf/scalar/detect.h>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this included twice?

Comment on lines +132 to +135
#include <simdutf/scalar/utf8.h>
#include <simdutf/scalar/utf16.h>
#include <simdutf/scalar/utf32.h>
#include <simdutf/scalar/detect.h>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is ok to move around the includes, but remove those that are duplicates

#include <simdutf/scalar/utf32.h>
#include <simdutf/scalar/detect.h>

#if SIMDUTF_SPAN

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed?

* of units processed if successful.
*/
simdutf_warn_unused result
simdutf_warn_unused simdutf_constexpr23 result

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this changed?

Comment thread tests/autodetect_constexpr_tests.cpp Outdated
}

template <endianness big_endian>
template <endianness big_endian, typename InputPtr>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a macro guarded c++20 concept check.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and reused the already existing concept and style)

Signed-off-by: Shikhar <shikharish05@gmail.com>
Signed-off-by: Shikhar <shikharish05@gmail.com>
@lemire

lemire commented Jan 16, 2026

Copy link
Copy Markdown
Member

@shikharish Could you have a look at @pauldreik's comments ? There are a few that are apparently outstanding (meaning that it is unclear whether you answered or changed the code accordingly).

@shikharish

Copy link
Copy Markdown
Contributor Author

@lemire I made all the requested changes. There were a few things I misunderstood before but I've fixed them in the last few commits.

@lemire

lemire commented Jan 16, 2026

Copy link
Copy Markdown
Member

@pauldreik Can you check that your concerns were addressed?

Comment thread include/simdutf/encoding_types.h Outdated
#if SIMDUTF_CPLUSPLUS20
#include <concepts>
template <typename BytePtr>
concept check_bom_byteptr = requires(BytePtr p, size_t i) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please look at the other constexpr changes recently merged and reuse the already existing concepts.

}

template <endianness big_endian>
template <endianness big_endian, typename InputPtr>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and reused the already existing concept and style)

Comment thread include/simdutf/scalar/detect.h
Comment thread tests/autodetect_constexpr_tests.cpp Outdated
Signed-off-by: Shikhar <shikharish05@gmail.com>
@shikharish
shikharish requested a review from pauldreik January 21, 2026 11:39
@shikharish

Copy link
Copy Markdown
Contributor Author

@pauldreik Please review.

@pauldreik

Copy link
Copy Markdown
Collaborator

@shikharish when you get review comments, please go through them one by one and fix/answer them. otherwise I have to go through everything again. there are still issues left from earlier comments.

what is also left to do:

  • update the README which says these two functions miss constexpr functionality.
  • a function template is already implicitly inline, don't mark as inline.
  • the changes in base64, why are they there? surprised to see them in this PR.

Comment thread tests/autodetect_constexpr_tests.cpp Outdated
Comment on lines +2 to +3
#include <iostream>
#include <array>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these don't seem to be used.

Comment thread include/simdutf/scalar/utf16.h Outdated
Comment on lines +20 to +24
#if SIMDUTF_SPAN
template <endianness big_endian, simdutf::detail::indexes_into_utf16 InputPtr>
#else
template <endianness big_endian, typename InputPtr>
#endif

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

template <endianness big_endian, typename InputPtr>
#if SIMDUTF_CPLUSPLUS20
  requires simdutf::detail::indexes_into_utf16<InputPtr>
#endif
simdutf_warn_unused simdutf_constexpr23 bool

Comment thread include/simdutf/scalar/utf16.h Outdated
}

template <endianness big_endian>
inline simdutf_warn_unused simdutf_constexpr23 bool

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a simdutf really inline

Signed-off-by: Shikhar <shikharish05@gmail.com>
@lemire

lemire commented Apr 6, 2026

Copy link
Copy Markdown
Member

@shikharish Could you have a look at the comments ?

@shikharish

Copy link
Copy Markdown
Contributor Author

@lemire The last commit addressed all the previous comments.

@lemire

lemire commented Apr 14, 2026

Copy link
Copy Markdown
Member

@shikharish Ok, can you access the web interface at #920 and look at @pauldreik's comments. For each one of them, can you reply to Paul. It can be as simple as 'ok, I did it in my last commit', and so forth.

Otherwise, we have to go through all the comments and cross-reference them with you code changes and make sure that they have been addressed. It should be far easier for you to check each comment and confirm that it was addressed, with explanations where necessary.

Thanks!!!

This branch has not been deployed

No deployments
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.

Make immediate versions of autodetect_encoding and detect_encodings (constexpr)

3 participants