1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-09 14:30:46 +00:00
Commit Graph

3168 Commits

Author SHA1 Message Date
Shannon Booth
8d2ccf0f4f AK: Implement IPV4 host URL parsing to specification
This implements both the parsing and serialization IPV4 parts from
the URL spec.
2023-07-24 17:07:16 -04:00
Shannon Booth
50359567e0 AK: Add spec comments for URL spec defined member variables 2023-07-24 17:07:16 -04:00
Timothy Flynn
685c8c3d40 Revert "AK: Automatically copy all warn/warnln logs to debug console"
This reverts commit d48c68cf3f.

Unfortunately, this currently copies some warn() invocations that we do
*not* want in the debug console, such as test-js's use of OSC command 9
to report progress.
2023-07-22 12:19:53 -04:00
Lucas CHOLLET
f79165cefe AK: Make FixedArray movable 2023-07-21 10:47:34 -06:00
Andrew Kaster
3533d3e452 AK: Enable consteval workaround for Android NDK
Android isn't shipping clang-15 yet in any NDK, so use the existing
workaround on that platform.
2023-07-19 04:22:28 -06:00
Andreas Kling
f0ec104131 AK: Implement IPv6 host parsing in URLParser
This is just a straight (and fairly inefficient) implementation of IPv6
parsing and serialization from the URL spec.

Note that we don't use AK::IPv6Address here because the URL spec
requires a specific serialization behavior.
2023-07-17 07:47:58 +02:00
Sam Atkins
d48c68cf3f AK: Automatically copy all warn/warnln logs to debug console
This is only enabled inside Serenity, as on Lagom, all out/warn/dbg logs
go to the same console anyway.
2023-07-16 00:59:13 +02:00
Shannon Booth
5625ca5cb9 AK: Rename URLParser::parse to URLParser::basic_parse
To make it more clear that this function implements
'concept-basic-url-parser' instead of 'concept-url-parser'.
2023-07-15 09:45:16 +02:00
Shannon Booth
7ef4689383 AK: Implement steps for state override in URL parser 2023-07-15 09:45:16 +02:00
Daniel Bertalan
aaf1b762ea AK: Remove redundant information from TypeErasedFormatParams
The array which contains the actual parameters is always located
immediately after the base `TypeErasedFormatParams` object of
`VariadicFormatParams`. Hence, storing a pointer to it inside a `Span`
is redundant. Changing it to a zero-length array saves 8 bytes.

Secondly, we limit the number of parameters to 256, so `m_size` and
`m_next_index` can be stored in a smaller data type than `size_t`,
saving us another 8 bytes.

This decreases the size of a single-element `VariadicFormatParams` from
48 to 32 bytes, thus reducing the code size overhead of setting up
parameters for `dbgln()`.

Note that [arrays of length zero][1] are a GNU extension, but it's used
elsewhere in the codebase already and is explicitly supported by Clang
and GCC.

[1]: https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
2023-07-14 06:37:11 +02:00
Nico Weber
9fb0de1cfe AK: Mark Error nodiscard
...instead of manually marking all methods returning Error nodiscard.

No real behavior change.
2023-07-12 17:03:07 +02:00
Daniel Bertalan
cfadbcd950 AK: Work around Xcode 15 beta mishandling trailing requires clauses
Xcode 15 betas 1-3 lack https://reviews.llvm.org/D135772, which fixes a
bug that causes trailing `requires` clauses to be evaluated twice,
failing the second time. Reported as FB12284201.

This caused compile errors when instantiating types derived from RefPtr:
> error: invalid reference to function 'NonnullRefPtr': constraints not
> satisfied
> note: because substituted constraint expression is ill-formed: value
> of type '<dependent type>' is not contextually convertible to 'bool'.

This commit works around the issue by moving the `requires` clauses
after the template parameter list.

In most cases, trailing `requires` clauses and those specified after the
template parameter list work identically, so this change should not
impact the code's behavior. The only difference is that trailing
requires clauses are evaluated *after* constrained placeholder types
(i.e. `Integral auto i` function parameter).
2023-07-12 15:43:18 +01:00
Lucas CHOLLET
398f7ae988 AK: Move chunks a single time in cleanup_unused_chunks()
All elements of the vector were moved to the left, for each element to
remove. This patch makes the function move each element exactly once.

On the same test case as the previous commit, it makes the function
disappear from the profile. These two commits combined reduce the
decompression time by 12%.
2023-07-10 21:35:10 -04:00
Lucas CHOLLET
44bedf7844 AK: Don't reuse chunks in AllocatingMemoryStream
As confusing as it may sound, reusing them is terrible performance wise.
When profiling the PNG decoder, the result (which is dominated by the
Zlib decompression) shows that the `cleanup_unused_chunks()` function
represented 14.26% of the profile before this patch and only 7.7%
afterward.

On a 6.5 MB PNG image, it reduces the decompression time by more than
5%.
2023-07-10 21:35:10 -04:00
Tim Schumacher
8a9761de20 AK: Let Array::from_span take a readonly Span
We are copying here, so there is no need to require a non-const Span.
2023-07-09 15:40:41 +01:00
Hendiadyoin1
467bc5b093 AK: Add a generic version of log2
This uses one of Sun OS's algorithms, for a comparison to other
algorithms please refer to
https://gist.github.com/Hendiadyoin1/f58346d66637deb9156ef360aa158bf9

This is used on aarch64 builds and for x86 floats and doubles
for performance gains check
https://quick-bench.com/q/_2jTykshP6cUqtgdepFaoQ53YC8
which shows approximately 2x gains

Co-Authored-By: Ben Wiederhake <BenWiederhake.GitHub@gmx.de>
Co-Authored-By: kleines Filmröllchen <filmroellchen@serenityos.org>
Co-Authored-By: Dan Klishch <danilklishch@gmail.com>
2023-07-09 15:39:52 +01:00
Ali Mohammad Pur
5a0ad6812c AK: Add a CallableAs<R, Args...> concept
This is just the concept version of the IsCallableWithArguments type
trait previously defined in Function.h.
2023-07-08 23:13:00 +01:00
Timothy Flynn
996c020b0d Everywhere: Remove 'clang-format off' comments that are no longer needed 2023-07-08 10:32:56 +01:00
Timothy Flynn
c911781c21 Everywhere: Remove needless trailing semi-colons after functions
This is a new option in clang-format-16.
2023-07-08 10:32:56 +01:00
Timothy Flynn
aff81d318b Everywhere: Run clang-format
The following command was used to clang-format these files:

    clang-format-16 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Base/*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -not \( -path "./Ports/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.h")
2023-07-08 10:32:56 +01:00
Tim Schumacher
60ac254df6 AK: Use hashing to accelerate searching a CircularBuffer 2023-07-06 15:06:20 +01:00
Tim Schumacher
4a10cf1506 AK: Make CircularBuffer::read_with_seekback const
Compared to the other read and write functions, this doesn't modify the
internal state of the circular buffer.
2023-07-06 15:06:20 +01:00
Tim Schumacher
42d01b21d8 AK: Rewrite the hint-based CircularBuffer::find_copy_in_seekback
This now searches the memory in blocks, which should be slightly more
efficient. However, it doesn't make much difference (e.g. ~1% in LZMA
compression) in most real-world applications, as the non-hint function
is more expensive by orders of magnitude.
2023-07-06 15:06:20 +01:00
Tim Schumacher
3526d67694 AK: Add Span<T>::matching_prefix_length 2023-07-06 15:06:20 +01:00
Tim Schumacher
2109f61b0d AK: Add search-related helpers to CircularBuffer
This factors out a lot of complicated math into somewhat understandable
functions.

While at it, rename `next_read_span_with_seekback` to
`next_seekback_span` to keep the naming consistent and to avoid making
function names any longer.
2023-07-06 15:06:20 +01:00
Tim Schumacher
d12036132e AK: Allow passing an offset to CircularBuffer::next_read_span() 2023-07-06 15:06:20 +01:00
Tim Schumacher
046a9faeb3 AK: Split up CircularBuffer::find_copy_in_seekback
The "operation modes" of this function have very different focuses, and
trying to combine both in a way where we share the most amount of code
probably results in the worst performance.

Instead, split up the function into "existing distances" and "no
existing distances" so that we can optimize either case separately.
2023-07-06 15:06:20 +01:00
Tim Schumacher
9e82ad758e AK: Move parts for searching CircularBuffer into a new class
We will be adding extra logic to the CircularBuffer to optimize
searching, but this would negatively impact the performance of
CircularBuffer users that don't need that functionality.
2023-07-06 15:06:20 +01:00
Shannon Booth
6acce60393 AK: Fix typo in URL basic parse authority state
We weren't actually ever iterating over the buffer, and only what we
were intending to append to (which is empty!).
2023-07-05 11:41:10 +02:00
Shannon Booth
16b43ed03e AK: Correct faulty logic for host state in basic URL parse
The '[' and ']' code points were not being appended to the buffer for
this case.
2023-07-05 11:41:10 +02:00
Shannon Booth
dc27d19b21 AK: Remove superfluous check for file state in URL basic parse
The spec does not mention any of the other checks we were doing.
2023-07-05 11:41:10 +02:00
Shannon Booth
b76972ff32 AK: Correct faulty logic in file slash state in basic URL parsing
We were not correctly decrementing the pointer in the case that either
the base URL was non-null or the base URL's scheme was not a file.
2023-07-05 11:41:10 +02:00
Shannon Booth
a809d1634f AK: Add missing spec assert in relative state basic URL parsing 2023-07-05 11:41:10 +02:00
Shannon Booth
4dd4ff68d3 AK: Correct logic in file state decrementing a path in URL basic parsing 2023-07-05 11:41:10 +02:00
Shannon Booth
983441b67f AK: Check for state override in more places for basic URL parsing 2023-07-05 11:41:10 +02:00
Shannon Booth
c6c424e982 AK: Add spec comments for 'basic URL parser'
By golly, this is a lot more spec comments than I originally thought
I would need to do! This has exposed some bugs in the implementation,
as well as a whole lot of things which we are yet to implement.

No functional changes intended in this commit (already pretty large
as is!).
2023-07-05 11:41:10 +02:00
Jelle Raaijmakers
eacc0bfa02 AK+LibC: Remove AK/Atomic.h includes from our RefPtrs
We don't seem to be using it there.
2023-07-04 16:30:13 +02:00
Daniel Bertalan
0cd85ab0fc AK+LibJS: Make Number.MIN_VALUE a denormal
ECMA-262 implies that `MIN_VALUE` should be a denormalized value if
denormal arithmetic is supported. This is the case on x86-64 and AArch64
using standard GCC/Clang compilation settings.

test262 checks whether `Number.MIN_VALUE / 2.0` is equal to 0, which
only holds if `MIN_VALUE` is the smallest denormalized value.

This commit renames the existing `NumericLimits<FloatingPoint>::min()`
to `min_normal()` and adds a `min_denormal()` method to force users to
explicitly think about which one is appropriate for their use case. We
shouldn't follow the STL's confusingly designed interface in this
regard.
2023-07-02 21:19:09 +01:00
Andrew Kaster
7d71acf1bb AK: Use __builtin_frame_address to find current stack depth remaining
Instead of checking the address of a temporary, grab the address of the
current frame pointer to determine how much memory is left on the stack.

This better communicates to the compiler what we're trying to do, and
resolves some crashes with ASAN in test-js while the option
detect_stack_use_after_return is turned on.
2023-07-01 07:03:11 +02:00
Andrew Kaster
bfd6deed1e AK+Meta: Disable consteval completely when building for oss-fuzz
This was missed in 02b74e5a70

We need to disable consteval in AK::String as well as AK::StringView,
and we need to disable it when building both the tools build and the
fuzzer build.
2023-06-29 15:55:54 -06:00
Daniel Bertalan
1a10e904b5 AK: Use compiler builtins for MakeIntegerSequence/TypeListElement
These recursive templates have a measurable impact on the compile speed
of Variant-heavy code like LibWeb. Using these builtins leads to a 2.5%
speedup for the measured compilation units.
2023-06-28 16:18:32 +02:00
Andrew Kaster
02b74e5a70 AK: Re-enable consteval StringView literal workaround for oss-fuzz
oss-fuzz ships a pre-release commit of clang-15 for all of their build
bots. Until they update to a release of clang-15 that includes the fix
for this bug, or a later release, we need to keep the workaround in
place.
2023-06-28 12:18:06 +02:00
Andrew Kaster
cd2a6767bc AK: Never use assert() when targeting Windows platforms
The Windows CRT definition of assert() is not noreturn, and causes
compile errors when using it as the backing for VERIFY() in debug
configurations of applications like the Jakt compiler.
2023-06-26 05:09:00 +02:00
Shannon Booth
be9fcaf92d AK: Expose URLParser::percent_encode_after_encoding
This function is useful in places outside of the URLParser in LibWeb.
2023-06-25 11:28:32 +02:00
Daniel Bertalan
9d4dfc1061 AK: Work around Apple Clang __builtin_subc codegen issue
Apple Clang 14.0.3 (Xcode 14.3) miscompiles this builtin on AArch64,
causing the borrow flag to be set incorrectly. I have added a detailed
writeup on Qemu's issue tracker, where the same issue led to a hang when
emulating x86:

https://gitlab.com/qemu-project/qemu/-/issues/1659#note_1408275831

I don't know of any specific issue caused by this on Lagom, but better
safe than sorry.
2023-06-24 18:31:14 +02:00
Daniel Bertalan
7dadc9ff33 AK: Prefer __builtin_{subc,addc} intrinsics to x86-specific ones
GCC 14 (https://gcc.gnu.org/g:2b4e0415ad664cdb3ce87d1f7eee5ca26911a05b)
has added support for the previously Clang-specific add/subtract with
borrow builtins. Let's use `__has_builtin` to detect them instead of
assuming that only Clang has them. We should prefer these to the
x86-specific ones as architecture-independent middle-end optimizations
might deal with them better.

As an added bonus, this significantly improves codegen on AArch64
compared to the fallback implementation that uses
`__builtin_{add,sub}_overflow`.

For now, the code path with the x86-specific intrinsics stays so as to
avoid regressing the performance of builds with GCC 12 and 13.
2023-06-24 18:31:14 +02:00
kleines Filmröllchen
80a228383b AK: Simplify MaybeOwned constructor
The previous version had a sequence of calls that are likely not
optimized out, while this version is strictly a sequence of static type
conversion which are always fully optimized out.
2023-06-23 01:34:27 +02:00
kleines Filmröllchen
7a6b1f179b AK: Explicitly make MaybeOwned noncopyable
Copying an owning MaybeOwned is forbidden.
2023-06-23 01:34:27 +02:00
Lucas CHOLLET
102fdf6305 AK: Override read_until_filled in FixedMemoryStream
This specialized method allow significant performance improvements for
the user.
2023-06-22 21:32:45 +02:00
Timothy Flynn
2714f99c1c AK: Update clang workaround for consteval StringView literals
The underlying issue was fixed in clang-15. See:
a4f8590247

However, Apple and BSD distributions do not yet have this patch.
2023-06-21 06:49:47 -04:00