Skip to content

AK: Add an OptionalBase helper, and allow specializing Optional with dedicated empty values #25894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

Hendiadyoin1
Copy link
Contributor

CC: @LucasChollet
CC: @nico to cross check if apple-clang really supports this or if wikipedia is weird
CC: Whoever knows if the CI changes are correct

Based on LadybirdBrowser/ladybird#2032
But still need to cherry-pick and adapt the String changes

Depends on #25891 for the GCC version bump

@Hendiadyoin1
Copy link
Contributor Author

Ah wait the CI containers dont ship gcc-14?

@Hendiadyoin1 Hendiadyoin1 force-pushed the OptionalBase branch 3 times, most recently from 3f18ba3 to 5654981 Compare April 18, 2025 18:32
@Hendiadyoin1 Hendiadyoin1 marked this pull request as ready for review April 18, 2025 18:32
@Hendiadyoin1 Hendiadyoin1 requested a review from alimpfard as a code owner April 18, 2025 18:32
@github-actions github-actions bot added the 👀 pr-needs-review PR needs review from a maintainer or community member label Apr 18, 2025
@@ -4,6 +4,7 @@ set -e

script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)

# shellcheck source=/dev/null
Copy link
Member

Choose a reason for hiding this comment

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

IIRC these don't fail in CI, but only in the pre-commit check, because we only pass the changed scripts to shellcheck, which doesn't include shell_include.sh.

So most (if not all) # shellcheck source=/dev/null we already have in master might be unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well it failed CI without the one in this exact file you point out....

Copy link
Member

@spholz spholz Apr 18, 2025

Choose a reason for hiding this comment

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

Weird, I have no idea why it fails here then.
I'm 99% sure that the build-image-raspberry-pi.sh one only failed in the pre-commit hook.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should pass -x in lint-shell-scripts.sh then. That should make these comments unnecessary.
That flag seems to do the same thing as setting external-sources=true in .shellcheckrc.

The man page says that option can be safely enabled for normal development: https://github.com/koalaman/shellcheck/blob/master/shellcheck.1.md#directives

You don't need to do that in this PR though.

@Hendiadyoin1
Copy link
Contributor Author

Whoops, this breaks jakt builds

@Hendiadyoin1
Copy link
Contributor Author

Also Something in the NNRP code still seems off, will continue to test

@Hendiadyoin1 Hendiadyoin1 force-pushed the OptionalBase branch 2 times, most recently from b40676b to fd5a34f Compare April 18, 2025 22:24
Copy link

stale bot commented May 10, 2025

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions!

@stale stale bot added the stale label May 10, 2025
@stale stale bot removed the stale label May 10, 2025
Comment on lines +645 to +646
else if constexpr (IsCallableWithArguments<decltype(Traits<T>::special_optional_empty_value), T>)
return Traits<T>::special_optional_empty_value();
Copy link
Member

Choose a reason for hiding this comment

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

Is this branch ever used? We seem to always define special_optional_empty_value(Badge<Optional<T>>)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, not using this version yet, as all special values are currently "illegal" values, so all APIs are currently Badged
left it in as it might come usefull

Note the immediate value branch is also currently unused

Copy link
Member

Choose a reason for hiding this comment

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

left it in as it might come usefull

I think that we usually don't add unused code. So we should probably remove these two branches.

@alimpfard
Copy link
Member

Jakt stuff should be good on master, just drop the last commit and rebase.

Copy link

stale bot commented Jun 20, 2025

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions!

@stale stale bot added the stale label Jun 20, 2025
This also makes the monadic helpers a bit stricter with their value
types, hence the drive-by changes.
Not sure why it wasn't in there in the first place...
This will be needed in the next commit, as Optional then starts to
call into Traits, and the affected Types initialize their own Optional
so a Traits specialization needs to already be declared.
The new Optional implementation is chosen when a
`Traits<T>::special_optional_empty_value` exists,
this can be an immediate value or a function optionally taking a
Badge<Optional<T>>.

You can also define a custom specialization of
`Traits<T>::optional_has_value`, as otherwise the default goes through
the `==`/`!=` operators, which may not be defined.
@stale stale bot removed the stale label Jun 20, 2025
Copy link
Member

@spholz spholz left a comment

Choose a reason for hiding this comment

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

I can't really comment on the Optional changes. That is too much C++ metapogramming for me. But here are some more general comments from me.


sudo add-apt-repository ppa:ubuntu-toolchain-r/test

sudo apt-get update
sudo apt-get install ccache clang-18 clang++-18 clang-format-18 lld-18 gcc-13 g++-13 libstdc++-13-dev ninja-build unzip qt6-base-dev qt6-tools-dev-tools libqt6svg6-dev qt6-multimedia-dev libgl1-mesa-dev libpulse-dev libssl-dev libegl1-mesa-dev libclang-18-dev

sudo apt-get remove clang-{13,14,15} clang++-{13,14,15} libclang-{13,14,15}-dev llvm-{13,14,15}
sudo apt-get remove clang-{14,15} clang++-{14,15} libclang-{14,15}-dev llvm-{14,15}
Copy link
Member

Choose a reason for hiding this comment

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

Should we remove other clang versions that are now in the repos as well?
clang-14 to clang-18 seem to be in the repos.

I think that also means we don't really need the ubuntu-toolchain PPA or LLVM toolchain repo?

# cmake libgmp-dev npm shellcheck
# Packages below aren't.

set -e

wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main'
sudo add-apt-repository 'deb http://apt.llvm.org/noble/ llvm-toolchain-noble-18 main'

sudo add-apt-repository ppa:ubuntu-toolchain-r/test

sudo apt-get update
sudo apt-get install ccache clang-18 clang++-18 clang-format-18 lld-18 gcc-13 g++-13 libstdc++-13-dev ninja-build unzip qt6-base-dev qt6-tools-dev-tools libqt6svg6-dev qt6-multimedia-dev libgl1-mesa-dev libpulse-dev libssl-dev libegl1-mesa-dev libclang-18-dev
Copy link
Member

Choose a reason for hiding this comment

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

Ninja, unzip, gcc-{13,14}, g++-{13,14}, libssl-dev, and all llvm stuff seems to be preinstalled now:
https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md

@@ -29,15 +29,15 @@ runs:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test

sudo apt-get update
sudo apt-get install ccache clang-18 clang++-18 clang-format-18 lld-18 gcc-13 g++-13 libstdc++-13-dev ninja-build unzip qt6-base-dev qt6-tools-dev-tools libqt6svg6-dev qt6-multimedia-dev libgl1-mesa-dev libpulse-dev libssl-dev libegl1-mesa-dev libclang-18-dev
sudo apt-get install ccache clang-18 clang++-18 clang-format-18 lld-18 gcc-14 g++-14 libstdc++-13-dev ninja-build unzip qt6-base-dev qt6-tools-dev-tools libqt6svg6-dev qt6-multimedia-dev libgl1-mesa-dev libpulse-dev libssl-dev libegl1-mesa-dev libclang-18-dev
Copy link
Member

Choose a reason for hiding this comment

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

I think you want libstdc++-14 here if we want to keep installing gcc packages explicitly.

@@ -69,7 +69,7 @@ runs:

sudo apt-get update
sudo apt-get remove clang-{14,15} clang++-{14,15} libclang-{14,15}-dev llvm-{14,15}
sudo apt-get install clang-format-18 ccache e2fsprogs gcc-13 g++-13 libstdc++-13-dev libmpfr-dev libmpc-dev ninja-build optipng qemu-utils qemu-system-i386 unzip generate-ninja libegl1-mesa-dev
sudo apt-get install clang-format-18 ccache e2fsprogs gcc-14 g++-14 libstdc++-13-dev libmpfr-dev libmpc-dev ninja-build optipng qemu-utils qemu-system-i386 unzip generate-ninja libegl1-mesa-dev
Copy link
Member

Choose a reason for hiding this comment

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

Same here

Comment on lines +15 to +17
#### GCC 14 or Clang 18+

A host compiler that supports C++23 features is required for building host tools, the newer the better. Tested versions include gcc-13 and Clang 17 through 19.
A host compiler that supports C++23 features is required for building host tools, the newer the better. Tested versions include gcc-14 and Clang 18 through 19.
Copy link
Member

Choose a reason for hiding this comment

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

GCC 15 and Clang 20 as well.

Comment on lines +59 to +66
find_newest_compiler clang clang-18 /opt/homebrew/opt/llvm/bin/clang
if is_supported_compiler "$HOST_COMPILER"; then
export CC="${HOST_COMPILER}"
export CXX="${HOST_COMPILER/clang/clang++}"
return
fi

find_newest_compiler egcc gcc gcc-13 gcc-14 /usr/local/bin/gcc-{13,14} /opt/homebrew/bin/gcc-{13,14}
find_newest_compiler egcc gcc gcc-14 /usr/local/bin/gcc-14 /opt/homebrew/bin/gcc-14
Copy link
Member

Choose a reason for hiding this comment

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

What about Clang 19/20 and GCC 15?

@@ -25,13 +25,13 @@ sudo add-apt-repository ppa:canonical-server/server-backports
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main'
apt update
apt install git build-essential make cmake clang-format-16 gcc-13 g++-13 libstdc++-13-dev libgmp-dev ccache libmpfr-dev libmpc-dev ninja-build e2fsprogs qemu-utils qemu-system-i386 wabt
apt install git build-essential make cmake clang-format-16 gcc-14 g++-14 libstdc++-13-dev libgmp-dev ccache libmpfr-dev libmpc-dev ninja-build e2fsprogs qemu-utils qemu-system-i386 wabt
Copy link
Member

Choose a reason for hiding this comment

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

Also this libstdc++-13-dev here.

@@ -25,13 +25,13 @@ sudo add-apt-repository ppa:canonical-server/server-backports
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository 'deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main'
apt update
apt install git build-essential make cmake clang-format-16 gcc-13 g++-13 libstdc++-13-dev libgmp-dev ccache libmpfr-dev libmpc-dev ninja-build e2fsprogs qemu-utils qemu-system-i386 wabt
apt install git build-essential make cmake clang-format-16 gcc-14 g++-14 libstdc++-13-dev libgmp-dev ccache libmpfr-dev libmpc-dev ninja-build e2fsprogs qemu-utils qemu-system-i386 wabt
```

### Force usage of GCC 13
Copy link
Member

Choose a reason for hiding this comment

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

GCC 14

Copy link
Member

Choose a reason for hiding this comment

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

You also need to update

  • "brew install gcc@13" in BuildInstructionsMacOS.md
  • "a suitable C++ compiler (g++ >= 13, clang >= 14, Apple Clang >= 14.3) via the CMAKE_CXX_COMPILER and" in BuildInstructionsLadybird.md
  • "Toolchain/Local/x86_64/x86_64-pc-serenity/include/c++/13.1.0" in QtCreatorConfiguration.md
  • "If you have Xcode version 14.2 or older, also install a newer host compiler from homebrew. Xcode 14.3 is known to work." in BuildInstructionsMacOS.md
  • "Xcode 14 versions before 14.3 might crash while building ladybird. Xcode 14.3 or clang from homebrew may be required to successfully build ladybird." in BuildInstructionsLadybird.md

Comment on lines +23 to +25
class MACAddress;
template<>
struct Traits<MACAddress>;
Copy link
Member

Choose a reason for hiding this comment

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

These forward declarations seem unrelated.
I think you meant to add them in the next commit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👀 pr-needs-review PR needs review from a maintainer or community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants