1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-07 21:17:07 +09:00
Commit graph

3839 commits

Author SHA1 Message Date
Timothy Flynn
5e40db5a17 AK: Remove some now-unnecessary workarounds for simdutf base64 usage 2025-06-01 08:03:00 -04:00
Daniel Bertalan
04fac0031c AK: Add fast path for formatting common types
This commit changes `AK::TypeErasedParameter` to store integer,
floating-point and string types as well as characters and booleans
directly instead of through a type-erased `void const*`.

This is advantageous for binary size:
- The compiler no longer needs to push both the parameter value and a
  pointer to it to the stack (which contains the argument array);
  storing just the value is enough.
- Instead of instantiating `__format_value` for these types and taking
  its address (which generates a GOT entry and an ADRP+LDR pair in
  assembly), we just store a constant `TypeErasedParameter::Type` value.
- The biggest saving comes from the fact that we used to instantiate a
  distinct `__format_value` for each length of string literal. For
  LibJS, this meant 69 different functions! We can now just store them
  as a `char const*`.

I opted to use a manual tagged union instead of `Variant`: the code
wouldn't be much shorter if we used a `Variant` since we'd have to
handle converting the standard integer types to `u64`/`i64` and custom
types to the type erased wrapper via explicit constructors anyway. And
compile time overhead is smaller this way.

This gives us some nice binary size savings (numbers are from arm64
macOS LibJS):

     FILE SIZE        VM SIZE
  --------------  --------------
    +52% +10.3Ki   +52% +10.3Ki    [__TEXT]
   +5.2%    +768  +5.2%    +768    [__DATA_CONST]
   -0.0%      -7  -0.0%      -7    __TEXT,__cstring
   -3.0%    -144  -3.0%    -144    __TEXT,__stubs
   -1.2%    -176  -1.2%    -176    Function Start Addresses
  -11.6%    -432 -11.6%    -432    Indirect Symbol Table
   -1.0%    -448  -1.0%    -448    Code Signature
  -18.1%    -768 -18.1%    -768    __DATA_CONST,__got
   -0.8% -6.83Ki  -0.8% -6.83Ki    Symbol Table
   -1.0% -11.2Ki  -1.0% -11.2Ki    String Table
   -0.9% -26.1Ki  -0.9% -26.1Ki    __TEXT,__text
   -7.2% -20.9Ki  -9.6% -28.9Ki    [__LINKEDIT]
   -1.0% -56.0Ki  -1.1% -64.0Ki    TOTAL
2025-05-26 13:02:39 -06:00
Daniel Bertalan
9aaa4fd022 AK: Remove the formatter for unsigned char[N]
This is not used anywhere and its semantics are questionable.
2025-05-26 13:02:39 -06:00
Manuel Zahariev
666c323577 AK/Error: Add value_or convenience method
- In the style of Optional::value_or
- Only const& flavor
- WARNING: no unit test (no unit tests for Error), but seems benign
2025-05-26 18:48:09 +02:00
ayeteadoe
8cf01a25c2 AK: Add initial support for AK testsuite on Windows
We now explicitly enabling support for the minimum libraries needed
to build and run the AK testsuite. 81/82 tests are running and
passing. The exception is LexicalPath, as some path behaviour on
Windows is different than Unix, so the current tests will have lots of
platform specific failures. The implementer of LexicalPathWindows
recommended windows-specific tests here, so I will do that in a
follow up.
2025-05-20 10:58:43 -06:00
Andrew Kaster
da106177b4 AK: Move install rules into AK's CMakeLists 2025-05-19 18:37:15 -04:00
Ashton
5f5ae6bf8b AK: Replace wchar_t formatting with char32_t
This makes TestFormat fully cross-platform as we no longer have to
work around the 16 vs 32-bit wide strings
2025-05-18 19:18:13 -06:00
Ashton
7f0f513159 AK: Remove unnecessary Aarch64 wchar_t handling
This is legacy from the Serenity codebase, but given there are no
consumers using wchar_t in Ladybird, this can be removed.
2025-05-18 19:18:13 -06:00
Andreas Kling
734bc2a0ea AK: Strip trailing zero decimals in default formatting of float numbers
This gives us a more human-looking serialization of numbers by default,
and in case a fixed number of decimal digits is actually wanted, we
still have the 'f' specifier.
2025-05-18 17:23:34 +02:00
Daniel Bertalan
33dbe385ce AK: Replace CallableWrapper::destroy() with a destructor
Previously, heap-allocated `CallableWrapper` objects were destroyed in a
very roundabout way: `AK::Function` would call a virtual `destroy()`
method, which then invoked delete manually. This was unnecessary, since
`CallableWrapper` already has a virtual destructor — deleting it through
a `CallableWrapperBase*` correctly calls the closure's destructor.

This fixes GCC `-Wfree-nonheap-object` false positive warnings (#4721)
and coincidentally removes 8 KB of vtable entries (and the corresponding
relative relocations) from LibJS.
2025-05-17 15:07:42 -06:00
Shannon Booth
5cf87dcfdc AK: Add a Utf16View::is_code_unit_less_than helper
This seems like the natural place to put this since it is specific
to UTF-16.
2025-05-17 08:00:59 -04:00
Andrew Kaster
564f5ca2cc AK: Propagate -U flag to dependencies when built as a static library
We added a weak symbol to AK to support overriding the default assertion
handler for test cases. However, on macOS, we need to explicitly mark
the possibly-null symbol as 'it's ok for this to be undefined'.

When AK is a shared library, the flag can be applied to the link step of
the dylib, but when it's a static library, we need to apply it to the
executable that links against it.
2025-05-16 14:59:44 -06:00
ayeteadoe
dc707e6ed8 AK: Expose ak_assertion_handler weak symbol for custom death handling
When a `VERIFY()` assertion fails `ak_verification_failed` is invoked
which means the program will invoke `__builtin_trap` and immediately
quit. But with this change we have now allowed for an optional hook
into `ak_*_failed` that lets us perform some custom
action before program exits. This foundation is what we will
(ab)use to implement death tests without the process cloning
CrashTest infrastructure.
2025-05-16 13:23:32 -06:00
R-Goc
20662f0dc9 AK: Add windows support in AK/Random
This commit adds support in AK/Random for a high quality RNG on windows.
This requires moving the code into a cpp file not to spread windows
headers around.
2025-05-15 07:41:02 -06:00
Timothy Flynn
7280ed6312 Meta: Enforce newlines around namespaces
This has come up several times during code review, so let's just enforce
it using a new clang-format 20 option.
2025-05-14 02:01:59 -06:00
Timothy Flynn
ca9f3673c5 Everywhere: Run clang-format
The following command was used to clang-format these files:

    clang-format-20 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.mm" -o -name "*.h")
2025-05-14 02:01:59 -06:00
Andrew Kaster
905c5ecb4c AK: Silence -Wfree-nonheap-object more generally in Function for gcc
We were already silencing it at the site of the delete call, but gcc in
distribution mode is more aggressive about inlining and still sees a
delete that it doesn't like.
2025-05-14 02:01:50 -06:00
Timothy Flynn
a71d909b39 AK: Remove unused Error functionality 2025-05-10 21:19:46 -04:00
Timothy Flynn
95441dabd5 AK: Define some simple getters in a single line
This matches our coding style everywhere else. clang-format used to have
trouble with these, but it doesn't any longer.
2025-05-10 21:19:46 -04:00
Timothy Flynn
dceed08058 AK+LibCore: Avoid double-negation of syscall error values
This is a remnant from SerenityOS. Let's avoid confusion as to why we
negate errno when we call Error::from_syscall just to negate it again
when we store the error code.
2025-05-10 21:19:46 -04:00
Timothy Flynn
24ac5e2eee AK+LibCore: Remove SerenityOS handling from Error and Core::System
This is just to make some syscall error handling changes simpler.
2025-05-10 21:19:46 -04:00
Timothy Flynn
4f132b9e40 AK: Remove Error::from_string_view_or_print_error_and_return_errno
This was for use within Serenity's kernel. In Ladybird, it is just some
indirection to Error::from_string_view.
2025-05-10 21:19:46 -04:00
Timothy Flynn
e2b863ed3f AK: Remove unused Jakt methods 2025-05-10 21:19:46 -04:00
R-Goc
7cccdb3bcf AK: Fix error is_errno
Previously the check for is_errno did not check if the error kind was
syscall, which also set errno so that behavior was incorrect.
2025-05-10 11:25:12 -04:00
R-Goc
79b652c74e AK: Rework error types to store kind as an enum
This commit makes windows errors store the code instead of being a
formatted string literal. This will allow comparing against the error,
and checking what it is. The formatting is now done in the formatter,
and moved to an implementation file to avoid polluting headers with
windows.h. The kind of the error is now determined by an enum Kind which
will allow matching against the error kind.

Co-Authored-By: Andrew Kaster <andrew@ladybird.org>
2025-05-10 00:03:31 -06:00
Andrew Kaster
f0004fa690 AK+CMake: Remove workaround for swiftc mishandling [[no_unique_address]] 2025-05-09 23:14:27 -06:00
Andreas Kling
6efc5c54b5 AK: Make Utf16View::to_utf8() use simdutf fast path more often
By piggybacking on the already-optimized implementation in
StringBuilder, we can get simdutf for the AllowInvalidCodeUnits::Yes
case here as well.

1.03x speedup on Speedometer's TodoMVC-jQuery.
2025-05-09 21:36:59 +02:00
InvalidUsernameException
1d63398cbd AK: Expose dump_backtrace() publicly for debugging purposes
At this point, I've repeatedly felt the desire to be able to log
stacktraces to be able to see more easily what kind of call-sites exist
for a given piece of code. So this commit exposes `dump_backtrace()` in
the header so it can be used for this purpose.
2025-05-06 10:03:57 -04:00
stelar7
93d7a29306 AK: Implement {first|last}_matching for Span 2025-05-06 11:16:01 +02:00
Andreas Kling
a453da2906 AK: Allow specifying HashSetExistingEntryBehavior in HashMap::set() 2025-05-03 17:33:54 +02:00
Timothy Flynn
8a80ff7b3b AK+LibJS: Use simdutf for all base64 operations
We were previously unable to use simdutf for base64 decoding operations
other than "loose". Upstream has added support for the "strict" and
"stop-before-partial" operations, so let's make use of them!
2025-05-03 11:21:10 -04:00
Andreas Kling
cf6e2531d9 AK: Make String::number() much faster for integer types
Instead of going through String::formatted(), we now have a specialized
code path for base-10 serialization directly to UTF-8.

This is roughly 5-10x faster than the previous implementation, depending
on how many digits we end up outputting.

1.07x speedup on MicroBench/for-in-indexed-properties.js
2025-05-02 19:13:03 +02:00
Shannon Booth
23f3ecbe98 AK: Don't iterate through entire String for String::ends_with 2025-04-28 10:50:31 -04:00
Andreas Kling
580b892b9e AK: Demote VERIFY in NonnullRefPtr to ASSERT
NonnullRefPtr almost always has a non-null pointer internally, that's
what the class is for, after all! The one edge case where it has null
internally is after you move() it. But it's always a bug to use an
NNRP after moving from it, and we have clang-tidy yelling at us if
that ever happens.

Demoting this removes a gazillion overly paranoid null checks.
2025-04-28 10:39:42 -04:00
Aliaksandr Kalenik
cd9e491742 AK: Use TypedTransfer in Span::overwrite()
Using `__builtin_memmove` was unsafe if items in source buffer are not
trivially copyable.
2025-04-24 10:30:52 +02:00
Aliaksandr Kalenik
005551b530 AK: Fix out of bound access check in Span::overwrite()
Previously `data_size` (in bytes) was mistakenly compared with `size()`
that returns number of elements in a span.
2025-04-24 10:30:52 +02:00
Ali Mohammad Pur
eea81738cd AK+Everywhere: Recognise that surrogates in utf16 aren't all that common
For the slight cost of counting code points when converting between
encodings and a teeny bit of memory, this commit adds a fast path for
all-happy utf-16 substrings and code point operations.

This seems to be a significant chunk of time spent in many regex
benchmarks.
2025-04-23 07:56:02 -06:00
Tim Ledbetter
31dea89fe0 AK: Add lowest common multiple and greatest common divisor functions 2025-04-23 09:13:45 +01:00
Pavel Shliak
84e29f791c Revert "AK: Work around Apple Clang __builtin_subc codegen issue"
This reverts commit 9d4dfc1061.
2025-04-22 22:31:28 -06:00
Jonne Ransijn
bb20a0d8f8 AK: Allow the Optional<T> move assignment operator to be trivial
This will change behaviour for moved-from `Optional<T>`s, since they
will now no longer clear their value if `T` is trivial. However, a
moved-from value should be considered to be in an unspecified state.
Use `Optional<T>::clear` or `Optional<T>::release_value` instead.
2025-04-22 21:19:31 -06:00
Jonne Ransijn
50bc6fb9d9 AK: Loosen the restrictions on non-copyable/non-movable containers
If a type is non-move constructible but move assignable,
its container type may still be move assignable.

Similairly, if a type is non-copy constructible but copy assignable,
its container type may still be copy assignable.
2025-04-22 21:19:31 -06:00
Jonne Ransijn
eff9d4881c AK: Add IsScalar to StdLibExtraDetails.h
This matches the behaviour of `std::is_scalar_v`
2025-04-22 21:19:31 -06:00
Jonne Ransijn
0d1ba5c37d AK: Add IsMemberPointer to StdLibExtraDetails.h
Does exactly what it says on the tin.
2025-04-22 21:19:31 -06:00
Jonne Ransijn
e37377600d AK: Allow Optional<{,Fly}String> to be used in constant expressions 2025-04-22 21:19:31 -06:00
Jonne Ransijn
a059ab4677 AK: Allow Optional<T> to be used in constant expressions 2025-04-22 21:19:31 -06:00
Jonne Ransijn
063be28e90 AK: Add IsOneOfIgnoringCVReference to StdLibExtraDetails.h
Much like `IsOneOfIgnoringCV`, some functions want to ignore both
cv-qualifiers _and_ references. Add a template and concept for it.
2025-04-22 21:19:31 -06:00
Ali Mohammad Pur
76f5dce3db LibRegex: Flatten capture group list in MatchState
This makes copying the capture group COWVector significantly cheaper,
as we no longer have to run any constructors for it - just memcpy.
2025-04-18 17:09:27 +02:00
Andrew Kaster
ad00306daf AK: Disallow constness laundering in RefPtr and NonnullRefPtr
This is a re-application of 3c7a0ef1ac

Co-Authored-By: Andreas Kling <andreas@ladybird.org>
2025-04-16 10:41:44 -06:00
Andrew Kaster
703abac9c8 AK: Add const_cast escape hatch for converting const T& to RefPtr<T>
There are parts of the codebase where properly const-correctifying the
the code would be a giant spaghetti mess, so add this loud workaround
to defer the refactoring for later.
2025-04-16 10:41:44 -06:00
Andreas Kling
0c93a07fb1 AK: Shrink Utf16View
Use a sentinel value instead of Optional for the cached length in code
points, shrinking Utf16View from 32 to 24 bytes.
2025-04-16 10:04:50 +02:00