Commit graph

3266 commits

Author SHA1 Message Date
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
MacDue d4d92184b3 AK: Align Function storage to __BIGGEST_ALIGNMENT__ outside kernel
The previous alignment would always resolve to 8-bytes, which is below
the required alignments of types that could exist in userspace (long
double, 128-bit integers, SSE, etc).
2023-06-19 21:59:35 +02:00
Valtteri Koskivuori 838d586b25 AK: Fix relative file URL parsing in URLParser
The FileSlash state was erroneously copying the base URL host, instead
of the base URL path excluding the last path component. This resulted in
invalid file URLs.
2023-06-18 15:16:08 +02:00
Ben Wiederhake 041f5e931d AK: Use AK_MAKE_DEFAULT_MOVABLE to avoid mistakes in default impls 2023-06-18 08:47:51 +01:00
Ben Wiederhake 3d3dfc8da8 AK: Introduce AK_MAKE_DEFAULT_MOVABLE macro for easier default impls 2023-06-18 08:47:51 +01:00
Kenneth Myhra c03c0ec900 AK: Add URL::to_string() returning a String
For convenience wire up a to_string() method which returns a new String.
2023-06-17 20:38:20 +02:00
Sam Atkins 8e53e5afc4 AK: Propagate errors from SourceGenerator::fork() 2023-06-17 17:48:06 +01:00
Sam Atkins f902d4d5e7 AK: Introduce fallible SourceGenerator API 2023-06-17 17:48:06 +01:00
Sam Atkins 747d1aaa98 AK: Use String internally for SourceGenerator
Also sneak in a little error propagation. We keep the existing
DeprecatedString API for now.
2023-06-17 17:48:06 +01:00
Sam Atkins 9c05b83540 AK: Use consume_until in SourceGenerator
This got fixed a while ago to not consume the stop character, so we can
remove the workaround.
2023-06-17 17:48:06 +01:00
Sam Atkins c8eafd3700 AK: Remove SourceGenerator::as_string()
Turns out nobody uses this!
2023-06-17 17:48:06 +01:00
wertzuz f8527e1cad AK: Rename fixme to match other FIXMEs 2023-06-15 15:38:50 +01:00
Jelle Raaijmakers 65a9eb1fdf AK: Simplify Vector::padded_capacity
We don't need to do `max(4, ...)` if the RHS always adds 4.
2023-06-13 13:08:14 +02:00
Timothy Flynn 936ec94f81 AK+LibAudio+AudioServer: Silence very noisy debug statements by default
These are spammed quite heavily on the debug console, especially at the
end of audio playback.
2023-06-13 06:14:01 +02:00
Hendiadyoin1 ca0106ba1d AK: Forbid from_utf8 and from_deprecated_{...} with unintended types
Calling `from_utf8` with a DeprecatedString will hide the fact that we
have a DeprecatedString, while using `from_deprecated_string` with a
StringView will silently and needlessly allocate a DeprecatedString,
so let's forbid that.
2023-06-13 01:49:02 +02:00
Ali Mohammad Pur 47248a3511 LibWasm: Keep track of created directory fds in path_create_directory 2023-06-10 07:18:02 +02:00
Zaggy1024 873b0e9470 LibGfx/LibVideo: Read batches of multiple bytes in VPX BooleanDecoder
This does a few things:

- The decoder uses a 32- or 64-bit integer as a reservoir of the data
  being decoded, rather than one single byte as it was previously.
- `read_bool()` only refills the reservoir (value) when the size drops
  below one byte. Previously, it would read out a bit-sized range from
  the data to completely refill the 8-bit value, doing much more work
  than necessary for each individual read.
- VP9-specific code for reading the marker bit was moved to its own
  function in Context.h.
- A debug flag `VPX_DEBUG` was added to optionally enable checking of
  the final bits in a VPX ranged arithmetic decode and ensure that it
  contains all zeroes. These zeroes are a bitstream requirement for
  VP9, and are also present for all our lossy WebP test inputs
  currently. This can be useful to test whether all the data present in
  the range has been consumed.

A lot of the size of this diff comes from the removal of error handling
from all the range decoder reads in LibVideo/VP9 and LibGfx/WebP (VP8),
since it is now checked only at the end of the range.

In a benchmark decoding `Tests/LibGfx/test-inputs/4.webp`, decode times
are improved by about 22.8%, reducing average runtime from 35.5ms±1.1ms
down to 27.4±1.1ms.

This should cause no behavioral changes.
2023-06-10 07:17:12 +02:00
Peter Brottveit Bock 49b29332f2 AK: Migrate IPv6Address::to_deprecated_string() to ::to_string()
Change the name and return type of
`IPv6Address::to_deprecated_string()` to `IPv6Address::to_string()`
with return type `ErrorOr<String>`.

It will now propagate errors that occur when writing to the
StringBuilder.

There are two users of `to_deprecated_string()` that now use
`to_string()`:

1. `Formatted<IPv6Address>`: it now propagates errors.

2. `inet_ntop`: it now sets errno to ENOMEM and returns.
2023-06-09 19:38:14 +01:00
Peter Brottveit Bock 10aed80b29 AK: Define IPv6Address::loopback(), the IPv6 loopback address '::1' 2023-06-09 19:38:14 +01:00
Liav A 7c0540a229 Everywhere: Move global Kernel pattern code to Kernel/Library directory
This has KString, KBuffer, DoubleBuffer, KBufferBuilder, IOWindow,
UserOrKernelBuffer and ScopedCritical classes being moved to the
Kernel/Library subdirectory.

Also, move the panic and assertions handling code to that directory.
2023-06-04 21:32:34 +02:00
Liav A aaa1de7878 Kernel: Move {Virtual,Physical}Address classes to the Memory directory 2023-06-04 21:32:34 +02:00
Liav A 1b04726c85 Kernel: Move all tasks-related code to the Tasks subdirectory 2023-06-04 21:32:34 +02:00
Jelle Raaijmakers 75c8e07cc3 AK: Remove conditional noexcept from Complex
C++11 has been a requirement for some time now, no need to bother the
preprocessor with it.
2023-06-01 06:26:08 +02:00
MacDue 81ff242e86 AK: Mark generic shorthand functions as constexpr 2023-06-01 06:25:00 +02:00
Tim Schumacher 58b1d9c319 AK: Correctly calculate size of the last AllocatingMemoryStream chunk 2023-05-29 13:30:46 +02:00
Tim Schumacher 52aab50914 AK: Handle empty trailing chunks in AllocatingMemoryStream::offset_of 2023-05-29 13:30:46 +02:00
Tim Schumacher 9a7ae52b31 AK: Expose AllocatingMemoryStream::CHUNK_SIZE
This allows the tests to use that information confidently.
2023-05-29 13:30:46 +02:00
Ali Mohammad Pur e90752cc21 LibWeb: Add preliminary support for CSS animations
This partially implements CSS-Animations-1 (though there are references
to CSS-Animations-2).
Current limitations:
- Multi-selector keyframes are not supported.
- Most animation properties are ignored.
- Timing functions are not applied.
- Non-absolute values are not interpolated unless the target is also of
  the same non-absolute type (e.g. 10% -> 25%, but not 10% -> 20px).
- The JavaScript interface is left as an exercise for the next poor soul
  looking at this code.

With those said, this commit implements:
- Interpolation for most common types
- Proper keyframe resolution (including the synthetic from-keyframe
  containing the initial state)
- Properly driven animations, and proper style invalidation

Co-Authored-By: Andreas Kling <kling@serenityos.org>
2023-05-29 05:35:41 +02:00
Sam Atkins c140b67be3 AK: Verify that we don't call Error::from_errno(0)
We shouldn't ever make an Error if there wasn't actually an error. :^)
2023-05-28 05:51:27 -06:00
Ben Wiederhake 5fafd82927 AK+Everywhere: Don't crash on invalid months
Sadly, we don't have proper error propagation here. However, crashing
the Kernel just because a CDROM contains an invalid month seems like a
bad idea.
2023-05-27 12:17:50 +02:00
Ben Wiederhake 9d40ecacb5 AK: Fix signed overflow in unix time parts parsing 2023-05-27 12:17:50 +02:00
kleines Filmröllchen 3c212c8535 AK: Remove Duration::now_monotonic
This is the end of absolute time support in Duration. :^)
2023-05-24 23:18:07 +02:00
kleines Filmröllchen fc5cab5c21 Everywhere: Use MonotonicTime instead of Duration
This is easily identifiable by anyone who uses Duration::now_monotonic,
and any downstream users of that data.
2023-05-24 23:18:07 +02:00
kleines Filmröllchen b2e7b8cdff AK: Introduce MonotonicTime
This class takes on the duties of CLOCK_MONOTONIC, a time without a
defined reference point that always increases. This informs some
important design decisions about the class API: MonotonicTime cannot be
constructed from external time data, except as a computation based on
other monotonic time, or the current monotonic time. Importantly, there
is no default constructor, since the reference point of monotonic time
is unspecified and therefore without meaning as a default.

The current use of monotonic time (via Duration) includes some potential
problems that may be caught when we move most to all code to
MonotonicTime in the next commit.

The API restrictions have one important relaxation:
Kernel::TimeManagement is allowed to exchange raw time data within
MonotonicTime freely. This is required for the clock-agnostic time
accessors for timeouts and syscalls, as well as creating monotonic time
data from hardware in the first place.
2023-05-24 23:18:07 +02:00
kleines Filmröllchen 69e27169c4 AK: Remove now-unused Duration methods
These are not applicable to Duration, since it's not a timestamp class.
2023-05-24 23:18:07 +02:00
kleines Filmröllchen 939600d2d4 Kernel: Use UnixDateTime wherever applicable
"Wherever applicable" = most places, actually :^), especially for
networking and filesystem timestamps.

This includes changes to unzip, which uses DOSPackedTime, since that is
changed for the FAT file systems.
2023-05-24 23:18:07 +02:00
kleines Filmröllchen c1323febc2 AK: Introduce UnixDateTime
This is a generic wrapper for a time instant relative to the unix epoch,
and does not account for leap seconds. It should be used in place of
Duration in most current cases.
2023-05-24 23:18:07 +02:00
kleines Filmröllchen 0dfcaf1389 AK: Make Duration arithmetic constexpr
This is a trivial change, and since this batch of commits will make a
large-scale rebuild necessary anyways, it seems sensible. The feature is
useful for e.g. building compound constant durations at compile time in
a readable way.
2023-05-24 23:18:07 +02:00
kleines Filmröllchen 213025f210 AK: Rename Time to Duration
That's what this class really is; in fact that's what the first line of
the comment says it is.

This commit does not rename the main files, since those will contain
other time-related classes in a little bit.
2023-05-24 23:18:07 +02:00
Daniel Bertalan fd316945f5 AK: Define NAKED more resiliently for AArch64
This attribute is used for functions in the kernel that are entirely
written in assembly, yet defined in C++ source files.

Without `__attribute__((naked))`, Clang might decide to inline these
functions, making any `ret` instructions within them actually exit the
caller, or discard argument values as they appear "dead". This issue
caused a kernel panic when using the `execve` syscall in AArch64
SerenityOS built by Clang.

While the empty definition so far appears to work fine with GCC, simpler
test cases do similarly suffer from unintended inlining, so define
`NAKED` as a synonym of `NEVER_INLINE` to avert future issues.

Perhaps we should move users of `NAKED` to plain assembly files?

This makes aarch64Clang builds boot :^)
2023-05-23 23:45:01 +02:00
Caoimhe fd4f00ee91 AK: Add SPICE_AGENT_DEBUG flag 2023-05-21 18:45:53 +02:00
Ben Wiederhake d43d51eedc AK: Add FIXMEs to HashMap copy-construct and copy-assign
This underlines that we still copy-construct and copy-assign HashMaps.

Primarily, this makes it easier to develop towards OOM-safe(r) internal
data structures, by providing a reminder (the FIXME) and an easy error-
checking switch (just change it to "delete" to see some of the errors).
2023-05-19 22:33:57 +02:00
Ben Wiederhake 95d90a760b AK: Make all HashMap copy-constructs explicit 2023-05-19 22:33:57 +02:00
Ben Wiederhake 6421899078 AK: Rewrite HashMap::clone signature with template-args and const 2023-05-19 22:33:57 +02:00
Muhammad Zahalqa 0f0d16bbec AK: Include Array.h in Base64.h
Array.h should be included in Base64.h and removed from Base64.cpp
2023-05-18 22:49:02 +02:00
kleines Filmröllchen c9f6605fb2 AK: Account for bit position 8 in bit stream alignment
See identical code in LittleEndianBitStream; even in the bytewise
reading BigEndianBitStream an offset of 8 is not inconsistent state and
handled just fine by read_bits.
2023-05-18 22:23:15 +02:00
Timothy Flynn 70c977aa56 AK: Discard bits from LittleEndianInputBitStream as they are read
Rather than tracking our position in the bit buffer, we can simply shift
away the bits that we read. This is mostly for simplicity, but also does
help performance a bit.

Using the "enwik8" file as a test (100MB uncompressed, commonly used in
benchmarks: https://www.mattmahoney.net/dc/enwik8.zip), compression time
decreases from:

    3.96s to 3.79s on Serenity (cold)
    1.08s to 1.04s on Serenity (warm)
    0.83s to 0.82s on Linux
2023-05-18 11:21:56 -07:00
Nico Weber 0c53b02149 AK: Add dbg()
We have outln() and out(), warnln() and warn(),
now we have dbgln() and dbg().

This is useful for printing arrays element-by-element while still
only printing one line per array.
2023-05-18 18:20:54 +02:00
Tim Schumacher df071d8a76 LibCompress: Add a lot of debug logging to LZMA 2023-05-17 09:08:53 +02:00
Tim Schumacher 221b91ff61 AK: Add CircularBuffer::find_copy_in_seekback()
This is useful for compressors, which quite frequently need to find a
matching span of data within the seekback.
2023-05-17 09:08:53 +02:00
Tim Schumacher d194011570 AK: Add count_required_bits 2023-05-17 09:08:53 +02:00
Daniel Bertalan 8df5bd53da AK: Silence false positive -Warray-bounds warning
This regression has been reported to GCC's Bugzilla:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109727

The formatting change looks like a clang-format 15 bug :(
2023-05-15 07:00:29 +02:00
Ben Wiederhake 173f872cda Meta: Remove unused debug flags, add missing GENERATE_DEBUG
Commands that were helpful while investigating this:
```
grep -P '^set' Meta/CMake/all_the_debug_macros.cmake \
  | sed -Ee 's,set\((.+) ON\)$,\1,' > macros.lst
for i in $(cat macros.lst); do
  echo -n "$i "; git grep -Pn '\b'"$i"'\b' | wc -l
done | tee matches.lst
sort -k2 -n matches.lst
```
2023-05-14 16:01:57 -06:00
Ben Wiederhake 32a777347f AK: Fix typo in instructions for adopt_nonnull_REF_or_enomem 2023-05-13 18:35:02 +02:00
Lucas CHOLLET 4a2ef231b8 AK: Add FixedArray::unchecked_at 2023-05-09 11:18:46 +02:00
Lucas CHOLLET af6dc267d3 AK: Add OutputBufferedStream
This class, in a similar fashion to what has been done with
`InputBufferedStream`, postpones write to the stream until an internal
buffer is full.

This patch also adds the `OutputBufferedFile` alias.
2023-05-09 11:18:46 +02:00
Lucas CHOLLET 8c34959b53 AK: Add the Input word to input-only buffered streams
This concerns both `BufferedSeekable` and `BufferedFile`.
2023-05-09 11:18:46 +02:00
Lucas CHOLLET 48b000a36c AK: Add CircularBuffer::flush_to_stream
In a similar fashion to what have been done with `fill_from_stream`,
this new method allows to write CircularBuffer's data to a Stream
without additional copies.
2023-05-09 11:18:46 +02:00
Kemal Zebari eda2a2f5da AK: Remove must_set() from JsonArray
Due to 582c55a, both `must_set()` and `set()` should be providing the
same behavior. Not only is that a reason to remove `must_set()`, but
it also performs erroneous behavior since it inserts an element at
a specified index instead of modifying an element at that index.
2023-05-09 06:21:34 +02:00
Timothy Flynn d6b786b3fe AK: Use consteval String factories on macOS
Xcode 14.3 ships with clang 15, which supports our usage of consteval to
validate short strings at compile time.
2023-05-08 20:54:31 -06:00
Ben Wiederhake 36ff6187f6 Everywhere: Change spelling of 'behaviour' to 'behavior'
"The official project language is American English […]."
5d2e915623/CONTRIBUTING.md?plain=1#L30

Here's a short statistic of the occurrences of the word "behavio(u)r":

$ git grep -IPioh 'behaviou?r' | sort | uniq -c | sort -n
      2 BEHAVIOR
     24 Behaviour
     32 behaviour
    407 Behavior
    992 behavior

Therefore, it is clear that "behaviour" (56 occurrences) should be
regarded a typo, and "behavior" (1401 occurrences) should be preferred.

Note that The occurrences in LibJS are intentionally NOT changed,
because there are taken verbatim from the specification. Hence:

$ git grep -IPioh 'behaviou?r' | sort | uniq -c | sort -n
      2 BEHAVIOR
     10 behaviour
     24 Behaviour
    407 Behavior
   1014 behavior
2023-05-07 01:05:09 +02:00
Ben Wiederhake ee47c0275e Everywhere: Run spellcheck on all documentation 2023-05-07 01:05:09 +02:00
Tim Schumacher 56d861ebe0 AK: Prevent bit counter underflows in the new BitStream
Our current `peek_bits` function allows retrieving more bits than we can
actually provide, so whenever someone discards the requested bit count
afterwards we were underflowing the value instead.
2023-05-04 20:01:16 +02:00
Kemal Zebari 582c55a1c8 AK: Have JsonArray::set() change values instead of inserting values
Resolves #18618.

8134dcc changed `JsonArray::set()` to insert elements at an index
instead of changing existing elements in-place. Since no behavior
such as `Vector::try_at()` exists yet, it returns nothing.
2023-05-03 21:39:09 +01:00
Ali Mohammad Pur 2306219ef9 AK: Accomodate always-32-bit data member pointers in IntrusiveList
This only exists on windows, but we've made an effort to keep jakt
working on windows, so let's support this silliness.
2023-05-02 17:46:39 +03:30
Daniel Bertalan 00b4976f2c Everywhere: Make Lagom build with GCC 13
GCC 13 was released on 2023-04-26. This commit fixes Lagom build errors
when using an updated host toolchain:
- Adds a workaround for a bug in constraint handling, which made LibJS
  fail to compile: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109683
- Silences the new `-Wdangling-reference` diagnostic globally. It
  produces multiple false positives with no clear way to silence them
  without `#pragmas`.
- Silences `-Wself-move` in `RefPtr` tests as GCC 13 adds this
  previously Clang-exclusive warning.
2023-05-02 07:03:57 -04:00
Dan Klishch 4653b38808 AK: Replace linear exponentiation by binary in MinimalBigInt
This further optimizes floating point parsing (specifically with a large
amount of digits). The commit shaves additional 20% of the run time for
750-digit numbers. No performance degradation is noticeable for small
numbers.
2023-04-30 06:05:54 +02:00
Dan Klishch 80517b5a70 AK: Use helpers from BigIntBase.h in MinimalBigInt
Although it might seem like we've switched to more generic functions,
which must run slower, it is not the case. The time required to parse
"1", for example, decreased by 1%. For numbers with more digits, the
effect is more noticeable: 8-digit numbers are parsed ~5% faster; for
gigantic 750-digit numbers, parsing is 2 times faster.

The later result is achieved by using UFixedBigInt<64>::wide_multiply
instead of u128::operator*(u128).
2023-04-30 06:05:54 +02:00
Dan Klishch 3c900765bc AK: Move taint_for_optimizer to StdLibExtras.h
Additionally, split it into two versions (for IsIntegral<T> -- asking
to place value into register and for !IsIntegral<T> -- asking to place
value into memory with memory clobber), so that Clang is no more
completely confused about `taint_for_optimizer(AK::StringView&)`.
2023-04-30 06:05:54 +02:00
thankyouverycool 9a03e4dd73 AK: Add count() helper to String 2023-04-30 05:48:14 +02:00
Daniel Bertalan c911fb0150 AK: Add Span::align_to
This method returns a sub-span whose data pointer and size is aligned to
a specified alignment.
2023-04-29 08:24:18 +02:00
Aliaksandr Kalenik 4c6564e3c1 AK: Add values() method in HashTable
Add HashTable::values() method that returns all values.
2023-04-28 18:11:44 +02:00
Ali Mohammad Pur 41cf52a623 AK: Make the Optional formatter always available and tweak its format
There's no real reason to make this a debug-only formatter, on top of
that, jakt has a optional formatter that prints None/foo instead of
OptionalNone/Optional(foo), which is more concise anyway, so switch to
that.
2023-04-28 14:55:56 +02:00
MacDue 454ecf24ea AK+LibTimeZone: Add debug only formatter for Optional
I found this handy for debugging, and so might others.

This now also adds a formatter for TimeZone::TimeZone. This is needed
for FormatIfSupported<Optional<TimeZone::TimeZone>> to compile. As
FormatIfSupported sees a formatter for Optional exists, but not that
there's not one for TimeZone::TimeZone.
2023-04-28 09:42:28 +02:00
Ali Mohammad Pur d06057f88b AK: Don't refer to AK::swap() as ::swap()
While swap() is available in the global namespace in normal conditions,
!USING_AK_GLOBALLY will make this name unavailable in the global
namespace, making these calls fail to compile.
2023-04-28 05:56:04 +02:00
Ali Mohammad Pur 7e6341587b AK+Everywhere: Disallow Error::from_string_view(FooString)
That pattern seems to show up a lot in code written by people that
aren't intimately familiar with the lifetime model of Error and Strings.
This commit makes the compiler detect it and present a more helpful
diagnostic than "garbage string at runtime".
2023-04-28 05:55:20 +02:00
Ali Mohammad Pur 7e4e9fdb8f LibWasm: Start implementing WASI
This commit starts adding support for WASI, along with the framework to
implement all the functions (though only a couple are currently
implemented).
2023-04-26 03:47:15 +03:30
Tim Schumacher 5e7c838160 AK: Rename Stream::format() to Stream::write_formatted()
This brings the function name in line with how we usually name those
functions, which is with a `read_` or `write_` prefix depending on what
they do.

While at it, make the internal `_impl` function private and not-virtual,
since there is no good reason to ever override that function.
2023-04-25 07:30:16 +01:00
Cameron Youell ada6dbf636 AK: Use JsonArray::append when parsing array 2023-04-24 09:21:51 +02:00
Cameron Youell 8134dccdc7 AK: Add new failable JsonArray::{append/set} functions
Move all old usages to the more explicit `JsonArray:must_{append/set}`
2023-04-24 09:21:51 +02:00
Zaggy1024 ba5bf412e5 LibThreading: Create WorkerThread class run a single task concurrently
This class can be used to run a task in another thread, and allows the
caller to wait for the task to complete to retrieve any error that may
have occurred.

Currently, it doesn't support functions returning a value on success,
but with some template magic that should be possible. :^)
2023-04-23 23:14:30 +02:00
Peter Brottveit Bock 6f6d6c654d AK: Implement Stream::format(fmtstr, args...)
Based on `out()` and `vout()` from AK/Format.h. As opposed to those,
this propagates errors.

As `Core::File` extends `AK::Stream`, this allows formatted
printing directly on `Core::File`s.
2023-04-23 16:56:06 +02:00
Sam Atkins 892470a912 AK: Add Array::contains_slow() and ::first_index_of(), with tests :^) 2023-04-21 20:44:47 +01:00
Andreas Kling b7e847e58b AK: Fix crash during teardown of self-owning objects
We now null out smart pointers *before* calling unref on the pointee.
This ensures that the same smart pointer can't be used to acquire a new
reference to the pointee after its destruction has begun.

I ran into this when destroying a non-empty IntrusiveList of RefPtrs,
but the problem was more general so this fixes it for all of RefPtr,
NonnullRefPtr, OwnPtr and NonnullOwnPtr.
2023-04-21 18:15:00 +02:00
MacDue 5db1eb9961 AK+Everywhere: Replace URL::paths() with path_segment_at_index()
This allows accessing and looping over the path segments in a URL
without necessarily allocating a new vector if you want them percent
decoded too (which path_segment_at_index() has an option for).
2023-04-15 06:37:04 +02:00
MacDue 35612c6a7f AK+Everywhere: Change URL::path() to serialize_path()
This now defaults to serializing the path with percent decoded segments
(which is what all callers expect), but has an option not to. This fixes
`file://` URLs with spaces in their paths.

The name has been changed to serialize_path() path to make it more clear
that this method will generate a new string each call (except for the
cannot_be_a_base_url() case). A few callers have then been updated to
avoid repeatedly calling this function.
2023-04-15 06:37:04 +02:00
MacDue 5acd40c525 AK+Everywhere: Add ApplyPercentDecoding option to URL getters
The defaults selected for this are based on the behaviour of URL
when it applied percent decoding during parsing. This does mean now
in some cases the getters will allocate, but percent_decode() checks
if there's anything to decode first, so in many cases still won't.
2023-04-15 06:37:04 +02:00
MacDue b9e03071cc AK: Remove unnecessary parameter names in URL.h 2023-04-15 06:37:04 +02:00
Nico Weber afcbdad1e3 AK: Remove workaround for old macOS SDK
https://github.com/SerenityOS/serenity/pull/9716#issuecomment-1508606204
has details.
2023-04-14 19:15:42 +02:00
Nico Weber eae1e61a88 AK: Remove unused AK_ARCH_ defines
ARCH() uses the AK_IS_ARCH_ macros internally since 349e54d537,
and all user code uses the ARCH() macro instead of AK_ARCH_.

(Why it's called ARCH() and not AK_ARCH(), I don't know.)

If any ports not in the main repo use AK_ARCH_, they should switch
to using ARCH() instead.
2023-04-14 19:15:19 +02:00
Nico Weber 97b7e494e4 Everywhere: Use ARCH(AARCH64) instead of AK_ARCH_AARCH64
The former is typo-resistant after 349e54d537, so make use of that.
2023-04-14 19:15:19 +02:00
Nico Weber fc15fc36ce AK: Make math work on arm hosts again
957f89ce4a added some tweaks for serenity-on-aarch64.
It broke anythingelse-on-aarch64 hosts though, so only do these tweaks
when targeting serenity.

(I wonder if AK/Math.h should fall back to the system math routines
when not targeting serenity in general. Would probably help ladybird
performance. On the other hand, the serenity routines would see less
use and hence exposure and love.)
2023-04-14 16:16:42 +02:00
Tim Schumacher b1136ba357 AK: Efficiently resize CircularBuffer seekback copy distance
Previously, if we copied the last byte for a length of 100, we'd
recalculate the read span 100 times and memmove one byte 100 times,
which resulted in a lot of overhead.

Now, if we know that we have two consecutive copies of the data, we just
extend the distance to cover both copies, which halves the number of
times that we recalculate the span and actually call memmove.

This takes the running time of the attached benchmark case from 150ms
down to 15ms.
2023-04-14 10:03:42 +02:00
Timon Kruiper 957f89ce4a AK: Add very naive implementation of {sin,cos,tan} for aarch64
The {sin,cos,tan} functions in AK are used as the implementation of the
same function in libm. We cannot use the __builtin_foo functions as
these would just call the libc functions. This was causing an infinite
loop. Fix this by adding a very naive implementation of
AK::{sin, cos,tan}, that is only valid for small inputs. For the other
functions in this file, I added a TODO() such that we'll crash, instead
of infinite looping.
2023-04-13 20:24:25 +02:00
Sam Atkins 89e55c5297 AK+Tests: Add Vector::find_first_index_if() 2023-04-13 09:53:47 +02:00
Nico Weber f56b897622 Everywhere: Fix a few typos
Some even user-visible!
2023-04-12 19:37:35 +02:00
Nico Weber 077164ae15 AK: Make grepping for "lerp" find mix() 2023-04-12 15:23:51 +02:00
Tim Schumacher adfda6a271 AK: Remove the Endian bytes accessor
This is a remnant from when we didn't have a `read_value` and
`write_value` implementation for `AK::Endian` and instead used the
generic functions for reading a span of bytes. Now that we have a more
ergonomic alternative, remove the helper that is no longer needed.
2023-04-12 07:33:15 -04:00
MacDue 8283e8b88c AK: Don't store parts of URLs percent decoded
As noted in serval comments doing this goes against the WC3 spec,
and breaks parsing then re-serializing URLs that contain percent
encoded data, that was not encoded using the same character set as
the serializer.

For example, previously if you had a URL like:

https:://foo.com/what%2F%2F (the path is what + '//' percent encoded)

Creating URL("https:://foo.com/what%2F%2F").serialize() would return:

https://foo.com/what//

Which is incorrect and not the same as the URL we passed. This is
because the re-serializing uses the PercentEncodeSet::Path which
does not include '/'.

Only doing the percent encoding in the setters fixes this, which
is required to navigate to Google Street View (which includes a
percent encoded URL in its URL).

Seems to fix #13477 too
2023-04-12 07:40:22 +02:00
networkException 9915fa72fb AK+Everywhere: Use Optional for URLParser::parse's base_url parameter 2023-04-11 16:28:20 +02:00
Tim Ledbetter 54539c42c2 AK: Allow human_readable_size_long to use a thousands separator 2023-04-11 13:03:30 +02:00
Tim Ledbetter 72ea046b68 AK: Add option to the string formatter to use a digit separator
`vformat()` can now accept format specifiers of the form
{:'[numeric-type]}. This will output a number with a comma separator
every 3 digits.

For example:

`dbgln("{:'d}", 9999999);` will output 9,999,999.

Binary, octal and hexadecimal numbers can also use this feature, for
example:

`dbgln("{:'x}", 0xffffffff);` will output ff,fff,fff.
2023-04-11 13:03:30 +02:00
Rodrigo Tobar 5a8373c6b9 LibCore: Fix corner case for files without newlines
When BufferedFile.can_read_line() was invoked on files with no newlines,
t incorrectly returned a false result for this single line that, even
though doesn't finish with a newline character, is still a line. Since
this method is usually used in tandem with read_line(), users would miss
reading this line (and hence all the file contents).

This commit fixes this corner case by adding another check after a
negative result from finding a newline character. This new check does
the same as the check that is done *before* looking for newlines, which
takes care of this problem, but only works for files that have at least
one newline (hence the buffer has already been filled).

A new unit test has been added that shows the use case. Without the
changes in this commit the test fails, which is a testament that this
commit really fixes the underlying issue.
2023-04-09 18:09:23 -06:00