Commit graph

3600 commits

Author SHA1 Message Date
Andrew Kaster b03b13b720 AK+LibGfx+LibWebView: Add wrapper header around swift/bridging
When using a configuration without a swift compiler, we need to no-op
the swift annotations. Other, cleverer solutions beyond the has include
all fell flat in the face of the clang modules implementation used by
swift to parse-once use-everywhere each module.
2024-08-19 12:56:55 +02:00
Andrew Kaster 7f0044a721 CMake: Add helper to swiftify imported properties from dependencies
Works around https://gitlab.kitware.com/cmake/cmake/-/issues/26195
2024-08-17 17:44:37 -06:00
Andrew Kaster 756ef2c722 AK: Conform SimpleIterator to the random access iterator requirements
This requires pulling in some of the STL, but the result is that our
iterator is now STL Approved ™️ and our containers can be
auto-conformed to Swift protocols.
2024-08-17 17:44:37 -06:00
Timothy Flynn 831e5ed4e2 AK: Allow comparing spans of different constness
Otherwise, the following code would not compile:

    constexpr Array<int, 3> array { 4, 5, 6 };
    Vector<int> vector { 4, 5, 6 };

    if (array == vector.span()) { }

We do such comparisons in tests quite a bit. But it currently doesn't
become an issue because of the way EXPECT_EQ copies its input parameters
to non-const locals. In a future patch, that copying will be removed,
and the compiler would otherwise complain about not finding a suitable
comparison operator.
2024-08-13 14:11:05 +02:00
Shannon Booth b3bf5c4ea8 AK: Add BOM handling to String::from_utf8_with_replacement_character 2024-08-12 06:38:58 -04:00
Shannon Booth 1e8cc97b73 AK: Add fast-path in from_utf8_with_replacement_character for utf-8
This ports the same optimization which was made in
1a46d8df5f to this function as well.
2024-08-12 06:38:58 -04:00
Shannon Booth 033ea0e7fb AK: Add String::from_utf8_with_replacement_character
This takes a byte sequence and converts it to a UTF-8 string with the
replacement character.
2024-08-10 10:39:43 +02:00
Tim Ledbetter 82a63e350c AK: Assert that is<T>() input and output types are not the same
This makes it a compile error to use is<T>() where the input and output
types are known to be the same at compile time.
2024-08-08 17:50:59 +02:00
Andrew Kaster 7758875cfd AK+LibGfx: Only generate clang module map if ENABLE_SWIFT
The script pulls in a dependency on the `yaml` python package. Instead
of updating all the docs and CI jobs to account for this, let's guard
calling the script behind our experimental flag instead.
2024-08-07 09:04:09 +02:00
Andrew Kaster 2d6a65884c AK: Generate clang module map 2024-08-06 18:28:10 -06:00
Andrew Kaster 15f25d56b8 AK: Disable -Wunqualified-std-cast-call explicitly in CMake
When importing libraries with swiftc, the pragma to ignore this
warning isn't respected. So apply it on the command line.
2024-08-06 18:28:10 -06:00
Shannon Booth cfa8a8cea2 AK: Add is_ascii_c0_control_or_space 2024-08-05 17:21:26 +01:00
Timothy Flynn 7a17c654d2 AK: Add a method to compute UTF-16 length from a UTF-8 string 2024-07-31 05:55:34 -04:00
Andrew Kaster 66c939599c AK: Add a clang modules module map 2024-07-30 18:38:02 -06:00
Andrew Kaster 45301e8169 Everywhere: Remove AK_DONT_REPLACE_STD macro
Let's just always include `<utility>`. Placing our own incompatible with
the STL declaration of these functions in AK was always fishy to begin
with.
2024-07-30 18:38:02 -06:00
Diego Frias a168bec7ef AK/SIMDExtras: Fix masking logic in shuffle_or_0 2024-07-27 15:02:37 +02:00
Diego Frias a6ebd100ec AK/LEB128: Speed up reading unsigned LEB128 values
Unroll the first byte as a fast path, and remove a branch. This speeds
up the instantiation of spidermonkey by 10ms.
2024-07-27 08:19:51 +02:00
Diego Frias 9cc3e7d32d LibWasm: Fix SIMD shuffle and swizzle
`swizzle` had the wrong operands, and the vector masking boolean logic
was incorrect in the internal `shuffle_or_0` implementation. `shuffle`
was previously implemented as a dynamic swizzle, when it uses an
immediate operand for lane indices in the spec.
2024-07-24 23:23:09 +02:00
Timothy Flynn 74d644a216 AK: Explicitly check for null data in Utf16View
The underlying CPU-specific instructions for operating on UTF-16 strings
behave differently for null inputs. Add an explicit check for this state
for consistency.
2024-07-21 19:57:07 +02:00
Timothy Flynn 144452d638 AK: Explicitly check for null data in Utf8View
The underlying CPU-specific instructions for operating on UTF-8 strings
behave differently for null inputs. Add an explicit check for this state
for consistency.
2024-07-21 19:57:07 +02:00
Timothy Flynn 29879a69a4 AK: Construct Strings from StringBuilder without re-allocating the data
Currently, invoking StringBuilder::to_string will re-allocate the string
data to construct the String. This is wasteful both in terms of memory
and speed.

The goal here is to simply hand the string buffer over to String, and
let String take ownership of that buffer. To do this, StringBuilder must
have the same memory layout as Detail::StringData. This layout is just
the members of the StringData class followed by the string itself.

So when a StringBuilder is created, we reserve sizeof(StringData) bytes
at the front of the buffer. StringData can then construct itself into
the buffer with placement new.

Things to note:
* StringData must now be aware of the actual capacity of its buffer, as
  that can be larger than the string size.
* We must take care not to pass ownership of inlined string buffers, as
  these live on the stack.
2024-07-20 06:45:49 +02:00
Timothy Flynn 77eef8a8f6 AK: Add missing includes to StringData.h
Opening StringData.h in any clangd-enabled editor previously resulted in
a sea of clangd errors.
2024-07-20 06:45:49 +02:00
Timothy Flynn af220af8bf AK: Remove StringBuilder's UseInlineCapacityOnly feature
This feature is unused in Ladybird and will complicate an upcoming patch
to hand-off StringBuilder's memory to String.
2024-07-20 06:45:49 +02:00
Timothy Flynn 71c29504af AK: Support non-native endianness in Utf16View
Utf16View currently assumes host endianness. Add support for specifying
either big or little endianness (which we mostly just pipe through to
simdutf). This will allow using simdutf facilities with LibTextCodec.
2024-07-18 19:43:57 +02:00
Timothy Flynn 0c14a9417a AK: Replace converting to and from UTF-16 with simdutf
The one behavior difference is that we will now actually fail on invalid
code units with Utf16View::to_utf8(AllowInvalidCodeUnits::No). It was
arguably a bug that this wasn't already the case.
2024-07-18 14:46:25 +02:00
Timothy Flynn 32ffe9bbfc AK: Replace UTF-16 validation and length computation with simdutf 2024-07-18 14:46:25 +02:00
Timothy Flynn a2bcb2ab8d AK: Replace UTF-8 validation and length computation with simdutf 2024-07-18 14:46:25 +02:00
Timothy Flynn 3b96ef1a4d AK: Remove Lagom tools workaround for simdutf 2024-07-18 14:46:25 +02:00
Andrew Kaster 88044f59c6 AK: Stop exporting AK::FixedPoint into the global namespace
This declaration has conflicts with the macOS SDK, which becomes a
problem when trying to interact with system clang modules.
2024-07-18 09:43:38 +01:00
Andrew Kaster bf600c8e1d AK: Stop exporting AK::Duration into the global namespace
This has conflicts with MacTypes.h from the Apple macOS SDKs, which
becomes a huge problem when trying to interact with system clang modules
2024-07-18 09:43:38 +01:00
Daniel Bertalan c62240aa80 Everywhere: Warn on function definitions without prototypes
If no header includes the prototype of a function, then it cannot be
used from outside the translation unit it was defined in. In that case,
it should be marked as `static`, in order to avoid possible ODR
problems, unnecessary exported symbols, and allow the compiler to better
optimize those.

If this warning triggers in a function defined in a header, `inline`
needs to be added, otherwise if the header is included in more than one
TU, it will fail to link with a duplicate definition error.

The reason this diff got so big is that Lagom-only code wasn't built
with this flag even in Serenity times.
2024-07-17 21:51:29 +02:00
Dan Klishch 7e9dc9c1fd AK: Use bit_cast in SIMDExtras.h/AK::Detail::byte_reverse_impl
This necessitates marking bit_cast as ALWAYS_INLINE since emitting it as
a function call there will create an unnecessary potential SSE
registers -> plain registers/memory round-trip.
2024-07-17 09:56:13 -06:00
Hendiadyoin1 9c583154b0 AK: Add generic SIMD shuffle/reverse functions
(cherry picked from commit 1b8fd5c35afda8f797f1e8a39c332fa14950006e)
2024-07-17 09:56:13 -06:00
Hendiadyoin1 873b03f661 AK: Add generic SIMD vector load/store functions
(cherry picked from commit 27c386797df64b9c4dcbe6a27e57d9f54837e9b4)
2024-07-17 09:56:13 -06:00
Hendiadyoin1 9ee334e970 AK: Add introspection helpers to SIMD.h
(cherry picked from commit 8d6028d366c918b3656c0a4c6808a570dcecf8f4)
2024-07-17 09:56:13 -06:00
Timothy Flynn f29c3684a6 AK: Enable ASSERT in debug builds only
NDEBUG is defined in release builds. So we want to enable the ASSERT
macro when it *isn't* defined.
2024-07-17 09:45:43 -06:00
Timothy Flynn bfc9dc447f AK+LibWeb: Replace our home-grown base64 encoder/decoders with simdutf
We currently have 2 base64 coders: one in AK, another in LibWeb for a
"forgiving" implementation. ECMA-262 has an upcoming proposal which will
require a third implementation.

Instead, let's use the base64 implementation that is used by Node.js and
recommended by the upcoming proposal. It handles forgiving decoding as
well.

Our users of AK's implementation should be fine with the forgiving
implementation. The AK impl originally had naive forgiving behavior, but
that was removed solely for performance reasons.

Using http://mattmahoney.net/dc/enwik8.zip (100MB unzipped) as a test,
performance of our old home-grown implementations vs. the simdutf
implementation (on Linux x64):

                Encode    Decode
AK base64       0.226s    0.169s
LibWeb base64   N/A       1.244s
simdutf         0.161s    0.047s
2024-07-16 10:27:39 +02:00
Timothy Flynn 58dfe5424f AK: Make the AK library's CMake a bit more standard
We no longer have multiple locations including AK (e.g. LibC). So let's
avoid awkwardly defining the AK library across multiple CMake files.

This is to allow more easily adding third-party dependencies to AK in
the future.
2024-07-16 10:27:39 +02:00
Andreas Kling df18a76ad2 AK: Add ASSERT() and ASSERT_NOT_REACHED() for debug-only assertions
Let's move towards using these for things that are "nice to check in
debug builds, but not essential".
2024-07-10 07:03:20 +02:00
Diego aee2f25929 AK: Add remaining method to ConstrainedStream
Simply returns how many bytes can be read from the stream.
2024-07-09 14:22:31 +02:00
Tim Ledbetter 634f2f655b AK: Allow escaping of keys in SourceGenerator
This allows the opening and closing characters of the SourceGenerator
to be used in the source text to be used for purposes other than keys.
2024-07-09 11:21:07 +02:00
Andrew Kaster fc7af577fc AK: Ignore -Wstring-op-overflow in another ByteBuffer instance
gcc 14.1 from Fedora 40 likes to warn on this on aarch64.
2024-07-07 15:56:59 +02:00
Salem Yaslem ab82fc8993 LibCore: Support IPv6 for TCP and UDP connection 2024-07-05 14:26:22 -06:00
Dennis Camera 186057bf92 AK: Add TODO_PPC* assertions 2024-07-05 09:50:13 -06:00
Dennis Camera ffe2f16c58 AK: Add AK_IS_ARCH defines for PowerPC CPU architecture 2024-07-05 09:50:13 -06:00
Dennis Camera b54a1c6284 AK: Implement ShortString for big-endian 2024-07-05 09:49:23 -06:00
Dennis Camera b4d13d060a AK: Fix {:c} formatter for big-endian 2024-07-05 09:48:15 -06:00
Dennis Camera 1bc44376c0 AK: Implement floating-point conversions for big-endian 2024-07-05 09:47:08 -06:00
Timothy Flynn 698a95d2de AK: Decode paired UTF-16 surrogates in a JSON string
For example, such use is seen on Twitter.
2024-07-04 14:16:16 +02:00
Timothy Flynn c39a3fef17 AK: Make a couple of GenericLexer helper methods protected
We will want to use the exact behavior of these methods in JsonParser.
2024-07-04 14:16:16 +02:00